优化更新

This commit is contained in:
2026-09-14 09:44:33 +08:00
parent b3a9e21254
commit 5b8e178970
60 changed files with 1243 additions and 1022 deletions
@@ -208,17 +208,20 @@ transformRequestData: (res: AxiosResponse<Result>, options: RequestOptions) => {
// 业务失败(code === 1)
if (code === ResultEnum.ERROR) {
ElMessage.error(msg);
message.error(msg);
throw new Error(msg);
}
// 登录超时(code === 401)
if (code === ResultEnum.TIMEOUT) {
ElMessageBox.confirm('登录身份已失效,请重新登录!', '提示', { ... })
.then(() => {
Modal.confirm({
title: '提示',
content: '登录身份已失效,请重新登录!',
onOk: () => {
storage.clear();
window.location.href = '/login';
});
},
});
throw new Error(msg);
}
},
@@ -291,7 +294,7 @@ const loadDataTable = async (res: any) => {
const handleSubmit = async () => {
await formRef.value?.validate();
await positionAdd(formData);
message('操作成功');
message.success('操作成功');
emit('success');
};
```
@@ -304,20 +307,28 @@ const handleSubmit = async () => {
错误处理分两层:
1. **业务错误**(code !== 0):拦截器统一弹出 `ElMessage.error(msg)`,并 `throw new Error`
1. **业务错误**(code !== 0):拦截器统一弹出 `message.error(msg)`,并 `throw new Error`
2. **HTTP 错误**(网络异常、超时等):`responseInterceptorsCatch` 处理
```typescript
import { message, Modal } from 'ant-design-vue';
responseInterceptorsCatch: (error: any) => {
const { response, code } = error || {};
// 超时
if (code === 'ECONNABORTED') {
ElMessage.error('接口请求超时,请刷新页面重试!');
message.error('接口请求超时,请刷新页面重试!');
return;
}
// 网络异常
if (error.toString().includes('Network Error')) {
ElMessageBox.confirm('请检查您的网络连接是否正常', '网络异常', { ... });
Modal.confirm({
title: '网络异常',
content: '请检查您的网络连接是否正常',
onOk: () => {
// 处理确认操作
},
});
return Promise.reject(error);
}
// 其他 HTTP 状态码