重构(学习页): 前端仅展示并修复运行稳定性问题

This commit is contained in:
2026-04-12 10:36:59 +08:00
parent 4c73991d64
commit 0f2f0460df
3 changed files with 60 additions and 45 deletions
+11 -2
View File
@@ -11,10 +11,19 @@ const axiosInstance = axios.create({
const handleError = (error: any) => {
console.log(error);
// 业务异常由 validateResponse 负责提示,这里透传,避免被网络错误文案覆盖。
if (error && typeof error === "object" && "code" in error) {
return Promise.reject(error);
}
if (error.response) {
ElMessage.error(`请求失败,服务器返回: ${error.response.data}`);
const backendMessage = error.response?.data?.message || JSON.stringify(error.response?.data);
ElMessage.error(`请求失败,服务器返回: ${backendMessage}`);
} else if (error.request) {
ElMessage.error("请求未收到响应,请检查接口运行状态");
} else {
ElMessage.error(error.message || "请求失败");
}
throw new Error("网络不通畅,请检查您的网络连接或服务器状态");
};
@@ -61,7 +70,7 @@ const put = (url: string, data: any, config: any = {}) => {
.catch(handleError);
};
const del = (url: string, params: {}, config: any = {}) => {
const del = (url: string, params: Record<string, any> = {}, config: any = {}) => {
console.log("开始DELETE请求", basic_url + url, "参数:", params);
return axiosInstance.delete(url, { params, ...config })
.then(validateResponse)