From 529f48641122af7c0aec185e4283d02e97aa0f89 Mon Sep 17 00:00:00 2001
From: shikeying <pxzsky@163.com>
Date: 星期三, 19 四月 2023 14:40:51 +0800
Subject: [PATCH] 增加 websocket

---
 src/store/modules/user.js |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index 3538789..d9b29c6 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -1,6 +1,10 @@
 import { login, logout, getInfo } from '@/api/login'
 import { getToken, setToken, removeToken } from '@/utils/auth'
 import {encrypt} from '@/utils/jsencrypt'
+// import Vue from 'vue'
+import {Message} from "element-ui";
+// import WebConnection from "@/utils/webconnection";
+import WebConnection from "@/utils/web-connection";
 
 const user = {
   state: {
@@ -8,7 +12,12 @@
     name: '',
     avatar: '',
     roles: [],
-    permissions: []
+    permissions: [],
+    // 2023-04-17 娣诲姞websocket
+    webConnection: null, // 鍗曚緥瀵硅薄
+    webSocketMsg: null,  // 鎺ユ敹鍒扮殑娑堟伅
+    uri: null,  // 杩炴帴websocket鍦板潃
+    uid: null   // 杩炴帴鐢ㄦ埛鏍囪瘑
   },
 
   mutations: {
@@ -26,6 +35,29 @@
     },
     SET_PERMISSIONS: (state, permissions) => {
       state.permissions = permissions
+    },
+
+    // 2023-04-17
+    SET_CONNECTION: (state, data) => {
+      // var webConnection = new WebConnection();
+      // if(state.webConnection == null){
+        state.webConnection = new WebConnection(data.uri, data.uid);
+        state.webConnection.startConnect();
+      // }
+    },
+    SET_CONNECTION_CLEAR: (state, data) => {
+      if(state.webConnection != null){
+        state.webConnection.shutdown();
+      }
+      state.webConnection = null;
+    },
+    // 2023-04-17锛岀洃鎺ф秷鎭彉鍖�
+    SET_WS_MSG: (state, data)=>{
+      state.webSocketMsg = data;
+    },
+    SET_WS_INFO: (state, data)=>{
+      state.uri = data.uri;
+      state.uid = data.uid;
     }
   },
 
@@ -68,7 +100,23 @@
           }
           commit('SET_NAME', user.user_name)
           commit('SET_AVATAR', avatar)
+
+          // 2023-04-17锛岃幏鍙栫敤鎴峰悓鏃讹紝鍚姩锛歸ebsocket
+          // this.webConnection = new WebConnection();
+          // this.webConnection.uri = res.data.uri;
+          // this.webConnection.uid = res.data.uid;
+          // vue.webConnection.setInfo(res.data.uri, res.data.uid);
+          // this.webConnection.timedCheckConnection();
+          // this.$store.dispatch('CreateWebConnection', res.data).then(()=>{
+          // }).catch(err => {
+          //   Message.error(err);
+          // });
+          commit('SET_WS_INFO', res.data);
+          commit('SET_CONNECTION', res.data);
+          console.log(".............CreateWebConnection()");
+
           resolve(res)
+
         }).catch(error => {
           reject(error)
         })
@@ -82,6 +130,7 @@
           commit('SET_TOKEN', '')
           commit('SET_ROLES', [])
           commit('SET_PERMISSIONS', [])
+          commit('SET_CONNECTION_CLEAR', null)
           removeToken()
           // console.log("鍒犻櫎娴忚鍣╰oken...");
           resolve()

--
Gitblit v1.9.1