VoiceBroadcastGsd.vue 9.3 KB

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