소스 검색

字典修改, 包含dicts和users。

jxq 1 주 전
부모
커밋
54cf0c271f
3개의 변경된 파일59개의 추가작업 그리고 60개의 파일을 삭제
  1. 0 14
      src/plugins/permission.ts
  2. 44 44
      src/store/modules/dictionary.ts
  3. 15 2
      src/views/login/index.vue

+ 0 - 14
src/plugins/permission.ts

@@ -31,18 +31,6 @@ export function setupPermission() {
         // next({ path: "/" });
         NProgress.done();
       } else {
-        const dictStore = useDictionaryStore();
-        dictStore.checkAllData();
-        if (
-          !dictStore.dicts.value ||
-          JSON.stringify(dictStore.dicts.value) === "{}"
-        ) {
-          const res = await getUserDicts(dictStore.types);
-          if (res.data) {
-            dictStore.dicts = res?.data ?? [];
-          }
-        }
-
         next();
         NProgress.done();
       }
@@ -50,8 +38,6 @@ export function setupPermission() {
       // 未登录可以访问白名单页面
 
       if (whiteList.indexOf(to.name as string) !== -1) {
-        const dictStore = useDictionaryStore();
-        dictStore.checkAllData();
         next();
       } else {
         if (to.path === "/login") {

+ 44 - 44
src/store/modules/dictionary.ts

@@ -2,55 +2,55 @@ import { store } from "@/store";
 import { defineStore } from "pinia";
 import { getUserList } from "@/api/auth";
 
-export const useDictionaryStore = defineStore("dictionaryStore", () => {
-  const types = [
-    "defect_mana",
-    "stage",
-    "process_state",
-    "outsource_state",
-    "work_order_seq_state",
-    "station_task_state",
-    "accessories_type",
-    "danwei_type",
-    "system_message_type",
-    "plan_work_order_state",
-    "disposal_measures_type",
-    "escalation_fault_state",
-    "excel_type",
-    "device_type",
-    "station_type",
-    "work_order_seq_state",
-  ];
-  const dicts = ref<{ [key: string]: any[] }>({});
+export const useDictionaryStore = defineStore(
+  "dictionaryStore",
+  () => {
+    const types = [
+      "defect_mana",
+      "stage",
+      "process_state",
+      "outsource_state",
+      "work_order_seq_state",
+      "station_task_state",
+      "accessories_type",
+      "danwei_type",
+      "system_message_type",
+      "plan_work_order_state",
+      "disposal_measures_type",
+      "escalation_fault_state",
+      "excel_type",
+      "device_type",
+      "station_type",
+      "work_order_seq_state",
+    ];
+    const dicts = ref<{ [key: string]: any[] }>({});
 
-  // 所有的用户列表
-  const allUsers = ref<any[]>([]);
+    // 所有的用户列表
+    const allUsers = ref<any[]>([]);
 
-  function checkAllData() {
-    if (allUsers.value.length === 0) {
-      getUserList().then((res) => {
-        allUsers.value = res.data || [];
-      });
+    function getLableByValue(type: string, value: string) {
+      const dict = dicts.value[type];
+      if (dict) {
+        const lable = dict.find((item: any) => item.dictValue === value);
+        return lable?.dictLabel;
+      }
+      return "";
     }
-  }
 
-  function getLableByValue(type: string, value: string) {
-    const dict = dicts.value[type];
-    if (dict) {
-      const lable = dict.find((item: any) => item.dictValue === value);
-      return lable?.dictLabel;
-    }
-    return "";
+    return {
+      types,
+      dicts,
+      allUsers,
+      getLableByValue,
+    };
+  },
+  {
+    persist: {
+      storage: localStorage,
+      pick: ["dicts", "allUsers"],
+    },
   }
-
-  return {
-    types,
-    dicts,
-    allUsers,
-    checkAllData,
-    getLableByValue,
-  };
-});
+);
 
 export function useDictionaryStoreHook() {
   // console.log('dicts:',useDictionaryStore(store))

+ 15 - 2
src/views/login/index.vue

@@ -147,11 +147,13 @@
 </template>
 
 <script lang="ts" setup>
-import { useSettingsStore, useUserStore } from "@/store";
+import { useDictionaryStore, useSettingsStore, useUserStore } from "@/store";
 import {
   getCaptchaApi,
   getOrgListApi,
   getProductionList,
+  getUserDicts,
+  getUserList,
   stationListByCode,
 } from "@/api/auth";
 import { LoginData } from "@/api/auth/types";
@@ -298,10 +300,21 @@ function handleLogin() {
       localStorage.setItem("local_stationId", loginData.value.stationId);
       userStore
         .login(showJobNumber.value ? numberP : acountP)
-        .then(() => {
+        .then(async () => {
           userStore.user.station = stationName;
           userStore.user.proCode = loginData.value.proCode;
 
+          // 获取字典
+          const dictStore = useDictionaryStore();
+          let res = await getUserDicts(dictStore.types);
+          if (res?.data) {
+            dictStore.dicts = res?.data ?? {};
+          }
+          const userRes = await getUserList();
+          if (userRes?.data) {
+            dictStore.allUsers = userRes?.data ?? [];
+          }
+
           // 捡选 装配 测试 维修站 预齐套
           if (stationType == "5") {
             router.replace({ name: "PrepareMain" });