소스 검색

feat(api): add FlawResult conveter

gemercheung 3 년 전
부모
커밋
599a84fae2

+ 1 - 1
.env.development

@@ -6,7 +6,7 @@ VITE_PUBLIC_PATH = /
 
 # Cross-domain proxy, you can configure multiple
 # Please note that no line breaks
-VITE_PROXY = [["/basic-api","http://192.168.0.47:8190"],["/upload","http://localhost:3300/upload"],["/zfb-api","https://cszfb.4dkankan.com"]]
+VITE_PROXY = [["/basic-api","http://192.168.0.47:8190"],["/upload","http://localhost:3300/upload"],["/zfb-api","http://192.168.0.47:7081"]]
 # VITE_PROXY=[["/api","https://vvbin.cn/test"]]
 
 # Delete console

+ 2 - 2
src/api/feedback/list.ts

@@ -2,7 +2,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { PageParams, RentListGetResultModel } from './model';
 
 enum Api {
-  pageList = '/zfb/feedback/list',
+  pageList = '/basic-api/feedback/list',
 }
 
 /**
@@ -10,7 +10,7 @@ enum Api {
  */
 
 export const ListApi = (params: PageParams) =>
-  defHttp.get<RentListGetResultModel>({
+  defHttp.post<RentListGetResultModel>({
     url: Api.pageList,
     params,
     headers: {

+ 1 - 1
src/api/member/list.ts

@@ -2,7 +2,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { PageParams, MemberListGetResultModel } from './model';
 
 enum Api {
-  pageList = '/zfb/member/list',
+  pageList = '/basic-api/member/list',
 }
 
 /**

+ 2 - 2
src/api/order/list.ts

@@ -2,7 +2,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { PageParams, RentListGetResultModel } from './model';
 
 enum Api {
-  pageList = '/zfb/order/list',
+  pageList = '/zfb-api/order/list',
 }
 
 /**
@@ -10,7 +10,7 @@ enum Api {
  */
 
 export const ListApi = (params: PageParams) =>
-  defHttp.get<RentListGetResultModel>({
+  defHttp.post<RentListGetResultModel>({
     url: Api.pageList,
     params,
     headers: {

+ 2 - 2
src/api/product/list.ts

@@ -2,8 +2,8 @@ import { defHttp } from '/@/utils/http/axios';
 import { PageParams, RentListGetResultModel } from './model';
 
 enum Api {
-  pageList = '/zfb/product/list',
-  category = '/zfb/product/category',
+  pageList = '/basic-api/product/list',
+  category = '/basic-api/product/category',
 }
 
 /**

+ 1 - 1
src/api/staff/list.ts

@@ -2,7 +2,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { PageParams, RentListGetResultModel } from './model';
 
 enum Api {
-  pageList = '/zfb/staff/list',
+  pageList = '/basic-api/staff/list',
 }
 
 /**

+ 0 - 1
src/components/Form/src/components/FormItem.vue

@@ -309,7 +309,6 @@
         const { itemProps, slot, render, field, suffix, component } = props.schema;
         const { labelCol, wrapperCol } = unref(itemLabelWidthProp);
         const { colon } = props.formProps;
-        console.log('itemProps', itemProps);
 
         if (component === 'Divider') {
           return (

+ 2 - 1
src/store/modules/user.ts

@@ -91,8 +91,9 @@ export const useUserStore = defineStore({
       try {
         const { goHome = true, mode, ...loginParams } = params;
         const data = await loginApi(loginParams, mode);
+        const { token, user } = data;
 
-        const { token } = data;
+        console.log('user', user);
 
         // save token
         this.setToken(token);

+ 8 - 6
src/utils/http/axios/index.ts

@@ -50,7 +50,7 @@ const transform: AxiosTransform = {
     }
     //  这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
 
-    const { code, result, message } = data;
+    const { code, error, message } = data;
     // TODO
     // 这里逻辑可以根据项目进行修改
     const hasSuccess =
@@ -58,11 +58,13 @@ const transform: AxiosTransform = {
       Reflect.has(data, 'code') &&
       (code === ResultEnum.SUCCESS || code === ResultEnum.NORMAL);
     if (hasSuccess) {
-      if (typeof message === 'object' && Reflect.has(message, 'pageSize')) {
-        return message;
-      } else {
-        return result || data;
-      }
+      const converterResult = data.message;
+      const converterMessage = error;
+      data.result = converterResult;
+      data.message = converterMessage;
+      delete data.error;
+
+      return data.result || data;
     }
 
     // 在此处根据自己项目的实际情况对不同的code执行不同的操作

+ 13 - 4
types/axios.d.ts

@@ -25,11 +25,20 @@ export interface RequestOptions {
   withToken?: boolean;
 }
 
-export interface Result<T = any> {
+// export interface Result<T = any> {
+//   code: number;
+//   type: 'success' | 'error' | 'warning';
+//   message: string | T;
+//   result: T;
+// }
+export type Result = FlawResult;
+//TODO 后端不标准的返回字段
+export interface FlawResult<T = any> {
   code: number;
-  type: 'success' | 'error' | 'warning';
-  message: string | T;
-  result: T;
+  type?: 'success' | 'error' | 'warning';
+  message: T;
+  result?: T;
+  error?: string;
 }
 
 // multipart/form-data: upload file