1
0

VoiceBroadcastGsd.vue 8.9 KB

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