VoiceBroadcastGsd.vue 9.0 KB

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