菜单动态路由及头部角色切换修改
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import type { App } from 'vue';
|
||||
import { createPinia } from 'pinia';
|
||||
const store = createPinia();
|
||||
// import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||
// store.use(piniaPluginPersistedstate)
|
||||
|
||||
export function setupStore(app: App<Element>) {
|
||||
app.use(store);
|
||||
|
@@ -135,4 +135,6 @@ export const useRouteStore = defineStore({
|
||||
});
|
||||
},
|
||||
},
|
||||
// //开启数据缓存
|
||||
// persist:true,
|
||||
});
|
||||
|
@@ -266,18 +266,18 @@
|
||||
resizeButtom() {
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.tags !== undefined) {
|
||||
const clientWidth = (this.$refs.tags as HTMLElement).clientWidth;
|
||||
if (this.currentPage === 0) {
|
||||
this.isdisabledl = this.tagList.length * 100 > clientWidth;
|
||||
} else {
|
||||
this.isdisabledl =
|
||||
(this.tagList.length - this.number * this.currentPage) * 100 > clientWidth;
|
||||
if (this.tagList.length * 100 < clientWidth) {
|
||||
(this.$refs.tags as HTMLElement).style.cssText = `transform: translateX(${0}px)`;
|
||||
this.isdisabledr = false;
|
||||
this.currentPage = 0;
|
||||
const clientWidth = (this.$refs.tags as HTMLElement).clientWidth;
|
||||
if (this.currentPage === 0) {
|
||||
this.isdisabledl = this.tagList.length * 100 > clientWidth;
|
||||
} else {
|
||||
this.isdisabledl =
|
||||
(this.tagList.length - this.number * this.currentPage) * 100 > clientWidth;
|
||||
if (this.tagList.length * 100 < clientWidth) {
|
||||
(this.$refs.tags as HTMLElement).style.cssText = `transform: translateX(${0}px)`;
|
||||
this.isdisabledr = false;
|
||||
this.currentPage = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@@ -79,6 +79,7 @@
|
||||
import { Cookies } from '/nerv-lib/util/cookie';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { NsMessage } from '/nerv-lib/component';
|
||||
import { replyDynamRoutesPath } from '/nerv-lib/util/dynamicRoutesss';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'UserLogin',
|
||||
@@ -194,12 +195,22 @@
|
||||
name: initRouterList.length === 0 ? 'error403' : res.data[0]['code'],
|
||||
});
|
||||
} else {
|
||||
router.replace({ name: 'root' });
|
||||
const sessionStoreRoute = sessionStorage.getItem("dynamicRouteList");
|
||||
let getDynamicRouteList = sessionStoreRoute?JSON.parse(sessionStoreRoute):[];
|
||||
if(getDynamicRouteList && getDynamicRouteList.lenght>0){
|
||||
let addDynamicRoutes = replyDynamRoutesPath(getDynamicRouteList);
|
||||
addDynamicRoutes.forEach(item => {
|
||||
if (item.children && !item.component) {
|
||||
item.component = () => import('/nerv-lib/saas/view/system/application.vue');//hx-ai-intelligent项目下的首页
|
||||
}
|
||||
router.addRoute(item);
|
||||
});
|
||||
}
|
||||
router.replace({ name: 'home' });
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
25
lib/util/dynamicRoutesss.ts
Normal file
25
lib/util/dynamicRoutesss.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
//处理路由compontent路径
|
||||
export const replyDynamRoutesPath = (data:any) => {
|
||||
return data.map(item => {
|
||||
if(item.children && item.children.length > 0){
|
||||
item.children.map(itemChild => {
|
||||
if(itemChild.component){
|
||||
const modulePath0 = itemChild.component;
|
||||
itemChild.component = () => new Function(`return import('/nerv-lib/saas/view/${modulePath0}')`)();
|
||||
if(itemChild.children && itemChild.children.length > 0){
|
||||
itemChild.children.map(itemChildChild => {
|
||||
if(itemChildChild.component){
|
||||
const modulePath1 = itemChildChild.component;
|
||||
itemChildChild.component = () => new Function(`return import('/@/view/${modulePath1}')`)();
|
||||
}
|
||||
})
|
||||
}else{
|
||||
itemChild.component = () => new Function(`return import('/@/view/${modulePath0}')`)();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
return item;
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user