榆钱落尽槿花稀 d6012c7cf4 1.入会流程字段同步
2.入会表单验证
3.国家数据接口对接
4.入会表单提交接口对接,问题处理
5.回显查询详情接口对接,问题处理
2025-04-21 18:08:16 +08:00

71 lines
1.7 KiB
TypeScript

import axios from 'axios';
import store from '../store';
//const API_HOST = env === 'mock' ? '/' : proxy[env].API; // 如果是mock模式 就不配置host 会走本地Mock拦截
//const API_HOST = 'https://hnyea.0rui.cn/api/';
const API_HOST = '/api/';
const CODE = {
LOGIN_TIMEOUT: 1000000,
REQUEST_SUCCESS: 0,
REQUEST_FOBID: 1001,
};
const instance = axios.create({
baseURL: API_HOST,
timeout: 10000,
withCredentials: true,
});
// eslint-disable-next-line
// @ts-ignore
// axios的retry ts类型有问题
instance.interceptors.retry = 3;
instance.interceptors.request.use((config) => {
// 在原有配置基础上添加新参数
if (store.state.user.association) {
if (typeof store.state.user.association == 'object') {
var association = store.state.user.association;
} else {
var association = JSON.parse(store.state.user.association);
}
const token = store.state.user.token;
if (token) {
// 添加token请求头
config.headers.token = token;
}
config.data = { ...config.data, association_id: 1 };
}
return config;
});
instance.interceptors.response.use(
(response) => {
const { data } = response;
console.log(data);
return data;
},
(err) => {
const { config } = err;
if (!config || !config.retry) return Promise.reject(err);
config.retryCount = config.retryCount || 0;
if (config.retryCount >= config.retry) {
return Promise.reject(err);
}
config.retryCount += 1;
const backoff = new Promise((resolve) => {
setTimeout(() => {
resolve({});
}, config.retryDelay || 1);
});
return backoff.then(() => instance(config));
},
);
export default instance;