提交100J代码
This commit is contained in:
@ -525,7 +525,11 @@
|
||||
},
|
||||
Apply(item, index) {
|
||||
this.updateProgress = 0;
|
||||
this.isUpdating = true;
|
||||
if (this.upgradeTimer) {
|
||||
clearTimeout(this.upgradeTimer);
|
||||
this.upgradeTimer = null;
|
||||
}
|
||||
// 本地项在无网时禁止下发,仅弹窗(isUpdating 在确认可执行后再置 true)
|
||||
// 本地项优先用 localPath;云端项用 fileUrl(兼容多种字段名),相对路径补全 baseURL
|
||||
let fileUrl = '';
|
||||
let localPath = (item.localPath && typeof item.localPath === 'string') ? item.localPath : '';
|
||||
@ -548,67 +552,99 @@
|
||||
// 不传「蓝牙连接中」类提示:关蓝牙走 4G 时易误导;进度条 + 必要时全局请稍候即可
|
||||
onWaiting: () => {}
|
||||
};
|
||||
// 整体超时 60 秒(仅影响蓝牙上传,4G HTTP 很快返回)
|
||||
const overallTimer = setTimeout(() => {
|
||||
if (this.isUpdating) {
|
||||
uni.showToast({ title: '操作超时', icon: 'none', duration: 2000 });
|
||||
const runDeviceUpdate = () => {
|
||||
const overallTimer = setTimeout(() => {
|
||||
if (this.isUpdating) {
|
||||
uni.showToast({ title: '操作超时', icon: 'none', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
this.updateProgress = 0;
|
||||
}
|
||||
}, 120000);
|
||||
// 进入列表时的蓝牙快照可能过期;与 HBY100 详情页一致,从 BleHelper 按 MAC 再对齐一次
|
||||
sync100JBleProtocolFromHelper(this.device).then(() => deviceUpdateVoice(data)).then((RES) => {
|
||||
clearTimeout(overallTimer);
|
||||
if (RES.code == 200) {
|
||||
// 蓝牙上传:进度已由 onProgress 更新,直接完成
|
||||
if (RES._channel === 'ble') {
|
||||
if (this.upgradeTimer) {
|
||||
clearTimeout(this.upgradeTimer);
|
||||
this.upgradeTimer = null;
|
||||
}
|
||||
const title = RES._updateVoiceAfterBleFailed
|
||||
? '蓝牙已下发,云端同步失败可稍后重试'
|
||||
: '音频上传成功';
|
||||
this.syncVoiceListUseStatus(item);
|
||||
uni.showToast({ title, icon: RES._updateVoiceAfterBleFailed ? 'none' : 'success', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
setTimeout(() => { uni.navigateBack(); }, 1500);
|
||||
return;
|
||||
}
|
||||
// 4G:订阅 MQTT 获取设备端进度,6 秒超时
|
||||
this.upgradeTimer = setTimeout(() => {
|
||||
if (this.isUpdating) {
|
||||
uni.showToast({ title: '音频进度同步超时', icon: 'none', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
this.updateProgress = 0;
|
||||
}
|
||||
}, 6000);
|
||||
this.mqttClient = this.mqttClient || new MqttClient();
|
||||
this.mqttClient.connect(() => {
|
||||
const statusTopic = `status/894078/HBY100/${this.device.deviceImei}`;
|
||||
this.mqttClient.subscribe(statusTopic, (payload) => {
|
||||
try {
|
||||
const payloadObj = typeof payload === 'string' ? JSON.parse(payload) : payload;
|
||||
const progress = payloadObj.data?.progress;
|
||||
if (progress !== undefined && !isNaN(progress) && progress >= 0 && progress <= 100) {
|
||||
this.updateProgress = progress;
|
||||
if (progress === 100) {
|
||||
clearTimeout(this.upgradeTimer);
|
||||
this.syncVoiceListUseStatus(item);
|
||||
uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
setTimeout(() => { uni.navigateBack(); }, 1500);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
clearTimeout(this.upgradeTimer);
|
||||
console.error('解析MQTT payload失败:', e);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.isUpdating = false;
|
||||
uni.showToast({ title: RES.msg || '操作失败', icon: 'none', duration: 1000 });
|
||||
}
|
||||
}).catch((err) => {
|
||||
clearTimeout(overallTimer);
|
||||
this.isUpdating = false;
|
||||
this.updateProgress = 0;
|
||||
}
|
||||
}, 120000); // 蓝牙分片+MTU 协商+大包写入较慢,60s 易误报「操作超时」
|
||||
// 进入列表时的蓝牙快照可能过期;与 HBY100 详情页一致,从 BleHelper 按 MAC 再对齐一次,否则常静默走 4G、看不到 [100J-蓝牙] 分片日志
|
||||
sync100JBleProtocolFromHelper(this.device).then(() => deviceUpdateVoice(data)).then((RES) => {
|
||||
clearTimeout(overallTimer);
|
||||
if (RES.code == 200) {
|
||||
// 蓝牙上传:进度已由 onProgress 更新,直接完成
|
||||
if (RES._channel === 'ble') {
|
||||
this.syncVoiceListUseStatus(item);
|
||||
uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
setTimeout(() => { uni.navigateBack(); }, 1500);
|
||||
return;
|
||||
}
|
||||
// 4G:订阅 MQTT 获取设备端进度,6 秒超时
|
||||
this.upgradeTimer = setTimeout(() => {
|
||||
if (this.isUpdating) {
|
||||
uni.showToast({ title: '音频进度同步超时', icon: 'none', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
this.updateProgress = 0;
|
||||
uni.showToast({ title: err.message || '操作失败', icon: 'none', duration: 2500 });
|
||||
});
|
||||
};
|
||||
if (item._isLocal) {
|
||||
uni.getNetworkType({
|
||||
success: (net) => {
|
||||
if (net.networkType === 'none') {
|
||||
uni.showModal({
|
||||
title: '无法使用',
|
||||
content: '无网保存的本地语音无法通过蓝牙下发。请先连接 WiFi 或移动网络后,重新录制并保存(上传云端),再点「使用」。',
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
});
|
||||
return;
|
||||
}
|
||||
}, 6000);
|
||||
this.mqttClient = this.mqttClient || new MqttClient();
|
||||
this.mqttClient.connect(() => {
|
||||
const statusTopic = `status/894078/HBY100/${this.device.deviceImei}`;
|
||||
this.mqttClient.subscribe(statusTopic, (payload) => {
|
||||
try {
|
||||
const payloadObj = typeof payload === 'string' ? JSON.parse(payload) : payload;
|
||||
const progress = payloadObj.data?.progress;
|
||||
if (progress !== undefined && !isNaN(progress) && progress >= 0 && progress <= 100) {
|
||||
this.updateProgress = progress;
|
||||
if (progress === 100) {
|
||||
clearTimeout(this.upgradeTimer);
|
||||
this.syncVoiceListUseStatus(item);
|
||||
uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
setTimeout(() => { uni.navigateBack(); }, 1500);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
clearTimeout(this.upgradeTimer);
|
||||
console.error('解析MQTT payload失败:', e);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.isUpdating = false;
|
||||
uni.showToast({ title: RES.msg || '操作失败', icon: 'none', duration: 1000 });
|
||||
}
|
||||
}).catch((err) => {
|
||||
clearTimeout(overallTimer);
|
||||
this.isUpdating = false;
|
||||
this.updateProgress = 0;
|
||||
uni.showToast({ title: err.message || '操作失败', icon: 'none', duration: 2500 });
|
||||
});
|
||||
this.isUpdating = true;
|
||||
runDeviceUpdate();
|
||||
},
|
||||
fail: () => {
|
||||
this.isUpdating = true;
|
||||
runDeviceUpdate();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.isUpdating = true;
|
||||
runDeviceUpdate();
|
||||
},
|
||||
closePop: function() {
|
||||
this.Status.Pop.showPop = false;
|
||||
|
||||
Reference in New Issue
Block a user