浏览代码

修改登录。字典登录获取。

jxq 2 周之前
父节点
当前提交
89bc902c3f
共有 3 个文件被更改,包括 60 次插入52 次删除
  1. 0 11
      src/plugins/permission.ts
  2. 51 35
      src/store/modules/dictionary.ts
  3. 9 6
      src/views/login/index.vue

+ 0 - 11
src/plugins/permission.ts

@@ -19,17 +19,6 @@ export function setupPermission() {
         next({ path: "/" });
         NProgress.done();
       } else {
-        const dictStore = useDictionaryStore();
-        if (
-          !dictStore.dicts.value ||
-          JSON.stringify(dictStore.dicts.value) === "{}"
-        ) {
-          const res = await getUserDicts(dictStore.types);
-          if (res.data) {
-            dictStore.dicts = res?.data;
-          }
-        }
-
         const userStore = useUserStore();
         // const hasRoles =
         //   userStore.user.roles && userStore.user.roles.length > 0;

+ 51 - 35
src/store/modules/dictionary.ts

@@ -2,42 +2,58 @@ import { store } from "@/store";
 import { defineStore } from "pinia";
 import { getUserDicts } from "@/api/auth";
 
-export const useDictionaryStore = defineStore("dictionaryStore", () => {
-  const types = [
-    "station_type",
-    "station_operate_type",
-    "applicable_platforms",
-    "material_properties",
-    "quality_testing_plan",
-    "material_level",
-    "packaging_method",
-    "quality_grade",
-    "selection_type",
-    "device_type",
-    "stage",
-    "danwei_type",
-    "process_type",
-    "workshop_section",
-    "skill_requirements",
-    "accessories_type",
-    "trace_type",
-    "skill_type",
-    "drawing_type",
-    "vehicle_level",
-    "fault_current_state",
-    "escalation_fault_state",
-    "defect_mana",
-    "disposal_measures_type",
-    "process_check_result",
-    "excel_states",
-  ];
-  const dicts = ref<{ [key: string]: any[] }>({});
+export const useDictionaryStore = defineStore(
+  "dictionaryStore",
+  () => {
+    const types = [
+      "station_type",
+      "station_operate_type",
+      "applicable_platforms",
+      "material_properties",
+      "quality_testing_plan",
+      "material_level",
+      "packaging_method",
+      "quality_grade",
+      "selection_type",
+      "device_type",
+      "stage",
+      "danwei_type",
+      "process_type",
+      "workshop_section",
+      "skill_requirements",
+      "accessories_type",
+      "trace_type",
+      "skill_type",
+      "drawing_type",
+      "vehicle_level",
+      "fault_current_state",
+      "escalation_fault_state",
+      "defect_mana",
+      "disposal_measures_type",
+      "process_check_result",
+      "excel_states",
+    ];
+    const dicts = ref<{ [key: string]: any[] }>({});
 
-  return {
-    types,
-    dicts,
-  };
-});
+    return {
+      types,
+      dicts,
+    };
+  },
+  {
+    // 持久化配置
+    persist: {
+      enabled: true,
+      strategies: [
+        {
+          key: "mes-dictionaryData", // 自定义存储键名
+          storage: localStorage, // 使用 localStorage
+          paths: ["dicts"], // 只持久化 dicts 数据
+        },
+      ],
+    },
+  }
+);
 
 export function useDictionaryStoreHook() {
   // console.log('dicts:',useDictionaryStore(store))

+ 9 - 6
src/views/login/index.vue

@@ -118,10 +118,11 @@ import { getCaptchaApi, getOrgListApi, getUserDicts } from "@/api/auth";
 import { LoginData } from "@/api/auth/types";
 import { Sunny, Moon } from "@element-plus/icons-vue";
 import { LocationQuery, LocationQueryValue, useRoute } from "vue-router";
-import router from "@/router";
+
 import defaultSettings from "@/settings";
 import { ThemeEnum } from "@/enums/ThemeEnum";
 import { usePermissionStore } from "@/store/modules/permission";
+
 // Stores
 const userStore = useUserStore();
 const settingsStore = useSettingsStore();
@@ -200,6 +201,7 @@ function getOrgList() {
  * 登录
  */
 const route = useRoute();
+const router = useRouter();
 
 function handleLogin() {
   loginFormRef.value.validate((valid: boolean) => {
@@ -223,12 +225,13 @@ function handleLogin() {
             },
             {}
           );
+
           // 获取字典
-          getUserDicts(dictStore.types).then((res) => {
-            if (res.data) {
-              dictStore.dicts = res?.data ?? [];
-            }
-          });
+          const dictStore = useDictionaryStore();
+          let res = await getUserDicts(dictStore.types);
+          if (res?.data) {
+            dictStore.dicts = res?.data ?? {};
+          }
 
           // router.push({ path: redirect, query: otherQueryParams });
           router.push("/welcome");