|
|
@@ -184,6 +184,49 @@ export interface WorkerMetadataPayload {
|
|
|
error?: string;
|
|
|
}
|
|
|
|
|
|
+interface WorkerMessageScanDone {
|
|
|
+ code: 101;
|
|
|
+ data: Record<string, never>;
|
|
|
+}
|
|
|
+
|
|
|
+interface WorkerMessageMediaList {
|
|
|
+ code: 102;
|
|
|
+ data: Array<VideoItem>;
|
|
|
+ totalCount: number;
|
|
|
+}
|
|
|
+
|
|
|
+interface WorkerMessageArtistList {
|
|
|
+ code: 103;
|
|
|
+ data1: Map<string, Array<VideoItem>>;
|
|
|
+ data2: Array<VideoItem>;
|
|
|
+ totalCount: number;
|
|
|
+}
|
|
|
+
|
|
|
+interface WorkerMessageAlbumList {
|
|
|
+ code: 104;
|
|
|
+ data1: Map<string, Array<VideoItem>>;
|
|
|
+ data2: Array<VideoItem>;
|
|
|
+ totalCount: number;
|
|
|
+}
|
|
|
+
|
|
|
+interface WorkerMessageMetadata {
|
|
|
+ code: 105;
|
|
|
+ data: WorkerMetadataPayload;
|
|
|
+}
|
|
|
+
|
|
|
+interface WorkerMessageEditResult {
|
|
|
+ code: 106;
|
|
|
+ data: WorkerEditMusicResult;
|
|
|
+}
|
|
|
+
|
|
|
+type LocalMusicWorkerMessage =
|
|
|
+ WorkerMessageScanDone
|
|
|
+ | WorkerMessageMediaList
|
|
|
+ | WorkerMessageArtistList
|
|
|
+ | WorkerMessageAlbumList
|
|
|
+ | WorkerMessageMetadata
|
|
|
+ | WorkerMessageEditResult;
|
|
|
+
|
|
|
/**
|
|
|
* 歌单播放事件数据
|
|
|
*/
|
|
|
@@ -1139,8 +1182,8 @@ export struct LocalMusic {
|
|
|
|
|
|
|
|
|
workerInstance.onmessage = (e: MessageEvents): void => {
|
|
|
-
|
|
|
- switch (e.data.code) {
|
|
|
+ const message = e.data as LocalMusicWorkerMessage;
|
|
|
+ switch (message.code) {
|
|
|
case 101: //第一次扫描文件夹入库
|
|
|
ToastUtil.showToast('刷新同步数据库成功!')
|
|
|
Logger.info('onecold 扫描数据库结束 this.mediaKuList length= ' + this.mediaKuList.length)
|
|
|
@@ -1148,56 +1191,50 @@ export struct LocalMusic {
|
|
|
break;
|
|
|
case 102: //查询媒体库列表
|
|
|
this.isRefreshing = false
|
|
|
- this.mediaKuList = e.data.data
|
|
|
- Logger.info('onecold 查询媒体库列表 this.mediaKuList length= ' + this.mediaKuList.length)
|
|
|
+ this.mediaKuList = message.data // 只包含前100条
|
|
|
+ const mediaTotalCount: number = message.totalCount ?? this.mediaKuList.length;
|
|
|
+ this.mediaKuCount = mediaTotalCount;
|
|
|
+ Logger.info(`heanup 查询媒体库列表 缓存数=${this.mediaKuList.length}, 总数=${mediaTotalCount}`)
|
|
|
Utility.doSortListAscending(this.mediaKuList)
|
|
|
AppStorage.setOrCreate('mediaKuList', this.mediaKuList);
|
|
|
// 媒体库模式下重新加载第一页(分页查询)
|
|
|
if (this.modeType === 1) {
|
|
|
this.resetAndLoadFirstPage();
|
|
|
}
|
|
|
- PreferencesUtil.putSync('mediaKuCount', this.mediaKuList.length)
|
|
|
- // 处理媒体库前100条记录,列表长度并存储到PreferencesUtil
|
|
|
- if (ArrayUtil.isNotEmpty(this.mediaKuList)&&this.mediaKuList.length > 100) {
|
|
|
- // 只保存前100条记录到缓存中
|
|
|
- let truncatedList = this.mediaKuList.slice(0, 100);
|
|
|
- PreferencesUtil.putSync('mediaKuList', JSON.stringify(truncatedList));
|
|
|
- } else {
|
|
|
- PreferencesUtil.putSync('mediaKuList', JSON.stringify(this.mediaKuList));
|
|
|
- }
|
|
|
+ PreferencesUtil.putSync('mediaKuCount', mediaTotalCount)
|
|
|
+ // 只保存前100条记录到缓存中
|
|
|
+ PreferencesUtil.putSync('mediaKuList', JSON.stringify(this.mediaKuList));
|
|
|
break;
|
|
|
case 103: //收到查询艺术家列表
|
|
|
this.isRefreshing = false
|
|
|
- this.artistMap = e.data.data1;
|
|
|
- this.artistList = e.data.data2;
|
|
|
- PreferencesUtil.putSync('artistCount', this.artistList.length)
|
|
|
+ this.artistMap = message.data1; // 只包含前60个艺术家的歌曲
|
|
|
+ this.artistList = message.data2; // 只包含前100个艺术家
|
|
|
+ const artistTotalCount: number = message.totalCount ?? this.artistList.length;
|
|
|
+ this.artistCount = artistTotalCount;
|
|
|
+ Logger.info(`heanup 查询艺术家列表 缓存数=${this.artistList.length}, 总数=${artistTotalCount}`)
|
|
|
+ PreferencesUtil.putSync('artistCount', artistTotalCount)
|
|
|
|
|
|
// 艺术家模式下重新加载第一页(分页查询)
|
|
|
if (this.modeType === 2) {
|
|
|
this.resetAndLoadFirstPage();
|
|
|
}
|
|
|
|
|
|
- // 处理艺术家前100条记录,列表长度并存储到PreferencesUtil
|
|
|
- if (ArrayUtil.isNotEmpty(this.artistList)&&this.artistList.length > 100) {
|
|
|
- // 只保存前100条记录到缓存中
|
|
|
- let truncatedList = this.artistList.slice(0, 100);
|
|
|
- PreferencesUtil.putSync('artistList', JSON.stringify(truncatedList));
|
|
|
- } else {
|
|
|
- PreferencesUtil.putSync('artistList', JSON.stringify(this.artistList));
|
|
|
- }
|
|
|
- // 处理并缓存前60条艺术家数据
|
|
|
- const sortedEntries = Array.from(this.artistMap.entries())
|
|
|
- .sort((a, b) => b[1].length - a[1].length)
|
|
|
- .slice(0, 60);
|
|
|
-
|
|
|
+ // 保存前100条艺术家列表
|
|
|
+ PreferencesUtil.putSync('artistList', JSON.stringify(this.artistList));
|
|
|
+
|
|
|
+ // 保存前60条艺术家的歌曲Map
|
|
|
+ const sortedEntries = Array.from(this.artistMap.entries());
|
|
|
PreferencesUtil.putSync('artistMap', JSON.stringify(sortedEntries));
|
|
|
break;
|
|
|
|
|
|
case 104: //收到查询专辑列表
|
|
|
this.isRefreshing = false
|
|
|
- this.albumMap = e.data.data1;
|
|
|
+ this.albumMap = message.data1;
|
|
|
|
|
|
- this.albumList = e.data.data2
|
|
|
+ this.albumList = message.data2
|
|
|
+ const albumTotalCount: number = message.totalCount ?? this.albumList.length;
|
|
|
+ this.albumCount = albumTotalCount;
|
|
|
+ Logger.info(`heanup 查询专辑列表 缓存数=${this.albumList.length}, 总数=${albumTotalCount}`)
|
|
|
|
|
|
// 专辑模式下重新加载第一页(分页查询)
|
|
|
if (this.modeType === 3) {
|
|
|
@@ -1210,25 +1247,19 @@ export struct LocalMusic {
|
|
|
console.info('onecold startPlayOrResumePlay 757')
|
|
|
this.startPlayOrResumePlay()
|
|
|
}
|
|
|
- PreferencesUtil.putSync('albumCount', this.albumList.length)
|
|
|
- // 处理专辑前100条记录,列表长度并存储到PreferencesUtil
|
|
|
- if (ArrayUtil.isNotEmpty(this.albumList)&&this.albumList.length > 100) {
|
|
|
- // 只保存前100条记录到缓存中
|
|
|
- let truncatedList = this.albumList.slice(0, 100);
|
|
|
- PreferencesUtil.putSync('albumList', JSON.stringify(truncatedList));
|
|
|
- } else {
|
|
|
- PreferencesUtil.putSync('albumList', JSON.stringify(this.albumList));
|
|
|
- }
|
|
|
- const mapArrayAlbum = Array.from(this.albumMap.entries())
|
|
|
- .sort((a, b) => b[1].length - a[1].length)
|
|
|
- .slice(0, 60);
|
|
|
+ PreferencesUtil.putSync('albumCount', albumTotalCount)
|
|
|
+ // 保存前100条专辑列表(Worker已经只发送了100条)
|
|
|
+ PreferencesUtil.putSync('albumList', JSON.stringify(this.albumList));
|
|
|
+
|
|
|
+ // 保存前60条专辑Map(Worker已经只发送了60条)
|
|
|
+ const mapArrayAlbum = Array.from(this.albumMap.entries());
|
|
|
PreferencesUtil.putSync('albumMap', JSON.stringify(mapArrayAlbum));
|
|
|
break;
|
|
|
case 105: // 缓存完成后返回的元数据
|
|
|
- this.handleWorkerMetadataPayload(e.data.data as WorkerMetadataPayload);
|
|
|
+ this.handleWorkerMetadataPayload(message.data);
|
|
|
break;
|
|
|
case 106: // 编辑音乐元数据和封面完成
|
|
|
- this.handleEditMusicResult(e.data);
|
|
|
+ this.handleEditMusicResult(message.data);
|
|
|
break;
|
|
|
|
|
|
}
|