VoiceBroadcast.vue 9.3 KB

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