基于若依ruoyi-nbcio增加flowable流程待办消息的提醒,并提供右上角的红字数字提醒(六)

news2024/10/7 12:21:29

更多ruoyi-nbcio功能请看演示系统

gitee源代码地址

前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio

演示地址:RuoYi-Nbcio后台管理系统

这个部分主要是前端方面的。

1、在Navbar.vue显示右上角的图标栏里增加一项显示消息提醒的组件

<el-tooltip content="消息" effect="dark" placement="bottom">
           <!--<message id="message" class="right-menu-item hover-effect"  /> -->
           <header-notice id="message" class="right-menu-item-message hover-effect" />
        </el-tooltip>

        <el-tooltip content="源码地址" effect="dark" placement="bottom">
          <ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />
        </el-tooltip>

2、组件HeaderNotice.vue代码如下:

这里主要先获取系统消息,并进行显示提醒,

其中调用了接口listByUser,

<template>
  <div>
    <a-popover trigger="click" placement="bottomRight" :autoAdjustOverflow="true" :arrowPointAtCenter="true"
      overlayClassName="header-notice-wrapper" @visibleChange="handleHoverChange"
      :overlayStyle="{ width: '400px', top: '50px' }">
      <template slot="content">
        <a-spin :spinning="loadding">
          <a-tabs>
            <a-tab-pane :tab="msg1Title" key="1">
              <a-list>
                <a-list-item :key="index" v-for="(record, index) in notice1">
                  <div style="margin-left: 5%;width: 50%">
                    <p><a @click="showNotice(record)">{{ record.titile }}</a></p>
                    <p style="color: rgba(0,0,0,.45);margin-bottom: 0px">{{ record.createTime }} 发布</p>
                  </div>
                  <div style="text-align: right">
                    <a-tag @click="showNotice(record)" v-if="record.priority === 'L'" color="blue">一般消息</a-tag>
                    <a-tag @click="showNotice(record)" v-if="record.priority === 'M'" color="orange">重要消息</a-tag>
                    <a-tag @click="showNotice(record)" v-if="record.priority === 'H'" color="red">紧急消息</a-tag>
                  </div>
                </a-list-item>
                <div style="margin-top: 5px;text-align: center">
                  <a-button @click="toMyNotice()" type="dashed" block>查看更多</a-button>
                </div>
              </a-list>
            </a-tab-pane>
            <a-tab-pane :tab="msg2Title" key="2">
              <a-list>
                <a-list-item :key="index" v-for="(record, index) in notice2">
                  <div style="margin-left: 5%;width: 50%">
                    <p><a @click="showNotice(record)">{{ record.titile }}</a></p>
                    <p style="color: rgba(0,0,0,.45);margin-bottom: 0px">{{ record.createTime }} 发布</p>
                  </div>
                  <div style="text-align: right">
                    <a-tag @click="showNotice(record)" v-if="record.priority === 'L'" color="blue">一般消息</a-tag>
                    <a-tag @click="showNotice(record)" v-if="record.priority === 'M'" color="orange">重要消息</a-tag>
                    <a-tag @click="showNotice(record)" v-if="record.priority === 'H'" color="red">紧急消息</a-tag>
                  </div>
                </a-list-item>
                <div style="margin-top: 5px;text-align: center">
                  <a-button @click="toMyNotice()" type="dashed" block>查看更多</a-button>
                </div>
              </a-list>
            </a-tab-pane>
            <a-tab-pane :tab="msg3Title" key="3">
              <a-list>
                <a-list-item :key="index" v-for="(record, index) in notice3">
                  <div style="margin-left: 5%;width: 50%">
                    <p><a @click="showNotice(record)">{{ record.titile }}</a></p>
                    <p style="color: rgba(0,0,0,.45);margin-bottom: 0px">{{ record.createTime }} 发布</p>
                  </div>
                  <div style="text-align: right">
                    <a-tag @click="showNotice(record)" v-if="record.priority === 'L'" color="blue">一般消息</a-tag>
                    <a-tag @click="showNotice(record)" v-if="record.priority === 'M'" color="orange">重要消息</a-tag>
                    <a-tag @click="showNotice(record)" v-if="record.priority === 'H'" color="red">紧急消息</a-tag>
                  </div>
                </a-list-item>
                <div style="margin-top: 5px;text-align: center">
                  <a-button @click="toMyNotice()" type="dashed" block>查看更多</a-button>
                </div>
              </a-list>
            </a-tab-pane>
          </a-tabs>
        </a-spin>
      </template>
      <span @click="fetchNotice" class="header-notice">
        <a-badge :count="msgTotal">
          <a-icon style="font-size: 16px; padding: 4px" type="bell" />
        </a-badge>
      </span>
      <show-notice ref="ShowNotice" @ok="modalFormOk"></show-notice>
      <dynamic-notice ref="showDynamNotice" :path="openPath" :formData="formData" />
    </a-popover>
  </div>
