From eafc031e3e6e48778d22b5455358273714944012 Mon Sep 17 00:00:00 2001
From: Your Name <123456>
Date: 星期一, 05 九月 2022 09:53:16 +0800
Subject: [PATCH] Merge branch 'master' of https://sinanoaq.cn:8888/r/gtqt
---
src/router/index.ts | 139 +++++++++++++++++++++++-----------------------
1 files changed, 70 insertions(+), 69 deletions(-)
diff --git a/src/router/index.ts b/src/router/index.ts
index c789ab0..11ec534 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -10,8 +10,8 @@
import { staticRoutes } from '/@/router/route';
import { initFrontEndControlRoutes } from '/@/router/frontEnd';
import { initBackEndControlRoutes } from '/@/router/backEnd';
-
-
+import { useUserInfo } from '/@/stores/userInfo';
+import { nextTick } from 'vue';
// 读取 `/src/stores/themeConfig.ts` 是否开启后端控制路由配置
const storesThemeConfig = useThemeConfig(pinia);
@@ -19,89 +19,90 @@
const { isRequestRoutes } = themeConfig.value;
if (isRequestRoutes) staticRoutes.splice(0, 1);
-
export const router = createRouter({
- history: createWebHashHistory(),
- routes: staticRoutes,
+ history: createWebHashHistory(),
+ routes: staticRoutes
});
-
export function formatFlatteningRoutes(arr: any) {
- if (arr.length <= 0) return false;
- for (let i = 0; i < arr.length; i++) {
- if (arr[i].children) {
- arr = arr.slice(0, i + 1).concat(arr[i].children, arr.slice(i + 1));
- }
- }
- return arr;
+ if (arr.length <= 0) return false;
+ for (let i = 0; i < arr.length; i++) {
+ if (arr[i].children) {
+ arr = arr.slice(0, i + 1).concat(arr[i].children, arr.slice(i + 1));
+ }
+ }
+ return arr;
}
-
export function formatTwoStageRoutes(arr: any) {
- if (arr.length <= 0) return false;
- const newArr: any = [];
- const cacheList: Array<string> = [];
- arr.forEach((v: any) => {
- if (v.path === '/') {
- newArr.push({ component: v.component, name: v.name, path: v.path, redirect: v.redirect, meta: v.meta, children: [] });
- } else {
- // 判断是否是动态路由(xx/:id/:name),用于 tagsView 等中使用
- // 修复:https://gitee.com/lyt-top/vue-next-admin/issues/I3YX6G
- if (v.path.indexOf('/:') > -1) {
- v.meta['isDynamic'] = true;
- v.meta['isDynamicPath'] = v.path;
- }
- newArr[0].children.push({ ...v });
- // 存 name 值,keep-alive 中 include 使用,实现路由的缓存
- // 路径:/@/layout/routerView/parent.vue
- if (newArr[0].meta.isKeepAlive && v.meta.isKeepAlive) {
- cacheList.push(v.name);
- const stores = useKeepALiveNames(pinia);
- stores.setCacheKeepAlive(cacheList);
- }
- }
- });
- return newArr;
+ if (arr.length <= 0) return false;
+ const newArr: any = [];
+ const cacheList: Array<string> = [];
+ arr.forEach((v: any) => {
+ if (v.path === '/') {
+ newArr.push({ component: v.component, name: v.name, path: v.path, redirect: v.redirect, meta: v.meta, children: [] });
+ } else {
+ // 判断是否是动态路由(xx/:id/:name),用于 tagsView 等中使用
+ // 修复:https://gitee.com/lyt-top/vue-next-admin/issues/I3YX6G
+ if (v.path.indexOf('/:') > -1) {
+ v.meta['isDynamic'] = true;
+ v.meta['isDynamicPath'] = v.path;
+ }
+ newArr[0].children.push({ ...v });
+ // 存 name 值,keep-alive 中 include 使用,实现路由的缓存
+ // 路径:/@/layout/routerView/parent.vue
+ if (newArr[0].meta.isKeepAlive && v.meta.isKeepAlive) {
+ cacheList.push(v.name);
+ const stores = useKeepALiveNames(pinia);
+ stores.setCacheKeepAlive(cacheList);
+ }
+ }
+ });
+ return newArr;
}
-// isRequestRoutes 为 true,则开启后端控制路由,路径:`/src/stores/themeConfig.ts`
-if (!isRequestRoutes) initFrontEndControlRoutes();
+// // isRequestRoutes 为 true,则开启后端控制路由,路径:`/src/stores/themeConfig.ts`
+// if (!isRequestRoutes) initFrontEndControlRoutes();
// 路由加载前
router.beforeEach(async (to, from, next) => {
- NProgress.configure({ showSpinner: false });
- if (to.meta.title) NProgress.start();
- const token = Session.get('token');
- if (to.path === '/login' && !token) {
- next();
- NProgress.done();
- } else {
- if (!token) {
- next(`/login?redirect=${to.path}¶ms=${JSON.stringify(to.query ? to.query : to.params)}`);
- Session.clear();
- NProgress.done();
- } else if (token && to.path === '/login') {
- next('/home');
- NProgress.done();
- } else {
- const storesRoutesList = useRoutesList(pinia);
- const { routesList } = storeToRefs(storesRoutesList);
- if (routesList.value.length === 0) {
- // 后端控制路由:路由数据初始化,防止刷新时丢失
- await initBackEndControlRoutes();
- // 动态添加路由:防止非首页刷新时跳转回首页的问题
- // 确保 addRoute() 时动态添加的路由已经被完全加载上去
- next({ ...to, replace: true });
- } else {
- next();
- }
- }
- }
+ if (to.path === '/intelligentLine') {
+ next();
+ } else {
+ NProgress.configure({ showSpinner: false });
+ if (to.meta.title) NProgress.start();
+ const token = Session.get('token');
+ if (to.path === '/login' && !token) {
+ next();
+ NProgress.done();
+ } else {
+ if (!token) {
+ next(`/login?redirect=${to.path}¶ms=${JSON.stringify(to.query ? to.query : to.params)}`);
+ Session.clear();
+ NProgress.done();
+ } else if (token && to.path === '/login') {
+ next('/homeMenu');
+ NProgress.done();
+ } else {
+ const storesRoutesList = useRoutesList(pinia);
+ const { routesList } = storeToRefs(storesRoutesList);
+ if (routesList.value.length === 0) {
+ // 后端控制路由:路由数据初始化,防止刷新时丢失
+ await initBackEndControlRoutes();
+ // 动态添加路由:防止非首页刷新时跳转回首页的问题
+ // 确保 addRoute() 时动态添加的路由已经被完全加载上去
+ next({ ...to, replace: true });
+ } else {
+ next();
+ }
+ }
+ }
+ }
});
// 路由加载后
router.afterEach(() => {
- NProgress.done();
+ NProgress.done();
});
// 导出路由
--
Gitblit v1.9.2