VoiceBroadcast.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div style="position: fixed; z-index: 999; right: 95px; top: 18px; 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: 20px; color: #000" @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.length == 0" 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 ? 'red' : '#000' }"
  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 v-if="broadcastList.length > 0" class="more" @click="toMore">更多>></div>
  41. </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: 400px;
  150. height: 250px;
  151. border-radius: 4px;
  152. position: fixed;
  153. top: 42px;
  154. right: 20px;
  155. background-color: rgb(255, 255, 255);
  156. z-index: 9999999;
  157. color: #000;
  158. .title {
  159. height: 48px;
  160. padding: 0 20px;
  161. box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2);
  162. :deep(.ant-badge:not(.ant-badge-status)) {
  163. margin-right: 40px !important;
  164. }
  165. display: flex;
  166. align-items: center;
  167. justify-content: space-between;
  168. margin-bottom: 5px;
  169. .message-title {
  170. font-size: 20px;
  171. // font-weight: 600;
  172. }
  173. .badge-box {
  174. display: flex;
  175. align-items: center;
  176. .badge-title {
  177. display: inline-block;
  178. width: 62px;
  179. line-height: 24px;
  180. background-color: #2174f0;
  181. border-radius: 26px;
  182. text-align: center;
  183. color: #fff;
  184. padding-bottom: 2px;
  185. }
  186. }
  187. }
  188. .broadcast-context {
  189. .context-tab {
  190. display: flex;
  191. .context-tab-item {
  192. line-height: 30px;
  193. background-color: #6b6b6b;
  194. border-radius: 26px;
  195. text-align: center;
  196. padding: 0 10px;
  197. color: #fff;
  198. margin: 5px;
  199. cursor: pointer;
  200. }
  201. .context-tab-item-active {
  202. background-color: #2174f0;
  203. }
  204. }
  205. .context-box {
  206. flex: 1;
  207. padding: 0 10px;
  208. height: 150px;
  209. overflow-y: auto;
  210. .no-context {
  211. display: flex;
  212. justify-content: center;
  213. padding-top: 30px;
  214. font-size: 16px;
  215. }
  216. .context-detail {
  217. display: flex;
  218. div {
  219. padding: 0 3px;
  220. line-height: 24px;
  221. }
  222. }
  223. .more {
  224. cursor: pointer;
  225. &:hover {
  226. color: #2174f0;
  227. }
  228. }
  229. }
  230. }
  231. }
  232. </style>