完善100J蓝牙
This commit is contained in:
@ -106,6 +106,7 @@
|
||||
deviceDeleteAudioFile,
|
||||
deviceUpdateVoice
|
||||
} from '@/api/100J/HBY100-J.js'
|
||||
import { baseURL } from '@/utils/request.js'
|
||||
import {
|
||||
showLoading,
|
||||
hideLoading,
|
||||
@ -237,7 +238,9 @@
|
||||
if (!deviceId) return;
|
||||
const mergeLocal = (serverList) => {
|
||||
const key = `100J_local_audio_${deviceId}`;
|
||||
const cacheKey = `100J_local_path_cache_${deviceId}`;
|
||||
const localList = uni.getStorageSync(key) || [];
|
||||
const pathCache = uni.getStorageSync(cacheKey) || {};
|
||||
const localMapped = localList.map(item => ({
|
||||
...item,
|
||||
fileNameExt: item.name || '本地语音',
|
||||
@ -246,7 +249,12 @@
|
||||
useStatus: 0,
|
||||
_isLocal: true
|
||||
}));
|
||||
return [...localMapped, ...(serverList || [])];
|
||||
const enriched = (serverList || []).map(item => {
|
||||
const urlKey = item.fileUrl || item.url || item.filePath || item.audioUrl || item.ossUrl;
|
||||
const localPath = pathCache[urlKey] || pathCache[item.id];
|
||||
return localPath ? { ...item, localPath } : item;
|
||||
});
|
||||
return [...localMapped, ...enriched];
|
||||
};
|
||||
deviceVoliceList({ deviceId }).then((res) => {
|
||||
if (res.code == 200) {
|
||||
@ -486,10 +494,17 @@
|
||||
Apply(item, index) {
|
||||
this.updateProgress = 0;
|
||||
this.isUpdating = true;
|
||||
// 本地项优先用 localPath;云端项用 fileUrl(兼容多种字段名),相对路径补全 baseURL
|
||||
let fileUrl = '';
|
||||
if (!item._isLocal) {
|
||||
const raw = item.fileUrl || item.url || item.filePath || item.audioUrl || item.ossUrl || '';
|
||||
fileUrl = (typeof raw === 'string' && raw) ? (raw.startsWith('/') ? (baseURL + raw) : raw) : '';
|
||||
}
|
||||
const localPath = (item.localPath && typeof item.localPath === 'string') ? item.localPath : '';
|
||||
const data = {
|
||||
id: item.id,
|
||||
fileUrl: item._isLocal ? '' : (item.fileUrl || item.url),
|
||||
localPath: item._isLocal ? item.localPath : '',
|
||||
fileUrl,
|
||||
localPath,
|
||||
onProgress: (p) => { this.updateProgress = p; }
|
||||
};
|
||||
// 整体超时 60 秒(仅影响蓝牙上传,4G HTTP 很快返回)
|
||||
@ -502,11 +517,15 @@
|
||||
}, 60000);
|
||||
deviceUpdateVoice(data).then((RES) => {
|
||||
clearTimeout(overallTimer);
|
||||
console.log(RES, 'RES');
|
||||
if (RES.code == 200) {
|
||||
// 更新列表选中状态:当前项设为使用中,其他项取消
|
||||
const targetId = item.id || item.Id;
|
||||
this.dataListA.forEach(it => {
|
||||
it.useStatus = ((it.id || it.Id) === targetId) ? 1 : 0;
|
||||
});
|
||||
// 蓝牙上传:进度已由 onProgress 更新,直接完成
|
||||
if (RES._channel === 'ble') {
|
||||
uni.showToast({ title: '升级完成!', icon: 'success', duration: 2000 });
|
||||
uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
setTimeout(() => { uni.navigateBack(); }, 1500);
|
||||
return;
|
||||
@ -514,7 +533,7 @@
|
||||
// 4G:订阅 MQTT 获取设备端进度,6 秒超时
|
||||
this.upgradeTimer = setTimeout(() => {
|
||||
if (this.isUpdating) {
|
||||
uni.showToast({ title: '升级进度同步超时', icon: 'none', duration: 2000 });
|
||||
uni.showToast({ title: '音频进度同步超时', icon: 'none', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
this.updateProgress = 0;
|
||||
}
|
||||
@ -530,7 +549,12 @@
|
||||
this.updateProgress = progress;
|
||||
if (progress === 100) {
|
||||
clearTimeout(this.upgradeTimer);
|
||||
uni.showToast({ title: '升级完成!', icon: 'success', duration: 2000 });
|
||||
// 更新列表选中状态(4G 成功时)
|
||||
const targetId = item.id || item.Id;
|
||||
this.dataListA.forEach(it => {
|
||||
it.useStatus = ((it.id || it.Id) === targetId) ? 1 : 0;
|
||||
});
|
||||
uni.showToast({ title: '音频上传成功', icon: 'success', duration: 2000 });
|
||||
this.isUpdating = false;
|
||||
setTimeout(() => { uni.navigateBack(); }, 1500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user