“yueshang” před 2 roky
rodič
revize
3b175c721f
4 změnil soubory, kde provedl 58 přidání a 13 odebrání
  1. 4 1
      package.json
  2. 6 12
      src/router/index.js
  3. 46 0
      src/store/modules/websocket.js
  4. 2 0
      src/views/liveChat/index.vue

+ 4 - 1
package.json

@@ -27,9 +27,12 @@
     "jsencrypt": "3.3.1",
     "nprogress": "0.2.0",
     "pinia": "2.0.22",
+    "sockjs-client": "^1.6.1",
     "vue": "3.2.45",
     "vue-cropper": "1.0.3",
-    "vue-router": "4.1.4"
+    "vue-native-websocket": "^2.0.15",
+    "vue-router": "4.1.4",
+    "vuex": "^4.1.0"
   },
   "devDependencies": {
     "@vitejs/plugin-vue": "3.1.0",

+ 6 - 12
src/router/index.js

@@ -88,12 +88,6 @@ export const constantRoutes = [
         name:'search',
         meta:{ title:'全文搜索',icon: 'dashboard' },
       },
-       {
-        path: 'swagger',
-        component: () => import('@/views/tool/swagger/index.vue'),
-        name: 'swagger',
-        meta: { title: '接口', icon: 'dashboard' },
-      },
       {
         path: "/myfile",
         component: () => import("@/views/myfile/MyFile"),
@@ -146,13 +140,13 @@ export const constantRoutes = [
     component: Layout,
     redirect: '/index',
     children: [
-      {
-        path: 'swagger',
-        component: () => import('@/views/tool/swagger/index.vue'),
-        name: 'swagger',
-        meta: { title: '接口', icon: 'dashboard' },
+      // {
+      //   path: 'swagger',
+      //   component: () => import('@/views/tool/swagger/index.vue'),
+      //   name: 'swagger',
+      //   meta: { title: '接口', icon: 'dashboard' },
 
-      },
+      // },
     ]
   },
 

+ 46 - 0
src/store/modules/websocket.js

@@ -0,0 +1,46 @@
+// websocket.js
+import { useWebSocket } from 'vue-native-websocket'
+import useDictStore from '@/store/modules/dict'
+export default {
+  namespaced: true,
+  state: {
+    messages: []
+  },
+  mutations: {
+    addMessage(state, message) {
+      state.messages.push(message)
+    }
+  },
+  actions: {
+    connect({ commit }) {
+      const options = {
+        url: "ws://localhost:8080/websocket/message/" + useUserStore().uid,
+        format: 'json'
+      }
+      const { send } = useWebSocket(options)
+
+      commit('addMessage', 'Connected to server')
+
+      // 监听消息事件
+      send({ type: 'listen' })
+
+      // 处理消息
+      return ({ type, payload }) => {
+        switch (type) {
+          case 'message':
+            commit('addMessage', payload)
+            break
+          // 处理其他消息类型
+          // ...
+        }
+      }
+    },
+    sendMessage(context, message) {
+      const { send } = useWebSocket()
+      send({
+        type: 'send',
+        payload: message
+      })
+    }
+  }
+}

+ 2 - 0
src/views/liveChat/index.vue

@@ -9,6 +9,7 @@ import chat from "@/assets/images/profile.jpg";
 import cebian from "@/assets/images/cebian.png";
 import send from "@/assets/images/send.png";
 import sendFile from "@/assets/images/send-file.png";
+import store from '@/store'
 const height = ref(document.documentElement.clientHeight - 74 + "px;");
 const searchText = ref(""); //搜
 const SearchChat = () => {}; //搜索的点击事件
@@ -78,6 +79,7 @@ const clickPerson = (index) => {
             >Header</el-header
           >
           <el-main class="right-container">Main</el-main>
+          <!-- 底部 -->
           <el-footer height="72px" class="right-footer">
             <img :src="sendFile" class="send-info-file" />
             <el-input