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