mirror of
				https://github.com/pure-admin/vue-pure-admin.git
				synced 2025-11-03 13:44:47 +08:00 
			
		
		
		
	fix: fix some bug
This commit is contained in:
		
							parent
							
								
									0a332731a4
								
							
						
					
					
						commit
						ef2aa27a87
					
				@ -35,8 +35,6 @@ export const constantRoutesArr = ascending(constantRoutes).concat(
 | 
				
			|||||||
  ...remainingRouter
 | 
					  ...remainingRouter
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const isLogin = storageSession.getItem("info");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const router = createRouter({
 | 
					const router = createRouter({
 | 
				
			||||||
  history: createWebHashHistory(),
 | 
					  history: createWebHashHistory(),
 | 
				
			||||||
  routes: ascending(constantRoutes).concat(...remainingRouter),
 | 
					  routes: ascending(constantRoutes).concat(...remainingRouter),
 | 
				
			||||||
@ -61,14 +59,15 @@ const whiteList = ["/login", "/register"];
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
router.beforeEach((to, _from, next) => {
 | 
					router.beforeEach((to, _from, next) => {
 | 
				
			||||||
  // _from?.name;
 | 
					  // _from?.name;
 | 
				
			||||||
  if (isLogin) {
 | 
					  let name = storageSession.getItem("info");
 | 
				
			||||||
 | 
					  if (name) {
 | 
				
			||||||
    usePermissionStoreHook().changeSetting();
 | 
					    usePermissionStoreHook().changeSetting();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  NProgress.start();
 | 
					  NProgress.start();
 | 
				
			||||||
  const { t } = i18n.global;
 | 
					  const { t } = i18n.global;
 | 
				
			||||||
  // @ts-ignore
 | 
					  // @ts-ignore
 | 
				
			||||||
  to.meta.title ? (document.title = t(to.meta.title)) : ""; // 动态title
 | 
					  to.meta.title ? (document.title = t(to.meta.title)) : ""; // 动态title
 | 
				
			||||||
  whiteList.indexOf(to.path) !== -1 || isLogin ? next() : next("/login"); // 全部重定向到登录页
 | 
					  whiteList.indexOf(to.path) !== -1 || name ? next() : next("/login"); // 全部重定向到登录页
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
router.afterEach(() => {
 | 
					router.afterEach(() => {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,11 +1,12 @@
 | 
				
			|||||||
import { defineStore } from "pinia";
 | 
					import { defineStore } from "pinia";
 | 
				
			||||||
import { store } from "/@/store";
 | 
					import { store } from "/@/store";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { constantRoutesArr, ascending, isLogin } from "/@/router/index";
 | 
					import { constantRoutesArr, ascending } from "/@/router/index";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { getAsyncRoutes } from "/@/api/routes";
 | 
					import { getAsyncRoutes } from "/@/api/routes";
 | 
				
			||||||
import Layout from "/@/layout/index.vue";
 | 
					import Layout from "/@/layout/index.vue";
 | 
				
			||||||
import router from "/@/router/index";
 | 
					import router from "/@/router/index";
 | 
				
			||||||
 | 
					import { storageSession } from "/@/utils/storage";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// https://cn.vitejs.dev/guide/features.html#glob-import
 | 
					// https://cn.vitejs.dev/guide/features.html#glob-import
 | 
				
			||||||
const modulesRoutes = import.meta.glob("/src/views/*/*/*.vue");
 | 
					const modulesRoutes = import.meta.glob("/src/views/*/*/*.vue");
 | 
				
			||||||
@ -41,8 +42,8 @@ export const usePermissionStore = defineStore({
 | 
				
			|||||||
      this.asyncRoutes.push(routes);
 | 
					      this.asyncRoutes.push(routes);
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    async changeSetting() {
 | 
					    async changeSetting() {
 | 
				
			||||||
      // 异步路由
 | 
					      let name = storageSession.getItem("info")?.username;
 | 
				
			||||||
      await getAsyncRoutes({ name: isLogin.username }).then(({ info }) => {
 | 
					      await getAsyncRoutes({ name }).then(({ info }) => {
 | 
				
			||||||
        if (info.length === 0) {
 | 
					        if (info.length === 0) {
 | 
				
			||||||
          this.wholeRoutes = router.options.routes.filter(
 | 
					          this.wholeRoutes = router.options.routes.filter(
 | 
				
			||||||
            (v) => v.meta.showLink
 | 
					            (v) => v.meta.showLink
 | 
				
			||||||
@ -55,14 +56,16 @@ export const usePermissionStore = defineStore({
 | 
				
			|||||||
            router.options.routes.findIndex(
 | 
					            router.options.routes.findIndex(
 | 
				
			||||||
              (value) => value.path === v.path
 | 
					              (value) => value.path === v.path
 | 
				
			||||||
            ) !== -1
 | 
					            ) !== -1
 | 
				
			||||||
          )
 | 
					          ) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
            // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
 | 
					            // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
 | 
				
			||||||
            router.options.routes.push(v);
 | 
					            router.options.routes.push(v);
 | 
				
			||||||
            // 最终路由进行升序
 | 
					            // 最终路由进行升序
 | 
				
			||||||
            ascending(router.options.routes);
 | 
					            ascending(router.options.routes);
 | 
				
			||||||
            router.addRoute(v.name, v);
 | 
					            router.addRoute(v.name, v);
 | 
				
			||||||
            this.asyncActionRoutes(v);
 | 
					            this.asyncActionRoutes(v);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user