From 0b67fd879ccd4fb6319dc016babd3bb8ea79dff0 Mon Sep 17 00:00:00 2001
From: shikeying <pxzsky@163.com>
Date: 星期二, 25 四月 2023 18:47:35 +0800
Subject: [PATCH] 修改列表组件,支持属性子属性

---
 src/store/modules/user.js |   68 ++++++++++++++++++++++++++++++++--
 1 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index d8f09ce..b45847f 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -1,5 +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: {
@@ -7,7 +12,12 @@
     name: '',
     avatar: '',
     roles: [],
-    permissions: []
+    permissions: [],
+    // 2023-04-17 娣诲姞websocket
+    webConnection: null, // 鍗曚緥瀵硅薄
+    webSocketMsg: null,  // 鎺ユ敹鍒扮殑娑堟伅
+    uri: null,  // 杩炴帴websocket鍦板潃
+    uid: null   // 杩炴帴鐢ㄦ埛鏍囪瘑
   },
 
   mutations: {
@@ -25,6 +35,35 @@
     },
     SET_PERMISSIONS: (state, permissions) => {
       state.permissions = permissions
+    },
+
+    // 2023-04-17
+    SET_CONNECTION: (state, data) => {
+      // var webConnection = new WebConnection();
+      // if(state.webConnection == null){
+      if(data.uri == '-1'){
+        return;
+      }
+      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)=>{
+      if(data.uri == '-1'){
+        return;
+      }
+      state.uri = data.uri;
+      state.uid = data.uid;
     }
   },
 
@@ -32,11 +71,15 @@
     // 鐧诲綍
     Login({ commit }, userInfo) {
       const username = userInfo.username.trim()
-      const password = userInfo.password
+      // const password = userInfo.password
+      const password = encrypt(userInfo.password)
       const code = userInfo.code
       const uuid = userInfo.uuid
+      const loginType = userInfo.loginType
+      const verifyType = userInfo.verifyType
+
       return new Promise((resolve, reject) => {
-        login(username, password, code, uuid).then(res => {
+        login(username, password, code, uuid, loginType, verifyType).then(res => {
           // console.log(res.data.token)
           // setToken(res.token)
           setToken(res.data.token)
@@ -61,9 +104,25 @@
           } else {
             commit('SET_ROLES', ['ROLE_DEFAULT'])
           }
-          commit('SET_NAME', user.userName)
+          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)
         })
@@ -77,6 +136,7 @@
           commit('SET_TOKEN', '')
           commit('SET_ROLES', [])
           commit('SET_PERMISSIONS', [])
+          commit('SET_CONNECTION_CLEAR', null)
           removeToken()
           // console.log("鍒犻櫎娴忚鍣╰oken...");
           resolve()

--
Gitblit v1.9.1