MrShi
2 天以前 39fc2d6754953e41a7334a2166347baacfcfb40a
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)
@@ -37,7 +38,7 @@
  router,
  store,
  computed: {
    ...mapState(['userInfo', 'homePage'])
    ...mapState(['userInfo', 'homePage','topMenuCurrent','menuData'])
  },
  watch: {
    async userInfo () {
@@ -45,10 +46,16 @@
        return
      }
      await this.initRoutes()
    },
    async topMenuCurrent () {
      if (this.topMenuCurrent == null) {
        return
      }
      await this.chagneRoutes()
    }
  },
  methods: {
    ...mapMutations(['switchCollapseMenu', 'setHomePage']),
    ...mapMutations(['switchCollapseMenu', 'setHomePage', 'setTopMenuCurrent', 'setTopMenuCurrent','cleartagsview']),
    // 初始化本地配置
    initLocalConfig () {
      // 菜单状态配置
@@ -74,17 +81,33 @@
      await fetchMenuTree()
        .then(allmenus => {
          // 添加菜单
          var menus = allmenus.filter(item => {
            return item.type !== 1
          })
          var topList = allmenus.filter(item => {
            return item.type === 1
          })
          console.log(topList)
          storeMenus.push.apply(storeMenus, menus)
          storeTopMenus.push.apply(storeTopMenus, topList)
          var topCurrent = null
          var tlist =[]
          topList.forEach(item => {
            if (item.linkType === 0 ) {
              if (topCurrent == null) {
                topCurrent = item
              }
              tlist.push(...item.children)
            }
          })
          this.setTopMenuCurrent(topCurrent)
          // console.log(topList)
          // var menus = []
          // topList.forEach(item => {
          //   console.log(topCurrent.id, item.id)
          //   if (item.id == this.topMenuCurrent.id) {
          //     menus = item.children
          //   }
          // })
          console.log('menus', this.menuData.list)
          storeMenus.push.apply(storeMenus, this.menuData.list)
          // 添加路由
          this.__addRouters(storeMenus)
          this.__addRouters(tlist)
          // 404
          router.addRoute({
            path: '*',
@@ -108,6 +131,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) {