diff --git a/code/web/regulatory-management-util/src/utils/api/request.ts b/code/web/regulatory-management-util/src/utils/api/request.ts new file mode 100644 index 0000000..9d64109 --- /dev/null +++ b/code/web/regulatory-management-util/src/utils/api/request.ts @@ -0,0 +1,59 @@ +/** + * @Author: Kane Wang + * @Date: 2025-12-18 10:02:42 + * @LastEditors: Kane Wang + * @LastModified: 2025-12-25 18:01:56 + * @FilePath: src/utils/api/request.ts + * @Description: + * + * Copyright (c) 2025 by Kane All rights reserved + */ +import axios, {type AxiosInstance } from "axios"; + +const service: AxiosInstance = axios.create( + { + baseURL: "", + timeout: 30000, + } +); +// #region 1111 +// #endregion + +// 请求拦截 +service.interceptors.request.use( + /** + * 请求拦截器,config对象用于给开发人员配置请求 + * @param config 配置对象,在配置中加入需要的token + * @returns 返回配置好的config + */ + ( config ) => + { + config.headers.token = "123"; + + return config; + }, + async ( error: any ) => + { + console.log( `配置请求拦截器错误:${error}` ); + + return await Promise.reject( error ); + } +); + +/** + * 响应拦截器 + */ +service.interceptors.response.use( + ( response ) => + { + return response; + }, + async ( error ) => + { + console.log( `配置响应拦截器失败:${error}` ); + + return await Promise.reject( error ); + } +); + +export { service }; \ No newline at end of file