新增数据,开始安全巡检模块
This commit is contained in:
@@ -35,6 +35,15 @@ const service = axios.create({
|
||||
}
|
||||
});
|
||||
|
||||
// 不需要小区id 或者 加上小区id报错的接口地址
|
||||
const whiteVillageId = ['/decoration/list', '/parking/list'];
|
||||
function handleWhiteVillageid(url) {
|
||||
const spliturl = url.split('?')[0];
|
||||
if (whiteVillageId.includes(spliturl)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// 请求拦截器
|
||||
service.interceptors.request.use(
|
||||
(config: InternalAxiosRequestConfig) => {
|
||||
@@ -51,17 +60,41 @@ service.interceptors.request.use(
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||
}
|
||||
// get请求映射params参数
|
||||
const villageid = localStorage.getItem('villageid');
|
||||
if (config.method === 'get' && config.params) {
|
||||
let url = config.url + '?' + tansParams(config.params);
|
||||
let url = '';
|
||||
if (villageid != 'null' && !Number.isNaN(Number(villageid)) && handleWhiteVillageid(config.url)) {
|
||||
url =
|
||||
config.url +
|
||||
'?' +
|
||||
tansParams({
|
||||
...config.params,
|
||||
villageId: Number(villageid)
|
||||
});
|
||||
} else {
|
||||
url = config.url + '?' + tansParams(config.params);
|
||||
}
|
||||
url = url.slice(0, -1);
|
||||
config.params = {};
|
||||
config.url = url;
|
||||
}
|
||||
|
||||
if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
|
||||
let obj = null;
|
||||
if (villageid != 'null' && !Number.isNaN(Number(villageid)) && handleWhiteVillageid(config.url)) {
|
||||
obj = {
|
||||
...config.data,
|
||||
villageId: Number(villageid)
|
||||
};
|
||||
} else {
|
||||
obj = config.data;
|
||||
}
|
||||
if (!config.data) config.data = {};
|
||||
Object.assign(config.data, obj);
|
||||
|
||||
const requestObj = {
|
||||
url: config.url,
|
||||
data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
|
||||
data: typeof obj === 'object' ? JSON.stringify(obj) : obj,
|
||||
time: new Date().getTime()
|
||||
};
|
||||
const sessionObj = cache.session.getJSON('sessionObj');
|
||||
@@ -128,6 +161,7 @@ service.interceptors.response.use(
|
||||
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
if (code === 401) {
|
||||
// prettier-ignore
|
||||
if (!isRelogin.show) {
|
||||
@@ -151,12 +185,15 @@ service.interceptors.response.use(
|
||||
});
|
||||
}
|
||||
return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
|
||||
// 500
|
||||
} else if (code === HttpStatus.SERVER_ERROR) {
|
||||
// 500
|
||||
console.log(res);
|
||||
|
||||
console.log(res.config.url.split('?')[0]);
|
||||
ElMessage({ message: msg, type: 'error' });
|
||||
return Promise.reject(res.data);
|
||||
// 601
|
||||
} else if (code === HttpStatus.WARN) {
|
||||
// 601
|
||||
ElMessage({ message: msg, type: 'warning' });
|
||||
return Promise.reject(new Error(msg));
|
||||
} else if (code !== HttpStatus.SUCCESS) {
|
||||
|
||||
Reference in New Issue
Block a user