优化100J代码
This commit is contained in:
@ -545,19 +545,48 @@ export function deviceDetail(id) {
|
|||||||
function execWithBleFirst(bleExec, httpExec, logName, onWaiting) {
|
function execWithBleFirst(bleExec, httpExec, logName, onWaiting) {
|
||||||
const doBle = () => bleExec().then(res => ({ ...(res || {}), _channel: 'ble' }));
|
const doBle = () => bleExec().then(res => ({ ...(res || {}), _channel: 'ble' }));
|
||||||
const do4G = () => httpExec().then(res => { res._channel = '4g'; return res; });
|
const do4G = () => httpExec().then(res => { res._channel = '4g'; return res; });
|
||||||
|
const hideWaitUi = () => {
|
||||||
|
if (typeof onWaiting === 'function') return;
|
||||||
|
try {
|
||||||
|
uni.hideLoading();
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
const showWaitUi = (title) => {
|
||||||
|
if (typeof onWaiting === 'function') return;
|
||||||
|
try {
|
||||||
|
uni.hideLoading();
|
||||||
|
uni.showLoading({ title, mask: false });
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
|
||||||
if (protocolInstance.isBleConnected && protocolInstance.bleDeviceId) {
|
if (protocolInstance.isBleConnected && protocolInstance.bleDeviceId) {
|
||||||
return doBle().catch(() => { console.log('[100J] 蓝牙失败,回退4G'); return do4G(); });
|
return doBle().catch(() => {
|
||||||
}
|
console.log('[100J]', logName || '指令', '蓝牙失败,回退4G');
|
||||||
// 无 bleDeviceId 时:可能扫描中,先等待连接(设备页在后台可能完成连接)
|
return do4G();
|
||||||
if (!protocolInstance.bleDeviceId) {
|
|
||||||
if (typeof onWaiting === 'function') onWaiting();
|
|
||||||
return waitForBleConnection(12000).then(connected => {
|
|
||||||
return connected ? doBle().catch(() => { console.log('[100J] 蓝牙失败,回退4G'); return do4G(); }) : do4G();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return tryReconnectBle(2500).then(reconnected => {
|
// 无 bleDeviceId:页面可能在扫描,最多等 12s(否则用户以为点了没反应)
|
||||||
return reconnected ? doBle().catch(() => { console.log('[100J] 蓝牙失败,回退4G'); return do4G(); }) : do4G();
|
if (!protocolInstance.bleDeviceId) {
|
||||||
});
|
if (typeof onWaiting === 'function') onWaiting();
|
||||||
|
else showWaitUi('蓝牙连接中…');
|
||||||
|
return waitForBleConnection(12000)
|
||||||
|
.then(connected => {
|
||||||
|
return connected ? doBle().catch(() => {
|
||||||
|
console.log('[100J]', logName || '指令', '蓝牙失败,回退4G');
|
||||||
|
return do4G();
|
||||||
|
}) : do4G();
|
||||||
|
})
|
||||||
|
.finally(hideWaitUi);
|
||||||
|
}
|
||||||
|
if (typeof onWaiting !== 'function') showWaitUi('正在重连蓝牙…');
|
||||||
|
return tryReconnectBle(2500)
|
||||||
|
.then(reconnected => {
|
||||||
|
return reconnected ? doBle().catch(() => {
|
||||||
|
console.log('[100J]', logName || '指令', '蓝牙失败,回退4G');
|
||||||
|
return do4G();
|
||||||
|
}) : do4G();
|
||||||
|
})
|
||||||
|
.finally(hideWaitUi);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 爆闪模式
|
// 爆闪模式
|
||||||
|
|||||||
@ -736,8 +736,11 @@
|
|||||||
}
|
}
|
||||||
if (this.formData.bleStatu === true) {
|
if (this.formData.bleStatu === true) {
|
||||||
this.formData.bleStatu = 'dicconnect';
|
this.formData.bleStatu = 'dicconnect';
|
||||||
bleTool.disconnectDevice(f.deviceId).finally(r => {
|
bleTool.disconnectDevice(f.deviceId).finally(() => {
|
||||||
this.formData.bleStatu = false;
|
this.formData.bleStatu = false;
|
||||||
|
if (this.deviceInfo && this.deviceInfo.deviceId) {
|
||||||
|
updateBleStatus(false, '', this.deviceInfo.deviceId);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1182,6 +1185,9 @@
|
|||||||
bleTool.StopSearch();
|
bleTool.StopSearch();
|
||||||
bleTool.removeDeviceFound('HBY100J_SCAN');
|
bleTool.removeDeviceFound('HBY100J_SCAN');
|
||||||
console.log('100J 蓝牙扫描超时,将使用4G');
|
console.log('100J 蓝牙扫描超时,将使用4G');
|
||||||
|
that.formData.bleStatu = false;
|
||||||
|
const devId = that.deviceInfo && that.deviceInfo.deviceId;
|
||||||
|
if (devId) updateBleStatus(false, '', devId);
|
||||||
}, timeout);
|
}, timeout);
|
||||||
|
|
||||||
bleTool.addDeviceFound((res) => {
|
bleTool.addDeviceFound((res) => {
|
||||||
@ -1219,6 +1225,9 @@
|
|||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
bleTool.removeDeviceFound('HBY100J_SCAN');
|
bleTool.removeDeviceFound('HBY100J_SCAN');
|
||||||
console.log('100J 蓝牙扫描启动失败,将使用4G', err);
|
console.log('100J 蓝牙扫描启动失败,将使用4G', err);
|
||||||
|
that.formData.bleStatu = 'err';
|
||||||
|
const devId = that.deviceInfo && that.deviceInfo.deviceId;
|
||||||
|
if (devId) updateBleStatus(false, '', devId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user