天宫框架更新,导致打开的界面,找不到路由的问题
# 问题
天宫框架更新,导致打开的界面,找不到路由的问题
# 解决方法
# 1,更新框架文件,在'tiangongCore\utils\common\tg.js' 文件中 添加如下safeImport方法
import {isFunction} from './is'
export default {
/**
* 安全引入模块
* @param {string|promise} path 模块地址,如何是动态模块请不要使用@等alias的方式,静态的是promise
* @param {function} [handler] 处理方式
* @param {Array} [modules] 通过import.meta.glob获取到模块集合
* @returns 如果模块不存在返回空,否则返回执行模块
*/
safeImport(path, modules, handler) {
if (!handler || !isFunction(handler)) {
handler = (component) => component.default
}
//path是字符串
if (modules && typeof path === 'string') {
if (modules[path] == undefined) {
// 模块不存在
// tg.msg.error(tm('tg.page.msg.M00459', '系统已经更新,即将刷新页面'));
return;
}
return modules[path]().catch((e) => {
if (e.message.includes('Failed to fetch dynamically imported module')) {
tg.msg.error(tm('tg.page.msg.M00459', '系统已经更新,即将刷新页面'));
setTimeout(() => {
window.location.reload(true); // 强制浏览器刷新页面
}, 3000);
}
}).then(handler);
} else {
return path.catch((e) => {
if (e.message.includes('Failed to fetch dynamically imported module')) {
tg.msg.error(tm('tg.page.msg.M00459', '系统已经更新,即将刷新页面'));
setTimeout(() => {
window.location.reload(true); // 强制浏览器刷新页面
}, 3000);
}
}).then(handler);
}
},
}
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
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
# 2,业务系统自定义的路由修改 router.js的文件
# 自定义的路由如果是固定的
扩展路由如果是固定的路由,需要用tg.safeImport包一下
const routerWhiteList = [
{
path: "/test2",
name: "测试Log",
component: () => tg.safeImport(import("@appTiangong/SysOperLog/SysOperLogList.vue")),
}
]
const routes = []
function setRouteWhiteList() {
return routerWhiteList
}
function setRoutes() {
return routes
}
export default {
setRoutes,
setRouteWhiteList
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 自定义的路由如果是动态的
需要添加方法safeImport的方法,在导入路由的时候,使用saveImport方法
const modules = import.meta.glob("../../web/**/**.vue");
const safeImport = (path, handler) => {
return tg.safeImport(path, modules, handler)
}
const routerWhiteList = [
{
path: "/login",
name: "登录",
component: () =>
safeImport(`../../web${SettingCore.VITE_TG_LOGIN_URL}.vue`),
},
]
const routes = [
]
function setRouteWhiteList() {
return routerWhiteList
}
function setRoutes() {
return routes
}
export default {
setRoutes,
setRouteWhiteList
}
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
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
上次更新: 2024/6/12 16:34:27