</template>

<script>
  import ShowNotice from './ShowNotice'
  import store from '@/store/'
  import DynamicNotice from './DynamicNotice'
  import { listByUser } from "@/api/system/notice";

  export default {
    name: "HeaderNotice",
    components: {
      DynamicNotice,
      ShowNotice,
    },
    data() {
      return {
        loadding: false,
        url: {
          listNoticeByUser: "/system/notice/listByUser",
          editNoticeSend: "/system/notice/editByAnntIdAndUserId",
          queryById: "/system/notice/queryById",
        },
        hovered: false,
        notice1: [],
        notice2: [],
        notice3: [],
        msg1Count: "0",
        msg2Count: "0",
        msg3Count: "0",
        msg1Title: "通知(0)",
        msg2Title: "",
        msg3Title: "",
        stopTimer: false,
        websock: null,
        lockReconnect: false,
        heartCheck: null,
        formData: {},
        openPath: ''
      }
    },
    computed: {
      msgTotal() {
        return parseInt(this.msg1Count) + parseInt(this.msg2Count) + parseInt(this.msg3Count);
      }
    },
    mounted() {
      this.loadData();
      //this.timerFun();
      this.initWebSocket();
      // this.heartCheckFun();
    },
    destroyed: function() { // 离开页面生命周期函数
      this.websocketOnclose();
    },
    methods: {
      timerFun() {
        this.stopTimer = false;
        let myTimer = setInterval(() => {
          // 停止定时器
          if (this.stopTimer == true) {
            clearInterval(myTimer);
            return;
          }
          this.loadData()
        }, 6000)
      },
      loadData() {
        try {
          // 获取系统消息
          listByUser().then((res) => {
            console.log("listByUser res",res);
            if (res.code == 200) {
              this.notice1 = res.data.anntMsgList;
              this.msg1Count = res.data.anntMsgTotal;
              this.msg1Title = "通知(" + res.data.anntMsgTotal + ")";
              this.notice2 = res.data.sysMsgList;
              this.msg2Count = res.data.sysMsgTotal;
              this.msg2Title = "系统消息(" + res.data.sysMsgTotal + ")";
              this.notice3 = res.data.todealMsgList;
              this.msg3Count = res.data.todealMsgTotal;
              this.msg3Title = "待办消息(" + res.data.todealMsgTotal + ")";
            }
          }).catch(error => {
            console.log("系统消息通知异常", error); //这行打印permissionName is undefined
            this.stopTimer = true;
            console.log("清理timer");
          });
        } catch (err) {
          this.stopTimer = true;
          console.log("通知异常", err);
        }
      },
      fetchNotice() {
        if (this.loadding) {
          this.loadding = false
          return
        }
        this.loadding = true
        setTimeout(() => {
          this.loadding = false
        }, 200)
      },
      showNotice(record) {
        putAction(this.url.editNoticeSend, {
          anntId: record.id
        }).then((res) => {
          if (res.success) {
            this.loadData();
          }
        });
        this.hovered = false;
        if (record.openType === 'component') {
          this.openPath = record.openPage;
          this.formData = {
            id: record.busId
          };
          this.$refs.showDynamNotice.detail(record.openPage);
        } else {
          this.$refs.ShowNotice.detail(record);
        }
      },
      toMyNotice() {
        this.$router.push({
          path: '/isps/userAnnouncement'
        });
      },
      modalFormOk() {},
      handleHoverChange(visible) {
        this.hovered = visible;
      },

      initWebSocket: function() {
        // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
        var uid = store.getters.name;
        var url = process.env.VUE_APP_WS_API + "/websocket/" + uid;
        console.log("url=",url);
        this.websock = new WebSocket(url);
        this.websock.onopen = this.websocketOnopen;
        this.websock.onerror = this.websocketOnerror;
        this.websock.onmessage = this.websocketOnmessage;
        this.websock.onclose = this.websocketOnclose;
      },
      websocketOnopen: function() {
        console.log("WebSocket连接成功");
        //心跳检测重置
        //this.heartCheck.reset().start();
      },
      websocketOnerror: function(e) {
        console.log("WebSocket连接发生错误");
        this.reconnect();
      },
      websocketOnmessage: function(e) {
        console.log("-----接收消息-------", e);
        console.log("-----接收消息-------", e.data);
        var data = eval("(" + e.data + ")"); //解析对象
        if (data.cmd == "topic") {
          //系统通知
          this.loadData();
          this.$notification.open({ //websocket消息通知弹出
            message: 'websocket消息通知',
            description: data.msgTxt,
            style: {
              width: '600px',
              marginLeft: `${335 - 600}px`,
            },
          });
        } else if (data.cmd == "user") {
          //用户消息
          this.loadData();
          this.$notification.open({
            message: 'websocket消息通知',
            description: data.msgTxt,
            style: {
              width: '600px',
              marginLeft: `${335 - 600}px`,
            },
          });
        }
        //心跳检测重置
        //this.heartCheck.reset().start();
      },
      websocketOnclose: function(e) {
        console.log("connection closed (" + e + ")");
        if (e) {
          console.log("connection closed (" + e.code + ")");
        }
        this.reconnect();
      },
      websocketSend(text) { // 数据发送
        try {
          this.websock.send(text);
        } catch (err) {
          console.log("send failed (" + err.code + ")");
        }
      },

      openNotification(data) {
        var text = data.msgTxt;
        const key = `open${Date.now()}`;
        this.$notification.open({
          message: '消息提醒',
          placement: 'bottomRight',
          description: text,
          key,
          btn: (h) => {
            return h('a-button', {
              props: {
                type: 'primary',
                size: 'small',
              },
              on: {
                click: () => this.showDetail(key, data)
              }
            }, '查看详情')
          },
        });
      },

      reconnect() {
        var that = this;
        if (that.lockReconnect) return;
        that.lockReconnect = true;
        //没连接上会一直重连,设置延迟避免请求过多
        setTimeout(function() {
          console.info("尝试重连...");
          that.initWebSocket();
          that.lockReconnect = false;
        }, 5000);
      },
      heartCheckFun() {
        var that = this;
        //心跳检测,每20s心跳一次
        that.heartCheck = {
          timeout: 20000,
          timeoutObj: null,
          serverTimeoutObj: null,
          reset: function() {
            clearTimeout(this.timeoutObj);
            //clearTimeout(this.serverTimeoutObj);
            return this;
          },
          start: function() {
            var self = this;
            this.timeoutObj = setTimeout(function() {
              //这里发送一个心跳,后端收到后,返回一个心跳消息,
              //onmessage拿到返回的心跳就说明连接正常
              that.websocketSend("HeartBeat");
              console.info("客户端发送心跳");
              //self.serverTimeoutObj = setTimeout(function(){//如果超过一定时间还没重置,说明后端主动断开了
              //  that.websock.close();//如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
              //}, self.timeout)
            }, this.timeout)
          }
        }
      },


      showDetail(key, data) {
        this.$notification.close(key);
        var id = data.msgId;
        getAction(this.url.queryById, {
          id: id
        }).then((res) => {
          if (res.success) {
            var record = res.result;
            this.showNotice(record);
          }
        })

      },
    }
  }
