From 92e032c948b008c4f0da1cd22cd89d0b673d4577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sat, 26 Aug 2023 07:40:33 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=E6=96=B0=E5=A2=9E=E5=89=94=E5=87=BA?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/monitor/online.js | 7 +++-- src/router/index.js | 16 ----------- src/utils/signalR.js | 23 +++++++++++++-- src/views/monitor/onlineuser/index.vue | 40 ++++++++++++++------------ src/views/monitor/operlog/index.vue | 2 +- 5 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/api/monitor/online.js b/src/api/monitor/online.js index a6d20ec..d51b88d 100644 --- a/src/api/monitor/online.js +++ b/src/api/monitor/online.js @@ -10,9 +10,10 @@ export function listOnline(query) { } // 强退用户 -export function forceLogout(tokenId) { +export function forceLogout(data) { return request({ - url: '/monitor/online/' + tokenId, - method: 'delete' + url: '/monitor/online/lock', + method: 'delete', + data: data }) } diff --git a/src/router/index.js b/src/router/index.js index 874564a..76f9155 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -85,22 +85,6 @@ export const constantRoutes = [ meta: { title: '个人中心', icon: 'user', titleKey: 'menu.personalCenter' } } ] - }, - // 不用可删掉 - { - path: '', - component: Layout, - hidden: false, - meta: { title: '组件示例', icon: 'icon', noCache: 'fasle' }, - children: [ - { - path: 'icon', - component: () => import('@/views/components/icons/index'), - //component: () => import('@/views/business/GenDemo'), - name: 'icon', - meta: { title: '图标icon', icon: 'icon1', noCache: 'fasle', titleKey: 'menu.icon' } - } - ] } ] diff --git a/src/utils/signalR.js b/src/utils/signalR.js index e4cbe60..e34acc4 100644 --- a/src/utils/signalR.js +++ b/src/utils/signalR.js @@ -1,15 +1,15 @@ // 官方文档:https://docs.microsoft.com/zh-cn/aspnet/core/signalr/javascript-client?view=aspnetcore-6.0&viewFallbackFrom=aspnetcore-2.2&tabs=visual-studio import * as signalR from '@microsoft/signalr' import { getToken } from '@/utils/auth' -import { ElNotification, ElMessage } from 'element-plus' +import { ElNotification, ElMessage, ElMessageBox } from 'element-plus' import useSocketStore from '@/store/modules/socket' +import useUserStore from '@/store/modules/user' import { webNotify } from './index' export default { // signalR对象 SR: {}, // 失败连接重试次数 failNum: 4, - baseUrl: '', init(url) { var socketUrl = window.location.origin + url const connection = new signalR.HubConnectionBuilder() @@ -80,6 +80,9 @@ export default { connection.on('welcome', (data) => { ElNotification.info(data) }) + connection.on('getConnId', (data) => { + // useUserStore().saveConnId(data) + }) // 接收后台手动推送消息 connection.on('receiveNotice', (title, data) => { ElNotification({ @@ -103,6 +106,22 @@ export default { // useSocketStore().setOnlineUsers(data) // }) + // 接收封锁通知 + connection.on('lockUser', (data) => { + ElMessageBox.alert(`你的账号已被锁定,剩余,${data.time}分,原因:${data.reason || '-'}`, '提示', { + confirmButtonText: '确定', + callback: (action) => { + useUserStore() + .logOut() + .then(() => { + var redirectUrl = window.location.pathname + if (location.pathname.indexOf('/login') != 0) { + location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'index?redirect=' + redirectUrl + } + }) + } + }) + }) // 接收聊天数据 connection.on('receiveChat', (data) => { const title = `来自${data.userName}的消息通知` diff --git a/src/views/monitor/onlineuser/index.vue b/src/views/monitor/onlineuser/index.vue index efe96a6..bef028d 100644 --- a/src/views/monitor/onlineuser/index.vue +++ b/src/views/monitor/onlineuser/index.vue @@ -15,40 +15,32 @@ - - - - + + + + - + - + diff --git a/src/views/monitor/operlog/index.vue b/src/views/monitor/operlog/index.vue index 21d6df9..c8637e6 100644 --- a/src/views/monitor/operlog/index.vue +++ b/src/views/monitor/operlog/index.vue @@ -91,7 +91,7 @@ - +