MessageBroadcast.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div style="position: fixed; z-index: 999; right: 120px; top: 20px; color: #fff">
  3. <div class="btn" @click="showWarningBroad">
  4. <a-badge :dot="isWarningDot">
  5. <BellOutlined style="font-size: 22px; color: #fff; margin-right: 20px" />
  6. </a-badge>
  7. </div>
  8. <div v-if="isShowWarningBroad" class="broadcast">
  9. <div class="title">
  10. <div class="message-title">预警通知</div>
  11. <div class="badge-box">
  12. <SoundOutlined :class="{ 'no-play': !isBroad }" style="font-size: 16px; color: #fff" @click="handleBroad" />
  13. </div>
  14. </div>
  15. <div class="broadcast-context">
  16. <div class="context-tab">
  17. <div class="context-tab-item" :class="{ 'context-tab-item-active': activeKey == 0 }" @click="toSelectList(0)">
  18. 全部</div>
  19. <div class="context-tab-item" :class="{ 'context-tab-item-active': activeKey == 1 }" @click="toSelectList(1)">
  20. 未读</div>
  21. <div class="context-tab-item" :class="{ 'context-tab-item-active': activeKey == 2 }" @click="toSelectList(2)">
  22. 已读</div>
  23. </div>
  24. <div class="context-box">
  25. <div v-if="broadcastList.length == 0" class="no-context">暂无内容</div>
  26. <div class="context-detail" v-else v-for="(item, index) in broadcastList" :key="index"
  27. :style="{ color: item['isok'] == 0 ? 'red' : '#eee' }">
  28. <div>{{ item['createTime'] }}</div>
  29. <div>{{ item['devicekind_dictText'] }}</div>
  30. <div>{{ item['wardescrip'] || item['nwartype_dictText'] }}</div>
  31. <div>{{ item['isok'] ? '已解决' : '未解决' }}</div>
  32. </div>
  33. <div v-if="broadcastList.length > 0" class="more" @click="toMore">更多>></div>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script lang="ts">
  40. import { Tooltip, Badge } from 'ant-design-vue';
  41. import { SoundOutlined, BellOutlined, WarningOutlined } from '@ant-design/icons-vue';
  42. import Icon from '/@/components/Icon';
  43. import { defineComponent, ref, unref, onMounted } from 'vue';
  44. import { defHttp } from '/@/utils/http/axios';
  45. import { useRouter } from 'vue-router';
  46. import { connectWebSocket, onWebSocket } from '/@/hooks/web/useWebSocket';
  47. import { getToken } from '/@/utils/auth';
  48. import { useUserStore } from '/@/store/modules/user';
  49. import { useGlobSetting } from '/@/hooks/setting';
  50. import SpeakVoice from './notify/speakVoice';
  51. export default defineComponent({
  52. name: 'VoiceBroadcast',
  53. components: { Icon, Tooltip, Badge, SoundOutlined, BellOutlined, WarningOutlined },
  54. setup() {
  55. const speakVoice = new SpeakVoice();
  56. const userStore = useUserStore();
  57. const glob = useGlobSetting();
  58. const router = useRouter();
  59. const list = (params) => defHttp.get({ url: '/safety/ventanalyAlarmLog/list', params });
  60. const activeKey = ref(0);
  61. const isShowWarningBroad = ref(false);
  62. const isBroad = ref(true);
  63. const isWarningDot = ref(false);
  64. const broadcastList = ref([]);
  65. function showWarningBroad() {
  66. isShowWarningBroad.value = !isShowWarningBroad.value;
  67. if (isShowWarningBroad.value) {
  68. toSelectList(0);
  69. }
  70. }
  71. function handleBroad() {
  72. isBroad.value = !isBroad.value;
  73. }
  74. async function toSelectList(key) {
  75. activeKey.value = key;
  76. const res = await list({ pageSize: 20, devicetype: '', isok: key == 1 ? 0 : key == 2 ? 1 : null });
  77. broadcastList.value = res['records'];
  78. // const isHasWarning = broadcastList.value.findIndex((item) => !item['isok']);
  79. // isWarningDot.value = isHasWarning > -1 ? true : false;
  80. }
  81. async function toMore() {
  82. await router.push({ path: '/monitorChannel/device-monitor/warningHistory' });
  83. showWarningBroad();
  84. }
  85. // 初始化 WebSocket
  86. function initWebSocket() {
  87. let token = getToken();
  88. //将登录token生成一个短的标识
  89. // let wsClientId = md5(token);
  90. // let userId = unref(userStore.getUserInfo).id + '_' + wsClientId;
  91. let userId = unref(userStore.getUserInfo).id + '?token=' + token;
  92. // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
  93. let url = glob.wsUrl?.replace('https://', 'wss://').replace('http://', 'ws://') + '/websocket/' + userId;
  94. connectWebSocket(url);
  95. onWebSocket(onWebSocketMessage);
  96. }
  97. function onWebSocketMessage(data) {
  98. // console.log('WebSocket 监测消息--------------》', data);
  99. if (data.topic === 'warn' || data.cmd === 'user') {
  100. if (isBroad.value) {
  101. const messageText = data['warndata'];
  102. // const messageText = '这是一个测试';
  103. speakVoice.handleReply(messageText);
  104. }
  105. if (!isShowWarningBroad.value) {
  106. isWarningDot.value = true;
  107. } else {
  108. isWarningDot.value = false;
  109. }
  110. setTimeout(() => {
  111. if (isShowWarningBroad.value) {
  112. toSelectList(0);
  113. }
  114. }, 0);
  115. }
  116. }
  117. onMounted(() => {
  118. initWebSocket();
  119. });
  120. return { showWarningBroad, isShowWarningBroad, activeKey, toSelectList, broadcastList, toMore, isBroad, handleBroad, isWarningDot };
  121. },
  122. });
  123. </script>
  124. <style lang="less" scoped>
  125. .btn {
  126. line-height: 30px;
  127. margin-right: 20px;
  128. cursor: pointer;
  129. display: flex;
  130. }
  131. .no-play {
  132. background: linear-gradient(to bottom left,
  133. transparent 0%,
  134. transparent calc(50% - 1px),
  135. #000000 50%,
  136. transparent calc(50% + 1px),
  137. transparent 100%);
  138. }
  139. .broadcast {
  140. width: 400px;
  141. height: 250px;
  142. border-radius: 4px;
  143. position: fixed;
  144. top: 50px;
  145. right: 20px;
  146. background-color: rgb(255, 255, 255);
  147. background: url('../../../../assets/images/warn-dialog-bg.png') no-repeat center;
  148. background-size: 100% 100%;
  149. z-index: 9999999;
  150. color: #FFF;
  151. .title {
  152. height: 32px;
  153. padding: 0 20px;
  154. :deep(.ant-badge:not(.ant-badge-status)) {
  155. margin-right: 40px !important;
  156. }
  157. display: flex;
  158. align-items: center;
  159. justify-content: space-between;
  160. margin-bottom: 5px;
  161. .message-title {
  162. font-size: 16px;
  163. }
  164. .badge-box {
  165. display: flex;
  166. align-items: center;
  167. .badge-title {
  168. display: inline-block;
  169. width: 62px;
  170. line-height: 32px;
  171. background-color: #2174f0;
  172. border-radius: 26px;
  173. text-align: center;
  174. color: #fff;
  175. padding-bottom: 2px;
  176. }
  177. }
  178. }
  179. .broadcast-context {
  180. .context-tab {
  181. display: flex;
  182. .context-tab-item {
  183. line-height: 24px;
  184. background-color: #6b6b6b;
  185. border-radius: 24px;
  186. text-align: center;
  187. padding: 0 10px;
  188. color: #fff;
  189. margin: 5px;
  190. cursor: pointer;
  191. font-size: 14px;
  192. }
  193. .context-tab-item-active {
  194. background-color: #2174f0;
  195. }
  196. }
  197. .context-box {
  198. flex: 1;
  199. padding: 0 10px;
  200. height: 178px;
  201. overflow-y: auto;
  202. .no-context {
  203. display: flex;
  204. justify-content: center;
  205. padding-top: 30px;
  206. font-size: 16px;
  207. }
  208. .context-detail {
  209. display: flex;
  210. justify-content: space-between;
  211. line-height: 24px;
  212. padding: 0px 3px;
  213. div {
  214. display: flex;
  215. justify-content: flex-start;
  216. &:nth-child(1) {
  217. width: 40%;
  218. }
  219. &:nth-child(2) {
  220. width: 20%;
  221. }
  222. &:nth-child(3) {
  223. width: 25%;
  224. }
  225. &:nth-child(4) {
  226. width: 15%;
  227. }
  228. }
  229. }
  230. .more {
  231. cursor: pointer;
  232. &:hover {
  233. color: #2174f0;
  234. }
  235. }
  236. }
  237. }
  238. }
  239. </style>