diff --git a/src/App.vue b/src/App.vue index 984458e..5359f2a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,33 +8,43 @@ import { ElConfigProvider } from 'element-plus'; import { useAppStore } from '@/store/modules/app'; import { userVersionRelation } from '@/api/user/index'; +import mitt from '@/plugins/bus'; const appStore = useAppStore(); -//系统更新通知 -// const notice = ref({}); -// const webVersion = sessionStorage.getItem('webVersion'); -// if (webVersion != '' && webVersion != null) { -// const version = JSON.parse(webVersion); -// notice.value = ElNotification({ -// title: version.noticeTitle, -// dangerouslyUseHTMLString: true, -// customClass: 'notice', -// duration: 0, -// message: version.noticeContent.replace(/\n/g, '
'), -// onClose: () => { -// noticeCloce(version.noticeId); -// } -// }); -// } -// function noticeCloce(id: any) { -// //更新日志关闭事件 -// const params = { -// noticeId: id -// }; -// userVersionRelation(params).then((res: any) => { -// if (res.code === 200) { -// console.log('更新日志关闭!'); -// } -// }); -// } +mitt.on('noticeMessage', (res: any) => { + //监听通告信息 + console.log('noticeMessage:', res); + noticeFn(res); +}); + +function noticeFn(data: any) { + //系统更新通知 + const notice = ref({}); + const webVersion = data.data; + console.log('webVersion:', webVersion); + if (Object.keys(webVersion).length != 0 && webVersion != null) { + const version = JSON.parse(webVersion); + notice.value = ElNotification({ + title: version.noticeTitle, + dangerouslyUseHTMLString: true, + customClass: 'notice', + duration: 0, + message: version.noticeContent.replace(/\n/g, '
'), + onClose: () => { + noticeCloce(version.noticeId); + } + }); + } +} +function noticeCloce(id: any) { + //更新日志关闭事件 + const params = { + noticeId: id + }; + userVersionRelation(params).then((res: any) => { + if (res.code === 200) { + console.log('更新日志关闭!'); + } + }); +} diff --git a/src/api/table/types.ts b/src/api/table/types.ts index da58aab..ca7f634 100644 --- a/src/api/table/types.ts +++ b/src/api/table/types.ts @@ -3,7 +3,7 @@ */ export interface TableVo { id: string; - deviceuuid: string; + assetInfo: assetInfoVo; areaid: string; C018: object; C019: object; @@ -57,6 +57,13 @@ export interface TableVo { C048: object; } +export interface assetInfoVo { + assetStatus: string; + id: number; + title: string; + assetCode: string; +} + /** * 底部面板信息 */ diff --git a/src/permission.ts b/src/permission.ts index 40fc005..11876cf 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -9,7 +9,7 @@ import router from '@/router'; import { useUserStoreHook } from '@/store/modules/user'; import { usePermissionStoreHook } from '@/store/modules/permission'; -// import socket from '@/utils/socket'; +import socket from '@/utils/socket'; import NProgress from 'nprogress'; import 'nprogress/nprogress.css'; NProgress.configure({ showSpinner: false }); // 进度条 @@ -35,11 +35,11 @@ router.beforeEach(async (to, from, next) => { if (to.matched.length === 0) { from.name ? next({ name: from.name }) : next('/404'); } else { - // console.log('切换页面发送websocket信息'); + console.log('切换页面发送websocket信息'); const exitStatu = { code: 'exitDataMonitor' }; - // socket.onSend(exitStatu); + socket.onSend(exitStatu); next(); } } else { @@ -50,13 +50,13 @@ router.beforeEach(async (to, from, next) => { router.addRoute(route); }); - // console.log('登录后链接websocket'); + console.log('登录后链接websocket'); //登录后连接webSocket const userStorageInfo = sessionStorage.getItem('userInfo'); const userInfo = JSON.parse(userStorageInfo === null ? '' : userStorageInfo); // const wsUrl = `ws://${window.location.host}/ws/websocket/${userInfo.userName}`; //websocket地址 - // const wsUrl = `ws://10.10.10.56:9010/websocket/${userInfo.userName}`; //websocket地址 - // socket.initialize(wsUrl); + const wsUrl = `ws://10.10.10.56:9010/websocket/${userInfo.userName}`; //websocket地址 + socket.initialize(wsUrl); next({ ...to, replace: true }); } catch (error) { // 移除 token 并跳转登录页 diff --git a/src/store/modules/date.js b/src/store/modules/date.js index d6c4c2f..a8bc58f 100644 --- a/src/store/modules/date.js +++ b/src/store/modules/date.js @@ -7,9 +7,10 @@ const useCounter = defineStore('date', { state: () => ({ deptIdStr: '', dateStr: '', + noticeStr: {}, orgStr: { title: '', - uuid: '' + assetCode: '' } }), @@ -28,6 +29,9 @@ const useCounter = defineStore('date', { dateStore(val) { this.dateStr = val; }, + noticeStore(val) { + this.noticeStr = val; + }, orgStore(val) { this.orgStr = val; } diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 3fbccca..15cc8c3 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -16,7 +16,7 @@ export const useUserStore = defineStore('user', () => { const userInfo = useSessionStorage('userInfo', {}); const nickname = ref(''); const avatar = ref(''); - const webVersion = useSessionStorage('webVersion', ''); + // const webVersion = useSessionStorage('webVersion', ''); const roles = ref>([]); // 用户角色编码集合 → 判断路由权限 const perms = ref>([]); // 用户权限编码集合 → 判断按钮权限 @@ -57,11 +57,11 @@ export const useUserStore = defineStore('user', () => { roles.value = data.roles; perms.value = data.permissions; userInfo.value = user; - if (data.notice === null) { - webVersion.value = ''; - } else { - webVersion.value = JSON.stringify(data.notice); - } + // if (data.notice === null) { + // webVersion.value = ''; + // } else { + // webVersion.value = JSON.stringify(data.notice); + // } // useStorage('userInfo', user); resolve(data); }) @@ -88,12 +88,16 @@ export const useUserStore = defineStore('user', () => { // 重置 function resetToken() { - token.value = ''; - userInfo.value = {}; - nickname.value = ''; - avatar.value = ''; - roles.value = []; - perms.value = []; + return new Promise(resolve => { + token.value = ''; + userInfo.value = {}; + nickname.value = ''; + avatar.value = ''; + roles.value = []; + perms.value = []; + resetRouter(); + resolve(); + }); } return { token, diff --git a/src/types/auto-imports.d.ts b/src/types/auto-imports.d.ts index 9ad07b5..5742656 100644 --- a/src/types/auto-imports.d.ts +++ b/src/types/auto-imports.d.ts @@ -6,6 +6,7 @@ declare global { const ElMessage: typeof import('element-plus/es')['ElMessage'] const ElMessageBox: typeof import('element-plus/es')['ElMessageBox'] const ElNotification: typeof import('element-plus/es')['ElNotification'] + const NEllipsis: typeof import('naive-ui')['NEllipsis'] const asyncComputed: typeof import('@vueuse/core')['asyncComputed'] const autoResetRef: typeof import('@vueuse/core')['autoResetRef'] const computed: typeof import('vue')['computed'] @@ -276,6 +277,7 @@ declare module 'vue' { readonly ElMessage: UnwrapRef readonly ElMessageBox: UnwrapRef readonly ElNotification: UnwrapRef + readonly NEllipsis: UnwrapRef readonly asyncComputed: UnwrapRef readonly autoResetRef: UnwrapRef readonly computed: UnwrapRef diff --git a/src/utils/request.ts b/src/utils/request.ts index 1587b3b..fe8d386 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -8,7 +8,7 @@ */ import axios, { InternalAxiosRequestConfig, AxiosResponse } from 'axios'; import { useUserStoreHook } from '@/store/modules/user'; -import { getUrlRouter } from '@/utils/index'; +// import { getUrlRouter } from '@/utils/index'; import { useDateFormat } from '@vueuse/core'; // 创建 axios 实例 @@ -48,11 +48,10 @@ service.interceptors.response.use( confirmButtonText: '确定', type: 'warning' }).then(() => { - localStorage.clear(); - sessionStorage.clear(); - if (getUrlRouter()[0] != 'login') { - window.location.href = '/'; - } + const userStore = useUserStoreHook(); + userStore.resetToken().then(() => { + location.reload(); + }); }); } else if (code === 500) { ElMessage({ message: msg || '未知错误', type: 'error' }); diff --git a/src/utils/socket.ts b/src/utils/socket.ts index dfce1bc..82c91cf 100644 --- a/src/utils/socket.ts +++ b/src/utils/socket.ts @@ -7,8 +7,8 @@ * Description:websocket方法封装 */ import type { Action } from 'element-plus'; +import { useSessionStorage } from '@vueuse/core'; import mitt from '@/plugins/bus'; - class WebSocketService { url: string; websocket: WebSocket | null; @@ -94,6 +94,8 @@ class WebSocketService { }); } console.log(response.msg); + } else if (response.code === 'notice') { + mitt.emit('noticeMessage', response); } } } diff --git a/src/views/dashboard/components/BarChart.vue b/src/views/dashboard/components/BarChart.vue index 78e0436..78fd2c6 100644 --- a/src/views/dashboard/components/BarChart.vue +++ b/src/views/dashboard/components/BarChart.vue @@ -1,9 +1,6 @@