|
@@ -1,15 +1,15 @@
|
|
|
import axios from 'axios';
|
|
|
import { useUserStore } from '@/stores/modules/userStore';
|
|
|
-// import { createDiscreteApi } from 'naive-ui';
|
|
|
+import { createDiscreteApi } from 'naive-ui';
|
|
|
|
|
|
import { tansParams } from "@/utils/tools";
|
|
|
|
|
|
import type { Result } from '@/types/data';
|
|
|
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, AxiosError } from 'axios';
|
|
|
|
|
|
-// import type { NotificationApi } from "naive-ui";
|
|
|
+import type { NotificationApi } from "naive-ui";
|
|
|
|
|
|
-// const { notification } = createDiscreteApi(["notification"]);
|
|
|
+const { notification } = createDiscreteApi(["notification"]);
|
|
|
|
|
|
const useStore = useUserStore();
|
|
|
|
|
@@ -32,14 +32,14 @@ enum errorCode {
|
|
|
'HTTP版本不受支持' = 505
|
|
|
}
|
|
|
|
|
|
-// const showNotification = (type: keyof NotificationApi = 'error', meta: string) => {
|
|
|
-// notification[type]({
|
|
|
-// content: '提示',
|
|
|
-// meta,
|
|
|
-// duration: 3 * 1000,
|
|
|
-// keepAliveOnHover: true
|
|
|
-// })
|
|
|
-// }
|
|
|
+const showNotification = (type: keyof NotificationApi = 'error', meta: string) => {
|
|
|
+ notification[type]({
|
|
|
+ content: '提示',
|
|
|
+ meta,
|
|
|
+ duration: 3 * 1000,
|
|
|
+ keepAliveOnHover: true
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
export class Request {
|
|
|
|
|
@@ -73,10 +73,10 @@ export class Request {
|
|
|
// !success && showNotification("error", message);
|
|
|
return code === 200 ? res.data : Promise.reject(res.data);
|
|
|
}, (error: AxiosError) => {
|
|
|
- const errorMessage = errorCode[error.response?.status as number] || '未知错误';
|
|
|
- // showNotification("error", errorMessage);
|
|
|
- console.log("error", error);
|
|
|
- return error;
|
|
|
+ console.log(error);
|
|
|
+ const errorMessage = errorCode[error.response?.status as number] || error.message ||'未知错误';
|
|
|
+ showNotification("error", errorMessage);
|
|
|
+ return Promise.reject(error);
|
|
|
})
|
|
|
}
|
|
|
|