100J优化语音逻辑
This commit is contained in:
@ -264,30 +264,14 @@
|
||||
uni.navigateBack();
|
||||
}, delayMs);
|
||||
},
|
||||
//语音管理列表(合并云端 + 本地无网络保存的语音)
|
||||
// 语音列表仅展示接口数据;上传落库后以服务端 URL 为准,不再写/读本地 path 与 BLE 字节缓存。
|
||||
getinitData(val, isLoadMore = false) {
|
||||
const deviceId = this.device.deviceId;
|
||||
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 || '本地语音',
|
||||
createTime: item._createTime || item.createTime || Common.DateFormat(new Date(), "yyyy年MM月dd日"),
|
||||
fileUrl: item.fileUrl || item.localPath,
|
||||
useStatus: 0,
|
||||
_isLocal: true
|
||||
}));
|
||||
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];
|
||||
};
|
||||
try {
|
||||
uni.removeStorageSync(`100J_local_path_cache_${deviceId}`);
|
||||
uni.removeStorageSync(`100J_local_audio_${deviceId}`);
|
||||
} catch (e) {}
|
||||
deviceVoliceList({ deviceId }).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.total = res.total;
|
||||
@ -296,14 +280,13 @@
|
||||
createTime: item.createTime || Common.DateFormat(new Date(), "yyyy年MM月dd日"),
|
||||
useStatus: Number(item.useStatus) === 1 ? 1 : 0
|
||||
}));
|
||||
this.dataListA = mergeLocal(list);
|
||||
if (this.mescroll) this.mescroll.endBySize(this.dataListA.length, this.total + (this.dataListA.length - list.length));
|
||||
this.dataListA = list;
|
||||
if (this.mescroll) this.mescroll.endBySize(this.dataListA.length, this.total);
|
||||
}
|
||||
}).catch(() => {
|
||||
// 无网络时仅显示本地保存的语音
|
||||
this.dataListA = mergeLocal([]);
|
||||
this.total = this.dataListA.length;
|
||||
if (this.mescroll) this.mescroll.endBySize(this.dataListA.length, this.total);
|
||||
this.dataListA = [];
|
||||
this.total = 0;
|
||||
if (this.mescroll) this.mescroll.endBySize(0, 0);
|
||||
});
|
||||
},
|
||||
createAudioPlayer(localPath) {
|
||||
@ -456,22 +439,11 @@
|
||||
return;
|
||||
}
|
||||
let task = () => {
|
||||
if (item._isLocal) {
|
||||
// 本地项:从本地存储移除
|
||||
const devId = this.device.deviceId;
|
||||
const vid = (item.id != null && item.id !== '') ? item.id : item.fileId;
|
||||
remove100JVoiceBleCache(devId, vid);
|
||||
const key = `100J_local_audio_${devId}`;
|
||||
let list = uni.getStorageSync(key) || [];
|
||||
list = list.filter(l => l.id !== item.id && l.Id !== item.Id);
|
||||
uni.setStorageSync(key, list);
|
||||
uni.showToast({ title: '已删除', icon: 'none', duration: 1000 });
|
||||
this.getinitData();
|
||||
this.$refs.swipeAction.closeAll();
|
||||
return;
|
||||
}
|
||||
deviceDeleteAudioFile({ fileId: item.fileId, deviceId: this.device.deviceId }).then((res) => {
|
||||
const devId = this.device.deviceId;
|
||||
const vid = (item.id != null && item.id !== '') ? item.id : item.fileId;
|
||||
deviceDeleteAudioFile({ fileId: item.fileId, deviceId: devId }).then((res) => {
|
||||
if (res.code == 200) {
|
||||
if (devId && vid != null && vid !== '') remove100JVoiceBleCache(devId, vid);
|
||||
uni.showToast({ title: res.msg, icon: 'none', duration: 1000 });
|
||||
this.getinitData();
|
||||
this.$refs.swipeAction.closeAll();
|
||||
@ -551,25 +523,14 @@
|
||||
Apply(item, index) {
|
||||
this.updateProgress = 0;
|
||||
this.clearVoiceApplyTimers();
|
||||
// 本地项在无网时禁止下发,仅弹窗(isUpdating 在确认可执行后再置 true)
|
||||
// 本地项优先用 localPath;云端项用 fileUrl(兼容多种字段名),相对路径补全 baseURL
|
||||
let fileUrl = '';
|
||||
let localPath = (item.localPath && typeof item.localPath === 'string') ? item.localPath : '';
|
||||
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) : '';
|
||||
} else {
|
||||
// 本地项:localPath 优先;mergeLocal 可能把路径放在 fileUrl,但勿把 http 当成本地路径
|
||||
if (!localPath && item.fileUrl) {
|
||||
const cand = String(item.fileUrl).trim();
|
||||
if (cand && !/^https?:\/\//i.test(cand)) localPath = cand;
|
||||
}
|
||||
}
|
||||
const raw = item.fileUrl || item.url || item.filePath || item.audioUrl || item.ossUrl || '';
|
||||
const fileUrl = (typeof raw === 'string' && raw)
|
||||
? (raw.startsWith('/') ? (baseURL + raw) : raw)
|
||||
: '';
|
||||
const data = {
|
||||
id: (item.id != null && item.id !== '') ? item.id : item.fileId,
|
||||
// 本地合并项 mergeLocal 会把路径写在 fileUrl,需带给接口层做 effectiveLocal 兜底
|
||||
fileUrl: item._isLocal ? (typeof item.fileUrl === 'string' ? item.fileUrl : '') : fileUrl,
|
||||
localPath,
|
||||
fileUrl,
|
||||
localPath: '',
|
||||
onProgress: (p) => {
|
||||
const n = Math.min(100, Math.max(0, Math.round(Number(p) || 0)));
|
||||
const cur = Number(this.updateProgress) || 0;
|
||||
@ -673,28 +634,6 @@
|
||||
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;
|
||||
}
|
||||
this.isUpdating = true;
|
||||
runDeviceUpdate();
|
||||
},
|
||||
fail: () => {
|
||||
this.isUpdating = true;
|
||||
runDeviceUpdate();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.isUpdating = true;
|
||||
runDeviceUpdate();
|
||||
},
|
||||
|
||||
@ -137,9 +137,6 @@
|
||||
updateLoading
|
||||
} from '@/utils/loading.js';
|
||||
import Common from '@/utils/Common.js';
|
||||
import {
|
||||
cache100JVoiceFileForBle
|
||||
} from '@/api/100J/HBY100-J.js';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@ -523,22 +520,6 @@
|
||||
}
|
||||
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);
|
||||
if (d && typeof d === 'object' && d.id) {
|
||||
cache100JVoiceFileForBle(deviceId, d.id, filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 合并两个存储操作
|
||||
Promise.all([
|
||||
new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user