diff --git a/package.json b/package.json index c9ad9c3..f8b844d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wms-pda", - "version": "1.0.137", + "version": "1.0.139", "private": true, "description": "天豹云仓 WMS_PDA(uni-app Vue2 + @vue/cli 4.5)", "scripts": { diff --git a/src/components/pagination/pagination.vue b/src/components/pagination/pagination.vue index 69b3fc1..aafb0ef 100644 --- a/src/components/pagination/pagination.vue +++ b/src/components/pagination/pagination.vue @@ -25,7 +25,7 @@ - 总数:{{ total }} + 总数:{{ total }} @@ -219,7 +219,14 @@ export default { .total-info { margin-left: 40rpx; color: #909399; - font-size: 30rpx; + font-size: 28rpx; + + .total-info__num { + margin-left: 4rpx; + color: #2979ff; + font-size: 34rpx; + font-weight: bold; + } } diff --git a/src/core/store/modules/bluetoothScale.js b/src/core/store/modules/bluetoothScale.js index 1098df1..2ad35a8 100644 --- a/src/core/store/modules/bluetoothScale.js +++ b/src/core/store/modules/bluetoothScale.js @@ -153,6 +153,11 @@ let discoveredDeviceIds = new Set(); let dataWatchdogTimer = null; let lastConnectedAt = 0; let watchdogRetries = 0; +// 读轮询兜底:部分电子秤不主动 notify(或 notify 特征无 CCCD 描述符),只能主动 read 取重量; +// read 结果同样由 onBLECharacteristicValueChange 回调上报,复用 parseIncoming 解析 +let readPollDelayTimer = null; +let readPollTimer = null; +let readPolling = false; const SCAN_TIMEOUT_MS = 12000; @@ -184,6 +189,22 @@ function clearDataWatchdog() { } } +function clearReadPollDelay() { + if (readPollDelayTimer) { + clearTimeout(readPollDelayTimer); + readPollDelayTimer = null; + } +} + +function clearReadPoll() { + clearReadPollDelay(); + if (readPollTimer) { + clearInterval(readPollTimer); + readPollTimer = null; + } + readPolling = false; +} + // 连接成功后启动看门狗:若 3 秒内未收到任何数据,说明通知订阅未生效(安卓 GATT 缓存等),强制重连一次 function startDataWatchdog(commit, state, dispatch) { clearDataWatchdog(); @@ -202,6 +223,43 @@ function startDataWatchdog(commit, state, dispatch) { }, 3000); } +// 连接成功后短暂等待仍无推送数据时,启动读轮询:周期读取所有可读特征, +// read 返回值经 onBLECharacteristicValueChange → parseIncoming 解析(与 notify 共用同一条解析路径) +function startReadPolling(deviceId, readables, commit, state) { + clearReadPoll(); + if (!readables || !readables.length) return; + readPolling = true; + // 先等 1500ms:若期间 notify 已推送数据,parseIncoming 会 clearReadPoll,不再启动轮询 + readPollDelayTimer = setTimeout(() => { + if (!state.currentDevice || state.currentDevice.id !== deviceId) return; + if (state.connectionStatus !== 'connected') return; + if (state.lastDataTime && state.lastDataTime >= lastConnectedAt) return; // 已有数据,无需轮询 + commit('ADD_LOG', { type: 'info', message: '未收到推送数据,启动读轮询获取重量...' }); + let readInFlight = false; + const tick = () => { + if (readInFlight) return; + if (!state.currentDevice || state.currentDevice.id !== deviceId) return; + if (state.connectionStatus !== 'connected') return; + readInFlight = true; + let pending = readables.length; + const onComplete = () => { + pending -= 1; + if (pending <= 0) readInFlight = false; + }; + readables.forEach(ch => { + uni.readBLECharacteristicValue({ + deviceId, + serviceId: ch.serviceId, + characteristicId: ch.characteristicId, + complete: onComplete + }); + }); + }; + tick(); + readPollTimer = setInterval(tick, 400); + }, 1500); +} + // ---------------- 模块定义 ---------------- const state = () => ({ @@ -355,6 +413,18 @@ function parseIncoming(commit, state, res) { commit('RAW_DATA', { text, hex, time: Date.now() }); // 收到任意数据即说明通知订阅生效,清除“已连接但无数据”看门狗 clearDataWatchdog(); + // 数据来源判定:来自可读特征(主动 read 返回)则保持读轮询继续;来自 notify 推送则停止读轮询 + const fromReadable = + state.currentDevice && + Array.isArray(state.currentDevice.readables) && + state.currentDevice.readables.some( + ch => String(ch.characteristicId || '').toUpperCase() === String(res.characteristicId || '').toUpperCase() + ); + if (fromReadable) { + clearReadPollDelay(); + } else { + clearReadPoll(); + } watchdogRetries = 0; const parsed = parseWeight(text); @@ -380,9 +450,10 @@ function shortUuid(uuid) { async function discoverNotifyCharacteristics(deviceId, commit) { const [srvErr, srvRes] = await uni.getBLEDeviceServices({ deviceId }); if (srvErr || !srvRes || !srvRes.services || !srvRes.services.length) { - return { characteristics: [], error: new Error('未发现设备服务') }; + return { characteristics: [], readables: [], error: new Error('未发现设备服务') }; } const characteristics = []; + const readables = []; for (const service of srvRes.services) { const [chErr, chRes] = await uni.getBLEDeviceCharacteristics({ deviceId, @@ -401,9 +472,12 @@ async function discoverNotifyCharacteristics(deviceId, commit) { if (props.notify || props.indicate) { characteristics.push({ serviceId: service.uuid, characteristicId: ch.uuid }); } + if (props.read) { + readables.push({ serviceId: service.uuid, characteristicId: ch.uuid }); + } } } - return { characteristics, error: null }; + return { characteristics, readables, error: null }; } // 服务发现重试:部分安卓机型在切换同名设备后 getBLEDeviceServices 会短暂返回空/旧缓存, @@ -418,7 +492,7 @@ async function discoverNotifyCharacteristicsWithRetry(deviceId, commit, retries await delay(500); } } - return { characteristics: [], error: lastError || new Error('未找到可订阅的重量数据特征') }; + return { characteristics: [], readables: [], error: lastError || new Error('未找到可订阅的重量数据特征') }; } // 订阅全部可订阅特征,返回成功订阅数量 @@ -721,7 +795,8 @@ const actions = { commit('SET_CURRENT_DEVICE', { id: state.currentDevice.id, name: state.currentDevice.name || '未知设备', - characteristics: discovered.characteristics + characteristics: discovered.characteristics, + readables: discovered.readables || [] }); clearReconnectTimer(); @@ -732,6 +807,7 @@ const actions = { dispatch('stopScan'); commit('ADD_LOG', { type: 'success', message: `已恢复连接: ${state.currentDevice.name || state.currentDevice.id}` }); startDataWatchdog(commit, state, dispatch); + startReadPolling(state.currentDevice.id, discovered.readables, commit, state); return true; } catch (e) { commit('SET_RECONNECTING', false); @@ -768,6 +844,7 @@ const actions = { clearReconnectTimer(); clearDisconnectDebounceTimer(); clearDataWatchdog(); + clearReadPoll(); watchdogRetries = 0; manualDisconnect = false; @@ -818,7 +895,8 @@ const actions = { commit('SET_CURRENT_DEVICE', { id: device.deviceId, name: device.name || '未知设备', - characteristics: discovered.characteristics + characteristics: discovered.characteristics, + readables: discovered.readables || [] }); saveHistoryDevice({ deviceId: device.deviceId, name: device.name || '' }); manualDisconnect = false; @@ -829,6 +907,7 @@ const actions = { dispatch('stopScan'); commit('ADD_LOG', { type: 'warning', message: `设备已处于连接状态,已重新订阅重量数据: ${device.name || device.deviceId}` }); startDataWatchdog(commit, state, dispatch); + startReadPolling(device.deviceId, discovered.readables, commit, state); return true; } if (connErr) throw connErr; @@ -844,7 +923,8 @@ const actions = { commit('SET_CURRENT_DEVICE', { id: device.deviceId, name: device.name || '未知设备', - characteristics: discovered.characteristics + characteristics: discovered.characteristics, + readables: discovered.readables || [] }); saveHistoryDevice({ deviceId: device.deviceId, name: device.name || '' }); clearReconnectTimer(); @@ -856,6 +936,7 @@ const actions = { dispatch('stopScan'); commit('ADD_LOG', { type: 'success', message: `连接成功: ${device.name || device.deviceId}` }); startDataWatchdog(commit, state, dispatch); + startReadPolling(device.deviceId, discovered.readables, commit, state); return true; } catch (e) { manualDisconnect = false; @@ -884,6 +965,7 @@ const actions = { connectLock = true; connectLockAt = Date.now(); try { + clearReadPoll(); manualDisconnect = true; try { await uni.closeBLEConnection({ deviceId: device.id }); @@ -913,6 +995,7 @@ const actions = { clearDisconnectDebounceTimer(); clearScanStopTimer(); clearDataWatchdog(); + clearReadPoll(); watchdogRetries = 0; commit('SET_RECONNECTING', false); commit('SET_RECONNECT_MESSAGE', '已手动断开连接'); diff --git a/src/manifest.json b/src/manifest.json index 24c6feb..eb53c3e 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,8 +2,8 @@ "name" : "WMS_PDA", "appid" : "__UNI__0B3DAD3", "description" : "多平台快速开发的UI框架", - "versionName" : "1.0.137", - "versionCode" : 1000137, + "versionName" : "1.0.139", + "versionCode" : 1000139, "transformPx" : false, "app-plus" : { "statusbar" : { diff --git a/src/pages/home/edit-quick-actions.vue b/src/pages/home/edit-quick-actions.vue index 4b1d1e2..35b43db 100644 --- a/src/pages/home/edit-quick-actions.vue +++ b/src/pages/home/edit-quick-actions.vue @@ -102,6 +102,11 @@