修复:解决测试发现的问题

This commit is contained in:
2025-11-12 16:00:44 +08:00
parent 1da75a59f2
commit 1daa6367c9
29 changed files with 133 additions and 182 deletions

View File

@@ -3,6 +3,7 @@ import { requestInterceptor } from './interceptors/request';
import { responseInterceptor } from './interceptors/response';
import type { IRequestOptions, ICreateClientConfig } from './types';
import { REQUEST_TIMEOUT } from './config';
import { t } from '@/utils/i18n'
export function createRequestClient(cfg: ICreateClientConfig) {
const baseURL = cfg.baseURL;
@@ -17,14 +18,22 @@ export function createRequestClient(cfg: ICreateClientConfig) {
header: options.header || {},
};
// run request interceptor to mutate headers, etc.
// 运行请求拦截器,修改 headers
const intercepted = requestInterceptor(final as IRequestOptions);
// 全局处理请求 loading
const loading = !cfg.loading ? true : cfg.loading // 接口请求参数不传loading默认显示loading
loading && uni.showLoading()
return new Promise((resolve, reject) => {
uni.request({
...intercepted,
complete() {
// 请求完成关闭 loading
loading && uni.hideLoading()
},
success(res: any) {
// delegate to response interceptor
// 委托给响应拦截器处理
responseInterceptor(res)
.then((r) => {
resolve(r as any);
@@ -34,7 +43,7 @@ export function createRequestClient(cfg: ICreateClientConfig) {
});
},
fail(err: any) {
uni.showToast({ title: '网络连接失败', icon: 'none' });
uni.showToast({ title: t('global.networkConnectionError'), icon: 'none' });
reject(err);
},
} as any);