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


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

    gitee源代码地址

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

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

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

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

    1. "消息" effect="dark" placement="bottom">
    2. <header-notice id="message" class="right-menu-item-message hover-effect" />
    3. <el-tooltip content="源码地址" effect="dark" placement="bottom">
    4. <ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />
    5. el-tooltip>

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

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

    其中调用了接口listByUser,

    1. <script>
    2. import ShowNotice from './ShowNotice'
    3. import store from '@/store/'
    4. import DynamicNotice from './DynamicNotice'
    5. import { listByUser } from "@/api/system/notice";
    6. export default {
    7. name: "HeaderNotice",
    8. components: {
    9. DynamicNotice,
    10. ShowNotice,
    11. },
    12. data() {
    13. return {
    14. loadding: false,
    15. url: {
    16. listNoticeByUser: "/system/notice/listByUser",
    17. editNoticeSend: "/system/notice/editByAnntIdAndUserId",
    18. queryById: "/system/notice/queryById",
    19. },
    20. hovered: false,
    21. notice1: [],
    22. notice2: [],
    23. notice3: [],
    24. msg1Count: "0",
    25. msg2Count: "0",
    26. msg3Count: "0",
    27. msg1Title: "通知(0)",
    28. msg2Title: "",
    29. msg3Title: "",
    30. stopTimer: false,
    31. websock: null,
    32. lockReconnect: false,
    33. heartCheck: null,
    34. formData: {},
    35. openPath: ''
    36. }
    37. },
    38. computed: {
    39. msgTotal() {
    40. return parseInt(this.msg1Count) + parseInt(this.msg2Count) + parseInt(this.msg3Count);
    41. }
    42. },
    43. mounted() {
    44. this.loadData();
    45. //this.timerFun();
    46. this.initWebSocket();
    47. // this.heartCheckFun();
    48. },
    49. destroyed: function() { // 离开页面生命周期函数
    50. this.websocketOnclose();
    51. },
    52. methods: {
    53. timerFun() {
    54. this.stopTimer = false;
    55. let myTimer = setInterval(() => {
    56. // 停止定时器
    57. if (this.stopTimer == true) {
    58. clearInterval(myTimer);
    59. return;
    60. }
    61. this.loadData()
    62. }, 6000)
    63. },
    64. loadData() {
    65. try {
    66. // 获取系统消息
    67. listByUser().then((res) => {
    68. console.log("listByUser res",res);
    69. if (res.code == 200) {
    70. this.notice1 = res.data.anntMsgList;
    71. this.msg1Count = res.data.anntMsgTotal;
    72. this.msg1Title = "通知(" + res.data.anntMsgTotal + ")";
    73. this.notice2 = res.data.sysMsgList;
    74. this.msg2Count = res.data.sysMsgTotal;
    75. this.msg2Title = "系统消息(" + res.data.sysMsgTotal + ")";
    76. this.notice3 = res.data.todealMsgList;
    77. this.msg3Count = res.data.todealMsgTotal;
    78. this.msg3Title = "待办消息(" + res.data.todealMsgTotal + ")";
    79. }
    80. }).catch(error => {
    81. console.log("系统消息通知异常", error); //这行打印permissionName is undefined
    82. this.stopTimer = true;
    83. console.log("清理timer");
    84. });
    85. } catch (err) {
    86. this.stopTimer = true;
    87. console.log("通知异常", err);
    88. }
    89. },
    90. fetchNotice() {
    91. if (this.loadding) {
    92. this.loadding = false
    93. return
    94. }
    95. this.loadding = true
    96. setTimeout(() => {
    97. this.loadding = false
    98. }, 200)
    99. },
    100. showNotice(record) {
    101. putAction(this.url.editNoticeSend, {
    102. anntId: record.id
    103. }).then((res) => {
    104. if (res.success) {
    105. this.loadData();
    106. }
    107. });
    108. this.hovered = false;
    109. if (record.openType === 'component') {
    110. this.openPath = record.openPage;
    111. this.formData = {
    112. id: record.busId
    113. };
    114. this.$refs.showDynamNotice.detail(record.openPage);
    115. } else {
    116. this.$refs.ShowNotice.detail(record);
    117. }
    118. },
    119. toMyNotice() {
    120. this.$router.push({
    121. path: '/isps/userAnnouncement'
    122. });
    123. },
    124. modalFormOk() {},
    125. handleHoverChange(visible) {
    126. this.hovered = visible;
    127. },
    128. initWebSocket: function() {
    129. // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
    130. var uid = store.getters.name;
    131. var url = process.env.VUE_APP_WS_API + "/websocket/" + uid;
    132. console.log("url=",url);
    133. this.websock = new WebSocket(url);
    134. this.websock.onopen = this.websocketOnopen;
    135. this.websock.onerror = this.websocketOnerror;
    136. this.websock.onmessage = this.websocketOnmessage;
    137. this.websock.onclose = this.websocketOnclose;
    138. },
    139. websocketOnopen: function() {
    140. console.log("WebSocket连接成功");
    141. //心跳检测重置
    142. //this.heartCheck.reset().start();
    143. },
    144. websocketOnerror: function(e) {
    145. console.log("WebSocket连接发生错误");
    146. this.reconnect();
    147. },
    148. websocketOnmessage: function(e) {
    149. console.log("-----接收消息-------", e);
    150. console.log("-----接收消息-------", e.data);
    151. var data = eval("(" + e.data + ")"); //解析对象
    152. if (data.cmd == "topic") {
    153. //系统通知
    154. this.loadData();
    155. this.$notification.open({ //websocket消息通知弹出
    156. message: 'websocket消息通知',
    157. description: data.msgTxt,
    158. style: {
    159. width: '600px',
    160. marginLeft: `${335 - 600}px`,
    161. },
    162. });
    163. } else if (data.cmd == "user") {
    164. //用户消息
    165. this.loadData();
    166. this.$notification.open({
    167. message: 'websocket消息通知',
    168. description: data.msgTxt,
    169. style: {
    170. width: '600px',
    171. marginLeft: `${335 - 600}px`,
    172. },
    173. });
    174. }
    175. //心跳检测重置
    176. //this.heartCheck.reset().start();
    177. },
    178. websocketOnclose: function(e) {
    179. console.log("connection closed (" + e + ")");
    180. if (e) {
    181. console.log("connection closed (" + e.code + ")");
    182. }
    183. this.reconnect();
    184. },
    185. websocketSend(text) { // 数据发送
    186. try {
    187. this.websock.send(text);
    188. } catch (err) {
    189. console.log("send failed (" + err.code + ")");
    190. }
    191. },
    192. openNotification(data) {
    193. var text = data.msgTxt;
    194. const key = `open${Date.now()}`;
    195. this.$notification.open({
    196. message: '消息提醒',
    197. placement: 'bottomRight',
    198. description: text,
    199. key,
    200. btn: (h) => {
    201. return h('a-button', {
    202. props: {
    203. type: 'primary',
    204. size: 'small',
    205. },
    206. on: {
    207. click: () => this.showDetail(key, data)
    208. }
    209. }, '查看详情')
    210. },
    211. });
    212. },
    213. reconnect() {
    214. var that = this;
    215. if (that.lockReconnect) return;
    216. that.lockReconnect = true;
    217. //没连接上会一直重连,设置延迟避免请求过多
    218. setTimeout(function() {
    219. console.info("尝试重连...");
    220. that.initWebSocket();
    221. that.lockReconnect = false;
    222. }, 5000);
    223. },
    224. heartCheckFun() {
    225. var that = this;
    226. //心跳检测,每20s心跳一次
    227. that.heartCheck = {
    228. timeout: 20000,
    229. timeoutObj: null,
    230. serverTimeoutObj: null,
    231. reset: function() {
    232. clearTimeout(this.timeoutObj);
    233. //clearTimeout(this.serverTimeoutObj);
    234. return this;
    235. },
    236. start: function() {
    237. var self = this;
    238. this.timeoutObj = setTimeout(function() {
    239. //这里发送一个心跳,后端收到后,返回一个心跳消息,
    240. //onmessage拿到返回的心跳就说明连接正常
    241. that.websocketSend("HeartBeat");
    242. console.info("客户端发送心跳");
    243. //self.serverTimeoutObj = setTimeout(function(){//如果超过一定时间还没重置,说明后端主动断开了
    244. // that.websock.close();//如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
    245. //}, self.timeout)
    246. }, this.timeout)
    247. }
    248. }
    249. },
    250. showDetail(key, data) {
    251. this.$notification.close(key);
    252. var id = data.msgId;
    253. getAction(this.url.queryById, {
    254. id: id
    255. }).then((res) => {
    256. if (res.success) {
    257. var record = res.result;
    258. this.showNotice(record);
    259. }
    260. })
    261. },
    262. }
    263. }
    264. script>
    265. <style lang="css">
    266. .header-notice-wrapper {
    267. top: 50px !important;
    268. }
    269. style>
    270. <style lang="less" scoped>
    271. .header-notice {
    272. display: inline-block;
    273. transition: all 0.3s;
    274. span {
    275. vertical-align: initial;
    276. }
    277. }
    278. style>

    3、效果图如下:

  • 相关阅读:
    5个前端练手项目(html css js canvas)
    Linux XWindow的安装和配置
    计算机毕业设计ssm+vue基本微信小程序的校园生活助手系统
    SpringCloudAlibaba组件 — — OpenFeign的其他作用【超时时间、日志打印】
    crash问题常用分析方法
    Python和C++音调音符规划和算法
    plink如何更新表型数据
    【C语言入门】ZZULIOJ 1031-1035
    [UDS] --- ReadDataByIdentifier 0x22
    云计算的一些常见安全风险
  • 原文地址:https://blog.csdn.net/qq_40032778/article/details/133198751