Files
regulatory-management-system/code/web/regulatory-management-util/src/utils/api/request.ts
2025-12-25 23:37:43 +08:00

59 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @Author: Kane Wang <wangkane@qq.com>
* @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 };