VoiceBroadcastGsd.vue 10 KB

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