完善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);
|
||||
}
|
||||
|
||||
@ -422,25 +422,42 @@
|
||||
}, 1200);
|
||||
},
|
||||
// 无网络时保存到本地,供蓝牙直接发送(不依赖 OSS)
|
||||
// 将临时文件复制到持久化目录 _doc/100J_audio/,避免被系统清理
|
||||
saveLocalForBle(filePath) {
|
||||
const deviceId = these.Status.ID;
|
||||
if (!deviceId) return;
|
||||
const item = {
|
||||
...these.cEdit,
|
||||
localPath: filePath,
|
||||
fileUrl: '',
|
||||
deviceId,
|
||||
id: 'local_' + these.cEdit.Id,
|
||||
_createTime: these.cEdit.createTime || Common.DateFormat(new Date(), "yyyy年MM月dd日"),
|
||||
_isLocal: true
|
||||
const doSave = (persistentPath) => {
|
||||
const item = {
|
||||
...these.cEdit,
|
||||
localPath: persistentPath,
|
||||
fileUrl: '',
|
||||
deviceId,
|
||||
id: 'local_' + these.cEdit.Id,
|
||||
_createTime: these.cEdit.createTime || Common.DateFormat(new Date(), "yyyy年MM月dd日"),
|
||||
_isLocal: true
|
||||
};
|
||||
const key = `100J_local_audio_${deviceId}`;
|
||||
let list = uni.getStorageSync(key) || [];
|
||||
list.unshift(item);
|
||||
uni.setStorageSync(key, list);
|
||||
these.AudioData.tempFilePath = "";
|
||||
these.Status.isRecord = false;
|
||||
uni.navigateBack();
|
||||
};
|
||||
const key = `100J_local_audio_${deviceId}`;
|
||||
let list = uni.getStorageSync(key) || [];
|
||||
list.unshift(item);
|
||||
uni.setStorageSync(key, list);
|
||||
these.AudioData.tempFilePath = "";
|
||||
these.Status.isRecord = false;
|
||||
uni.navigateBack();
|
||||
if (typeof plus !== 'undefined' && plus.io) {
|
||||
const fileName = 'audio_' + (these.cEdit.Id || Date.now()) + '.mp3';
|
||||
plus.io.resolveLocalFileSystemURL(filePath, (entry) => {
|
||||
plus.io.resolveLocalFileSystemURL('_doc/', (docEntry) => {
|
||||
docEntry.getDirectory('100J_audio', { create: true }, (dirEntry) => {
|
||||
entry.copyTo(dirEntry, fileName, (newEntry) => {
|
||||
doSave(newEntry.fullPath);
|
||||
}, () => { doSave(filePath); });
|
||||
}, () => { doSave(filePath); });
|
||||
}, () => { doSave(filePath); });
|
||||
}, () => { doSave(filePath); });
|
||||
} else {
|
||||
doSave(filePath);
|
||||
}
|
||||
},
|
||||
// 保存录音并上传(已修复文件格式问题)
|
||||
uploadLuYin() {
|
||||
@ -507,6 +524,19 @@
|
||||
}
|
||||
const resData = JSON.parse(res.data);
|
||||
if (resData.code === 200) {
|
||||
// 缓存本地路径,Apply 时优先用本地文件走蓝牙,避免下载失败
|
||||
const deviceId = these.Status.ID;
|
||||
if (deviceId) {
|
||||
const cacheKey = `100J_local_path_cache_${deviceId}`;
|
||||
const d = resData.data;
|
||||
const fileUrl = (d && typeof d === 'object' && d.fileUrl) || (typeof d === 'string' ? d : '');
|
||||
if (filePath) {
|
||||
let cache = uni.getStorageSync(cacheKey) || {};
|
||||
if (fileUrl) cache[fileUrl] = filePath;
|
||||
if (d && typeof d === 'object' && d.id) cache[d.id] = filePath;
|
||||
uni.setStorageSync(cacheKey, cache);
|
||||
}
|
||||
}
|
||||
// 合并两个存储操作
|
||||
Promise.all([
|
||||
new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user