From 1da5772461f00e86fa22835425d9836c364a5040 Mon Sep 17 00:00:00 2001 From: Kylin Date: Wed, 28 Aug 2024 18:01:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20websocket=E5=89=8D=E7=AB=AF=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 还在完善websocket的前端通知代码部分。以及在思考怎么跟后端的用户状态表关联问题 --- src/api/notice-status.ts | 26 ++- .../NavBar/components/NavbarAction.vue | 77 ++++--- src/views/system/notice-status/index.vue | 69 +++++- src/views/system/notice/index.vue | 198 ++++++++++++------ 4 files changed, 270 insertions(+), 100 deletions(-) diff --git a/src/api/notice-status.ts b/src/api/notice-status.ts index 03433c37..93873cab 100644 --- a/src/api/notice-status.ts +++ b/src/api/notice-status.ts @@ -64,10 +64,32 @@ class NoticeStatusAPI { export default NoticeStatusAPI; /** 用户公告状态分页查询参数 */ -export interface NoticeStatusPageQuery extends PageQuery {} +export interface NoticeStatusPageQuery extends PageQuery { + /** id */ + id?: bigint; + /** 公共通知id */ + noticeId?: bigint; + /** 用户id */ + userId?: number; + /** 读取状态,0未读,1已读取 */ + readStatus?: bigint; + /** 用户阅读时间 */ + readTiem?: [string, string]; +} /** 用户公告状态表单对象 */ export interface NoticeStatusForm {} /** 用户公告状态分页对象 */ -export interface NoticeStatusPageVO {} +export interface NoticeStatusPageVO { + /** id */ + id?: bigint; + /** 公共通知id */ + noticeId?: bigint; + /** 用户id */ + userId?: number; + /** 读取状态,0未读,1已读取 */ + readStatus?: bigint; + /** 用户阅读时间 */ + readTiem?: Date; +} diff --git a/src/layout/components/NavBar/components/NavbarAction.vue b/src/layout/components/NavBar/components/NavbarAction.vue index 3f6a4273..102995fd 100644 --- a/src/layout/components/NavBar/components/NavbarAction.vue +++ b/src/layout/components/NavBar/components/NavbarAction.vue @@ -150,24 +150,24 @@ const messages = ref([ title: "重要提醒:请定期更改您的密码以保证账户安全。", type: MessageTypeEnum.MESSAGE, }, - { - id: 4, - title: "通知:您有一条未读的系统消息,请及时查看。", - type: MessageTypeEnum.NOTICE, - }, - { - id: 5, - title: "新订单通知:您有一笔新的订单需要处理。", - type: MessageTypeEnum.NOTICE, - }, - { - id: 6, - title: "审核提醒:您的审核请求已被批准。", - type: MessageTypeEnum.NOTICE, - }, - { id: 7, title: "待办事项:完成用户权限设置。", type: MessageTypeEnum.TODO }, - { id: 8, title: "待办事项:更新产品列表。", type: MessageTypeEnum.TODO }, - { id: 9, title: "待办事项:备份数据库。", type: MessageTypeEnum.TODO }, + // { + // id: 4, + // title: "通知:您有一条未读的系统消息,请及时查看。", + // type: MessageTypeEnum.NOTICE, + // }, + // { + // id: 5, + // title: "新订单通知:您有一笔新的订单需要处理。", + // type: MessageTypeEnum.NOTICE, + // }, + // { + // id: 6, + // title: "审核提醒:您的审核请求已被批准。", + // type: MessageTypeEnum.NOTICE, + // }, + // { id: 7, title: "待办事项:完成用户权限设置。", type: MessageTypeEnum.TODO }, + // { id: 8, title: "待办事项:更新产品列表。", type: MessageTypeEnum.TODO }, + // { id: 9, title: "待办事项:备份数据库。", type: MessageTypeEnum.TODO }, ]); const getFilteredMessages = (type: MessageTypeEnum) => { @@ -212,19 +212,30 @@ function connectWebSocket() { onConnect: () => { console.log("连接成功"); isConnected.value = true; - messages.value.push({ - sender: "Server", - content: "Websocket 已连接", - type: "tip", - }); + // messages.value.push({ + // sender: "Server", + // content: "Websocket 已连接", + // type: "tip", + // }); // 订阅 /topic/chat 主题 + while (messages.value.length > 3) { + messages.value.shift(); + } stompClient.subscribe("/topic/chat", (res) => { - debugger; console.log("收到消息:" + res.body); - // messages.value.push({ - // sender: "Server", - // content: res.body, - // }); + const message = JSON.parse(res.body); + console.log("当前有:" + message.id); + console.log("数组已更新,强制重新渲染"); + messages.value.push({ + id: message.id, + title: message.title, + type: MessageTypeEnum.MESSAGE, + }); + while (messages.value.length > 3) { + messages.value.shift(); + } + console.log("当前还有:" + messages.value); + nextTick(async () => {}); }); }, onStompError: (frame) => { @@ -233,11 +244,11 @@ function connectWebSocket() { }, onDisconnect: () => { isConnected.value = false; - messages.value.push({ - sender: "Server", - content: "Websocket 已断开", - type: "tip", - }); + // messages.value.push({ + // sender: "Server", + // content: "Websocket 已断开", + // type: "tip", + // }); }, }); diff --git a/src/views/system/notice-status/index.vue b/src/views/system/notice-status/index.vue index a6e39fd8..70a6a452 100644 --- a/src/views/system/notice-status/index.vue +++ b/src/views/system/notice-status/index.vue @@ -2,6 +2,48 @@
+ + + + + + + + + + + + + + + @@ -45,6 +87,31 @@ @selection-change="handleSelectionChange" > + + + + +