Jelajahi Sumber

fix:请求响应code逻辑更改、权限判断更改

snow 1 tahun lalu
induk
melakukan
663f2761a5

+ 1 - 1
src/hooks/core/useAsync.ts

@@ -65,7 +65,7 @@ export function useAsync<D = any>({
         handler: () => {
           setData(isList ? (data as any).list : data);
           isError.value = false;
-          if (pagination) pagination.total = (data as any).count;
+          if (pagination && data && data.count) pagination.total = (data as any).count;
           success && success(unref(data));
         }
       });

+ 1 - 1
src/hooks/response/use-response-handle.ts

@@ -19,7 +19,7 @@ export function useResponseHandle() {
     noMessage = false
   }: Params) {
     const c = Number(code);
-    if (c === 0) {
+    if (c === 1) {
       handler();
     } else if (c >= 100 && c <= 140) {
       logout();

+ 3 - 4
src/router/utils.ts

@@ -32,9 +32,8 @@ function ascending(arr: any[]) {
     }
   });
   return arr.sort(
-    (a: { meta: { rank: number } }, b: { meta: { rank: number } }) => {
-      return a?.meta?.rank - b?.meta?.rank;
-    }
+    (a: { meta: { rank: number } }, b: { meta: { rank: number } }) =>
+      a?.meta?.rank - b?.meta?.rank
   );
 }
 
@@ -213,11 +212,11 @@ function initRouter(data = {}) {
 
           resolve(router);
         } else {
+          console.log(111);
           reject(false);
         }
       })
       .catch(err => {
-        console.log(err)
         reject(err);
       });
   });

+ 11 - 16
src/store/modules/user.ts

@@ -6,13 +6,9 @@ import { routerArrays } from "/@/layout/types";
 import { storageSession } from "@pureadmin/utils";
 import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";
 
-import { getRelaComNo, setRelaComName, removeRelaComNo } from "/@/utils/auth";
+import { removeRelaComNo } from "/@/utils/auth";
 import { ElMessage } from "element-plus";
 
