update
This commit is contained in:
@@ -1,9 +1,47 @@
|
||||
import {defineStore} from "pinia";
|
||||
import {ref} from "vue";
|
||||
import mockRoutes from './mock.js';
|
||||
import router from "../../router/index.js";
|
||||
import generateRouter from "../../router/generateRouter.js";
|
||||
|
||||
export const useSystemStore = defineStore("SystemStore", () => {
|
||||
const isRoot = ref(false);
|
||||
const RoutesTemp = ref([]);
|
||||
|
||||
const installRoute = async () => {
|
||||
const routes = generateRouter(RoutesTemp.value);
|
||||
router.removeRoute('home');
|
||||
router.addRoute({
|
||||
path: '/home',
|
||||
name: 'home',
|
||||
component: () => import('../../pages/layout/index.vue'),
|
||||
redirect: `/home/${routes[0].path}`,
|
||||
children: routes
|
||||
});
|
||||
await router.replace(router.currentRoute.value.fullPath);
|
||||
}
|
||||
|
||||
const setRouter = async () => {
|
||||
RoutesTemp.value.length = 0;
|
||||
// 请求资源 mockRoutes
|
||||
const routes = generateRouter(mockRoutes);
|
||||
RoutesTemp.value.push(...mockRoutes);
|
||||
await installRoute();
|
||||
}
|
||||
|
||||
return {
|
||||
isRoot
|
||||
isRoot,
|
||||
RoutesTemp,
|
||||
setRouter,
|
||||
installRoute,
|
||||
}
|
||||
}, {
|
||||
persist: {
|
||||
key: 'SystemStore',
|
||||
storage: localStorage,
|
||||
afterHydrate: (val) => {
|
||||
val.store.installRoute && val.store.installRoute();
|
||||
},
|
||||
pick: ['RoutesTemp']
|
||||
}
|
||||
});
|
||||
|
||||
27
src/pinia/SystemStore/mock.js
Normal file
27
src/pinia/SystemStore/mock.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const mockRoutes = [
|
||||
{
|
||||
path: 'task-center',
|
||||
name: 'task-center',
|
||||
title: '任务中心',
|
||||
icon: '',
|
||||
component: 'task-center',
|
||||
children: [
|
||||
{
|
||||
path: 'reward-mission',
|
||||
name: 'reward-mission',
|
||||
title: '悬赏任务',
|
||||
icon: '',
|
||||
component: 'reward-mission',
|
||||
},
|
||||
{
|
||||
path: 'appointed-task',
|
||||
name: 'appointed-task',
|
||||
title: '任务指派',
|
||||
icon: '',
|
||||
component: 'appointed-task',
|
||||
}
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
export default mockRoutes;
|
||||
Reference in New Issue
Block a user