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 10:00:13 +08:00
|
|
|
const token = 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOjE5ODU1OTk2NjUxNDk4NjE4OTAsImFjY291bnQiOiJyZWd1bGFyQWRtaW4iLCJ1dWlkIjoiNDI2MjNkMGUtZGRjYy00NzllLTgxZTQtMWRmYTBhMWQyZTc1IiwicmVtZW1iZXJNZSI6dHJ1ZSwiZXhwaXJhdGlvbkRhdGUiOjE3NjI3NjY5NzM4NjgsIm90aGVycyI6bnVsbCwic3ViIjoiMTk4NTU5OTY2NTE0OTg2MTg5MCIsImlhdCI6MTc2MjczODE3MywiZXhwIjoxNzYyNzY2OTczfQ._Fv2MpHjv5BubzjEwp6SPEol4P5wBGXONrG1oEGApXjNiJU5WkgvuPWmaruaimNIyvnrMKtZO8yMBoGrHqIHqQ'
|
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
|
|
|
}
|
|
|
|
|
}
|