</script>

<style lang="css">
  .header-notice-wrapper {
    top: 50px !important;
  }
</style>
<style lang="less" scoped>
  .header-notice {
    display: inline-block;
    transition: all 0.3s;

    span {
      vertical-align: initial;
    }
  }
</style>

3、效果图如下:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1033716.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【数据结构】二叉树之堆的实现

&#x1f525;博客主页&#xff1a;小王又困了 &#x1f4da;系列专栏&#xff1a;数据结构 &#x1f31f;人之为学&#xff0c;不日近则日退 ❤️感谢大家点赞&#x1f44d;收藏⭐评论✍️ 目录 一、二叉树的顺序结构 &#x1f4d2;1.1顺序存储 &#x1f4d2;1.2堆的性质…

【力扣每日一题】2023.9.23 树上的操作

目录 题目&#xff1a; 示例&#xff1a; 分析&#xff1a; 代码&#xff1a; 题目&#xff1a; 示例&#xff1a; 分析&#xff1a; 这是一道程序设计类的题目&#xff0c;题目比较长&#xff0c;我稍微概括一下。 构造函数中给我们一个数组&#xff0c;第i个元素表示第…

进程的状态和转换

一、进程的状态 1.创建态&#xff1a;进程正在被创建的阶段。此阶段&#xff0c;操作系统会为进程分配资源、初始化PCB。 2.就绪态&#xff1a;进程创建完毕即进入就绪态。此阶段&#xff0c;进程具备已经具备所有运行条件&#xff0c;但是此时CPU比较繁忙&#xff0c;没有空闲…

