|
|
@ -1,11 +1,12 @@ |
|
|
import axios from 'axios' |
|
|
import axios from 'axios' |
|
|
import { Notification, MessageBox, Message, Loading } from 'element-ui' |
|
|
|
|
|
|
|
|
import { Notification, MessageBox, Message, Loading, Dialog } from 'element-ui' |
|
|
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 { tansParams, blobValidate } from '@/utils/ruoyi' |
|
|
import cache from '@/plugins/cache' |
|
|
import cache from '@/plugins/cache' |
|
|
import { saveAs } from 'file-saver' |
|
|
import { saveAs } from 'file-saver' |
|
|
|
|
|
import i18n from '@/lang' |
|
|
|
|
|
|
|
|
let downloadLoadingInstance |
|
|
let downloadLoadingInstance |
|
|
// 是否显示重新登录
|
|
|
// 是否显示重新登录
|
|
|
@ -106,25 +107,118 @@ service.interceptors.response.use( |
|
|
return res.data |
|
|
return res.data |
|
|
} |
|
|
} |
|
|
if (code === 401) { |
|
|
if (code === 401) { |
|
|
|
|
|
store.dispatch('LogOut').then(() => { |
|
|
|
|
|
// location.href = '/user/work'
|
|
|
|
|
|
}) |
|
|
if (!isRelogin.show) { |
|
|
if (!isRelogin.show) { |
|
|
isRelogin.show = true |
|
|
isRelogin.show = true |
|
|
MessageBox.confirm( |
|
|
|
|
|
'登录状态已过期,您可以继续留在该页面,或者重新登录', |
|
|
|
|
|
'系统提示', |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MessageBox.confirm(
|
|
|
|
|
|
// '登录状态已过期,您可以继续留在该页面,或者重新登录',
|
|
|
|
|
|
// '系统提示',
|
|
|
|
|
|
// {
|
|
|
|
|
|
// confirmButtonText: '重新登录',
|
|
|
|
|
|
// cancelButtonText: '取消',
|
|
|
|
|
|
// type: 'warning'
|
|
|
|
|
|
// }
|
|
|
|
|
|
// )
|
|
|
|
|
|
// .then(() => {
|
|
|
|
|
|
// isRelogin.show = false
|
|
|
|
|
|
// store.dispatch('LogOut').then(() => {
|
|
|
|
|
|
// location.href = '/user/work'
|
|
|
|
|
|
// })
|
|
|
|
|
|
// })
|
|
|
|
|
|
// .catch(() => {
|
|
|
|
|
|
// isRelogin.show = false
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
MessageBox.prompt( |
|
|
|
|
|
'登录状态已过期,您可以输入密码进入页面,或者取消', |
|
|
|
|
|
'提示', |
|
|
{ |
|
|
{ |
|
|
confirmButtonText: '重新登录', |
|
|
|
|
|
|
|
|
confirmButtonText: '进入页面', |
|
|
cancelButtonText: '取消', |
|
|
cancelButtonText: '取消', |
|
|
type: 'warning' |
|
|
|
|
|
|
|
|
inputPattern: /^\S+$/, |
|
|
|
|
|
inputErrorMessage: '请输入密码', |
|
|
|
|
|
showClose: false, |
|
|
|
|
|
closeOnPressEscape: false, |
|
|
|
|
|
closeOnClickModal: false, |
|
|
|
|
|
beforeClose: (action, instance, done) => { |
|
|
|
|
|
if (action === 'confirm') { |
|
|
|
|
|
let password = instance.inputValue |
|
|
|
|
|
store |
|
|
|
|
|
.dispatch('Login', { |
|
|
|
|
|
username: store.getters.name, |
|
|
|
|
|
password: password, |
|
|
|
|
|
force: false |
|
|
|
|
|
}) |
|
|
|
|
|
.then(() => { |
|
|
|
|
|
console.log('重新登录成功') |
|
|
|
|
|
isRelogin.show = false |
|
|
|
|
|
done() |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((err) => { |
|
|
|
|
|
if (err && err.message === 'exists') { |
|
|
|
|
|
isRelogin.show = false |
|
|
|
|
|
done() |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
MessageBox.confirm( |
|
|
|
|
|
i18n.t('system.crowdOut'), |
|
|
|
|
|
i18n.t('system.tip'), |
|
|
|
|
|
{ |
|
|
|
|
|
confirmButtonText: i18n.t('form.confirm'), |
|
|
|
|
|
cancelButtonText: i18n.t('form.cancel'), |
|
|
|
|
|
type: 'warning', |
|
|
|
|
|
showClose: false, |
|
|
|
|
|
closeOnPressEscape: false, |
|
|
|
|
|
closeOnClickModal: false |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
.then(() => { |
|
|
|
|
|
store |
|
|
|
|
|
.dispatch('Login', { |
|
|
|
|
|
username: store.getters.name, |
|
|
|
|
|
password: password, |
|
|
|
|
|
force: true |
|
|
|
|
|
}) |
|
|
|
|
|
.then(() => { |
|
|
|
|
|
console.log('重新登录成功') |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((err) => { |
|
|
|
|
|
console.log( |
|
|
|
|
|
'重新登录失败' + JSON.stringify(err) |
|
|
|
|
|
) |
|
|
|
|
|
return false |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(() => { |
|
|
|
|
|
// if (this.captchaEnabled) {
|
|
|
|
|
|
// this.getCode()
|
|
|
|
|
|
// }
|
|
|
|
|
|
location.href = '/user/work' |
|
|
|
|
|
}) |
|
|
|
|
|
}, 0) |
|
|
|
|
|
} else { |
|
|
|
|
|
// if (this.captchaEnabled) {
|
|
|
|
|
|
// this.getCode()
|
|
|
|
|
|
// }
|
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
done() |
|
|
|
|
|
isRelogin.show = false |
|
|
|
|
|
location.href = '/user/work' |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
.then(() => { |
|
|
|
|
|
|
|
|
.then(({ value }) => { |
|
|
isRelogin.show = false |
|
|
isRelogin.show = false |
|
|
store.dispatch('LogOut').then(() => { |
|
|
|
|
|
location.href = '/user/work' |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
}) |
|
|
.catch(() => { |
|
|
.catch(() => { |
|
|
isRelogin.show = false |
|
|
isRelogin.show = false |
|
|
|
|
|
location.href = '/user/work' |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
return Promise.reject('无效的会话,或者会话已过期,请重新登录。') |
|
|
return Promise.reject('无效的会话,或者会话已过期,请重新登录。') |
|
|
@ -158,6 +252,35 @@ service.interceptors.response.use( |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
export function login(username, password, force) { |
|
|
|
|
|
store |
|
|
|
|
|
.dispatch('Login', { username: username, password: password, force: force }) |
|
|
|
|
|
.then(() => { |
|
|
|
|
|
console.log('重新登录成功') |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((err) => { |
|
|
|
|
|
if (err && err.message === 'exists') { |
|
|
|
|
|
MessageBox.confirm(i18n.t('system.crowdOut'), i18n.t('system.tip'), { |
|
|
|
|
|
confirmButtonText: i18n.t('form.confirm'), |
|
|
|
|
|
cancelButtonText: i18n.t('form.cancel'), |
|
|
|
|
|
type: 'warning' |
|
|
|
|
|
}) |
|
|
|
|
|
.then(() => { |
|
|
|
|
|
login(username, password, true) |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(() => { |
|
|
|
|
|
// if (this.captchaEnabled) {
|
|
|
|
|
|
// this.getCode()
|
|
|
|
|
|
// }
|
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
// if (this.captchaEnabled) {
|
|
|
|
|
|
// this.getCode()
|
|
|
|
|
|
// }
|
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 通用下载方法
|
|
|
// 通用下载方法
|
|
|
export function download(url, params, filename, config) { |
|
|
export function download(url, params, filename, config) { |
|
|
downloadLoadingInstance = Loading.service({ |
|
|
downloadLoadingInstance = Loading.service({ |
|
|
|