|
|
@@ -5,6 +5,7 @@
|
|
|
* @params alwaysShow: 只有一个子路由时是否总是展示菜单,默认false
|
|
|
*/
|
|
|
import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'
|
|
|
+import store from '@/store'
|
|
|
import NProgress from '@/utils/system/nprogress'
|
|
|
import {changeTitle} from '@/utils/system/title'
|
|
|
|
|
|
@@ -14,16 +15,14 @@ import Dashboard from './modules/dashboard'
|
|
|
import {getUserMenu, IntergrationMenu} from "@/api/settings/menu-settings";
|
|
|
import {createVNode, defineComponent, h} from "vue";
|
|
|
import Layout from "@/layout/index.vue";
|
|
|
+import {userInfoStore} from "@/utils/store-public";
|
|
|
import {stringIsBlank} from "@/utils/blank-utils";
|
|
|
import XEUtils from "xe-utils";
|
|
|
-import {useUserStore} from "@/pinia/user-store";
|
|
|
|
|
|
-const whiteNameRouting = []
|
|
|
|
|
|
function dashboardRouter(data: Array<RouteRecordRaw>) {
|
|
|
data.forEach((item) => {
|
|
|
XEUtils.set(item, "meta.needToken", false)
|
|
|
- whiteNameRouting.push(item.path)
|
|
|
if (item.children && item.children.length > 0) {
|
|
|
dashboardRouter(item.children)
|
|
|
}
|
|
|
@@ -37,7 +36,6 @@ const router = createRouter({
|
|
|
routes: [...Dashboard],
|
|
|
})
|
|
|
|
|
|
-
|
|
|
const vueFile = import.meta.glob('../views/**/*.{vue,tsx}');
|
|
|
vueFile.EmptyRouter = import.meta.glob('../layout/EmptyRouter.vue')['../layout/EmptyRouter.vue']
|
|
|
vueFile.Layout = import.meta.glob('../layout/index.vue')['../layout/index.vue']
|
|
|
@@ -65,10 +63,12 @@ async function beforeAddRoutes() {
|
|
|
function createNameComponent(item) {
|
|
|
return () => {
|
|
|
return new Promise(resolve => {
|
|
|
+
|
|
|
vueFile[`${item.component}`]().then(res => {
|
|
|
const tmp = defineComponent({
|
|
|
name: item.name,
|
|
|
render() {
|
|
|
+ let children = [createVNode(res.default)]
|
|
|
const style = {
|
|
|
height: '100%',
|
|
|
width: '100%',
|
|
|
@@ -80,10 +80,17 @@ function createNameComponent(item) {
|
|
|
props.class = 'cy_card'
|
|
|
}
|
|
|
if (item.mainOverflowAuto) {
|
|
|
- style.overflow = "auto";
|
|
|
+ children = [
|
|
|
+ h('div', {
|
|
|
+ style: {
|
|
|
+ height: '100%',
|
|
|
+ width: '100%',
|
|
|
+ overflow: 'auto'
|
|
|
+ }
|
|
|
+ }, [createVNode(res.default)])
|
|
|
+ ]
|
|
|
}
|
|
|
-
|
|
|
- return h('div', props, [createVNode(res.default)]);
|
|
|
+ return h('div', props, children);
|
|
|
}
|
|
|
})
|
|
|
resolve(tmp)
|
|
|
@@ -127,19 +134,16 @@ router.beforeEach(async (to, _from, next) => {
|
|
|
|
|
|
function tmpNext(...arg) {
|
|
|
to.meta.title && changeTitle(to.meta.title)
|
|
|
- if (to.meta.needToken && stringIsBlank(useUserStore().getToken)) {
|
|
|
+ if (to.meta.needToken && stringIsBlank(userInfoStore.value.token)) {
|
|
|
next('/login')
|
|
|
return
|
|
|
}
|
|
|
next(...arg);
|
|
|
}
|
|
|
|
|
|
- for (let i = 0; i < whiteNameRouting.length; i++) {
|
|
|
- const tmp: string = whiteNameRouting[i]
|
|
|
- if (tmp.startsWith(to.path)) {
|
|
|
- tmpNext()
|
|
|
- return
|
|
|
- }
|
|
|
+ if (XEUtils.has(to, 'meta.needToken') && !to.meta.needToken) {
|
|
|
+ tmpNext()
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
if (!asyncFinished) {
|
|
|
@@ -153,6 +157,11 @@ router.beforeEach(async (to, _from, next) => {
|
|
|
)
|
|
|
|
|
|
router.afterEach((to, _from) => {
|
|
|
+ const keepAliveComponentsName = store.getters['keepAlive/keepAliveComponentsName'] || []
|
|
|
+ const name = to.matched[to.matched.length - 1].components.default.name
|
|
|
+ if (to.meta && to.meta.cache && name && !keepAliveComponentsName.includes(name)) {
|
|
|
+ store.commit('keepAlive/addKeepAliveComponentsName', name)
|
|
|
+ }
|
|
|
NProgress.done()
|
|
|
})
|
|
|
|