App.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div v-cloak id="app">
  3. <router-view />
  4. </div>
  5. </template>
  6. <script>
  7. import { mapGetters } from 'vuex'
  8. export default {
  9. name: 'App',
  10. data() {
  11. return {
  12. code: ''
  13. }
  14. },
  15. computed: {
  16. ...mapGetters(['isSupertube'])
  17. },
  18. async created() {
  19. await this.getMenu()
  20. },
  21. mounted() {
  22. this.jumpToListPageWithDetailPage()
  23. },
  24. methods: {
  25. jumpToListPageWithDetailPage() {
  26. if (!this.isDetailPage() || this.isSupertube) return
  27. const listPageUrl = this.getListPageUrl()
  28. this.$router.push(listPageUrl)
  29. },
  30. isDetailPage() {
  31. const { path } = this.$route
  32. return path && path.indexOf('Detail')
  33. },
  34. getListPageUrl() {
  35. const { path = '' } = this.$route
  36. const [listPageUrl] = path.split('Detail')
  37. return listPageUrl
  38. },
  39. async getMenu() {
  40. this.$store
  41. .dispatch('user/getMenuList', this)
  42. .then(async(res) => {
  43. console.log(res)
  44. if (res === 'noToken') {
  45. await this.logout()
  46. } else{
  47. if (
  48. this.$route.path === '/' ||
  49. this.$route.path === '/login' ||
  50. this.$route.path === '/loadingPage'
  51. ) {
  52. await window.vm.$router.replace('/welcome')
  53. }
  54. }
  55. })
  56. .catch((_err) => { this.logout() })
  57. },
  58. async logout() {
  59. if (this.$route.path !== '/login' && this.$route.path !== '/accept') {
  60. await this.$store.dispatch('user/logout')
  61. await this.$router.push(`/login`)
  62. }
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss">
  68. @import "./assets/css/index.scss";
  69. // 因为element-ui的confim组件并不是vue生成的不具有[data-v....],所以全局注入一个class
  70. // .lzx_BtnErr{
  71. // background: #f56c6c !important;
  72. // color: #fff !important;
  73. // }
  74. </style>