VoiceBroadcast.vue 8.4 KB

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