|
@@ -14,10 +14,10 @@ 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实例
|
|
|
const service = axios.create({
|
|
const service = axios.create({
|
|
|
- baseURL: 'http://ruixuan.api.tjyourong.com.cn',
|
|
|
|
|
- // baseURL: 'http://rocket.api.tjyourong.com.cn',
|
|
|
|
|
- // baseURL: 'http://mgs.api.tjyourong.com.cn',
|
|
|
|
|
- // baseURL: 'http://127.0.0.1:9003',
|
|
|
|
|
|
|
+ baseURL: 'http://api.ruixuan.bjhcstszkj.cn',
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // baseURL: 'http://127.0.0.1:9003',
|
|
|
// 超时
|
|
// 超时
|
|
|
timeout: 300000
|
|
timeout: 300000
|
|
|
})
|
|
})
|
|
@@ -69,79 +69,67 @@ service.interceptors.request.use(config => {
|
|
|
|
|
|
|
|
// 响应拦截器
|
|
// 响应拦截器
|
|
|
service.interceptors.response.use(res => {
|
|
service.interceptors.response.use(res => {
|
|
|
- // 未设置状态码则默认成功状态
|
|
|
|
|
- const code = res.data.code || 200;
|
|
|
|
|
- // 获取错误信息
|
|
|
|
|
- const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
|
|
|
- // 二进制数据则直接返回
|
|
|
|
|
- if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
|
|
|
|
- return res.data
|
|
|
|
|
- }
|
|
|
|
|
- if (code === 401) {
|
|
|
|
|
- if (!isRelogin.show) {
|
|
|
|
|
- isRelogin.show = true;
|
|
|
|
|
- MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
|
|
|
|
- confirmButtonText: '重新登录',
|
|
|
|
|
- cancelButtonText: '取消',
|
|
|
|
|
- type: 'warning'
|
|
|
|
|
- }
|
|
|
|
|
- ).then(() => {
|
|
|
|
|
- isRelogin.show = false;
|
|
|
|
|
- store.dispatch('LogOut').then(() => {
|
|
|
|
|
- location.href = '/index';
|
|
|
|
|
- })
|
|
|
|
|
- }).catch(() => {
|
|
|
|
|
- isRelogin.show = false;
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
|
|
|
- } else if (code === 500 || code === -1) {
|
|
|
|
|
- Message({
|
|
|
|
|
- message: res.data.message || res.data.msg,
|
|
|
|
|
- type: 'error'
|
|
|
|
|
- })
|
|
|
|
|
- return Promise.reject(new Error(res.data.message || res.data.msg))
|
|
|
|
|
- } else if (code !== 200) {
|
|
|
|
|
- Notification.error({
|
|
|
|
|
- title: res.message
|
|
|
|
|
- })
|
|
|
|
|
- return Promise.reject('error')
|
|
|
|
|
- } else {
|
|
|
|
|
- return res.data
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- error => {
|
|
|
|
|
- console.log('err' + error)
|
|
|
|
|
- let {message} = error;
|
|
|
|
|
- if (message == "Network Error") {
|
|
|
|
|
- message = "后端接口连接异常";
|
|
|
|
|
- } else if (message.includes("timeout")) {
|
|
|
|
|
- message = "系统接口请求超时";
|
|
|
|
|
- } else if (message.includes("Request failed with status code")) {
|
|
|
|
|
- message = "系统接口" + message.substr(message.length - 3) + "异常";
|
|
|
|
|
|
|
+ // 未设置状态码则默认成功状态
|
|
|
|
|
+ const code = res.data.code || 200;
|
|
|
|
|
+ // 获取错误信息
|
|
|
|
|
+ const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
|
|
|
+ // 二进制数据则直接返回
|
|
|
|
|
+ if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
|
|
|
|
+ return res.data
|
|
|
|
|
+ }
|
|
|
|
|
+ if (code === 401) {
|
|
|
|
|
+ if (!isRelogin.show) {
|
|
|
|
|
+ isRelogin.show = true;
|
|
|
|
|
+ MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
|
|
|
|
+ confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning'
|
|
|
|
|
+ }).then(() => {
|
|
|
|
|
+ isRelogin.show = false;
|
|
|
|
|
+ store.dispatch('LogOut').then(() => {
|
|
|
|
|
+ location.href = '/index';
|
|
|
|
|
+ })
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ isRelogin.show = false;
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
+ return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
|
|
|
+ } else if (code === 500 || code === -1) {
|
|
|
Message({
|
|
Message({
|
|
|
- message: message,
|
|
|
|
|
- type: 'error',
|
|
|
|
|
- duration: 5 * 1000
|
|
|
|
|
|
|
+ message: res.data.message || res.data.msg, type: 'error'
|
|
|
|
|
+ })
|
|
|
|
|
+ return Promise.reject(new Error(res.data.message || res.data.msg))
|
|
|
|
|
+ } else if (code !== 200) {
|
|
|
|
|
+ Notification.error({
|
|
|
|
|
+ title: res.message
|
|
|
})
|
|
})
|
|
|
- return Promise.reject(error)
|
|
|
|
|
|
|
+ return Promise.reject('error')
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return res.data
|
|
|
|
|
+ }
|
|
|
|
|
+}, error => {
|
|
|
|
|
+ console.log('err' + error)
|
|
|
|
|
+ let {message} = error;
|
|
|
|
|
+ if (message == "Network Error") {
|
|
|
|
|
+ message = "后端接口连接异常";
|
|
|
|
|
+ } else if (message.includes("timeout")) {
|
|
|
|
|
+ message = "系统接口请求超时";
|
|
|
|
|
+ } else if (message.includes("Request failed with status code")) {
|
|
|
|
|
+ message = "系统接口" + message.substr(message.length - 3) + "异常";
|
|
|
}
|
|
}
|
|
|
-)
|
|
|
|
|
|
|
+ Message({
|
|
|
|
|
+ message: message, type: 'error', duration: 5 * 1000
|
|
|
|
|
+ })
|
|
|
|
|
+ return Promise.reject(error)
|
|
|
|
|
+})
|
|
|
|
|
|
|
|
// 通用下载方法
|
|
// 通用下载方法
|
|
|
export function download(url, params, filename) {
|
|
export function download(url, params, filename) {
|
|
|
downloadLoadingInstance = Loading.service({
|
|
downloadLoadingInstance = Loading.service({
|
|
|
- text: "正在下载数据,请稍候",
|
|
|
|
|
- spinner: "el-icon-loading",
|
|
|
|
|
- background: "rgba(0, 0, 0, 0.7)",
|
|
|
|
|
|
|
+ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)",
|
|
|
})
|
|
})
|
|
|
return service.post(url, params, {
|
|
return service.post(url, params, {
|
|
|
transformRequest: [(params) => {
|
|
transformRequest: [(params) => {
|
|
|
return tansParams(params)
|
|
return tansParams(params)
|
|
|
- }],
|
|
|
|
|
- headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
|
|
|
|
- responseType: 'blob'
|
|
|
|
|
|
|
+ }], headers: {'Content-Type': 'application/x-www-form-urlencoded'}, responseType: 'blob'
|
|
|
}).then(async (data) => {
|
|
}).then(async (data) => {
|
|
|
const isLogin = await blobValidate(data);
|
|
const isLogin = await blobValidate(data);
|
|
|
if (isLogin) {
|
|
if (isLogin) {
|