1
0

VoiceBroadcast.vue 10 KB

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