接口错误返回多次弹窗问题
parent
e8ddecfc68
commit
1b66fd6573
|
@ -7,10 +7,11 @@ export function login(data) {
|
|||
data
|
||||
})
|
||||
}
|
||||
export function loginOut() {
|
||||
export function loginOut(params) {
|
||||
return request({
|
||||
url: `/User/loginOut`,
|
||||
method: 'get'
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
export function getAllDictionary() {
|
||||
|
|
|
@ -181,8 +181,10 @@ const actions = {
|
|||
// user logout
|
||||
async logout({ commit, state }) {
|
||||
try {
|
||||
await loginOut()
|
||||
removeToken() // must remove token first
|
||||
await loginOut({
|
||||
Userd: zzSessionStorage.getItem('userId')
|
||||
})
|
||||
resetRouter()
|
||||
removeName()
|
||||
zzSessionStorage.clear()
|
||||
|
|
|
@ -49,13 +49,13 @@ service.interceptors.request.use(
|
|||
}
|
||||
)
|
||||
|
||||
var isConfirm = true
|
||||
let timer = null;
|
||||
let time = 1000;
|
||||
|
||||
service.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data
|
||||
if (res.IsSuccess) {
|
||||
isConfirm = true
|
||||
return Promise.resolve(res)
|
||||
} else if (res.IsSuccess === false) {
|
||||
if (res.Code !== 5) {
|
||||
|
@ -105,11 +105,11 @@ service.interceptors.response.use(
|
|||
if (error.response.status === 401) {
|
||||
if (store.getters.token) {
|
||||
if (message !== '') {
|
||||
Message({
|
||||
setTimer({
|
||||
message: message,
|
||||
type: 'warning',
|
||||
showClose: true
|
||||
})
|
||||
}, 'message')
|
||||
}
|
||||
store.dispatch('user/logout').then(() => {
|
||||
router.push(`/login`)
|
||||
|
@ -118,34 +118,52 @@ service.interceptors.response.use(
|
|||
this.$updateDictionary()
|
||||
})
|
||||
} else {
|
||||
Message({
|
||||
setTimer({
|
||||
message: store.state.lang.language === 'en' ? 'You are not authorized to access the interface' : '您无权访问接口',
|
||||
type: 'warning',
|
||||
showClose: true
|
||||
})
|
||||
}, 'message')
|
||||
}
|
||||
} else {
|
||||
if(message !== '' && isConfirm){
|
||||
MessageBox.confirm(message, store.state.lang.language === 'en'? 'Warning' : '警告', {
|
||||
if (message !== '') {
|
||||
setTimer([message, store.state.lang.language === 'en' ? 'Warning' : '警告', {
|
||||
type: 'warning',
|
||||
showCancelButton: false,
|
||||
callback: action => { }
|
||||
})
|
||||
}], 'confirm')
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!window.navigator.onLine && isConfirm) {
|
||||
MessageBox.confirm(store.state.lang.language === 'en'? 'Please check your network,and try again later!' : '请检查网络,稍后重试!', store.state.lang.language === 'en'? 'Warning' : '警告', {
|
||||
if (!window.navigator.onLine) {
|
||||
setTimer(
|
||||
[store.state.lang.language === 'en' ? 'Please check your network,and try again later!' : '请检查网络,稍后重试!', store.state.lang.language === 'en' ? 'Warning' : '警告', {
|
||||
type: 'warning',
|
||||
showCancelButton: false,
|
||||
callback: action => { }
|
||||
})
|
||||
isConfirm = false
|
||||
}], "confirm"
|
||||
)
|
||||
}
|
||||
return Promise.reject(new Error(message || 'Error'))
|
||||
}
|
||||
)
|
||||
|
||||
const setTimer = (obj, type) => {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
if (type === 'message') {
|
||||
Message(obj)
|
||||
}
|
||||
if (type === 'confirm') {
|
||||
MessageBox.confirm(...obj)
|
||||
}
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}, time)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue