Java+Vue 实现消息通知示例

news/2025/2/21 7:39:21/

 

前端代码部分:

右上方小铃铛组件

 

 

<template><div><el-popover placement="bottom" :width="280" trigger="click"><template #reference><el-badge :is-dot="isDot" class="item" style="line-height: 40px"><!--      <svg-icon :icon-class="Bell" @click="toggle" />--><el-icon  class="el-icon-bell" style="font-size: 20px;cursor:pointer;transform: translateY(0.6px);" @click="bellClick"></el-icon>
<!--          <svg-icon class-name="search-icon" icon-class="search" @click.stop="click" />--></el-badge></template><div v-if="noticeList.length>0"><el-tabs><el-tab-pane label="通知"><div v-for="(item,index) in noticeList.slice(0,5)"><table><tr><td rowspan="2"><el-avatar icon="message" style="width:20px;height:20px;margin-right: 20px;background-color: #4d88ff"/></td><td><el-tooltipclass="box-item"effect="dark":content="item.messageTitle"placement="bottom"><el-link  type="primary" @click="handleRead(item)" style="font-size: 15px">{{item.messageTitle}}</el-link></el-tooltip></td></tr><tr><td><span>{{item.createTime}}</span></td></tr></table><hr v-if="index<noticeList.length-1" color="#e6e6e6"/></div><div style="text-align: center;margin-top: 10px"><el-button v-show="showAllBtn" align="center" type="primary" @click="showAll()">查看更多</el-button></div></el-tab-pane></el-tabs></div><div v-else><div style="text-align: center">暂无未读消息</div></div></el-popover><!-- 添加或修改我的消息对话框 --><el-dialog title="我的消息" :visible.sync="open" width="500px" append-to-body><el-form ref="form" :model="form" :rules="rules" label-width="80px"><el-form-item label="消息标题" prop="messageTitle"><el-input disabled v-model="form.messageTitle" placeholder="请输入消息标题" /></el-form-item><!--        <el-form-item label="用户ID" prop="userId">--><!--          <el-input disabled v-model="form.userId" placeholder="请输入用户ID" />--><!--        </el-form-item>--><el-form-item label="消息内容"><editor :readOnly="true" v-model="form.messageContent" :min-height="192"/></el-form-item><!--        <el-form-item label="备注" prop="remark">--><!--          <el-input disabled v-model="form.remark" placeholder="请输入备注" />--><!--        </el-form-item>--></el-form><div slot="footer" class="dialog-footer"><!--        <el-button type="primary" @click="submitForm">确 定</el-button>--><el-button @click="cancel">关闭</el-button></div></el-dialog></div>
</template><script>import {mapGetters} from "vuex";import  router from 'vue-router'import {listMyUnreadNotice,getSysmessage,listSysmessage} from "@/api/system/sysmessage";import events from '@/utils/events'export default {name: "index",components: {},data() {return {noticeList: [],showAllBtn: false,form:{},rules:{},open:false,queryParams:{id:null,status:'0',}}},computed: {...mapGetters(["isDot",'id']),},created() {this.getUnRead(); //查询是否有未读消息通知events.$on('noticePush', this.getUnRead)events.$on('noticePushByMsg', this.getUnRead)this.$nextTick(()=>{events.$on('noticeCheckByMsg', this.getUnRead)})},mounted() {},methods: {/** 查询是否存在未读消息 根据当前用户匹配消息表中得ID*/getUnRead() {this.queryParams.id = this.idlistSysmessage(this.queryParams).then(res => {if(res.code == 200){if (res.rows.length>0) {let object = res.rowsthis.noticeList = objectif(object.length >5){this.showAllBtn=true}else{this.showAllBtn=false}this.$store.dispatch('app/setIsDot', true)} else {this.noticeList = []this.$store.dispatch('app/setIsDot', false)}}});},bellClick() {this.getUnRead()},cancel(){this.open = falsethis.getUnRead();},//查看更多showAll() {this.$router.push({path: "/monitor/myMessage"});},//查看消息 弹窗显示handleRead(data){const messageId = data.messageIdgetSysmessage(messageId).then(response => {this.form = response.data;// this.form.messageTitle = data.messageTitle// this.form.messageContent = data.messageContentthis.open = true});}}}
</script><style scoped></style>

把是否有消息的状态通过vuex存到公共状态里来管理

 

 

this.$store.dispatch('app/setIsDot', true) //设置红点
this.$store.dispatch('app/setIsDot', false) //去掉红点

 首先新建通知公告 发布通知

 我的消息列表

JAVA部分

两个表 通知公告表和我的消息表 做关联

发布消息根据指定的用户类型去插入数据 通过userID分别插入到我的消息表中

全部设置已读 首先去查未读的消息根据userID,在遍历集合更新状态

 

 


http://www.ppmy.cn/news/1128009.html

相关文章

求各区域热门商品Top3 - HiveSQL

背景&#xff1a;这是尚硅谷SparkSQL练习题&#xff0c;本文用HiveSQL进行了实现。 数据集&#xff1a;用户点击表&#xff0c;商品表&#xff0c;城市表 题目: ① 求每个地区点击量前三的商品&#xff1b; ② 在①的基础上&#xff0c;求出每个地区点击量前三的商品后&a…

【OSCAR开源产业大会分论坛】开源大模型走向何方?

再过俩月&#xff0c;ChatGPT 即将迎来推出一周年纪念日。作为开历史先河的 AI 大模型&#xff0c;ChatGPT 像一针猛戳进千行百业中枢神经的兴奋剂&#xff0c;在全球掀起空前绝后的 AI 军备竞赛热潮。 近一年来&#xff0c;我们看到 GPT-3.5 完成向多模态的 GPT-4 进化&#x…

【Win11 搭建miniconda 的pytorch1.12环境】

请不要质疑我一直在水文章&#xff0c;因为我电脑被格式化了&#xff0c;需求又变了&#xff0c;这不得多多与时代接轨哦&#xff01; 为我的GRCNN抓取打基础&#xff0c;之前是在Ubuntu上跑&#xff1a;【机械臂视觉抓取从理论到实战】&#xff0c;没错现在就是在WIN11上跑&am…

Unity 制作登录功能02-创建和链接数据库(SQlite)

国际惯例&#xff1a;先看效果 1.SQlite是一种嵌入型数据库 在Unity开发游戏时使用SQLite有多种原因&#xff0c;以下是其中一些主要原因&#xff1a; 嵌入式数据库&#xff1a;SQLite是一个嵌入式数据库引擎&#xff0c;这意味着它不需要单独的服务器进程。这使得使用SQLite非…

Halcon Region相关算子(一)

(1) closing_circle(Region : RegionClosing : Radius : ) 功能&#xff1a;闭运算(先膨胀后腐蚀)&#xff1a;使用圆形结构元素进行闭合区域。 图形输入参数&#xff1a;Region: 输入的待闭运算的区域&#xff1b; 图形输出参数&#xff1a;RegionClosing: 输出区域&#x…

【数据库——MySQL】(5)运算符、表达式和系统函数

目录 1. 常量1.1 数值常量1.2 字符串常量1.3 日期时间常量1.4布尔值1.5 NULL值 2. 变量2.1 系统变量2.2 用户变量 3. 运算符与表达式3.1 赋值运算符3.2 算术运算符3.3 比较运算符3.4 判断运算符3.5 字符串匹配3.6 逻辑运算符和位运算符3.7 表达式和运算符的优先级 4. 系统函数参…

命运2中文wiki搭建记录——MediaWiki安装与初设置

命运2中文wiki搭建记录 本文转自我的博客&#xff0c;原文地址——>命运2中文wiki搭建记录——MediaWiki安装与初设置 可能是出于闲的发霉&#xff0c;想自己搭建一个命运2wiki。 因为bilibili上的命运2Bwiki也全是自己搭的。指路——>命运2Bwiki 但是当自己实际上手Me…

详解FreeRTOS:FreeRTOS任务挂起过程源码分析(进阶篇—3)

本篇博文讲解FreeRTOS中任务挂起过程的源代码,帮助各位更好理解挂起任务的原理和流程。 在详解FreeRTOS:FreeRTOS任务管理函数(基础篇—11)中,讲述了可以使用vTaskSuspend()函数实现挂起任务。 函数源码如下: 程序说明如下: (1)、通过函数 prvGetTCBFromHandle()获取要…