5+非肿瘤+WGCNA+单细胞

今天给同学们分享一篇5非肿瘤WGCNA单细胞的生信文章“Integrative network-based analysis on multiple Gene Expression Omnibus datasets identifies novel immune molecular markers implicated in non-alcoholic steatohepatitis”&#xff0c;这篇文章于2023年3月16日发表…

基于SpringBoot的房产销售系统

目录 前言 一、技术栈 二、系统功能介绍 用户功能模块 管理员功能模块 销售经理功能模块 前台首页功能模块 三、核心代码 1、登录模块 2、文件上传模块 3、代码封装 前言 随着科学技术的飞速发展&#xff0c;各行各业都在努力与现代先进技术接轨&#xff0c;通过科技手…

Java对比对象修改前与修改后字段发生的变化

开发过程中&#xff0c;我们通常会对系统操作人对系统的操作进行记录&#xff0c;记录操作前后某个字段的变化&#xff0c;如下图 2. 提供一个工具类&#xff0c;可以比较一个对象里面&#xff0c;源对象&#xff0c;与修改后的对象&#xff0c;有哪些字段发生了改变&#…

地球系统模式(CESM)应用及进阶

目前通用地球系统模式&#xff08;Community Earth System Model&#xff0c;CESM&#xff09;在研究地球的过去、现在和未来的气候状况中具有越来越普遍的应用。CESM由美国NCAR于2010年07月推出以来&#xff0c;一直受到气候学界的密切关注。近年升级的CESM2.0在大气、陆地、海…

在pandas中使matplotlib动态画子图的两种方法【推荐gridspec】

先上对比图&#xff0c; 第一种方法&#xff0c;这里仅展示1个大区&#xff0c;多个的话需要加一层循环就可以了&#xff0c;主要是看子图的画法 当大区下面的国家为1个或2个时&#xff0c;会进行报错 # 获取非洲国家列表 african_countries df[df[大区] 南亚大区][进口国…

ARM DAY3

硬件模块与总线连接&#xff1a;各种硬件模块&#xff08;如 GPIO 控制器&#xff09;与 CPU&#xff08;或内核&#xff09;通过总线进行连接。这个总线负责数据和指令的传输。 特殊功能寄存器&#xff08;SFRs&#xff09;的角色&#xff1a;每个硬件模块内部都有一组特殊功…

