Prechádzať zdrojové kódy

feat(navi): 增加通用性api useResult 放行特许业务

gemercheung 1 rok pred
rodič
commit
e0efcaab3a

+ 8 - 9
src/request/index.ts

@@ -62,19 +62,18 @@ export const sendFetch = <T>(
       }
     })
     .then((data) => {
-      if (data.code !== 0) {
-        error(data.message);
-        errorHook.map((err) => {
-          err(data.code, data.msg);
-        });
-        throw data.message;
+      if (other && other.useResult) {
+        return data
       } else {
-        if (other && other.useResult) {
-          return data
+        if (data.code !== 0) {
+          error(data.message);
+          errorHook.map((err) => {
+            err(data.code, data.msg);
+          });
+          throw data.message;
         } else {
           return data.data;
         }
-
       }
     });
 };

+ 23 - 5
src/request/organization.ts

@@ -1,9 +1,11 @@
 import { sendFetch, PageProps } from './index'
-import { ResPage } from './type'
+import { ResPage, ResResult } from './type'
 import { organizationTypeEnum } from '@/store/organization'
 import * as URL from "./URL";
-
-// 
+import { ElMessage } from "element-plus";
+import { throttle } from "@/util";
+const error = throttle((msg: string) => ElMessage.error(msg), 2000);
+const success = throttle((msg: string) => ElMessage.success(msg), 2000);
 
 export type OrganizationType = {
     ancestors: string
@@ -20,11 +22,27 @@ export type OrganizationType = {
 
 }
 
-export const addOrgFetch = (params: Partial<OrganizationType>) =>
-    sendFetch<PageProps<OrganizationType>>(URL.addOrganization, {
+export const addOrgFetch = async (params: Partial<OrganizationType>) => {
+    const api = await sendFetch<ResResult>(URL.addOrganization, {
         method: "post",
         body: JSON.stringify(params),
+    }, {
+        useResult: true
     });
+    if (api.code === 0) {
+        success('添加成功')
+    } else {
+        if (api.code === 2008) {
+            success(api.message)
+        } else {
+            error(api.message)
+            throw (api.message)
+        }
+    }
+
+}
+
+
 export const alterOrgFetch = (params: Partial<OrganizationType>) =>
     sendFetch<PageProps<OrganizationType>>(URL.alterOrganization, {
         method: "post",

+ 8 - 2
src/request/users.ts

@@ -57,14 +57,14 @@ export const updateUserStatusFetch = (params: Pick<UserType, 'userId' | 'status'
     });
 
 export type ChangePasswordParam = Pick<UserType, 'confirmPwd' | 'msgAuthCode' | 'password' | 'phoneNum'>
-export const changePassword = (params: ChangePasswordParam) => {
+export const changePassword = async (params: ChangePasswordParam) => {
 
     const ent = encodePwd(params.password)
     if (params.password !== params.confirmPwd) {
         ElMessage.error("当前密码与密码确认不一致!");
         return Promise.reject()
     } else {
-        return sendFetch<ResResult>(URL.changePassword, {
+        const api = await sendFetch<ResResult>(URL.changePassword, {
             method: "post",
             body: JSON.stringify({
                 confirmPwd: ent,
@@ -75,6 +75,12 @@ export const changePassword = (params: ChangePasswordParam) => {
         }, {
             useResult: true
         });
+        if (api.code === 0) {
+            ElMessage.success("编辑成功!");
+        } else {
+            ElMessage.error(api.message);
+            throw (api.message)
+        }
     }
 
 

+ 1 - 0
src/view/organization.vue

@@ -97,6 +97,7 @@ watch(pageProps, refresh, { deep: true, immediate: true });
 onActivated(refresh);
 
 
+
 const addHandler = async () => {
   await organizationAdd({ submit: addOrgFetch });
   await refresh();