index.ts
2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import type { AppRouteRecordRaw, AppRouteModule } from '/@/router/types';
import { PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '/@/router/routes/basic';
import { mainOutRoutes } from './mainOut';
import { PageEnum } from '/@/enums/pageEnum';
import { t } from '/@/hooks/web/useI18n';
import { LAYOUT } from '../constant';
import { getMenuList } from '/@/api/sys/menu';
import { router } from '/@/router';
const modules = import.meta.globEager('./modules/**/*.ts');
const routeModuleList: AppRouteModule[] = [];
Object.keys(modules).forEach((key) => {
const mod = modules[key].default || {};
const modList = Array.isArray(mod) ? [...mod] : [mod];
routeModuleList.push(...modList);
});
let pushPath = '';
let pushSubPath = '';
async function hashChangeFunc() {
const getMenuListData1 = window.localStorage.getItem('menuListStorage') || (await getMenuList());
const getMenuListData = JSON.parse(getMenuListData1);
const getHomePage = getMenuListData.find((f) => {
return f.path == '/dashboard/workbench';
});
if (getHomePage?.path == '/dashboard/workbench') {
setTimeout(() => {
router.push('/dashboard/workbench');
}, 200);
} else {
const routeF = getMenuListData[0]?.children[0]?.path || getMenuListData[0].path;
pushPath = routeF;
pushSubPath = pushPath.substring(1);
}
}
hashChangeFunc();
window.onhashchange = (e) => {
console.log(e);
setTimeout(() => {
if (
e.newURL == 'http://localhost:8083/#/' ||
e.newURL == 'http://localhost:8083/#' ||
e.newURL == 'http://localhost:8083/' ||
e.newURL == 'http://localhost:8083'
) {
window.location.href = e.newURL + pushSubPath;
}
}, 1000);
};
export const asyncRoutes = [PAGE_NOT_FOUND_ROUTE, ...routeModuleList];
export const RootRoute: AppRouteRecordRaw = {
path: '/',
name: 'Root',
redirect: PageEnum.BASE_HOME,
meta: {
title: 'Root',
},
};
export const LoginRoute: AppRouteRecordRaw = {
path: '/login',
name: 'Login',
component: () => import('/@/views/sys/login/Login.vue'),
meta: {
title: t('routes.basic.login'),
},
};
// 用户详情静态路由
export const AccountDetail: AppRouteRecordRaw = {
path: '/system',
name: '系统管理',
component: LAYOUT,
meta: {
title: '系统管理',
hideBreadcrumb: true,
hideChildrenInMenu: true,
},
children: [
{
path: 'account_detail/:id',
name: 'Account_Detail',
component: () => import('/@/views/system/account/AccountDetail.vue'),
meta: {
title: '用户详情',
},
},
],
};
// Basic routing without permission
export const basicRoutes = [
LoginRoute,
RootRoute,
AccountDetail,
...mainOutRoutes,
REDIRECT_ROUTE,
PAGE_NOT_FOUND_ROUTE,
];