style(projects): update prettier config

This commit is contained in:
Soybean
2022-04-01 14:47:57 +08:00
parent ca2dfa6185
commit df56abe18d
128 changed files with 2237 additions and 2037 deletions

View File

@ -6,7 +6,7 @@ import {
NETWORK_ERROR_MSG,
REQUEST_TIMEOUT_CODE,
REQUEST_TIMEOUT_MSG,
ERROR_STATUS,
ERROR_STATUS
} from '@/config';
import { exeStrategyActions } from '../common';
import { showErrorMsg } from './msg';
@ -21,7 +21,7 @@ export function handleAxiosError(axiosError: AxiosError) {
const error: Service.RequestError = {
type: 'axios',
code: DEFAULT_REQUEST_ERROR_CODE,
msg: DEFAULT_REQUEST_ERROR_MSG,
msg: DEFAULT_REQUEST_ERROR_MSG
};
const actions: Common.StrategyAction[] = [
@ -30,14 +30,14 @@ export function handleAxiosError(axiosError: AxiosError) {
!window.navigator.onLine || axiosError.message === 'Network Error',
() => {
Object.assign(error, { code: NETWORK_ERROR_CODE, msg: NETWORK_ERROR_MSG });
},
}
],
[
// 超时错误
axiosError.code === REQUEST_TIMEOUT_CODE && axiosError.message.includes('timeout'),
() => {
Object.assign(error, { code: REQUEST_TIMEOUT_CODE, msg: REQUEST_TIMEOUT_MSG });
},
}
],
[
// 请求不成功的错误
@ -46,8 +46,8 @@ export function handleAxiosError(axiosError: AxiosError) {
const errorCode: ErrorStatus = (axiosError.response?.status as ErrorStatus) || 'DEFAULT';
const msg = ERROR_STATUS[errorCode];
Object.assign(error, { code: errorCode, msg });
},
],
}
]
];
exeStrategyActions(actions);
@ -65,7 +65,7 @@ export function handleResponseError(response: AxiosResponse) {
const error: Service.RequestError = {
type: 'axios',
code: DEFAULT_REQUEST_ERROR_CODE,
msg: DEFAULT_REQUEST_ERROR_MSG,
msg: DEFAULT_REQUEST_ERROR_MSG
};
if (!window.navigator.onLine) {
@ -92,7 +92,7 @@ export function handleBackendError(backendResult: Record<string, any>, config: S
const error: Service.RequestError = {
type: 'backend',
code: backendResult[codeKey],
msg: backendResult[msgKey],
msg: backendResult[msgKey]
};
showErrorMsg(error);

View File

@ -3,13 +3,43 @@ export async function handleServiceResult<T = any>(error: Service.RequestError |
if (error) {
const fail: Service.FailedResult = {
error,
data: null,
data: null
};
return fail;
}
const success: Service.SuccessResult<T> = {
error: null,
data,
data
};
return success;
}
type Adapter<T = any> = (...args: Service.RequestResult[]) => T;
/**
* 请求结果的数据转换适配器
* @param adapter - 适配器函数
* @param args - 适配器函数的参数
*/
export function adapterOfServiceResult<T extends Adapter>(adapter: T, ...args: TypeUtil.GetFunArgs<T>) {
let result: Service.RequestResult | undefined;
const hasError = args.some(item => {
const flag = Boolean(item.error);
if (flag) {
result = {
error: item.error,
data: null
};
}
return flag;
});
if (!hasError) {
result = {
error: null,
data: adapter(...args)
};
}
return result as TypeUtil.GetFunReturn<T>;
}

View File

@ -34,7 +34,7 @@ async function transformFile(file: File[] | File, key: string) {
if (isArray(file)) {
// 多文件
await Promise.all(
(file as File[]).map((item) => {
(file as File[]).map(item => {
formData.append(key, item);
return true;
})