doum
2026-03-06 9ed63131e87df9fc45c35f445a24506ae662d23c
admin/src/main.js
@@ -79,66 +79,66 @@
        this.setHomePage(storeMenus[0])
      }
      await fetchMenuTree()
        .then(allmenus => {
          // 添加菜单
          var topList = allmenus.filter(item => {
            return item.type === 1
          })
          storeTopMenus.push.apply(storeTopMenus, topList)
          var topCurrent = null
          var tlist =[]
          topList.forEach(item => {
            if (item.linkType === 0 ) {
              if (topCurrent == null) {
                topCurrent = item
          .then(allmenus => {
            // 添加菜单
            var topList = allmenus.filter(item => {
              return item.type === 1
            })
            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)
              }
              tlist.push(...item.children)
            })
            if (this.$route.query && this.$route.query.menuparams) {
              let 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 => {
            //   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(tlist)
            // 404
            router.addRoute({
              path: '*',
              redirect: '/not-found'
            })
            // 首页
            router.addRoute({
              name: 'index',
              path: '/',
              redirect: this.homePage.url
            })
            // 路由加载完成后,如果访问的是/,跳转至动态识别的首页
            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)
            }
          })
          if (this.$route.query && this.$route.query.menuparams) {
            let 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 => {
          //   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(tlist)
          // 404
          router.addRoute({
            path: '*',
            redirect: '/not-found'
          .catch(e => {
            throw e
          })
          // 首页
          router.addRoute({
            name: 'index',
            path: '/',
            redirect: this.homePage.url
          .finally(() => {
            this.loading = false
          })
          // 路由加载完成后,如果访问的是/,跳转至动态识别的首页
          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)
          }
        })
        .catch(e => {
          throw e
        })
        .finally(() => {
          this.loading = false
        })
    },
    async chagneRoutes () {
      // 重置菜单
@@ -188,7 +188,7 @@
      return
    }
    await this.initRoutes()
      .catch(() => {})
        .catch(() => {})
  },
  mounted () {
    this.initLocalConfig()