调整联系方式字段为电话 列表中多个联系方式纵向排列显示 会增加公司信息的自定义输入框 排序搜索 等功能
This commit is contained in:
@@ -12,6 +12,42 @@ let reconnectAttempts = 0
|
||||
const maxReconnectDelayMs = 30000
|
||||
const heartbeatIntervalMs = 30000
|
||||
|
||||
// 生成全局唯一的 trace_id(优先使用 crypto.randomUUID)
|
||||
const generateTraceId = (): string => {
|
||||
try {
|
||||
// @ts-ignore
|
||||
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
||||
// @ts-ignore
|
||||
return `req-${crypto.randomUUID()}`
|
||||
}
|
||||
} catch (_) {}
|
||||
// Fallback:基于时间戳 + 随机数
|
||||
const timestampPart = Date.now().toString(36)
|
||||
let randomPart = ''
|
||||
try {
|
||||
// @ts-ignore
|
||||
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
||||
const buf = new Uint8Array(16)
|
||||
// @ts-ignore
|
||||
crypto.getRandomValues(buf)
|
||||
randomPart = Array.from(buf)
|
||||
.map((b) => b.toString(16).padStart(2, '0'))
|
||||
.join('')
|
||||
} else {
|
||||
randomPart = Array.from({ length: 16 })
|
||||
.map(() =>
|
||||
Math.floor(Math.random() * 256)
|
||||
.toString(16)
|
||||
.padStart(2, '0')
|
||||
)
|
||||
.join('')
|
||||
}
|
||||
} catch (_) {
|
||||
randomPart = Math.random().toString(36).slice(2)
|
||||
}
|
||||
return `req-${timestampPart}-${randomPart}`
|
||||
}
|
||||
|
||||
const getReconnectDelay = () => {
|
||||
const base = 1000 * Math.pow(2, reconnectAttempts)
|
||||
return Math.min(base, maxReconnectDelayMs)
|
||||
@@ -38,7 +74,12 @@ const startHeartbeat = () => {
|
||||
heartbeatTimer = setTimeout(() => {
|
||||
try {
|
||||
if (socket && socket.readyState === WebSocket.OPEN) {
|
||||
socket.send(JSON.stringify({ type: 'ping' }))
|
||||
const msg = {
|
||||
event: 'system.ping',
|
||||
data: {},
|
||||
trace_id: generateTraceId() // 可选,用于请求-响应匹配
|
||||
}
|
||||
socket.send(JSON.stringify(msg))
|
||||
}
|
||||
} catch (_) {}
|
||||
// 下一次心跳
|
||||
@@ -74,7 +115,12 @@ export const initWebSocket = (token: string) => {
|
||||
startHeartbeat()
|
||||
mittBus.emit('ws:open')
|
||||
try {
|
||||
socket?.send(JSON.stringify({ type: 'ping' }))
|
||||
const msg = {
|
||||
event: 'system.ping',
|
||||
data: {},
|
||||
trace_id: generateTraceId() // 可选,用于请求-响应匹配
|
||||
}
|
||||
socket?.send(JSON.stringify(msg))
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user