|
@@ -1,15 +1,29 @@
|
|
-import axios from 'axios'
|
|
|
|
-import { Notification, MessageBox, Message, Loading } from 'element-ui'
|
|
|
|
|
|
+import cache from '@/plugins/cache'
|
|
import store from '@/store'
|
|
import store from '@/store'
|
|
-import { getToken } from '@/utils/auth'
|
|
|
|
|
|
+import {
|
|
|
|
+ getToken
|
|
|
|
+} from '@/utils/auth'
|
|
import errorCode from '@/utils/errorCode'
|
|
import errorCode from '@/utils/errorCode'
|
|
-import { tansParams, blobValidate } from "@/utils/ruoyi";
|
|
|
|
-import cache from '@/plugins/cache'
|
|
|
|
-import { saveAs } from 'file-saver'
|
|
|
|
|
|
+import {
|
|
|
|
+ blobValidate,
|
|
|
|
+ tansParams
|
|
|
|
+} from "@/utils/ruoyi"
|
|
|
|
+import axios from 'axios'
|
|
|
|
+import {
|
|
|
|
+ Loading,
|
|
|
|
+ Message,
|
|
|
|
+ MessageBox,
|
|
|
|
+ Notification
|
|
|
|
+} from 'element-ui'
|
|
|
|
+import {
|
|
|
|
+ saveAs
|
|
|
|
+} from 'file-saver'
|
|
|
|
|
|
let downloadLoadingInstance;
|
|
let downloadLoadingInstance;
|
|
// 是否显示重新登录
|
|
// 是否显示重新登录
|
|
-export let isRelogin = { show: false };
|
|
|
|
|
|
+export let isRelogin = {
|
|
|
|
+ show: false
|
|
|
|
+};
|
|
|
|
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
// 创建axios实例
|
|
// 创建axios实例
|
|
@@ -46,10 +60,10 @@ service.interceptors.request.use(config => {
|
|
if (sessionObj === undefined || sessionObj === null || sessionObj === '') {
|
|
if (sessionObj === undefined || sessionObj === null || sessionObj === '') {
|
|
cache.session.setJSON('sessionObj', requestObj)
|
|
cache.session.setJSON('sessionObj', requestObj)
|
|
} else {
|
|
} else {
|
|
- const s_url = sessionObj.url; // 请求地址
|
|
|
|
- const s_data = sessionObj.data; // 请求数据
|
|
|
|
- const s_time = sessionObj.time; // 请求时间
|
|
|
|
- const interval = 1000; // 间隔时间(ms),小于此时间视为重复提交
|
|
|
|
|
|
+ const s_url = sessionObj.url; // 请求地址
|
|
|
|
+ const s_data = sessionObj.data; // 请求数据
|
|
|
|
+ const s_time = sessionObj.time; // 请求时间
|
|
|
|
+ const interval = 1000; // 间隔时间(ms),小于此时间视为重复提交
|
|
if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) {
|
|
if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) {
|
|
const message = '数据正在处理,请勿重复提交';
|
|
const message = '数据正在处理,请勿重复提交';
|
|
console.warn(`[${s_url}]: ` + message)
|
|
console.warn(`[${s_url}]: ` + message)
|
|
@@ -61,8 +75,8 @@ service.interceptors.request.use(config => {
|
|
}
|
|
}
|
|
return config
|
|
return config
|
|
}, error => {
|
|
}, error => {
|
|
- console.log(error)
|
|
|
|
- Promise.reject(error)
|
|
|
|
|
|
+ console.log(error)
|
|
|
|
+ Promise.reject(error)
|
|
})
|
|
})
|
|
|
|
|
|
// 响应拦截器
|
|
// 响应拦截器
|
|
@@ -71,8 +85,9 @@ service.interceptors.response.use(res => {
|
|
const code = res.data.code || 200;
|
|
const code = res.data.code || 200;
|
|
// 获取错误信息
|
|
// 获取错误信息
|
|
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
|
|
+
|
|
// 二进制数据则直接返回
|
|
// 二进制数据则直接返回
|
|
- if(res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer'){
|
|
|
|
|
|
+ if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
|
return res.data
|
|
return res.data
|
|
}
|
|
}
|
|
if (code === 401) {
|
|
if (code === 401) {
|
|
@@ -82,16 +97,15 @@ service.interceptors.response.use(res => {
|
|
confirmButtonText: '重新登录',
|
|
confirmButtonText: '重新登录',
|
|
cancelButtonText: '取消',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
type: 'warning'
|
|
- }
|
|
|
|
- ).then(() => {
|
|
|
|
- isRelogin.show = false;
|
|
|
|
- store.dispatch('LogOut').then(() => {
|
|
|
|
- location.href = '/index';
|
|
|
|
- })
|
|
|
|
- }).catch(() => {
|
|
|
|
- isRelogin.show = false;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
+ }).then(() => {
|
|
|
|
+ isRelogin.show = false;
|
|
|
|
+ store.dispatch('LogOut').then(() => {
|
|
|
|
+ location.href = '/index';
|
|
|
|
+ })
|
|
|
|
+ }).catch(() => {
|
|
|
|
+ isRelogin.show = false;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
} else if (code === 500) {
|
|
} else if (code === 500) {
|
|
Message({
|
|
Message({
|
|
@@ -110,14 +124,15 @@ service.interceptors.response.use(res => {
|
|
},
|
|
},
|
|
error => {
|
|
error => {
|
|
console.log('err' + error)
|
|
console.log('err' + error)
|
|
- let { message } = error;
|
|
|
|
|
|
+ let {
|
|
|
|
+ message
|
|
|
|
+ } = error;
|
|
|
|
+
|
|
if (message == "Network Error") {
|
|
if (message == "Network Error") {
|
|
message = "后端接口连接异常";
|
|
message = "后端接口连接异常";
|
|
- }
|
|
|
|
- else if (message.includes("timeout")) {
|
|
|
|
|
|
+ } else if (message.includes("timeout")) {
|
|
message = "系统接口请求超时";
|
|
message = "系统接口请求超时";
|
|
- }
|
|
|
|
- else if (message.includes("Request failed with status code")) {
|
|
|
|
|
|
+ } else if (message.includes("Request failed with status code")) {
|
|
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
|
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
|
}
|
|
}
|
|
Message({
|
|
Message({
|
|
@@ -131,10 +146,18 @@ service.interceptors.response.use(res => {
|
|
|
|
|
|
// 通用下载方法
|
|
// 通用下载方法
|
|
export function download(url, params, filename) {
|
|
export function download(url, params, filename) {
|
|
- downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", })
|
|
|
|
|
|
+ downloadLoadingInstance = Loading.service({
|
|
|
|
+ text: "正在下载数据,请稍候",
|
|
|
|
+ spinner: "el-icon-loading",
|
|
|
|
+ background: "rgba(0, 0, 0, 0.7)",
|
|
|
|
+ })
|
|
return service.post(url, params, {
|
|
return service.post(url, params, {
|
|
- transformRequest: [(params) => { return tansParams(params) }],
|
|
|
|
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
|
|
+ transformRequest: [(params) => {
|
|
|
|
+ return tansParams(params)
|
|
|
|
+ }],
|
|
|
|
+ headers: {
|
|
|
|
+ 'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
+ },
|
|
responseType: 'blob'
|
|
responseType: 'blob'
|
|
}).then(async (data) => {
|
|
}).then(async (data) => {
|
|
const isLogin = await blobValidate(data);
|
|
const isLogin = await blobValidate(data);
|