优化通知公告显示,只保留显示几条消息弹窗,解决token过期后发请求报401错误会多次弹出登录状态已过期,请重新登录弹窗的问题

This commit is contained in:
YUN-PC5\user 2023-11-22 16:35:42 +08:00
parent 3c24343c5a
commit 54a76c6b4d
3 changed files with 25 additions and 20 deletions

View File

@ -26,17 +26,14 @@ export default {
if (data.code == 200) {
useSocketStore().setUnreadNoticeList(data.data.unReadNotifications)
useSocketStore().setReadNoticeList(data.data.readNotifications)
data.data.unReadNotifications.forEach((ele) => {
const title = `来自${ele.create_name}的通知公告`
if (data.data.unReadNotifications.length > 0) {
ElNotification({
title: title,
message: ele.noticeContent,
title: import.meta.env.VITE_APP_TITLE,
message: `你有${data.data.unReadNotifications.length}条通知公告待查看`,
type: 'success',
duration: 0,
dangerouslyUseHTMLString: true
duration: 0
})
})
webNotify({ title: import.meta.env.VITE_APP_TITLE, body: `你有${data.data.unReadNotifications.length}条通知公告待查看` })
}
}
})
// 接受聊天数据

View File

@ -12,7 +12,8 @@ const useUserStore = defineStore('user', {
permissions: [],
userId: 0,
authSource: '',
userName: ''
userName: '',
lateFlag: 0
}),
actions: {
setAuthSource(source) {

View File

@ -49,19 +49,26 @@ service.interceptors.response.use(
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
return res
}
if (code == 401) {
ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
useUserStore()
.logOut()
if (code === 401) {
if (useUserStore().lateFlag === 0) {
useUserStore().lateFlag++
ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
})
.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('无效的会话,或者会话已过期,请重新登录。')
} else if (code == 0 || code == 1 || code == 110 || code == 101 || code == 403 || code == 500 || code == 429) {
ElMessage({