2025-10-30 16:34:29 +08:00
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
|
|
const service = axios.create({
|
|
|
|
|
baseURL: '',
|
|
|
|
|
timeout: 10000
|
|
|
|
|
})
|
|
|
|
|
|
2025-11-07 17:27:41 +08:00
|
|
|
// 请求拦截器
|
|
|
|
|
service.interceptors.request.use(config => {
|
|
|
|
|
// 暂时先写死token 实际项目中再调整token的获取位置
|
2025-11-10 16:52:03 +08:00
|
|
|
const token = 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOjE5ODY2ODgzMjY1MjAwNTc4NTcsImFjY291bnQiOiJieHp0IiwidXVpZCI6ImMyY2E5OGU4LTIyYzItNGZmZi1hZWE0LTBiNWNiZmE4YjNlMSIsInJlbWVtYmVyTWUiOnRydWUsImV4cGlyYXRpb25EYXRlIjoxNzYyNzgzOTkwMzUxLCJvdGhlcnMiOm51bGwsInN1YiI6IjE5ODY2ODgzMjY1MjAwNTc4NTciLCJpYXQiOjE3NjI3NTUxOTAsImV4cCI6MTc2Mjc4Mzk5MH0.zqQcAE08fr2jQd7HcQ9Y3i-gWb2TrCWuUxSzl1kXOoJe2rp1Yly0ffrY6_1jY0ybHJwihONChqiSc-8jRTKYKw'
|
2025-11-07 17:27:41 +08:00
|
|
|
// const token = localStorage.getItem('token');
|
|
|
|
|
if (token) {
|
|
|
|
|
config.headers.Authorization = `${token}`;
|
|
|
|
|
}
|
|
|
|
|
return config;
|
|
|
|
|
}, error => {
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-30 16:34:29 +08:00
|
|
|
export async function request(config) {
|
2025-10-31 16:16:56 +08:00
|
|
|
try {
|
|
|
|
|
const res = await service(config)
|
|
|
|
|
if (res === null || res === undefined) {
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
if (Object.prototype.hasOwnProperty.call(res, 'data')) {
|
|
|
|
|
return res.data
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error)
|
|
|
|
|
return null
|
2025-10-30 16:34:29 +08:00
|
|
|
}
|
|
|
|
|
}
|