-import { loadEnv } from "@build/index";
-
-const { VITE_IS_PROD } = loadEnv();
-
 import {
   getLogin,
   getAsyncRoutes,
@@ -134,19 +130,19 @@ export const useUserStore = defineStore({
 
         if (this.level === "3") {
           throw new Error(
-            JSON.stringify({ code: 101, message: "供应商端账号无法登录" })
+            JSON.stringify({ code: 10000, message: "供应商端账号无法登录" })
           );
         }
 
         this.isSuperUser = level === "1";
-
-        if (!this.isSuperUser && this.companyList.length === 0) {
-          const { data: companyData } = await httpCompany({ size: 10000 });
-          this.companyList = companyData.list;
-          if (!this.companyList || this.companyList.length === 0) {
-            return;
-          }
-        }
+        //
+        // if (!this.isSuperUser && this.companyList.length === 0) {
+        //   const { data: companyData } = await httpCompany({ size: 10000 });
+        //   this.companyList = companyData.list;
+        //   if (!this.companyList || this.companyList.length === 0) {
+        //     return;
+        //   }
+        // }
 
         return data;
       } else {
@@ -193,8 +189,6 @@ export const useUserStore = defineStore({
                       actionList.push(item);
                     });
                   });
-
-                  console.log(actionList);
                   setAction(JSON.stringify(actionList));
                   resolve(res);
                   break;
@@ -216,6 +210,7 @@ export const useUserStore = defineStore({
       } catch (err) {
         if (err && err.message) {
           const { code, message } = JSON.parse(err.message);
+
           if (!(Number(code) >= 100 && Number(code) <= 104)) {
             ElMessage.error(message);
           }

+ 44 - 37
src/views/login/index.vue

@@ -46,45 +46,52 @@ const ruleForm = reactive({
 const onLogin = async (formEl: FormInstance | undefined) => {
   loading.value = true;
   if (!formEl) return;
-  await formEl.validate(async (valid, fields) => {
-    if (valid) {
-      loginByUsername(ruleForm).then(async (res: resType) => {
-        const { code, message, data } = res;
-        if (Number(code) === 1) {
-          const { userinfo, token } = data ?? {};
-          const { nickname } = userinfo ?? {};
-          storageSession.setItem("info", {
-            username: nickname ?? "",
-            accessToken: token ?? ""
-          });
-
-          initRouter()
-            .then((list: any) => {
-              if (!list || list?.length === 0) {
-                loading.value = false;
-                ElMessage.warning("该用户当前公司无菜单权限!");
-              } else {
-                ElMessage.success("登录成功");
-                router.push("/");
-              }
-            })
-            .catch(err => {
-              if (err === 10000) {
-                router.push("/welcome?error=roleExcption");
-              }
+  await formEl
+    .validate(async (valid, fields) => {
+      if (valid) {
+        loginByUsername(ruleForm).then(async (res: resType) => {
+          const { code, message, data } = res;
+          if (Number(code) === 1) {
+            const { userinfo, token } = data ?? {};
+            const { nickname } = userinfo ?? {};
+            storageSession.setItem("info", {
+              username: nickname ?? "",
+              accessToken: token ?? ""
             });
-        } else if (code > 100 && code < 200) {
-          loading.value = false;
-        } else {
-          loading.value = false;
-          ElMessage.error(message ?? "");
-        }
-      });
-    } else {
+
+            initRouter()
+              .then((list: any) => {
+                if (!list || list?.length === 0) {
+                  loading.value = false;
+                  ElMessage.warning("该用户当前公司无菜单权限!");
+                } else {
+                  ElMessage.success("登录成功");
+                  router.push("/");
+                }
+              })
+              .catch(err => {
+                if (err === 10000) {
+                  router.push("/welcome?error=roleExcption");
+                }
+              })
+              .catch(() => {
+                loading.value = false;
+              });
+          } else if (code > 100 && code < 200) {
+            loading.value = false;
+          } else {
+            loading.value = false;
+            ElMessage.error(message ?? "");
+          }
+        });
+      } else {
+        loading.value = false;
+        return fields;
+      }
+    })
+    .catch(() => {
       loading.value = false;
-      return fields;
-    }
-  });
+    });
 };
 
 function toWindowPath() {

+ 4 - 2
src/views/system/accountRole/components/role-modal.vue

@@ -62,9 +62,11 @@ defineExpose({
     runRole(httpRoleQuery({}));
 
     if (_data) {
-      const { mobile, nickname, roleid, id, companyName } = _data;
+      const { mobile, nickname, role_id, id, companyName } = _data;
+
+      console.log(_data);
       company.value = companyName;
-      formData.value = { mobile, nickname, roleid, id };
+      formData.value = { mobile, nickname, roleid: role_id, id };
     }
   }
 });

+ 9 - 15
src/views/system/accountRole/index.vue

@@ -1,9 +1,9 @@
 <script setup lang="ts">
 import { ref } from "vue";
+import { usePageSearch, type PageHooks, type PageEvents } from "/@/hooks/page";
 import RoleModal from "./components/role-modal.vue";
 import contentConfig from "./config/content.config";
 import searchConfig from "./config/search.config";
-import { usePageSearch, type PageHooks, type PageEvents } from "/@/hooks/page";
 import { httpSetRole } from "/@/api/system/account";
 import { useAsync } from "/@/hooks/core/useAsync";
 import { ModalTypes } from "./types";
@@ -12,19 +12,13 @@ const PageName = "accountRole";
 const roleModalRef = ref<InstanceType<typeof RoleModal> | null>(null);
 const instance = ref(null);
 
+const searchCallback = params => ({
+  result: { ...(params ? params : {}), level: "2" },
+  deleteProp: []
+});
+
 const hooks: PageHooks = {
-  pageSearchHook: () =>
-    usePageSearch(
-      params => ({
-        result: {
-          ...(params ? params : {}),
-          level: "2"
-        },
-        deleteProp: []
-      }),
-      undefined,
-      searchConfig
-    )
+  pageSearchHook: () => usePageSearch(searchCallback, undefined, searchConfig)
 };
 
 const { run } = useAsync({
@@ -43,9 +37,9 @@ function handleSave(data: any, type: ModalTypes) {
   const { roleid, id } = data;
 
   const params = {
+    status: "1",
     user_id: id,
-    role_id: roleid,
-    status: "1"
+    role_id: roleid
   };
 
   switch (type) {

+ 9 - 9
src/views/system/actionSet/index.vue

@@ -46,11 +46,11 @@ const handleCheckAllChange = (checkAll, index, item, subIndex) => {
     const findindex = menuactionList.value[index].child[
       subIndex
     ].checkList.findIndex(
-      findItem => String(findItem) === String(element.action_id)
+      findItem => String(findItem) === String(element.id)
     );
     if (checkAll && findindex == -1) {
       menuactionList.value[index].child[subIndex].checkList.push(
-        String(element.action_id)
+        String(element.id)
       );
     } else if (!checkAll && findindex > -1) {
       menuactionList.value[index].child[subIndex].checkList.splice(
@@ -67,7 +67,7 @@ const handleCheckedGroupChange = (event, index, item, subIndex) => {
   ].child[subIndex].child.every(
     evitem =>
       menuactionList.value[index].child[subIndex].checkList.findIndex(
-        finditem => String(finditem) === String(evitem.action_id)
+        finditem => String(finditem) === String(evitem.id)
       ) > -1
   );
 };
@@ -191,7 +191,7 @@ const refreshRoleDetail = async id => {
       ruleForm.roleid = id;
       ruleForm.role_name = role_name ?? "";
       ruleForm.level = level ?? "1";
-      action_list.value = action ? action.map(code => Number(code)) : [];
+      action_list.value = action ? action.map(code => String(code)) : [];
       await refreshRoleCheckAllStatus();
     }
   });
@@ -208,7 +208,7 @@ const refreshRoleCheckAllStatus = async () => {
         if (y?.child?.length > 0) {
           y.child.forEach(z => {
             const Aindex = action_list.value.findIndex(
-              a => String(a) === String(z.action_id)
+              a => String(a) === String(z.id)
             );
             if (Aindex !== -1) {
               y.checkList.push(action_list.value[Aindex]);
@@ -326,7 +326,7 @@ onMounted(() => {
                     <div
                       class="fbody-item"
                       v-for="(subItem, subIndex) in item.child"
-                      :key="'yemian' + subItem.action_id + subIndex"
+                      :key="'yemian' + subItem.id + subIndex"
                     >
                       <template
                         v-if="
@@ -399,12 +399,12 @@ onMounted(() => {
                                 size="small"
                                 :disabled="editType === 'view'"
                                 v-for="children in subItem.child"
-                                :key="'checkItem' + children.action_id"
-                                :label="Number(children.action_id)"
+                                :key="'checkItem' + children.id"
+                                :label="String(children.id)"
                                 @change="
                                   handleCheckedChange(
                                     $event,
-                                    Number(children.action_id),
+                                    String(children.id),
                                     index,
                                     subIndex,
                                     item

+ 12 - 10
src/views/system/role/addEdit.vue

@@ -65,10 +65,10 @@ const handleCheckAllChange = (checkAll, index, item, subIndex) => {
   menuactionList.value[index].child[subIndex].child.forEach(element => {
     const findindex = menuactionList.value[index].child[
       subIndex
-    ].checkList.findIndex(findItem => findItem === String(element.action_id));
+    ].checkList.findIndex(findItem => findItem === Number(element.id));
     if (checkAll && findindex == -1) {
       menuactionList.value[index].child[subIndex].checkList.push(
-        String(element.action_id)
+        Number(element.id)
       );
     } else if (!checkAll && findindex > -1) {
       menuactionList.value[index].child[subIndex].checkList.splice(
@@ -104,7 +104,7 @@ const handleCheckedGroupChange = (event, index, item, subIndex) => {
   ].child[subIndex].child.every(
     evitem =>
       menuactionList.value[index].child[subIndex].checkList.findIndex(
-        finditem => finditem == evitem.action_id
+        finditem => finditem == Number(evitem.id)
       ) > -1
   );
 };
@@ -116,7 +116,7 @@ const handleFieldGroupChange = (event, index, item, subIndex) => {
   ].child[subIndex].child.every(
     evitem =>
       menuactionList.value[index].child[subIndex].fieldList.findIndex(
-        finditem => finditem == evitem.action_id
+        finditem => finditem == Number( evitem.id)
       ) > -1
   );
 };
@@ -296,7 +296,7 @@ const initData = async () => {
             y.child.map(z => {
               const Aindex =
                 action_list.value.length > 0
-                  ? action_list.value.findIndex(a => a == z.action_id)
+                  ? action_list.value.findIndex(a => a == z.id)
                   : -1;
               if (Aindex !== -1) {
                 y.checkList.push(action_list.value[Aindex]);
@@ -350,13 +350,15 @@ let indeterminateCheck = computed(() => {
     // 选中子节点的数量
     const selectItemLength = item.child.filter(
       filitem =>
-        item.checkList.findIndex(finditem => finditem == filitem.id) > -1
+        item.checkList.findIndex(finditem => Number(finditem) == filitem.id) > -1
     ).length;
     // 未选中子节点的数量
     const noSlectItemLength = item.child.filter(
       filitem =>
-        item.checkList.findIndex(finditem => finditem == filitem.id) == -1
+        item.checkList.findIndex(finditem => Number(finditem) == filitem.id) == -1
     ).length;
+
+    console.log(selectItemLength,noSlectItemLength)
     // // 当前节点的index
     // 存在选中子节点且存在未选中子节点为中间态
     return selectItemLength > 0 && noSlectItemLength > 0;
@@ -516,12 +518,12 @@ let indeterminateField = computed(() => {
                                 <el-checkbox
                                   :disabled="editType == 'view'"
                                   v-for="children in subItem.child"
-                                  :key="'checkItem' + children.action_id"
-                                  :label="Number(children.action_id)"
+                                  :key="'checkItem' + children.id"
+                                  :label="Number(children.id)"
                                   @change="
                                     handleCheckedChange(
                                       $event,
-                                      Number(children.action_id),
+                                      Number(children.id),
                                       index,
                                       subIndex,
                                       item

+ 6 - 8
src/views/system/role/index.vue

@@ -77,8 +77,8 @@ function handleSelectionChange(val) {
 
 async function onSearch() {
   loading.value = true;
-
   const { code, data, message } = await httpList(form);
+  loading.value = false;
 
   if (code === 1) {
     const { list, count } = data;
@@ -91,8 +91,6 @@ async function onSearch() {
   } else {
     ElMessage.error(message);
   }
-
-  loading.value = false;
 }
 async function resetSearch() {
   form.page = 1;
@@ -122,15 +120,15 @@ const resetForm = (formEl: FormInstance | undefined) => {
 
 onMounted(() => {
   powers.value = useUserStoreHook().getMenuActions("role");
-  if (powers.value.some(i => i == "001")) {
+  if (powers.value.some(i => i == "3")) {
     onSearch();
   }
 });
 
-watch(
-  () => currentCompany.value,
-  () => onSearch()
-);
+// watch(
+//   () => currentCompany.value,
+//   () => onSearch()
+// );
 </script>
 
 <template>