Explorar el Código

修复登录后台再刷新无菜单会无限循环查询的问题

zhontai hace 2 años
padre
commit
382f242e1d
Se han modificado 2 ficheros con 9 adiciones y 3 borrados
  1. 1 1
      src/layout/navBars/tagsView/tagsView.vue
  2. 8 2
      src/router/index.ts

+ 1 - 1
src/layout/navBars/tagsView/tagsView.vue

@@ -537,7 +537,7 @@ onBeforeMount(() => {
   // 监听布局配置开启 TagsView 共用,为了演示还原默认值
   mittBus.on('openShareTagsView', () => {
     if (getThemeConfig.value.isShareTagsView) {
-      router.push('/platform/workbench')
+      router.push('/')
       state.tagsViewList = []
       state.tagsViewRoutesList.map((v: RouteItem) => {
         if (v.meta?.isAffix && !v.meta.isHide) {

+ 8 - 2
src/router/index.ts

@@ -12,6 +12,7 @@ import { staticRoutes, notFoundAndNoPower } from '/@/router/route'
 import { initFrontEndControlRoutes } from '/@/router/frontEnd'
 import { initBackEndControlRoutes } from '/@/router/backEnd'
 import { adminTokenKey } from '/@/api/admin/http-client'
+import { ElMessage } from 'element-plus'
 
 /**
  * 1、前端控制路由时:isRequestRoutes 为 false,需要写 roles,需要走 setFilterRoute 方法。
@@ -107,7 +108,7 @@ router.beforeEach(async (to, from, next) => {
       Session.clear()
       NProgress.done()
     } else if (token && to.path === '/login') {
-      next('/platform/workbench')
+      next('/')
       NProgress.done()
     } else {
       const storesRoute = useRoute(pinia)
@@ -117,7 +118,12 @@ router.beforeEach(async (to, from, next) => {
       if (routesList.value.length === 0) {
         if (isRequestRoutes) {
           // 后端控制路由:路由数据初始化,防止刷新时丢失
-          await initBackEndControlRoutes()
+          const isNoPower = await initBackEndControlRoutes()
+          if (isNoPower) {
+            ElMessage.warning('抱歉,您没有分配权限,请联系管理员')
+            Local.remove(adminTokenKey)
+            Session.clear()
+          }
           // 解决刷新时,一直跳 404 页面问题,关联问题 No match found for location with path 'xxx'
           // to.query 防止页面刷新时,普通路由带参数时,参数丢失。动态路由(xxx/:id/:name")isDynamic 无需处理
           next({ path: to.path, query: to.query })