chore: 移除requestClient的一些冗余参数
This commit is contained in:
parent
da0ddfc8c7
commit
d214da3303
@ -7,6 +7,7 @@
|
|||||||
**OTHERS**
|
**OTHERS**
|
||||||
|
|
||||||
- 菜单管理 改为虚拟滚动
|
- 菜单管理 改为虚拟滚动
|
||||||
|
- 移除requestClient的一些冗余参数
|
||||||
|
|
||||||
**BUG FIXES**
|
**BUG FIXES**
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import {
|
|||||||
RequestClient,
|
RequestClient,
|
||||||
} from '@vben/request';
|
} from '@vben/request';
|
||||||
import { useAccessStore } from '@vben/stores';
|
import { useAccessStore } from '@vben/stores';
|
||||||
import { isString } from '@vben/utils';
|
|
||||||
|
|
||||||
import { message, Modal } from 'ant-design-vue';
|
import { message, Modal } from 'ant-design-vue';
|
||||||
import { isEmpty, isNull } from 'lodash-es';
|
import { isEmpty, isNull } from 'lodash-es';
|
||||||
@ -27,8 +26,6 @@ import {
|
|||||||
} from '#/utils/encryption/crypto';
|
} from '#/utils/encryption/crypto';
|
||||||
import * as encryptUtil from '#/utils/encryption/jsencrypt';
|
import * as encryptUtil from '#/utils/encryption/jsencrypt';
|
||||||
|
|
||||||
import { formatRequestDate, joinTimestamp, setObjToUrlParams } from './helper';
|
|
||||||
|
|
||||||
const { apiURL, clientId, enableEncrypt } = useAppConfig(
|
const { apiURL, clientId, enableEncrypt } = useAppConfig(
|
||||||
import.meta.env,
|
import.meta.env,
|
||||||
import.meta.env.PROD,
|
import.meta.env.PROD,
|
||||||
@ -46,16 +43,10 @@ function createRequestClient(baseURL: string) {
|
|||||||
baseURL,
|
baseURL,
|
||||||
// 消息提示类型
|
// 消息提示类型
|
||||||
errorMessageMode: 'message',
|
errorMessageMode: 'message',
|
||||||
// 格式化提交参数时间
|
|
||||||
formatDate: true,
|
|
||||||
// 是否返回原生响应 比如:需要获取响应头时使用该属性
|
// 是否返回原生响应 比如:需要获取响应头时使用该属性
|
||||||
isReturnNativeResponse: false,
|
isReturnNativeResponse: false,
|
||||||
// 需要对返回数据进行处理
|
// 需要对返回数据进行处理
|
||||||
isTransformResponse: true,
|
isTransformResponse: true,
|
||||||
// post请求的时候添加参数到url
|
|
||||||
joinParamsToUrl: false,
|
|
||||||
// 是否加入时间戳
|
|
||||||
joinTime: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,51 +94,7 @@ function createRequestClient(baseURL: string) {
|
|||||||
// 添加全局clientId
|
// 添加全局clientId
|
||||||
config.headers.clientId = clientId;
|
config.headers.clientId = clientId;
|
||||||
|
|
||||||
const { encrypt, formatDate, joinParamsToUrl, joinTime = true } = config;
|
const { encrypt } = config;
|
||||||
const params = config.params || {};
|
|
||||||
const data = config.data || false;
|
|
||||||
// TODO: 这块要重构 复杂度太高了
|
|
||||||
formatDate && data && !isString(data) && formatRequestDate(data);
|
|
||||||
if (config.method?.toUpperCase() === 'GET') {
|
|
||||||
if (isString(params)) {
|
|
||||||
// 兼容restful风格
|
|
||||||
config.url = `${config.url + params}${joinTimestamp(joinTime, true)}`;
|
|
||||||
config.params = undefined;
|
|
||||||
} else {
|
|
||||||
// 给 get 请求加上时间戳参数,避免从缓存中拿数据。
|
|
||||||
config.params = Object.assign(
|
|
||||||
params || {},
|
|
||||||
joinTimestamp(joinTime, false),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isString(params)) {
|
|
||||||
// 兼容restful风格
|
|
||||||
config.url = config.url + params;
|
|
||||||
config.params = undefined;
|
|
||||||
} else {
|
|
||||||
formatDate && formatRequestDate(params);
|
|
||||||
if (
|
|
||||||
Reflect.has(config, 'data') &&
|
|
||||||
config.data &&
|
|
||||||
(Object.keys(config.data).length > 0 ||
|
|
||||||
config.data instanceof FormData)
|
|
||||||
) {
|
|
||||||
config.data = data;
|
|
||||||
config.params = params;
|
|
||||||
} else {
|
|
||||||
// 非GET请求如果没有提供data,则将params视为data
|
|
||||||
config.data = params;
|
|
||||||
config.params = undefined;
|
|
||||||
}
|
|
||||||
if (joinParamsToUrl) {
|
|
||||||
config.url = setObjToUrlParams(
|
|
||||||
config.url as string,
|
|
||||||
Object.assign({}, config.params, config.data),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 全局开启请求加密功能 && 该请求开启 && 是post/put请求
|
// 全局开启请求加密功能 && 该请求开启 && 是post/put请求
|
||||||
if (
|
if (
|
||||||
enableEncrypt &&
|
enableEncrypt &&
|
||||||
|
@ -62,10 +62,6 @@ declare module 'axios' {
|
|||||||
* 错误弹窗类型
|
* 错误弹窗类型
|
||||||
*/
|
*/
|
||||||
errorMessageMode?: ErrorMessageMode;
|
errorMessageMode?: ErrorMessageMode;
|
||||||
/**
|
|
||||||
* 是否格式化日期
|
|
||||||
*/
|
|
||||||
formatDate?: boolean;
|
|
||||||
/**
|
/**
|
||||||
* 是否返回原生axios响应
|
* 是否返回原生axios响应
|
||||||
*/
|
*/
|
||||||
@ -74,14 +70,6 @@ declare module 'axios' {
|
|||||||
* 是否需要转换响应 即只获取{code, msg, data}中的data
|
* 是否需要转换响应 即只获取{code, msg, data}中的data
|
||||||
*/
|
*/
|
||||||
isTransformResponse?: boolean;
|
isTransformResponse?: boolean;
|
||||||
/**
|
|
||||||
* param添加到url后
|
|
||||||
*/
|
|
||||||
joinParamsToUrl?: boolean;
|
|
||||||
/**
|
|
||||||
* 加入时间戳
|
|
||||||
*/
|
|
||||||
joinTime?: boolean;
|
|
||||||
/**
|
/**
|
||||||
* 成功弹窗类型
|
* 成功弹窗类型
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user