|
@@ -1,38 +1,53 @@
|
|
|
import { defineStore, acceptHMRUpdate } from "pinia";
|
|
|
-import { RouteRecordRaw } from "vue-router";
|
|
|
-export const useStore = defineStore({
|
|
|
- id: "storeInfo",
|
|
|
+
|
|
|
+export const useStore = defineStore<
|
|
|
+ string,
|
|
|
+ SotreState,
|
|
|
+ SoreGetters,
|
|
|
+ SotreActions
|
|
|
+>("storeInfo", {
|
|
|
state: () => ({
|
|
|
- userInfo: { id: '' }, // 当前的用户信息
|
|
|
+ userInfo: {}, // 当前的用户信息
|
|
|
routers: [], // 返回的所有路由
|
|
|
asyncRoutesMark: false, // 是否添加过路由
|
|
|
}),
|
|
|
getters: {
|
|
|
- getRoutersList(): RouteRecordRaw[] { // 取值
|
|
|
+ getRoutersList() {
|
|
|
+ // 取值
|
|
|
return this.routers;
|
|
|
},
|
|
|
- getToken(): string {
|
|
|
- return this.userInfo?.id || ''
|
|
|
- }
|
|
|
+ getToken() {
|
|
|
+ return this.userInfo?.id || "";
|
|
|
+ },
|
|
|
},
|
|
|
actions: {
|
|
|
// 方法
|
|
|
- setRouters(arr: any) {
|
|
|
+ setRouters(arr) {
|
|
|
this.routers = arr;
|
|
|
},
|
|
|
- setAsyncRoutesMark(val: boolean) {
|
|
|
+ setAsyncRoutesMark(val) {
|
|
|
this.asyncRoutesMark = val;
|
|
|
},
|
|
|
- setValue(val: any, key: 'userInfo' | 'routers' | 'asyncRoutesMark') {
|
|
|
+ setValue(val, key) {
|
|
|
this[key] = val;
|
|
|
},
|
|
|
+ getPathConfig(path: string) {
|
|
|
+ return this.routers.find((item) => item.path === path);
|
|
|
+ },
|
|
|
+ getFunctionList(path: string) {
|
|
|
+ const config = this.getPathConfig(path);
|
|
|
+ if (!config) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ return config.functionList || [];
|
|
|
+ },
|
|
|
clearStore() {
|
|
|
localStorage.clear();
|
|
|
sessionStorage.clear();
|
|
|
- this.userInfo = { id: '' };
|
|
|
+ this.userInfo = {};
|
|
|
this.routers = [];
|
|
|
this.asyncRoutesMark = false;
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
persist: true, // 是否持久化
|
|
|
});
|