优化通知公告显示,只保留显示几条消息弹窗,解决token过期后发请求报401错误会多次弹出登录状态已过期,请重新登录弹窗的问题
This commit is contained in:
parent
3c24343c5a
commit
54a76c6b4d
@ -26,17 +26,14 @@ export default {
|
|||||||
if (data.code == 200) {
|
if (data.code == 200) {
|
||||||
useSocketStore().setUnreadNoticeList(data.data.unReadNotifications)
|
useSocketStore().setUnreadNoticeList(data.data.unReadNotifications)
|
||||||
useSocketStore().setReadNoticeList(data.data.readNotifications)
|
useSocketStore().setReadNoticeList(data.data.readNotifications)
|
||||||
data.data.unReadNotifications.forEach((ele) => {
|
if (data.data.unReadNotifications.length > 0) {
|
||||||
const title = `来自${ele.create_name}的通知公告`
|
|
||||||
ElNotification({
|
ElNotification({
|
||||||
title: title,
|
title: import.meta.env.VITE_APP_TITLE,
|
||||||
message: ele.noticeContent,
|
message: `你有${data.data.unReadNotifications.length}条通知公告待查看`,
|
||||||
type: 'success',
|
type: 'success',
|
||||||
duration: 0,
|
duration: 0
|
||||||
dangerouslyUseHTMLString: true
|
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
webNotify({ title: import.meta.env.VITE_APP_TITLE, body: `你有${data.data.unReadNotifications.length}条通知公告待查看` })
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 接受聊天数据
|
// 接受聊天数据
|
||||||
|
|||||||
@ -12,7 +12,8 @@ const useUserStore = defineStore('user', {
|
|||||||
permissions: [],
|
permissions: [],
|
||||||
userId: 0,
|
userId: 0,
|
||||||
authSource: '',
|
authSource: '',
|
||||||
userName: ''
|
userName: '',
|
||||||
|
lateFlag: 0
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
setAuthSource(source) {
|
setAuthSource(source) {
|
||||||
|
|||||||
@ -49,19 +49,26 @@ service.interceptors.response.use(
|
|||||||
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
if (code == 401) {
|
if (code === 401) {
|
||||||
ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', {
|
if (useUserStore().lateFlag === 0) {
|
||||||
confirmButtonText: '重新登录',
|
useUserStore().lateFlag++
|
||||||
cancelButtonText: '取消',
|
ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', {
|
||||||
type: 'warning'
|
confirmButtonText: '重新登录',
|
||||||
}).then(() => {
|
cancelButtonText: '取消',
|
||||||
useUserStore()
|
type: 'warning'
|
||||||
.logOut()
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'index'
|
useUserStore().lateFlag = 0
|
||||||
|
useUserStore()
|
||||||
|
.logOut()
|
||||||
|
.then(() => {
|
||||||
|
location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'index'
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
.catch(() => {
|
||||||
|
useUserStore().lateFlag = 0
|
||||||
|
})
|
||||||
|
}
|
||||||
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
||||||
} else if (code == 0 || code == 1 || code == 110 || code == 101 || code == 403 || code == 500 || code == 429) {
|
} else if (code == 0 || code == 1 || code == 110 || code == 101 || code == 403 || code == 500 || code == 429) {
|
||||||
ElMessage({
|
ElMessage({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user