|
@@ -38,15 +38,22 @@
|
|
|
import { Tooltip, Badge } from 'ant-design-vue';
|
|
|
import { SoundOutlined, BellOutlined } from '@ant-design/icons-vue';
|
|
|
import Icon from '/@/components/Icon';
|
|
|
- import { defineComponent, ref } from 'vue';
|
|
|
+ import { defineComponent, ref, unref, onMounted } from 'vue';
|
|
|
import { defHttp } from '/@/utils/http/axios';
|
|
|
import { useRouter } from 'vue-router';
|
|
|
+ import { connectWebSocket, onWebSocket } from '/@/hooks/web/useWebSocket';
|
|
|
+ import { getToken } from '/@/utils/auth';
|
|
|
+ import md5 from 'crypto-js/md5';
|
|
|
+ import { useUserStore } from '/@/store/modules/user';
|
|
|
+ import { useGlobSetting } from '/@/hooks/setting';
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'VoiceBroadcast',
|
|
|
components: { Icon, Tooltip, Badge, SoundOutlined, BellOutlined },
|
|
|
|
|
|
setup() {
|
|
|
+ const userStore = useUserStore();
|
|
|
+ const glob = useGlobSetting();
|
|
|
const router = useRouter();
|
|
|
const list = (params) => defHttp.get({ url: '/safety/ventanalyAlarmLog/list', params });
|
|
|
const activeKey = ref(0);
|
|
@@ -70,6 +77,32 @@
|
|
|
showWarningBroad();
|
|
|
}
|
|
|
|
|
|
+ // 初始化 WebSocket
|
|
|
+ function initWebSocket() {
|
|
|
+ let token = getToken();
|
|
|
+ //将登录token生成一个短的标识
|
|
|
+ let wsClientId = md5(token);
|
|
|
+ let userId = unref(userStore.getUserInfo).id + '_' + wsClientId;
|
|
|
+ // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
|
|
|
+ let url = glob.domainUrl?.replace('https://', 'wss://').replace('http://', 'ws://') + '/websocket/' + userId;
|
|
|
+ connectWebSocket(url);
|
|
|
+ onWebSocket(onWebSocketMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ function onWebSocketMessage(data) {
|
|
|
+ if (data.cmd === 'topic' || data.cmd === 'user') {
|
|
|
+ //
|
|
|
+ setTimeout(() => {
|
|
|
+ if (isShowWarningBroad.value) {
|
|
|
+ toSelectList(0);
|
|
|
+ }
|
|
|
+ }, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ onMounted(() => {
|
|
|
+ // initWebSocket();
|
|
|
+ });
|
|
|
+
|
|
|
return { showWarningBroad, isShowWarningBroad, activeKey, toSelectList, broadcastList, toMore };
|
|
|
},
|
|
|
});
|