软件系统开发定制vue通知提醒消息

目录

           

           



前言

软件系统开发定制最近有个项目需求就是软件系统开发定制在客户端的右上角要实软件系统开发定制时展示提醒消息,下面来看下简单的实现步骤


一、

这是基于悬浮出现在页面角落,显示全局的通知提醒消息。这个elmennt-ui组件可以实现我们上面的功能。

二、Notification引用

1.全局引用

element 为 Vue.prototype 添加了全局方法 $notify。因此在 vue instance 中可以采用本页面中的方式调用 Notification。

2.单独引用

import { Notification } from '';

此时调用方法为 Notification(options)。我们也为每个 type 定义了各自的方法,如 Notification.success(options)。并且可以调用 Notification.closeAll() 手动关闭所有实例。

三、参数说明


四、简单案例 

右上角就会弹出我们写的html代码段是不是特别简单

  1. <template>
  2. <el-button
  3. plain
  4. @click="open">
  5. 使用 HTML 片段
  6. </el-button>
  7. </template>
  8. <script>
  9. export default {
  10. methods: {
  11. open() {
  12. this.$notify({
  13. title: 'HTML 片段',
  14. dangerouslyUseHTMLString: true,
  15. message: '<strong>这是 <i>HTML</i> 片段</strong>'
  16. });
  17. }
  18. }
  19. }
  20. </script>

五、项目实战

这里大概说一下我的流程,我这里需要建立连接,服务器实时推送信息给客户端在右上角展示,这里需要用到Websocket以及本章学的通知。Websocket在前一章有讲。案例仅供参考。

1、定义全局Notification。

  1. /* 全局Notification */
  2. Vue.prototype.$baseNotify = (message, title, type, position) => {
  3. Notification({
  4. title: title,
  5. message: message,
  6. position: position || 'top-right',
  7. type: type || 'success',
  8. duration: messageDuration,
  9. })
  10. }

2、Websocket实时接收通知。

  1. initWebSocket() {
  2. const token = getAccessToken()
  3. const wsurl = `${this.troubelUrl}?code=trouble&token=${token}`
  4. this.twebsock = new WebSocket(wsurl)
  5. this.twebsock.onmessage = this.websocketonmessage
  6. this.twebsock.onopen = this.websocketonopen
  7. this.twebsock.onerror = this.websocketonerror
  8. this.twebsock.onclose = this.websocketclose
  9. },
  10. websocketonopen() {
  11. //webscoket定时心跳
  12. this.troubleTimer = setInterval(() => {
  13. let pageUrl = window.location.hash
  14. if (pageUrl !== '' && pageUrl !== '#/login') {
  15. this.websocketsend('heartbeat')
  16. }
  17. }, 50000)
  18. console.log('数据发送...')
  19. },
  20. websocketonerror(e) {
  21. //连接建立失败重连
  22. setTimeout(() => {
  23. this.initWebSocket()
  24. }, 10000)
  25. console.log('故障连接出错~')
  26. },
  27. websocketonmessage(evt) {
  28. var monitorData = evt.data
  29. monitorData = JSON.parse(monitorData)
  30. this.switchOther(this.troublePush, monitorData)
  31. },
  32. //根据数据判断进行弹框(紧急呼叫,长时间关人)
  33. switchOther(switchValue, monitorData) {
  34. if (switchValue === true || switchValue === 'true') {
  35. this.handleOpen(monitorData)
  36. }
  37. },
  38. websocketsend(data) {
  39. this.twebsock.send(data)
  40. },
  41. websocketclose(e) {
  42. if (this.twebsock == null) {
  43. return
  44. }
  45. this.twebsock.close()
  46. this.twebsock = null
  47. clearInterval(this.troubleTimer)
  48. console.log('故障推送关闭~')
  49. },

3、消息通知

  1. //monitorItem取的前面Websocket返回回来的值
  2. handleOpen(monitorItem) {
  3. this.openDialogflase = true
  4. const h = this.$createElement
  5. let notify = this.$notify({
  6. title: monitorItem.troubleType,
  7. message: h('p', null, [
  8. h(
  9. 'span',
  10. {
  11. style: {
  12. display: 'inline-block',
  13. margin: '0 0 10px 0',
  14. },
  15. },
  16. `${monitorItem.projectName}-${monitorItem.useCode}`
  17. ),
  18. h(
  19. 'p',
  20. {
  21. style: {
  22. display: 'flex',
  23. alignItems: 'center',
  24. justifyContent: 'space-between',
  25. margin: '0 0 5px 0',
  26. },
  27. },
  28. [
  29. h('span', null, monitorItem.duration),
  30. h(
  31. 'span',
  32. {
  33. style: {
  34. color: '#efefef',
  35. },
  36. },
  37. monitorItem.fromType
  38. ),
  39. ]
  40. ),
  41. h('p', null, monitorItem.address),
  42. h(
  43. 'button',
  44. {
  45. style: {
  46. padding: '5px 20px',
  47. fontSize: '14px',
  48. borderRadius: '4px',
  49. color: '#fff',
  50. background: '#ff575a',
  51. border: 'none',
  52. margin: '10px 10px 0 0',
  53. display: 'inline-block',
  54. },
  55. on: {
  56. click: this.clickBtn.bind(this, monitorItem),
  57. },
  58. },
  59. '查看详情'
  60. ),
  61. h(
  62. 'button',
  63. {
  64. style: {
  65. padding: '5px 20px',
  66. fontSize: '14px',
  67. borderRadius: '4px',
  68. color: '#fff',
  69. background: '#ff575a',
  70. border: 'none',
  71. margin: '10px 10px 0 0',
  72. display: 'inline-block',
  73. },
  74. on: {
  75. click: this.handleShi.bind(this, monitorItem),
  76. },
  77. },
  78. '双向视频'
  79. ),
  80. h(
  81. 'button',
  82. {
  83. style: {
  84. padding: '5px 20px',
  85. fontSize: '14px',
  86. borderRadius: '4px',
  87. color: '#fff',
  88. background: '#ff575a',
  89. border: 'none',
  90. margin: '10px 0 0 0',
  91. display: 'inline-block',
  92. },
  93. on: {
  94. click: this.handleQuXiao.bind(this, monitorItem),
  95. },
  96. },
  97. '取消'
  98. ),
  99. ]),
  100. duration: 0,
  101. showClose: false,
  102. })
  103. //将通知实例放入
  104. this.notifications[monitorItem.orderKey] = notify
  105. this.handleAudio()
  106. },
  107. //关闭当前故障弹框
  108. handleQuXiao(monitorItem) {
  109. this.openDialogflase = false
  110. this.notifications[monitorItem.orderKey].close()
  111. delete this.notifications[monitorItem.orderKey]
  112. },
  113. //关闭所有弹窗
  114. closeAll() {
  115. let vue = this
  116. for (let key in vue.notifications) {
  117. vue.notifications[key].close()
  118. delete vue.notifications[key]
  119. }
  120. },
网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发