VoiceBroadcast.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <div>
  3. <div class="btn" @click="showWarningBroad">
  4. <!-- <div>语音播报</div>
  5. <a-badge :count="10">
  6. <a href="#" class="head-example"></a>
  7. </a-badge> -->
  8. <a-badge :dot="isWarningDot" style="display: flex; flex-direction: row">
  9. <BellOutlined style="font-size: 22px; color: #fff; padding-left: 0" />
  10. <WarningOutlined style="font-size: 22px; color: #fff; padding-right: 0" />
  11. </a-badge>
  12. </div>
  13. <div v-if="isShowWarningBroad" class="broadcast" ref="VoiceBroadcastRef" id="VoiceBroadcast">
  14. <div class="title">
  15. <div class="message-title">预警通知</div>
  16. <div class="badge-box">
  17. <ClearOutlined style="font-size: 20px; color: #fff" @click="clearInfo" />
  18. <SoundOutlined :class="{ 'no-play': !isBroad }" style="font-size: 20px; color: #fff" @click="handleBroad" />
  19. <CloseOutlined style="font-size: 20px; color: #fff" @click="closeWarningBroad" />
  20. </div>
  21. </div>
  22. <div class="broadcast-context">
  23. <div class="context-tab">
  24. <div class="context-tab-item" :class="{ 'context-tab-item-active': activeKey == 0 }" @click="toSelectList(0)"> 全部</div>
  25. <div class="context-tab-item" :class="{ 'context-tab-item-active': activeKey == 1 }" @click="toSelectList(1)"> 未解决</div>
  26. <div class="context-tab-item" :class="{ 'context-tab-item-active': activeKey == 2 }" @click="toSelectList(2)"> 已解决</div>
  27. </div>
  28. <div class="context-box">
  29. <div v-if="(broadcastList && broadcastList.length == 0) || !broadcastList" class="no-context">暂无内容</div>
  30. <div
  31. class="context-detail"
  32. v-else
  33. v-for="(item, index) in broadcastList"
  34. :key="index"
  35. :style="{ color: item['isok'] == 0 ? '#f73210' : '#eee', fontWeight: item['isok'] == 0 ? '600' : '500' }"
  36. >
  37. <div>{{ item['createTime'] }}</div>
  38. <div>{{ item['devicename'] }}</div>
  39. <div>{{ item['wardescrip'] || item['nwartype_dictText'] }}</div>
  40. <div>{{ item['isok'] ? '已解决' : '未解决' }}</div>
  41. </div>
  42. </div>
  43. <div class="more" @click="toMore">更多>></div>
  44. <!-- <div v-if="broadcastList.length > 0" class="more" @click.self="test()">测试>></div> -->
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script lang="ts">
  50. import { SoundOutlined, ClearOutlined, BellOutlined, WarningOutlined, CloseOutlined } from '@ant-design/icons-vue';
  51. import { defineComponent, ref, unref, onMounted, onUnmounted, nextTick } from 'vue';
  52. import { defHttp } from '/@/utils/http/axios';
  53. import { useRouter } from 'vue-router';
  54. import { connectWebSocket, onWebSocket, offWebSocket } from '/@/hooks/web/useWebSocket';
  55. import { getToken } from '/@/utils/auth';
  56. import { useUserStore } from '/@/store/modules/user';
  57. import { usePermission } from '/@/hooks/web/usePermission';
  58. import { usePermissionStore } from '/@/store/modules/permission';
  59. import SpeakVoice from './notify/speakVoice';
  60. import { useDrag } from '@/hooks/event/useDrag';
  61. import { useGlobSetting } from '/@/hooks/setting';
  62. import dayjs from 'dayjs';
  63. export default defineComponent({
  64. name: 'VoiceBroadcast',
  65. components: { SoundOutlined, ClearOutlined, BellOutlined, WarningOutlined, CloseOutlined },
  66. setup() {
  67. // debugger;
  68. let speakVoice;
  69. const userStore = useUserStore();
  70. const { hasPermission } = usePermission();
  71. const permissionStore = usePermissionStore();
  72. const router = useRouter();
  73. const glob = useGlobSetting();
  74. const list = (params) => defHttp.get({ url: '/safety/ventanalyAlarmLog/list', params });
  75. const cleanAlarm = () => defHttp.get({ url: '/safety/ventanalyAlarmLog/cleanAlarmLog' });
  76. const activeKey = ref(0);
  77. const isShowWarningBroad = ref(false);
  78. const isBroad = ref(true);
  79. const isWarningDot = ref(false);
  80. const broadcastList = ref([]);
  81. function showWarningBroad() {
  82. isShowWarningBroad.value = !isShowWarningBroad.value;
  83. if (isShowWarningBroad.value) {
  84. toSelectList(0);
  85. nextTick(() => {
  86. const dom = document.getElementById('VoiceBroadcast');
  87. if (dom) useDrag(dom);
  88. });
  89. }
  90. }
  91. function handleBroad() {
  92. isBroad.value = !isBroad.value;
  93. }
  94. //点击关闭预警信息弹窗
  95. function closeWarningBroad() {
  96. isShowWarningBroad.value = false;
  97. }
  98. async function clearInfo() {
  99. await cleanAlarm();
  100. const res = await list({ pageSize: 20, devicetype: '', sort: 'createTime', delFlag: 0, nwartype_end: '999' });
  101. broadcastList.value = res['records'];
  102. }
  103. async function toSelectList(key) {
  104. activeKey.value = key;
  105. const res = await list({
  106. pageSize: 20,
  107. devicetype: '',
  108. isok: key == 1 ? 0 : key == 2 ? 1 : null,
  109. sort: 'createTime',
  110. delFlag: 0,
  111. nwartype_end: '999',
  112. });
  113. broadcastList.value = res['records'];
  114. const isHasWarning = broadcastList.value.findIndex((item) => !item['isok']);
  115. if (key !== 2) isWarningDot.value = isHasWarning > -1 ? true : false;
  116. }
  117. async function toMore() {
  118. await router.push({ path: '/monitorChannel/device-monitor/warningHistory/home' });
  119. showWarningBroad();
  120. }
  121. // 初始化 WebSocket
  122. function initWebSocket() {
  123. let token = getToken();
  124. //将登录token生成一个短的标识
  125. // let wsClientId = md5(token);
  126. // let userId = unref(userStore.getUserInfo).id + '_' + wsClientId;
  127. let userId = unref(userStore.getUserInfo).id + '?token=' + token;
  128. console.log(userStore.getUserInfo, 'userId---');
  129. // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
  130. // [SEC-20260913] 端点改读运行时配置 glob.wsUrl(public/js/config.js 单点),去掉 :9999 硬编码
  131. let url = glob.wsUrl?.replace('https://', 'wss://').replace('http://', 'ws://') + '/websocket/' + userId;
  132. console.log(url, 'url------');
  133. connectWebSocket(url);
  134. onWebSocket(onWebSocketMessage);
  135. }
  136. async function onWebSocketMessage(data) {
  137. console.log('WebSocket 监测消息--------------》', data);
  138. if (hasPermission('show:noWarning')) return;
  139. if (!permissionStore.getPermCodeList?.length) return;
  140. if (data.topic === 'warn' || data.cmd === 'user') {
  141. if (isBroad.value) {
  142. await speakVoice.getSpeechCnVoices();
  143. const messageText = data['warndata'];
  144. speakVoice.handleReply(messageText);
  145. const time = dayjs().format('YYYY-MM-DD HH:mm:ss');
  146. console.log(time + '语音播报开始报警------>', data);
  147. }
  148. if (!isShowWarningBroad.value) {
  149. isWarningDot.value = true;
  150. } else {
  151. isWarningDot.value = false;
  152. }
  153. setTimeout(() => {
  154. if (isShowWarningBroad.value) {
  155. toSelectList(0);
  156. }
  157. }, 0);
  158. }
  159. }
  160. onMounted(() => {
  161. speakVoice = new SpeakVoice();
  162. nextTick(async () => {
  163. initWebSocket();
  164. await toSelectList(1);
  165. });
  166. window.speechSynthesis.onvoiceschanged = () => {
  167. console.log('语音列表已更新');
  168. };
  169. });
  170. onUnmounted(() => {
  171. offWebSocket(onWebSocketMessage);
  172. window.speechSynthesis?.cancel();
  173. });
  174. return {
  175. showWarningBroad,
  176. isShowWarningBroad,
  177. activeKey,
  178. toSelectList,
  179. broadcastList,
  180. toMore,
  181. isBroad,
  182. handleBroad,
  183. clearInfo,
  184. closeWarningBroad,
  185. isWarningDot,
  186. };
  187. },
  188. });
  189. </script>
  190. <style lang="less" scoped>
  191. .btn {
  192. line-height: 30px;
  193. margin-right: 10px;
  194. cursor: pointer;
  195. display: flex;
  196. }
  197. .no-play {
  198. position: relative;
  199. &::after {
  200. position: absolute;
  201. width: 70%;
  202. height: 100%;
  203. content: '';
  204. left: 15%;
  205. top: 0;
  206. background: linear-gradient(
  207. to bottom left,
  208. transparent 0%,
  209. transparent calc(50% - 1px),
  210. #ffffff 50%,
  211. transparent calc(50% + 1px),
  212. transparent 100%
  213. );
  214. }
  215. }
  216. .broadcast {
  217. width: 500px;
  218. height: 350px;
  219. border-radius: 4px;
  220. position: fixed;
  221. top: 57px;
  222. right: 2px;
  223. background-color: rgb(255, 255, 255);
  224. background: url('../../../../assets/images/warn-dialog-bg.png') no-repeat center;
  225. background-size: 100% 100%;
  226. z-index: 9999999;
  227. color: #fff;
  228. .title {
  229. height: 32px;
  230. padding: 0 20px;
  231. :deep(.ant-badge:not(.ant-badge-status)) {
  232. margin-right: 40px !important;
  233. }
  234. display: flex;
  235. align-items: center;
  236. justify-content: space-between;
  237. margin-bottom: 5px;
  238. .message-title {
  239. font-size: 18px;
  240. padding-top: 10px;
  241. }
  242. .badge-box {
  243. display: flex;
  244. align-items: center;
  245. padding-top: 10px;
  246. .badge-title {
  247. display: inline-block;
  248. width: 62px;
  249. line-height: 32px;
  250. background-color: #2174f0;
  251. border-radius: 26px;
  252. text-align: center;
  253. color: #fff;
  254. padding-bottom: 2px;
  255. }
  256. }
  257. }
  258. .broadcast-context {
  259. .context-tab {
  260. display: flex;
  261. padding: 20px;
  262. .context-tab-item {
  263. line-height: 24px;
  264. background-color: #6b6b6b;
  265. border-radius: 24px;
  266. text-align: center;
  267. padding: 0 10px;
  268. color: #fff;
  269. margin: 5px;
  270. cursor: pointer;
  271. font-size: 14px;
  272. }
  273. .context-tab-item-active {
  274. background-color: #2174f0;
  275. }
  276. }
  277. .context-box {
  278. flex: 1;
  279. padding: 0 10px;
  280. height: 200px;
  281. overflow-y: auto;
  282. .no-context {
  283. display: flex;
  284. justify-content: center;
  285. padding-top: 30px;
  286. font-size: 16px;
  287. }
  288. .context-detail {
  289. display: flex;
  290. justify-content: space-between;
  291. line-height: 24px;
  292. padding: 0px 16px;
  293. div {
  294. display: flex;
  295. justify-content: flex-start;
  296. &:nth-child(1) {
  297. width: 44%;
  298. }
  299. &:nth-child(2) {
  300. width: 40%;
  301. }
  302. &:nth-child(3) {
  303. width: 25%;
  304. }
  305. &:nth-child(4) {
  306. width: 15%;
  307. }
  308. }
  309. }
  310. }
  311. .more {
  312. position: absolute;
  313. left: 24px;
  314. bottom: 10px;
  315. cursor: pointer;
  316. &:hover {
  317. color: #2174f0;
  318. }
  319. }
  320. }
  321. }
  322. :deep(.zxm-badge-count) {
  323. width: 8px;
  324. height: 8px;
  325. }
  326. </style>