diff --git a/src/components/Pagination/index.vue b/src/components/Pagination/index.vue index 7d36888..9bc3a58 100644 --- a/src/components/Pagination/index.vue +++ b/src/components/Pagination/index.vue @@ -1,114 +1,114 @@ diff --git a/src/signalr/analysis.js b/src/signalr/analysis.js index ccfd2e7..ca51aea 100644 --- a/src/signalr/analysis.js +++ b/src/signalr/analysis.js @@ -5,79 +5,82 @@ import { webNotify } from '@/utils/index' import gongaoIcon from '@/assets/icons/svg/gonggao.svg' export default { - onMessage(connection) { - connection.on(MsgType.M001, (data) => { - useSocketStore().setOnlineUsers(data) - }) - - // 接收后台手动推送消息 - connection.on('receiveNotice', (title, data) => { - ElNotification({ - type: 'info', - title: title, - message: data, - dangerouslyUseHTMLString: true, - duration: 0 - }) - webNotify({ title: title, body: '你有一条新消息', icon: gongaoIcon }) - }) - // 接收系统通知/公告 - connection.on('moreNotice', (data) => { - if (data.code == 200) { - useSocketStore().setNoticeList(data.data) - } - }) - - // 接收在线用户 - // connection.on('onlineUser', (data) => { - // useSocketStore().setOnlineUsers(data) - // }) - - // 接收强退通知 - connection.on('forceUser', (data) => { - useSocketStore().setGlobalError({ code: 0, msg: `你的账号已被强退,原因:${data.reason || '无'}` }) - useUserStore() - .logOut() - .then(() => { - location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'error' + onMessage(connection) { + connection.on(MsgType.M001, (data) => { + useSocketStore().setOnlineUsers(data) }) - }) - // 接收聊天数据 - connection.on('receiveChat', (data) => { - const { fromUser, message } = data - useSocketStore().setChat(data) - if (data.userId != useUserStore().userId) { - ElNotification({ - title: fromUser.nickName, - message: message, - type: 'success', - duration: 3000 + // 接收后台手动推送消息 + connection.on('receiveNotice', (title, data) => { + ElNotification({ + type: 'info', + title: title, + message: data, + dangerouslyUseHTMLString: true, + duration: 0 + }) + webNotify({ title: title, body: '你有一条新消息', icon: gongaoIcon }) }) - webNotify({ title: '来自:' + fromUser.nickName, body: message, icon: gongaoIcon }) - } - }) - - connection.on('onlineInfo', (data) => { - useSocketStore().getOnlineInfo(data) - }) - - connection.on(MsgType.LogOut, () => { - useUserStore() - .logOut() - .then(() => { - ElMessageBox.alert(`你的账号已在其他设备登录,如果不是你的操作请尽快修改密码`, '提示', { - confirmButtonText: '确定', - callback: () => { - location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'index' + // 接收系统通知/公告 + connection.on('moreNotice', (data) => { + if (data.code == 200) { + useSocketStore().setNoticeList(data.data) } - }) }) - }) - } + + // 接收在线用户 + // connection.on('onlineUser', (data) => { + // useSocketStore().setOnlineUsers(data) + // }) + + // 接收强退通知 + connection.on('forceUser', (data) => { + useSocketStore().setGlobalError({ code: 0, msg: `你的账号已被强退,原因:${data.reason || '无'}` }) + useUserStore() + .logOut() + .then(() => { + location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'error' + }) + }) + // 接收聊天数据 + connection.on('receiveChat', (data) => { + const { fromUser, message } = data + + useSocketStore().setChat(data) + if (data.userId != useUserStore().userId) { + ElNotification({ + title: fromUser.nickName, + message: message, + type: 'success', + duration: 3000 + }) + webNotify({ title: '来自:' + fromUser.nickName, body: message, icon: gongaoIcon }) + } + }) + + connection.on('onlineInfo', (data) => { + useSocketStore().getOnlineInfo(data) + }) + connection.on(MsgType.M002, (data) => { + console.log('connId', data) + }) + + connection.on(MsgType.LogOut, () => { + useUserStore() + .logOut() + .then(() => { + ElMessageBox.alert(`你的账号已在其他设备登录,如果不是你的操作请尽快修改密码`, '提示', { + confirmButtonText: '确定', + callback: () => { + location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'index' + } + }) + }) + }) + } } const MsgType = { - M001: 'onlineNum', - M002: 'connId', - LogOut: 'logOut' + M001: 'onlineNum', + M002: 'connId', + LogOut: 'logOut' } diff --git a/src/signalr/signalr.js b/src/signalr/signalr.js index f2ddc83..4c3ea33 100644 --- a/src/signalr/signalr.js +++ b/src/signalr/signalr.js @@ -5,120 +5,129 @@ import cache from '@/plugins/cache' import analysis from '@/signalr/analysis' export default { - // signalR对象 - SR: {}, - PBL_SR: {}, - // 失败连接重试次数 - failNum: 4, - PBL_failNum: 5, + // signalR对象 + SR: {}, + PBL_SR: {}, + // 失败连接重试次数 + failNum: 4, + PBL_failNum: 5, - init(url) { - var socketUrl = window.location.origin + url + '?clientId=' + cache.local.get('clientId') - const connection = new signalR.HubConnectionBuilder() - .withUrl(socketUrl, { accessTokenFactory: () => getToken() }) - .withAutomaticReconnect() //自动重新连接 - .configureLogging(signalR.LogLevel.Warning) - .build() + init(url) { + var socketUrl = window.location.origin + url + '?clientId=' + cache.local.get('clientId') + const connection = new signalR.HubConnectionBuilder() + .withUrl(socketUrl, { accessTokenFactory: () => getToken() }) + .withAutomaticReconnect() //自动重新连接 + .configureLogging(signalR.LogLevel.Warning) + .build() - this.SR = connection + this.SR = connection - // 断线重连 - connection.onclose(async (error) => { - console.error('断开连接了', error) - await this.start() - }) + // 断线重连 + connection.onclose(async (error) => { + console.error('断开连接了', error) + await this.start() + }) - connection.onreconnected((connectionId) => { - ElMessage({ - message: '主信号通道与服务器通讯已连接成功', - type: 'success', - duration: 2000 - }) - console.log('断线重新连接成功', connectionId) - }) + connection.onreconnected((connectionId) => { + ElMessage({ + message: '主信号通道与服务器通讯已连接成功', + type: 'success', + duration: 2000 + }) + console.log('断线重新连接成功', connectionId) + }) - connection.onreconnecting(() => { - console.log('断线重新连接中...') - }) + connection.onreconnecting(() => { + console.log('断线重新连接中...') + }) - // 启动连接后设置消息处理函数 - this.start().then(() => { - analysis.onMessage(connection) - }) - }, + // 启动连接后设置消息处理函数 + this.start().then(() => { + analysis.onMessage(connection) + }) + }, - async start() { - try { - console.log('signalR-1', this.SR.state) - if (this.SR.state === signalR.HubConnectionState.Disconnected) { - await this.SR.start() - } - console.log('signalR-2', this.SR.state) - return true - } catch (error) { - console.error(error) - this.failNum-- - if (this.failNum > 0 && this.SR.state === signalR.HubConnectionState.Disconnected) { - setTimeout(async () => { - await this.start() - }, 5000) - } - return false + async start() { + try { + console.log('signalR-1', this.SR.state) + if (this.SR.state === signalR.HubConnectionState.Disconnected) { + await this.SR.start() + } + console.log('signalR-2', this.SR.state) + return true + } catch (error) { + console.error(error) + this.failNum-- + if (this.failNum > 0 && this.SR.state === signalR.HubConnectionState.Disconnected) { + setTimeout(async () => { + await this.start() + }, 5000) + } + return false + } + }, + + initPBL(url) { + var socketUrl = window.location.origin + url + '?clientId=' + cache.local.get('clientId') + const connection = new signalR.HubConnectionBuilder() + .withUrl(socketUrl, { accessTokenFactory: () => getToken() }) + .withAutomaticReconnect() //自动重新连接 + .configureLogging(signalR.LogLevel.Warning) + .build() + + this.PBL_SR = connection + + // 断线重连 + connection.onclose(async (error) => { + console.error('PBL后台断开连接了', error) + await this.doPblSrStart() + }) + + connection.onreconnected((connectionId) => { + ElMessage({ + message: 'PBL后台信号通道与服务器通讯已连接成功', + type: 'success', + duration: 2000 + }) + console.log('断线重新连接成功', connectionId) + }) + + connection.onreconnecting(() => { + console.log('PBL后台断线重新连接中...') + }) + + // 启动连接后设置消息处理函数 + this.doPblSrStart().then(() => { + //analysis.onMessage(connection) + connection.on('PBL_bom_except', (data) => { + // console.log('PBL_bom_except', data) + }) + connection.on('PBL_storagelocation_change', (data) => { + // console.log('PBL_storagelocation_change', data) + }) + connection.on('pbl_lack_alarm', (data) => { + // console.log('pbl_lack_alarm', data) + }) + }) + }, + + async doPblSrStart() { + try { + console.log('PBL_signalR-1', this.PBL_SR.state) + if (this.PBL_SR.state === signalR.HubConnectionState.Disconnected) { + await this.PBL_SR.start() + } + console.log('PBL_signalR-2', this.PBL_SR.state) + return true + } catch (error) { + console.error(error) + this.PBL_failNum-- + if (this.PBL_failNum > 0 && this.PBL_SR.state === signalR.HubConnectionState.Disconnected) { + setTimeout(async () => { + await this.doPblSrStart() + }, 5000) + } + return false + } } - }, - - initPBL(url) { - var socketUrl = window.location.origin + url + '?clientId=' + cache.local.get('clientId') - const connection = new signalR.HubConnectionBuilder() - .withUrl(socketUrl, { accessTokenFactory: () => getToken() }) - .withAutomaticReconnect() //自动重新连接 - .configureLogging(signalR.LogLevel.Warning) - .build() - - this.PBL_SR = connection - - // 断线重连 - connection.onclose(async (error) => { - console.error('PBL后台断开连接了', error) - await this.doPblSrStart() - }) - - connection.onreconnected((connectionId) => { - ElMessage({ - message: 'PBL后台信号通道与服务器通讯已连接成功', - type: 'success', - duration: 2000 - }) - console.log('断线重新连接成功', connectionId) - }) - - connection.onreconnecting(() => { - console.log('PBL后台断线重新连接中...') - }) - - // 启动连接后设置消息处理函数 - this.doPblSrStart().then(() => { - analysis.onMessage(connection) - }) - }, - - async doPblSrStart() { - try { - console.log('PBL_signalR-1', this.PBL_SR.state) - if (this.PBL_SR.state === signalR.HubConnectionState.Disconnected) { - await this.PBL_SR.start() - } - console.log('PBL_signalR-2', this.PBL_SR.state) - return true - } catch (error) { - console.error(error) - this.PBL_failNum-- - if (this.PBL_failNum > 0 && this.PBL_SR.state === signalR.HubConnectionState.Disconnected) { - setTimeout(async () => { - await this.doPblSrStart() - }, 5000) - } - return false - } - } } diff --git a/src/views/PBL/Storagelocation.vue b/src/views/PBL/Storagelocation.vue index 4f08909..6f7dd20 100644 --- a/src/views/PBL/Storagelocation.vue +++ b/src/views/PBL/Storagelocation.vue @@ -30,9 +30,9 @@ 导出数据 - + @@ -49,6 +49,13 @@ + + + + @@ -85,6 +92,11 @@ + + + + + diff --git a/src/views/PBL/TVScreen/index.vue b/src/views/PBL/TVScreen/index.vue index 736f534..f39aa34 100644 --- a/src/views/PBL/TVScreen/index.vue +++ b/src/views/PBL/TVScreen/index.vue @@ -67,7 +67,7 @@
- +
@@ -160,6 +160,7 @@ function getBoxClass(packageCount, slotIndex) { const mqtt = mqttStore() function initializeSignalR() { const messageHandler = (data) => { + console.log('接收到消息[messageHandler]:', data) if (typeof data === 'string') { pblBomExceptMessage.value = data } else { @@ -167,9 +168,11 @@ function initializeSignalR() { } } const packageChangeHandler = () => { + console.log('接收到消息[packageChangeHandler]') fetchShelfData() } const lackAlarmHandler = () => { + console.log('接收到消息[lackAlarmHandler]') togglePlay() fetchShelfData() } @@ -198,8 +201,8 @@ onMounted(() => { // 自动刷新 // let refreshTimer = null // function startAutoRefresh() { -// clearInterval(refreshTimer) -// refreshTimer = setInterval(fetchShelfData, 1000) +// clearInterval(refreshTimer) +// refreshTimer = setInterval(fetchShelfData, 1000) // } // onMounted(startAutoRefresh)