ZaiZai 1 년 전
부모
커밋
466c48c1ad
4개의 변경된 파일12개의 추가작업 그리고 7개의 파일을 삭제
  1. 1 1
      public/version.json
  2. 1 1
      src/config/index.js
  3. 6 3
      src/layout/index.vue
  4. 4 2
      src/plugins/HcSocket.js

+ 1 - 1
public/version.json

@@ -1,3 +1,3 @@
 {
-  "value": "20240716102950"
+  "value": "20240717094632"
 }

+ 1 - 1
src/config/index.js

@@ -21,7 +21,7 @@ export default {
     ports: ['7777'],
     //其它地址
     ossUrl: 'https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com', //oss地址
-    socket: 'wss://business.hcxxy.com/wss/websocket/', //测试线上
+    socket: 'ws://192.168.0.125:9527/websocket', //测试线上
     //这里不再支持配置请求地址,请在 src/config/index.json 文件中配置。
     //相关参数,可查阅 src/config/index.md 文件说明
 }

+ 6 - 3
src/layout/index.vue

@@ -132,6 +132,10 @@ const cascaderSend = async ({ projectId, contractId }) => {
         if (!isNullES(timeExamples.value)) clearInterval(timeExamples.value)
         return
     }
+    //链接webSocket
+    HcSocket.create({ projectId, contractId, userId: userId.value }, (data) => {
+        console.log('socket:', data)
+    })
     //先获取一次
     await getUnreadMessage({ projectId, contractId })
     //切换项目合同段时,先清空轮询
@@ -163,10 +167,9 @@ const getUnreadMessage = async ({ projectId, contractId }) => {
 }
 
 //用户信息
+const userId = ref('')
 const userInfoLoad = ({ user_id }) => {
-    HcSocket.create(user_id, (data) => {
-        console.log('socket:', data)
-    })
+    userId.value = user_id
 }
 
 // 项目切换

+ 4 - 2
src/plugins/HcSocket.js

@@ -6,8 +6,9 @@ export default class HcSocket {
 
     static socket = null
 
-    static create(data, change) {
-        const socket = new WebSocket(website.socket + data)
+    static create({ projectId, contractId, userId }, change) {
+        const url = `${website.socket}/${website.clientId}/${projectId}/${contractId}/${userId}`
+        const socket = new WebSocket(url)
         socket.onopen = function () {
             console.log('websocket 链接成功')
         }
@@ -15,6 +16,7 @@ export default class HcSocket {
             console.log('websocket 链接已断开')
         }
         socket.onmessage = function ({ data }) {
+            console.log(data)
             if (typeof change !== 'function') {
                 return false
             } else {