Quellcode durchsuchen

提交store类型

hlp vor 1 Jahr
Ursprung
Commit
02c5f8eb8d

+ 17 - 0
fhKeeper/formulahousekeeper/customerBuler-crm/src/store/Store.d.ts

@@ -0,0 +1,17 @@
+type SotreState = {
+  userInfo: any;
+  routers: RouteRecordRaw[];
+  asyncRoutesMark: boolean;
+};
+type SoreGetters = {
+  getRoutersList: () => RouteRecordRaw[];
+  getToken: () => string;
+};
+type SotreActions = {
+  setRouters(arr: any): void;
+  setAsyncRoutesMark(val: boolean): void;
+  setValue(val: any, key: keyof SotreState): void;
+  getPathConfig(path: string): RouteRecordRaw | any;
+  getFunctionList(path: string): any[];
+  clearStore(): void;
+};

+ 28 - 13
fhKeeper/formulahousekeeper/customerBuler-crm/src/store/index.ts

@@ -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, // 是否持久化
 });