if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) {
const message = 'The request is in processing, please do not repeat the same request.';
console.warn(`[${s\_url}]: ${message}`);
return Promise.reject(new Error(message));
}
cache.session.setJSON('sessionObj', requestObj);
}
}
return config;
},
(error) => {
console.log(error);
Promise.reject(error);
},
);
// 响应拦截器
service.interceptors.response.use(
(res) => {
// 二进制数据则直接返回
if (res.request.responseType === ‘blob’ || res.request.responseType === ‘arraybuffer’) {
return res.data;
} else {
if (res.data.state === ‘S’) {
return Promise.resolve(res.data.payload);
} else {
//{“state”:“F”,“errorCode”:5001,“error”:“User is not exists!”}
// 未设置状态码则默认成功状态
const code = res.data.errorCode;
// 获取错误信息
const msg = res.data.error;
if (code == 4004 || code == 4005 || code == 4006 || code == 4007) {
if (!isReLogin.show) {
isReLogin.show = true;
ElMessageBox.confirm(‘Login state has been expired, Please re-login!’, ‘System Info’, {
confirmButtonText: ‘Re-Login’,
cancelButtonText: ‘Cancel’,
type: ‘warning’,
})
.then(() => {
isReLogin.show = false;
store.dispatch(‘LogOut’).then(() => {
location.href = import.meta.env.BASE_URL;
});
})
.catch(() => {
isReLogin.show = false;
});
}
return Promise.reject(‘Please re-login!’);
} else {
ElNotification.error({
title: msg,
});
return Promise.reject(‘error’);
}
}
}
return Promise.resolve(res.data.payload);
},
(error) => {
console.log(err${error}
);
let { message } = error;
ElMessage({
message,
type: ‘error’,
duration: 5 * 1000,
});
return Promise.reject(error);
},
);
// 通用下载方法
export function download(url, params, filename) {
downloadLoadingInstance = ElLoading.service({ text: ‘正在下载数据,请稍候’, background: ‘rgba(0, 0, 0, 0.7)’ });
return service
.post(url, params, {
transformRequest: [(params) => encodeURIParams(params)],
headers: { ‘Content-Type’: ‘application/x-www-form-urlencoded’ },
responseType: ‘blob’,
})
.then(async (data) => {
const isLogin = await isBlobData(data);
if (isLogin) {
const blob = new Blob([data]);
saveAs(blob, filename);
} else {
const resText = await data.text();
const rspObj = JSON.parse(resText);
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode.default;
ElMessage.error(errMsg);
}
downloadLoadingInstance.close();
})
.catch(® => {
console.error®;
ElMessage.error(‘下载文件出现错误,请联系管理员!’);
downloadLoadingInstance.close();
});
}
export default service;
### api
import request from ‘@/utils/request’;
export function addAccountSettingsSubscribeType(data) {
return request({
url: ‘/dic/common/accountSettingsSubscribeType’,
method: ‘post’,
data
});
}
export function removeAccountSettingsSubscribeType(data) {
return request({
url: /dic/common/accountSettingsSubscribeType
,
method: ‘delete’,
data
});
}
export function updateAccountSettingsSubscribeType(data) {
return request({
url: /dic/common/accountSettingsSubscribeType/
+ data.id,
method: ‘put’,
data,
});
}
export function getAccountSettingsSubscribeType(data) {
return request({
url: /dic/common/accountSettingsSubscribeType/
+ data,
method: ‘get’
});
}
export function getAccountSettingsSubscribeTypeList(data) {
return request({
url: ‘/dic/common/accountSettingsSubscribeType/findPage’ + data,
method: ‘get’,
data
});
}
### 功能管理