PowerDesigner 连接 MYSQL

我使用的是powerDesigner16的版本&#xff0c;使用前先保证安装了 mysql odbc 驱动包 选择&#xff1a;文件 -> 反向工程 -> database… 一大波图片正在来袭。。。 点击确认 至此连接成功

解决方案 | 如何构建市政综合管廊安全运行监测系统?

如何构建市政综合管廊安全运行监测系统&#xff1f;WITBEE万宾城市生命线智能监测仪器&#xff0c;5年免维护设计&#xff0c;集成10多项结构与气体健康监测指标&#xff0c;毫秒级快速响应&#xff0c;时刻感知综合管廊运行态势

make: /bin/nvcc: Command not found 解决找不到nvcc

首先输入nvcc -V查看nvcc路径&#xff0c;发现报错Command nvcc not found&#xff0c;接下来我们就要解决这个问题。 1&#xff09;进入cuda的bin目录cd /usr/local/cuda/bin&#xff0c;ls查看是否有nvcc 说明存在nvcc但cuda路径没有添加系统变量 2&#xff09;在bin目录下输…

C++中变量是按值访问的, Python 中变量的值是按引用访问的示例说明

C中变量是按值访问的&#xff0c; Python 中变量的值是按引用访问的示例说明 C、C、Python如何获取变量的地址 C语言 在C语言中&#xff0c;可以使用取地址运算符&#xff08;&&#xff09;来获取变量的地址。 例如&#xff1a; #include <stdio.h>int main() {…

基于SSM+Vue的网上超市系统设计与实现

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SSM 前端&#xff1a;采用Vue技术开发 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#x…

苏宁滑块验证

网址&#xff1a;https://passport.suning.com/ids/login总结一下&#xff0c;别被他的表面现象给骗了&#xff0c;这玩意儿&#xff0c;个人认为&#xff0c;腾讯的都没法跟他比&#xff01;&#xff01;&#xff01; 难点&#xff1a;动态混淆&#xff0c;vmp&#xff0c;图片…

PID学习

文章目录 1、 简介2、P 比例调节3、I 积分控制4、D 微分控制5、简单的模拟PID输出代码6、改进6.1 采样时间6.1.1 问题所在6.1.2 解决方案6.1.3 代码6.1.4 结果6.1.5 关于中断的旁注6.1.6 个人总结 6.2 微分项出现尖峰6.2.1 问题所在6.2.2 解决方案6.2.3 代码6.2.4 结果6.2.5 个…

执行上下文,js、React、HTML中的this

目录 执行上下文属性&#xff1a;变量对象、this&#xff0c;作用域链 变量对象是与执行上下文相关的数据作用域&#xff0c;存储&#xff1a;变量、函数声明 执行上下文生命周期 创建&#xff1a;生成变量对象、创建函数作用域&#xff0c;建立作用域链、确定this的指向 …

jdk 21发布的意义

jdk 21 最大的功能是虚拟线程&#xff0c;是一种绿色线程&#xff08;具体可以看周志明老师的书籍《深入理解java虚拟机》&#xff09;&#xff0c;目前 jvm 与操作系统的线程是一一对应的关系。 使用了虚拟线程可以减少资源消耗&#xff0c;减少操作系统上下文切换&#xff0…

AIGC绘本——海马搬家来喽

随着ChatGPT的快速发展&#xff0c;人工智能领域也发生了翻天覆地的变化。今天&#xff0c;我们迎合科技潮流&#xff0c;利用AIGC的强大能力&#xff0c;可以创作很多精彩的作品&#xff0c;比如这样一本名为《海马搬家》的绘本&#xff08;注&#xff1a;此绘本根据同名儿童故…

strtok()函数的使用方法

strtok() 函数用于将字符串分割成子字符串&#xff08;标记&#xff09;。它在 C 语言中非常常用&#xff0c;可以通过指定分隔符来拆分原始字符串&#xff0c;并依次返回每个子字符串。 以下是 strtok() 函数的使用方法&#xff1a; #include <stdio.h> #include <…