VoiceBroadcast.vue 11 KB

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