From a53ece5036c1fa61a63fe5f9e0cd3519210ab928 Mon Sep 17 00:00:00 2001
From: chenyao <1219716595@qq.com>
Date: Fri, 07 Aug 2026 09:44:27 +0800
Subject: [PATCH] feat:兼容分辨率低不出现滚动条
---
uniapps/work-app/src/utils/websocket.js | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/uniapps/work-app/src/utils/websocket.js b/uniapps/work-app/src/utils/websocket.js
index 5069d25..913dcc0 100644
--- a/uniapps/work-app/src/utils/websocket.js
+++ b/uniapps/work-app/src/utils/websocket.js
@@ -5,6 +5,7 @@
this.connected = false
this.url = ''
this.userId = ''
+ this.token = ''
this.onMessageCallback = null
this.onOpenCallback = null
this.onCloseCallback = null
@@ -13,14 +14,15 @@
}
// 初始化WebSocket连接
- init(userId, url) {
+ init(userId, url, token) {
if (!url) {
console.error('WebSocket初始化失败:缺少url')
return
}
this.userId = userId || ''
- this.url = url + encodeURIComponent(this.userId)
+ this.token = token || ''
+ this.url = url
this.connect()
}
@@ -29,10 +31,10 @@
try {
// 关闭现有连接
this.close()
-
// 使用uni-app的WebSocket API
this.socketTask = uni.connectSocket({
url: this.url,
+ protocols: [this.token],
success: () => {
// console.log('WebSocket连接已请求')
},
@@ -48,7 +50,7 @@
this.socketTask.onOpen(() => {
this.connected = true
// console.log('WebSocket已连接,userId:', this.userId)
- this.startPing()
+ // this.startPing()
if (this.onOpenCallback) {
this.onOpenCallback()
}
@@ -112,8 +114,8 @@
this.socketTask.send({
data: JSON.stringify(message),
success: () => {
- // console.log('WebSocket消息发送成功:', message)
- useGlobalWS();
+ console.log('WebSocket消息发送成功:', message)
+ // useGlobalWS();
},
fail: (error) => {
// console.error('WebSocket消息发送失败:', error)
@@ -122,15 +124,15 @@
}
// 开始心跳检测
- startPing() {
- this.stopPing()
- // 每25秒发送一次心跳
- this.pingTimer = setInterval(() => {
- if (this.connected) {
- this.send('ping', 'system')
- }
- }, 2000)
- }
+ // startPing() {
+ // this.stopPing()
+ // // 每25秒发送一次心跳
+ // this.pingTimer = setInterval(() => {
+ // if (this.connected) {
+ // this.send('ping', 'system')
+ // }
+ // }, 25000)
+ // }
// 停止心跳检测
stopPing() {
--
Gitblit v1.9.3