doum
2026-03-06 34fe52caba63e6a6337cb9c3e6bd0d4707fd6a99
admin/src/main.js
@@ -15,6 +15,7 @@
import preventReClick from '@/directives/directive'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
Vue.component('treeselect', Treeselect)
Vue.use(preventReClick)
@@ -29,6 +30,7 @@
Vue.use(directives)
Vue.use(filters)
Vue.use(plugins)
new Vue({
  data: {
    loading: false
@@ -36,7 +38,7 @@
  router,
  store,
  computed: {
    ...mapState(['userInfo', 'homePage','topMenuCurrent','menuData'])
    ...mapState(['userInfo', 'homePage', 'topMenuCurrent', 'menuData'])
  },
  watch: {
    async userInfo () {
@@ -44,10 +46,16 @@
        return
      }
      await this.initRoutes()
    },
    async topMenuCurrent () {
      if (this.topMenuCurrent == null) {
        return
      }
      await this.chagneRoutes()
    }
  },
  methods: {
    ...mapMutations(['switchCollapseMenu', 'setHomePage', 'setTopMenuCurrent', 'setTopMenuCurrent']),
    ...mapMutations(['switchCollapseMenu', 'setCurrentIndex', 'setHomePage', 'setTopMenuCurrent', 'setTopMenuCurrent', 'cleartagsview']),
    // 初始化本地配置
    initLocalConfig () {
      // 菜单状态配置
@@ -78,12 +86,23 @@
          })
          storeTopMenus.push.apply(storeTopMenus, topList)
          var topCurrent = null
          var tlist = []
          topList.forEach(item => {
            if (item.linkType === 0 && topCurrent == null) {
              topCurrent = item
            if (item.linkType === 0) {
              if (topCurrent == null) {
                topCurrent = item
              }
              tlist.push(...item.children)
            }
          })
          this.setTopMenuCurrent(topCurrent)
          if (this.$route.query && this.$route.query.menuparams) {
            const menu = topList.filter(item => item.params === this.$route.query.menuparams)
            this.setTopMenuCurrent(menu[0])
            this.setCurrentIndex(topList.findIndex(obj => obj.params === this.$route.query.menuparams))
          } else {
            this.setTopMenuCurrent(topCurrent)
            this.setCurrentIndex(0)
          }
          // console.log(topList)
          // var menus = []
          // topList.forEach(item => {
@@ -95,7 +114,7 @@
          console.log('menus', this.menuData.list)
          storeMenus.push.apply(storeMenus, this.menuData.list)
          // 添加路由
          this.__addRouters(storeMenus)
          this.__addRouters(tlist)
          // 404
          router.addRoute({
            path: '*',
@@ -108,7 +127,9 @@
            redirect: this.homePage.url
          })
          // 路由加载完成后,如果访问的是/,跳转至动态识别的首页
          if (this.$route.path === '/') {
          if (this.$route.query && this.$route.query.menuparams) {
            this.$router.push(topList.filter(item => item.params === this.$route.query.menuparams)[0].homeUrl)
          } else if (this.$route.path === '/') {
            this.$router.push(this.homePage.url)
          }
        })
@@ -119,6 +140,16 @@
          this.loading = false
        })
    },
    async chagneRoutes () {
      // 重置菜单
      this.cleartagsview('/index')
      console.log('menus', this.menuData.list)
      // 添加路由
      // this.__addRouters(this.menuData.list)
      if (this.topMenuCurrent.homeUrl) {
        await this.$router.push({ path: this.topMenuCurrent.homeUrl, query: {} })
      }
    },
    // 新建路由
    __addRouters (routes, parents = []) {
      if (routes == null || routes.length === 0) {