feat: 细节调整

This commit is contained in:
xuziqiang
2024-06-11 13:37:10 +08:00
parent cbfa942ff6
commit d58f066b39
8 changed files with 116 additions and 78 deletions

View File

@@ -72,31 +72,27 @@ export class NSAxios {
if (this.projectType !== 'web') config.url = `/${this.projectType}/${url}`;
}
// let newUrl = url as string;
// if (config.method === 'get' && config.params) {
// newUrl += '?';
// const keys = Object.keys(config.params);
// for (const key of keys) {
// if (config.params[key] !== undefined) {
// newUrl += `${key}=${encodeURIComponent(config.params[key])}&`;
// }
// }
// newUrl = newUrl.substring(0, newUrl.length - 1);
// config.params = {};
// }
// config.url = newUrl;
return config;
}, undefined);
const errCodeArr = [13, 1, 3005];
// const newMap = new Map([])
const errCodeMap = new Map([
[13, ''],
[1, ''],
[3005, JSON.stringify(() => routerConfig.logout())],
]);
// type closeType = (() => void) | undefined;
this.instance.interceptors.response.use(
(res: AxiosResponse) => {
console.log('success', res);
// todo
const code = res?.data?.retcode;
const msg = res?.data?.msg;
if (errCodeArr.includes(code)) {
NsMessage.error({ content: msg, key: this.errorMsgKey });
if (errCodeMap.has(code)) {
NsMessage.error({
content: msg,
key: this.errorMsgKey,
onClose: JSON.parse(errCodeMap.get(code)!),
});
return Promise.reject(res);
}
return res;