兰宝车间质量管理系统-前端
疯狂的狮子Li
2023-12-23 772885de35e57e6a2c805ef9274ab0ec874f6d3c
src/utils/websocket.ts
@@ -19,9 +19,8 @@
 */
import { getToken } from '@/utils/auth';
import { ElNotification } from 'element-plus';
import useNoticeStore from '@/store/modules/notice';
const { addNotice } = useNoticeStore();
let socketUrl: any = ''; // socket地址
let websocket: any = null; // websocket 实例
@@ -32,6 +31,9 @@
// 初始化socket
export const initWebSocket = (url: any) => {
  if (import.meta.env.VITE_APP_WEBSOCKET === 'false') {
    return;
  }
  socketUrl = url;
  // 初始化 websocket
  websocket = new WebSocket(url + '?Authorization=Bearer ' + getToken() + '&clientid=' + import.meta.env.VITE_APP_CLIENT_ID);
@@ -121,7 +123,7 @@
    if (e.data.indexOf('ping') > 0) {
      return;
    }
    addNotice({
    useNoticeStore().addNotice({
      message: e.data,
      read: false,
      time: new Date().toLocaleString()
@@ -131,7 +133,7 @@
      message: e.data,
      type: 'success',
      duration: 3000
    })
    });
    return e.data;
  };
};