Parcourir la source

1.获取字典逻辑修改。

jiaxiaoqiang il y a 1 an
Parent
commit
7a6cf1125d
3 fichiers modifiés avec 39 ajouts et 15 suppressions
  1. 30 6
      src/layout/components/header.vue
  2. 8 0
      src/plugins/permission.ts
  3. 1 9
      src/store/modules/dictionary.ts

+ 30 - 6
src/layout/components/header.vue

@@ -1,7 +1,12 @@
 <template>
   <div class="commonHeader">
     <div style="width: 155px">
-      <svg-icon v-if="routeMeta.back" icon-class="back" size="48" @click="commonBack" />
+      <svg-icon
+        v-if="routeMeta.back"
+        icon-class="back"
+        size="48"
+        @click="commonBack"
+      />
       <!-- <svg-icon v-else icon-class="LOGO" style="height: 48px; width: 155px" /> -->
     </div>
     <div v-if="routeMeta.back && routeMeta.title" class="middle-title">
@@ -14,19 +19,38 @@
     <div>
       <el-space>
         <div>
-          <svg-icon @click="messageStatus = !messageStatus" icon-class="lingdang" size="48" class="activeNotice" />
+          <svg-icon
+            class="activeNotice"
+            icon-class="lingdang"
+            size="48"
+            @click="messageStatus = !messageStatus"
+          />
         </div>
         <div class="task">
-          <el-progress :percentage="processCount" :show-text="false" :stroke-width="10" />
+          <el-progress
+            :percentage="processCount"
+            :show-text="false"
+            :stroke-width="10"
+          />
           <div class="process">任务进度: {{ processCount }}%</div>
         </div>
         <div>
           <div class="name">{{ userStore.user.username }}</div>
           <div class="work">{{ userStore.user.station }}</div>
         </div>
-        <el-dropdown ref="dropdown1" trigger="contextmenu" @command="handleCommand">
-          <img v-if="userStore.user.avatar" :alt="userStore.user.avatar" :src="userStore.user.avatar" object-fit="cover"
-            style="width: 48px; height: 48px; border-radius: 24px" @click="showClick" />
+        <el-dropdown
+          ref="dropdown1"
+          trigger="contextmenu"
+          @command="handleCommand"
+        >
+          <img
+            v-if="userStore.user.avatar"
+            :alt="userStore.user.avatar"
+            :src="userStore.user.avatar"
+            object-fit="cover"
+            style="width: 48px; height: 48px; border-radius: 24px"
+            @click="showClick"
+          />
           <svg-icon v-else icon-class="head" size="48" @click="showClick" />
           <template #dropdown>
             <el-dropdown-menu style="width: 150px">

+ 8 - 0
src/plugins/permission.ts

@@ -1,6 +1,7 @@
 import router from "@/router";
 import NProgress from "@/utils/nprogress";
 import { useDictionaryStore } from "@/store/modules/dictionary";
+import { getUserDicts } from "@/api/auth";
 
 export function setupPermission() {
   // 白名单路由
@@ -17,6 +18,13 @@ export function setupPermission() {
       } else {
         const dictStore = useDictionaryStore();
         dictStore.checkAllData();
+        if (JSON.stringify(dictStore.dicts.value) === "{}") {
+          const res = await getUserDicts(dictStore.types);
+          if (res.data) {
+            dictStore.dicts.value = res?.data ?? [];
+          }
+        }
+
         next();
         NProgress.done();
       }

+ 1 - 9
src/store/modules/dictionary.ts

@@ -1,6 +1,6 @@
 import { store } from "@/store";
 import { defineStore } from "pinia";
-import { getUserDicts, getUserList } from "@/api/auth";
+import { getUserList } from "@/api/auth";
 
 export const useDictionaryStore = defineStore("dictionaryStore", () => {
   const types = [
@@ -22,14 +22,6 @@ export const useDictionaryStore = defineStore("dictionaryStore", () => {
   const allUsers = ref<any[]>([]);
 
   function checkAllData() {
-    if (JSON.stringify(dicts.value) === "{}") {
-      getUserDicts(types).then((res) => {
-        if (res.data) {
-          dicts.value = res?.data ?? [];
-        }
-      });
-    }
-
     if (allUsers.value.length === 0) {
       getUserList().then((res) => {
         allUsers.value = res.data || [];