VoiceBroadcast.vue 10.0 KB

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