-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex2.js
More file actions
1840 lines (1838 loc) · 89.5 KB
/
Copy pathindex2.js
File metadata and controls
1840 lines (1838 loc) · 89.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
const common_vendor = require("./common/vendor.js");
const utils_system = require("./utils/system.js");
const store_modules_list = require("./store/modules/list.js");
const store_modules_player = require("./store/modules/player.js");
const utils_playInfoStorage = require("./utils/playInfoStorage.js");
const utils_api_music = require("./utils/api/music.js");
const utils_api_songlist = require("./utils/api/songlist.js");
const utils_api_songlistDirect = require("./utils/api/songlist-direct.js");
const utils_musicUrlCache = require("./utils/musicUrlCache.js");
const utils_musicSwitchSourceStorage = require("./utils/musicSwitchSourceStorage.js");
const utils_musicParams = require("./utils/musicParams.js");
const utils_imageProxy = require("./utils/imageProxy.js");
const composables_usePageLifecycle = require("./composables/usePageLifecycle.js");
const composables_useBottomHeight = require("./composables/useBottomHeight.js");
if (!Math) {
(RocIconPlus + VirtualList + MusicToggleModal + AutoUpdateToast + LoadingToast)();
}
const RocIconPlus = () => "./uni_modules/roc-icon-plus/components/roc-icon-plus/roc-icon-plus.js";
const MusicToggleModal = () => "./components/player/MusicToggleModal.js";
const AutoUpdateToast = () => "./components/common/AutoUpdateToast.js";
const LoadingToast = () => "./components/common/LoadingToast.js";
const VirtualList = () => "./components/common/VirtualList.js";
const LIST_PREV_SELECT_ID_KEY = "listPrevSelectId";
const _sfc_main = {
__name: "index",
props: {
isActive: {
type: Boolean,
default: false
}
},
setup(__props) {
const props = __props;
const showSidebar = common_vendor.ref(false);
common_vendor.computed(() => utils_system.getSafeAreaStyle());
const statusBarHeight = common_vendor.ref(utils_system.getStatusBarHeight());
common_vendor.ref(utils_system.getNavbarHeight());
const headerStyle = common_vendor.computed(() => ({
paddingTop: `${statusBarHeight.value}px`
}));
const sidebarStyle = common_vendor.computed(() => {
return {
paddingTop: `${statusBarHeight.value}px`,
paddingBottom: `${totalBottomHeight.value}px`
};
});
const tabletModalSafeTop = common_vendor.computed(() => {
if (!isTablet.value)
return "0px";
return `${utils_system.getNavbarHeight()}px`;
});
const trialListCount = common_vendor.computed(() => store_modules_list.listStore.state.defaultList.list.length);
const favoriteListCount = common_vendor.computed(() => store_modules_list.listStore.state.loveList.list.length);
const showImportModal = common_vendor.ref(false);
const importModalTitle = common_vendor.ref("");
const importLink = common_vendor.ref("");
const currentImportSource = common_vendor.ref("");
const currentImportPlatform = common_vendor.ref("");
const showSongMenuFlag = common_vendor.ref(false);
const selectedSong = common_vendor.ref(null);
const selectedSongIndex = common_vendor.ref(-1);
const showPlaylistMenu = common_vendor.ref(false);
const menuPlaylistInfo = common_vendor.ref(null);
const menuPlaylistIndex = common_vendor.ref(-1);
const menuPlaylistType = common_vendor.ref("custom");
const showMusicToggleModal = common_vendor.ref(false);
const toggleOriginalSong = common_vendor.ref(null);
const showAutoUpdateToast = common_vendor.ref(false);
const autoUpdatePlaylistName = common_vendor.ref("");
const showLoadingToast = common_vendor.ref(false);
const loadingToastTitle = common_vendor.ref("加载中");
const loadingToastSubtitle = common_vendor.ref("");
const isPlaylistLoading = common_vendor.ref(false);
const importedPlaylists = common_vendor.ref([]);
const listSource = common_vendor.ref("");
const customPlaylists = common_vendor.ref([]);
const autoUpdatedPlaylists = common_vendor.ref(/* @__PURE__ */ new Set());
const darkMode = common_vendor.ref(false);
const isTablet = common_vendor.ref(false);
const checkIsTablet = () => {
try {
const systemInfo = common_vendor.index.getSystemInfoSync();
const width = systemInfo.windowWidth || systemInfo.screenWidth || 0;
const height = systemInfo.windowHeight || systemInfo.screenHeight || 0;
const TABLET_ASPECT_RATIO = 0.85;
const TABLET_MIN_WIDTH = 400;
const aspectRatio = width / height;
isTablet.value = aspectRatio >= TABLET_ASPECT_RATIO && width >= TABLET_MIN_WIDTH;
} catch (e) {
isTablet.value = false;
}
};
const handleTabletModeChanged = (newIsTablet) => {
console.log("[Playlist] 收到平板模式变化事件:", newIsTablet, "当前值:", isTablet.value);
if (isTablet.value !== newIsTablet) {
isTablet.value = newIsTablet;
console.log("[Playlist] 平板模式已更新为:", newIsTablet);
}
};
const isDataLoaded = common_vendor.ref(false);
const showSidebarTip = common_vendor.ref(false);
const recordSidebarSwitch = () => {
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
let dates = common_vendor.index.getStorageSync("sidebarTipSwitchDates") || [];
if (!dates.includes(today)) {
dates.push(today);
common_vendor.index.setStorageSync("sidebarTipSwitchDates", dates);
console.log("[Playlist] 记录切换日期:", today, "累计:", dates.length);
}
};
const checkSidebarTip = () => {
const dates = common_vendor.index.getStorageSync("sidebarTipSwitchDates") || [];
if (dates.length >= 3) {
console.log("[Playlist] 用户已在不同日期切换过3次,不显示提示");
return;
}
const delay = Math.floor(Math.random() * 4e3) + 2e3;
console.log("[Playlist] 将在", delay, "ms后显示歌单切换提示");
setTimeout(() => {
showSidebarTip.value = true;
setTimeout(() => {
showSidebarTip.value = false;
}, 1e4);
}, delay);
};
const hideSidebarTip = () => {
showSidebarTip.value = false;
};
const saveListPrevSelectId = (id) => {
try {
common_vendor.index.setStorageSync(LIST_PREV_SELECT_ID_KEY, id);
console.log("[Playlist] 保存上次选择的歌单ID:", id);
} catch (error) {
console.error("[Playlist] 保存歌单ID失败:", error);
}
};
const getListPrevSelectId = () => {
try {
const id = common_vendor.index.getStorageSync(LIST_PREV_SELECT_ID_KEY);
console.log("[Playlist] 获取上次选择的歌单ID:", id);
return id || null;
} catch (error) {
console.error("[Playlist] 获取歌单ID失败:", error);
return null;
}
};
const { bottomPaddingStyle, totalBottomHeight } = composables_useBottomHeight.useBottomHeight();
const initDarkMode = () => {
darkMode.value = common_vendor.index.getStorageSync("darkMode") === "true";
console.log("[Playlist] 初始化暗黑模式:", darkMode.value);
};
const refreshCustomPlaylists = () => {
customPlaylists.value = store_modules_list.listStore.state.userLists.map((l) => ({
id: l.id,
name: l.name,
coverImgUrl: l.coverImgUrl || `https://images.unsplash.com/photo-1493225457124-a3eb161ffa5f?ixlib=rb-4.0.3&auto=format&fit=crop&w=100&q=80`,
trackCount: l.list ? l.list.length : 0
}));
};
common_vendor.watch(() => store_modules_list.listStore.state.userLists, () => {
refreshCustomPlaylists();
}, { deep: true });
composables_usePageLifecycle.usePageLifecycle(
() => props.isActive,
{
onInit: () => {
console.log("[Playlist] 页面初始化");
initDarkMode();
checkIsTablet();
refreshCustomPlaylists();
checkSidebarTip();
if (typeof requestAnimationFrame !== "undefined") {
requestAnimationFrame(() => {
setTimeout(() => {
loadPlaylistData();
}, 100);
});
} else {
setTimeout(() => {
loadPlaylistData();
}, 200);
}
},
onActivated: () => {
console.log("[Playlist] 页面激活");
initDarkMode();
checkIsTablet();
refreshCustomPlaylists();
console.log("[Playlist] 刷新自定义歌单:", customPlaylists.value.length, "个");
if (isDataLoaded.value) {
const importedList = common_vendor.index.getStorageSync("imported_playlists") || [];
importedPlaylists.value = importedList;
console.log("[Playlist] 刷新已导入歌单:", importedList.length, "个");
console.log("[Playlist] 当前 currentPlaylistId:", currentPlaylistId.value);
refreshCurrentPlaylist();
}
},
onDeactivated: () => {
console.log("[Playlist] 页面停用");
}
}
);
const handleThemeChanged = (data) => {
console.log("[Playlist] 收到主题变化事件:", data);
darkMode.value = data.isDark;
utils_system.setStatusBarTextColor(data.isDark ? "light" : "black");
};
const handleImportedPlaylistsChanged = () => {
console.log("[Playlist] 收到已导入歌单变化事件,刷新列表");
const importedList = common_vendor.index.getStorageSync("imported_playlists") || [];
importedPlaylists.value = importedList;
console.log("[Playlist] 已刷新已导入歌单:", importedList.length, "个");
};
common_vendor.onMounted(() => {
common_vendor.index.$on("themeChanged", handleThemeChanged);
common_vendor.index.$on("imported-playlists-changed", handleImportedPlaylistsChanged);
common_vendor.index.$on("tabletModeChanged", handleTabletModeChanged);
console.log("[Playlist] 已注册监听: themeChanged, imported-playlists-changed, tabletModeChanged");
});
common_vendor.onUnmounted(() => {
common_vendor.index.$off("themeChanged", handleThemeChanged);
common_vendor.index.$off("imported-playlists-changed", handleImportedPlaylistsChanged);
common_vendor.index.$off("tabletModeChanged", handleTabletModeChanged);
console.log("[Playlist] 已移除监听: themeChanged, imported-playlists-changed, tabletModeChanged");
});
const currentPlaylistId = common_vendor.ref("trial");
const currentPlaylist = common_vendor.reactive({
id: "trial",
name: "试听列表",
coverImgUrl: "",
creator: {
nickname: "拼好歌官方",
avatarUrl: ""
},
description: "试听列表,存放您最近试听的歌曲",
trackCount: 0,
playCount: 0
});
const songs = common_vendor.ref([]);
const isLoading = common_vendor.ref(false);
const setSongList = (allSongs) => {
if (!Array.isArray(allSongs)) {
console.warn("[Playlist] setSongList: allSongs 不是数组", typeof allSongs, allSongs);
songs.value = [];
showLoadingToast.value = false;
return;
}
const totalSongs = allSongs.length;
console.log("[Playlist] setSongList: 准备加载", totalSongs, "首歌曲");
if (totalSongs > 100) {
showLoadingToast.value = true;
loadingToastTitle.value = "正在加载";
loadingToastSubtitle.value = `${totalSongs}首歌曲`;
common_vendor.nextTick$1(() => {
songs.value = allSongs;
setTimeout(() => {
showLoadingToast.value = false;
}, 300);
});
} else {
songs.value = allSongs;
}
console.log(`[Playlist] 已设置歌曲列表,共 ${totalSongs} 首`);
};
const isPlaying = common_vendor.computed(() => store_modules_player.playerStore.state.isPlaying);
const isPlayerPlaying = common_vendor.computed(() => store_modules_player.playerStore.state.isPlaying);
const currentSongIndex = common_vendor.computed(() => {
const playerListId = store_modules_list.listStore.state.playInfo.playerListId;
const tempListMeta = store_modules_list.listStore.state.tempList.meta;
const currentListId = currentPlaylistId.value === "trial" || currentPlaylistId.value === store_modules_list.LIST_IDS.DEFAULT ? store_modules_list.LIST_IDS.DEFAULT : currentPlaylistId.value === "favorite" || currentPlaylistId.value === store_modules_list.LIST_IDS.LOVE ? store_modules_list.LIST_IDS.LOVE : currentPlaylistId.value;
const tempId = tempListMeta == null ? void 0 : tempListMeta.id;
let isPlayingImportedList = false;
if (playerListId === store_modules_list.LIST_IDS.TEMP && tempId) {
if (tempId === currentListId) {
isPlayingImportedList = true;
} else if (tempId === "trial" && currentListId === store_modules_list.LIST_IDS.DEFAULT) {
isPlayingImportedList = true;
}
}
if (playerListId !== currentListId && !isPlayingImportedList) {
return -1;
}
const playIndex = store_modules_list.listStore.state.playInfo.playIndex;
if (playIndex >= 0 && playIndex < songs.value.length) {
return playIndex;
}
return -1;
});
common_vendor.computed(() => {
if (currentSongIndex.value >= 0 && songs.value.length > currentSongIndex.value) {
return songs.value[currentSongIndex.value];
}
return null;
});
const scrollTop = common_vendor.ref(0);
const scrollIntoViewId = common_vendor.ref("");
const virtualListRef = common_vendor.ref(null);
const virtualListHeight = common_vendor.computed(() => {
var _a;
const systemInfo = common_vendor.index.getSystemInfoSync();
const windowHeight = systemInfo.windowHeight || 667;
const statusBar = statusBarHeight.value;
const headerHeight = 44;
const platform = systemInfo.platform;
let tabBarHeight;
if (platform === "ios") {
tabBarHeight = 12 + 50;
} else {
tabBarHeight = 12 + 55;
}
const safeAreaBottom = ((_a = systemInfo.safeAreaInsets) == null ? void 0 : _a.bottom) || 0;
const bottomHeight = tabBarHeight + safeAreaBottom;
console.log("[Playlist] virtualListHeight 计算:", { windowHeight, statusBar, headerHeight, tabBarHeight, safeAreaBottom, bottomHeight });
const height = windowHeight - statusBar - headerHeight - bottomHeight;
return `${Math.max(height, 300)}px`;
});
const onScrollHandler = (e) => {
};
const onVirtualItemClick = ({ index, item }) => {
console.log("[VirtualList] 点击歌曲:", index, item.name);
playSong(index);
};
const onVirtualMoreClick = ({ index, item }) => {
console.log("[VirtualList] 点击更多:", index, item.name);
showSongMenu(item, index);
};
const toggleSidebar = () => {
showSidebar.value = !showSidebar.value;
if (showSidebar.value) {
console.log("========== [Sidebar] 侧边栏打开 ==========");
console.log("[Sidebar] 当前选中歌单 currentPlaylistId:", currentPlaylistId.value);
console.log("[Sidebar] 已导入歌单数量:", importedPlaylists.value.length);
importedPlaylists.value.forEach((p, i) => {
console.log(`[Sidebar] [${i}] id="${p.id}" name="${p.name}" platform="${p.platform}" active=${currentPlaylistId.value === p.id}`);
});
console.log("==========================================");
}
};
const closeSidebar = () => {
showSidebar.value = false;
};
const handlePlaylistImageError = (event, playlist, type) => {
if (!playlist || !playlist.coverImgUrl)
return;
let currentProxyIndex = 0;
if (playlist.coverImgUrl.includes("wsrv.nl"))
currentProxyIndex = 1;
else if (playlist.coverImgUrl.includes("weserv.nl"))
currentProxyIndex = 2;
else if (playlist.coverImgUrl.includes("jina.ai"))
currentProxyIndex = 3;
const nextUrl = utils_imageProxy.handleImageError(event, playlist.coverImgUrl, currentProxyIndex);
if (nextUrl) {
playlist.coverImgUrl = nextUrl;
}
};
const saveImportedPlaylist = () => {
console.log("[saveImportedPlaylist] 开始保存,歌单ID:", currentPlaylistId.value);
const index = importedPlaylists.value.findIndex((p) => p.id === currentPlaylistId.value);
if (index > -1) {
console.log("[saveImportedPlaylist] 找到歌单,索引:", index);
importedPlaylists.value[index].songs = [...songs.value];
importedPlaylists.value[index].trackCount = songs.value.length;
console.log("[saveImportedPlaylist] 更新后的歌曲数量:", importedPlaylists.value[index].trackCount);
common_vendor.index.setStorageSync("imported_playlists", importedPlaylists.value);
console.log("[saveImportedPlaylist] 本地存储已保存");
const newPlaylists = [...importedPlaylists.value];
importedPlaylists.value = newPlaylists;
console.log("[saveImportedPlaylist] 已触发响应式更新");
} else {
console.warn("[saveImportedPlaylist] 未找到要保存的歌单,歌单ID:", currentPlaylistId.value);
}
};
const selectPlaylist = (playlistId, forceReload = false) => {
if (isPlaylistLoading.value) {
console.log("[Playlist] 歌单正在加载中,阻止切换");
return;
}
recordSidebarSwitch();
hideSidebarTip();
console.log("========== [Playlist] selectPlaylist 被调用 ==========");
console.log("[Playlist] 传入的 playlistId:", playlistId, "forceReload:", forceReload);
console.log("[Playlist] 当前 currentPlaylistId:", currentPlaylistId.value);
if (currentPlaylistId.value === playlistId && !forceReload) {
console.log("[Playlist] 歌单已选中,关闭侧边栏");
showSidebar.value = false;
return;
}
currentPlaylistId.value = playlistId;
showSidebar.value = false;
saveListPrevSelectId(playlistId);
if (playlistId === "trial" || playlistId === store_modules_list.LIST_IDS.DEFAULT) {
currentPlaylist.id = store_modules_list.LIST_IDS.DEFAULT;
currentPlaylist.name = "试听列表";
currentPlaylist.description = "试听列表,存放您最近试听的歌曲";
listSource.value = "";
} else if (playlistId === "favorite" || playlistId === store_modules_list.LIST_IDS.LOVE) {
currentPlaylist.id = store_modules_list.LIST_IDS.LOVE;
currentPlaylist.name = "我的收藏";
currentPlaylist.description = "您收藏的歌曲";
listSource.value = "";
} else if (playlistId.startsWith("custom_") || playlistId.startsWith("userlist_")) {
const userList = store_modules_list.listStore.state.userLists.find((l) => l.id === playlistId);
if (userList) {
console.log("[Playlist] 选择自定义歌单:", userList.name);
currentPlaylist.id = userList.id;
currentPlaylist.name = userList.name;
currentPlaylist.coverImgUrl = userList.coverImgUrl || `https://images.unsplash.com/photo-1493225457124-a3eb161ffa5f?ixlib=rb-4.0.3&auto=format&fit=crop&w=100&q=80`;
currentPlaylist.description = "自定义歌单";
listSource.value = "custom";
const playlistSongs = userList.list || [];
setSongList(playlistSongs);
scrollTop.value = 0;
console.log("[Playlist] 自定义歌单歌曲数:", playlistSongs.length);
return;
}
}
songs.value = [];
fetchSongs();
};
const selectImportedPlaylist = (playlist) => {
if (isPlaylistLoading.value) {
console.log("[Playlist] 歌单正在加载中,阻止切换");
return;
}
recordSidebarSwitch();
hideSidebarTip();
console.log("========== [Playlist] selectImportedPlaylist 被调用 ==========");
console.log("[Playlist] 传入的歌单:", JSON.stringify({ id: playlist.id, name: playlist.name }));
console.log("[Playlist] 当前 currentPlaylistId:", currentPlaylistId.value);
if (currentPlaylistId.value === playlist.id) {
console.log("[Playlist] 歌单已选中,关闭侧边栏");
showSidebar.value = false;
return;
}
currentPlaylistId.value = playlist.id;
showSidebar.value = false;
saveListPrevSelectId(playlist.id);
currentPlaylist.id = playlist.id;
currentPlaylist.name = playlist.name;
currentPlaylist.coverImgUrl = playlist.coverImgUrl;
currentPlaylist.description = `从${playlist.platform}导入的歌单`;
listSource.value = playlist.source || "";
const playlistSongs = playlist.songs || [];
setSongList(playlistSongs);
scrollTop.value = 0;
console.log("[Playlist] 选择已导入歌单:", playlist.name, "歌曲数量:", playlistSongs.length);
console.log("========== [Playlist] selectImportedPlaylist 完成 ==========");
};
const platforms = [
{ name: "网易云音乐", source: "wy" },
{ name: "QQ音乐", source: "tx" },
{ name: "酷狗音乐", source: "kg" },
{ name: "酷我音乐", source: "kw" },
{ name: "咪咕音乐", source: "mg" }
];
const createNewPlaylist = () => {
common_vendor.index.showModal({
title: "新建歌单",
editable: true,
placeholderText: "你想起啥名...",
success: (res) => {
if (res.confirm && res.content) {
const name = res.content.trim();
if (!name) {
common_vendor.index.showToast({ title: "歌单名称不能为空", icon: "none" });
return;
}
const exists = store_modules_list.listStore.state.userLists.some((l) => l.name === name);
if (exists) {
common_vendor.index.showModal({
title: "提示",
content: "已存在同名歌单,是否继续创建?",
success: (confirmRes) => {
if (confirmRes.confirm) {
doCreatePlaylist(name);
}
}
});
return;
}
doCreatePlaylist(name);
}
}
});
};
const doCreatePlaylist = (name) => {
const newList = store_modules_list.listStore.createUserList(name);
if (newList) {
refreshCustomPlaylists();
showSidebar.value = true;
common_vendor.index.showToast({ title: "创建成功", icon: "success" });
console.log("[createNewPlaylist] 新建歌单成功:", newList.name, "ID:", newList.id);
}
};
const importPlaylist = () => {
common_vendor.index.showActionSheet({
itemList: platforms.map((p) => p.name),
success: (res) => {
const platform = platforms[res.tapIndex];
currentImportSource.value = platform.source;
currentImportPlatform.value = platform.name;
importModalTitle.value = `从${platform.name}导入`;
importLink.value = "";
showImportModal.value = true;
}
});
};
const fetchSongs = async () => {
var _a;
if (isLoading.value)
return;
isLoading.value = true;
try {
if (currentPlaylistId.value === "trial" || currentPlaylistId.value === store_modules_list.LIST_IDS.DEFAULT) {
console.log("[fetchSongs] 从试听列表获取歌曲,数量:", store_modules_list.listStore.state.defaultList.list.length);
songs.value = [...store_modules_list.listStore.state.defaultList.list];
} else if (currentPlaylistId.value === "favorite" || currentPlaylistId.value === store_modules_list.LIST_IDS.LOVE) {
console.log("[fetchSongs] 从收藏列表获取歌曲,数量:", store_modules_list.listStore.state.loveList.list.length);
songs.value = [...store_modules_list.listStore.state.loveList.list];
} else if (currentPlaylistId.value.startsWith("custom_") || currentPlaylistId.value.startsWith("userlist_")) {
const userList = store_modules_list.listStore.state.userLists.find((l) => l.id === currentPlaylistId.value);
console.log("[fetchSongs] 从自定义歌单获取歌曲,歌单ID:", currentPlaylistId.value, "歌曲数量:", ((_a = userList == null ? void 0 : userList.list) == null ? void 0 : _a.length) || 0);
if (userList && userList.list) {
songs.value = [...userList.list];
} else {
songs.value = [];
}
} else {
const importedList = common_vendor.index.getStorageSync("imported_playlists") || [];
const currentPlaylistData = importedList.find((p) => p.id === currentPlaylistId.value);
if (currentPlaylistData && currentPlaylistData.songs) {
console.log("[fetchSongs] 从导入的歌单获取歌曲,歌单ID:", currentPlaylistId.value, "歌曲数量:", currentPlaylistData.songs.length);
const songsWithAr = currentPlaylistData.songs.map((song) => ({
...song,
ar: song.ar || (song.singer ? song.singer.split("/").map((name) => ({ name })) : [])
}));
songs.value = songsWithAr;
} else {
console.log("[fetchSongs] 未找到导入歌单数据");
songs.value = [];
}
}
console.log("[fetchSongs] 加载完成,共:", songs.value.length, "首");
} catch (error) {
console.error("[fetchSongs] 获取歌曲列表失败:", error);
} finally {
isLoading.value = false;
}
};
const onScrollToLower = () => {
console.log("[Playlist] onScrollToLower 触发,已加载全部", songs.value.length, "首歌曲");
};
const playSongWithIndex = async (index) => {
var _a, _b;
const song = songs.value[index];
if (!song)
return;
console.log("[Playlist] ========== 开始播放歌曲 ==========");
console.log("[Playlist] 歌曲索引:", index);
console.log("[Playlist] 歌曲名称:", song.name);
try {
if (songs.value.length > 0) {
console.log("[Playlist] 播放歌曲,设置临时列表");
store_modules_list.listStore.setTempList(
store_modules_list.LIST_IDS.TEMP,
songs.value,
{
id: currentPlaylist.id,
source: listSource.value || "",
name: currentPlaylist.name
}
);
store_modules_list.listStore.setPlayerListId(store_modules_list.LIST_IDS.TEMP);
store_modules_list.listStore.updatePlayIndexByListId(store_modules_list.LIST_IDS.TEMP, song.id);
console.log("[Playlist] 列表ID:", store_modules_list.LIST_IDS.TEMP, "播放索引:", index);
}
const musicInfo = {
id: song.id,
name: song.name,
singer: song.ar ? song.ar.map((a) => a.name).join("/") : song.singer || "",
ar: song.ar || (song.singer ? song.singer.split("/").map((name) => ({ name })) : []),
album: ((_a = song.al) == null ? void 0 : _a.name) || song.albumName || song.album || "",
duration: song.dt || song.interval || song.duration,
source: song.source || "tx",
songmid: song.songmid,
hash: song.hash,
copyrightId: song.copyrightId,
img: ((_b = song.al) == null ? void 0 : _b.picUrl) || song.img || song.albumPic || "",
// 不设置url和playUrl,让playerStore.playSong自己处理缓存和URL获取
url: "",
playUrl: "",
lyric: song.lyric || "",
tlyric: song.tlyric || "",
rlyric: song.rlyric || "",
lxlyric: song.lxlyric || ""
};
store_modules_list.listStore.setPlayMusicInfo(store_modules_list.LIST_IDS.TEMP, musicInfo, false);
console.log("[Playlist] 调用 playerStore.playSong");
store_modules_player.playerStore.playSong(musicInfo);
console.log("[Playlist] 播放完成");
} catch (error) {
console.error("[Playlist] 播放失败:", error);
store_modules_player.playerStore.clearStatusText();
common_vendor.index.showToast({ title: "播放失败", icon: "none" });
}
};
const playSong = (index) => {
if (currentSongIndex.value === index) {
if (isPlaying.value) {
store_modules_player.playerStore.pause();
} else {
store_modules_player.playerStore.resume();
}
return;
}
const listId = currentPlaylistId.value === "trial" || currentPlaylistId.value === store_modules_list.LIST_IDS.DEFAULT ? store_modules_list.LIST_IDS.DEFAULT : currentPlaylistId.value === "favorite" || currentPlaylistId.value === store_modules_list.LIST_IDS.LOVE ? store_modules_list.LIST_IDS.LOVE : currentPlaylistId.value;
store_modules_list.listStore.setPlayerListId(listId);
playSongWithIndex(index);
};
const locateCurrentSong = async () => {
var _a;
console.log("[locateCurrentSong] ========== 开始定位当前歌曲 ==========");
const playIndex = store_modules_list.listStore.state.playInfo.playIndex;
const playerListId = store_modules_list.listStore.state.playInfo.playerListId;
const tempListMeta = store_modules_list.listStore.state.tempList.meta;
console.log("[locateCurrentSong] 播放索引:", playIndex, "列表ID:", playerListId);
console.log("[locateCurrentSong] 当前列表歌曲数:", songs.value.length);
const currentListId = currentPlaylistId.value === "trial" || currentPlaylistId.value === store_modules_list.LIST_IDS.DEFAULT ? store_modules_list.LIST_IDS.DEFAULT : currentPlaylistId.value === "favorite" || currentPlaylistId.value === store_modules_list.LIST_IDS.LOVE ? store_modules_list.LIST_IDS.LOVE : currentPlaylistId.value;
const isPlayingImportedList = playerListId === store_modules_list.LIST_IDS.TEMP && (tempListMeta.id === currentListId || tempListMeta.id === `local_${currentListId}`);
if (playerListId !== currentListId && !isPlayingImportedList) {
console.warn("[locateCurrentSong] 当前没有播放本列表的歌曲");
common_vendor.index.showToast({ title: "当前没有播放本列表的歌曲", icon: "none" });
return;
}
if (playIndex < 0 || playIndex >= songs.value.length) {
console.warn("[locateCurrentSong] 播放索引无效:", playIndex, "列表长度:", songs.value.length);
common_vendor.index.showToast({ title: "无法定位当前歌曲", icon: "none" });
return;
}
console.log("[locateCurrentSong] 目标歌曲索引:", playIndex, "名称:", (_a = songs.value[playIndex]) == null ? void 0 : _a.name);
if (virtualListRef.value) {
console.log("[locateCurrentSong] 使用虚拟列表 scrollToIndex:", playIndex);
virtualListRef.value.scrollToIndex(playIndex, true);
} else {
const targetId = `virtual-item-${playIndex}`;
scrollIntoViewId.value = "";
await common_vendor.nextTick$1();
scrollIntoViewId.value = targetId;
console.log("[locateCurrentSong] 降级使用 scrollIntoViewId:", targetId);
}
common_vendor.index.showToast({
title: `已定位到第${playIndex + 1}首`,
icon: "none",
duration: 1500
});
console.log("[locateCurrentSong] ========== 定位完成 ==========");
};
const showSongMenu = (song, index) => {
selectedSong.value = song;
selectedSongIndex.value = index;
showSongMenuFlag.value = true;
};
const closeSongMenu = (clearSelection = true) => {
showSongMenuFlag.value = false;
if (clearSelection) {
selectedSong.value = null;
selectedSongIndex.value = -1;
}
};
const showPlaylistContextMenu = (playlist, index, type = "custom") => {
console.log("[showPlaylistContextMenu] 显示歌单菜单,歌单:", playlist.name, "ID:", playlist.id, "类型:", type);
console.log("[showPlaylistContextMenu] 歌单完整信息:", JSON.stringify(playlist));
console.log("[showPlaylistContextMenu] canAutoUpdate:", playlist.canAutoUpdate, "isFromImport:", playlist.isFromImport);
menuPlaylistInfo.value = playlist;
menuPlaylistIndex.value = index;
menuPlaylistType.value = type;
showPlaylistMenu.value = true;
};
const closePlaylistMenu = () => {
showPlaylistMenu.value = false;
menuPlaylistInfo.value = null;
menuPlaylistIndex.value = -1;
menuPlaylistType.value = "custom";
};
const renamePlaylist = () => {
if (!menuPlaylistInfo.value)
return;
const currentInfo = menuPlaylistInfo.value;
const currentType = menuPlaylistType.value;
const currentName = currentInfo.name;
const currentId = currentInfo.id;
const currentCoverImgUrl = currentInfo.coverImgUrl || "";
closePlaylistMenu();
common_vendor.index.showModal({
title: "重命名歌单",
editable: true,
placeholderText: "请输入新名称",
success: (editRes) => {
if (editRes.confirm && editRes.content) {
const newName = editRes.content.trim();
if (!newName) {
common_vendor.index.showToast({ title: "名称不能为空", icon: "none" });
return;
}
if (newName.length > 100) {
common_vendor.index.showToast({ title: "名称不能超过100个字符", icon: "none" });
return;
}
if (newName === currentName) {
common_vendor.index.showToast({ title: "名称未改变", icon: "none" });
return;
}
console.log("[renamePlaylist] 重命名歌单:", currentName, "->", newName, "类型:", currentType);
if (currentType === "imported") {
const index = importedPlaylists.value.findIndex((p) => p.id === currentId);
if (index > -1) {
importedPlaylists.value[index] = {
...importedPlaylists.value[index],
name: newName
};
common_vendor.index.setStorageSync("imported_playlists", importedPlaylists.value);
console.log("[renamePlaylist] 导入歌单已重命名并保存");
importedPlaylists.value = [...importedPlaylists.value];
}
} else {
store_modules_list.listStore.updateUserList([{
id: currentId,
name: newName,
coverImgUrl: currentCoverImgUrl
}]);
refreshCustomPlaylists();
}
common_vendor.index.showToast({ title: "重命名成功", icon: "success" });
}
}
});
};
const removePlaylist = () => {
if (!menuPlaylistInfo.value)
return;
const isImported = menuPlaylistType.value === "imported";
common_vendor.index.showModal({
title: "提示",
content: `确定删除歌单"${menuPlaylistInfo.value.name}"吗?${isImported ? "将从导入列表中移除,歌曲不会删除。" : "删除后无法恢复。"}`,
confirmText: "删除",
confirmColor: "#ff4d4f",
success: (res) => {
if (res.confirm) {
console.log("[removePlaylist] 开始移除歌单:", menuPlaylistInfo.value.name, "ID:", menuPlaylistInfo.value.id, "类型:", menuPlaylistType.value);
const playerListId = store_modules_list.listStore.state.playInfo.playerListId;
const isPlayingThisPlaylist = playerListId === menuPlaylistInfo.value.id;
if (currentPlaylistId.value === menuPlaylistInfo.value.id) {
console.log("[removePlaylist] 当前正在查看该歌单,清空列表并切换到试听列表");
songs.value = [];
currentPlaylistId.value = "";
selectPlaylist("trial");
}
if (isPlayingThisPlaylist) {
console.log("[removePlaylist] 播放器正在播放该歌单,更新播放列表");
store_modules_list.listStore.setPlayerListId(store_modules_list.LIST_IDS.DEFAULT);
const trialList = store_modules_list.listStore.state.defaultList.list;
if (trialList.length > 0) {
store_modules_list.listStore.setPlayMusicInfo(store_modules_list.LIST_IDS.DEFAULT, trialList[0], false);
} else {
store_modules_list.listStore.setPlayMusicInfo(store_modules_list.LIST_IDS.DEFAULT, null, false);
}
}
if (isImported) {
console.log("[removePlaylist] 从导入歌单中移除");
const index = importedPlaylists.value.findIndex((p) => p.id === menuPlaylistInfo.value.id);
if (index > -1) {
importedPlaylists.value.splice(index, 1);
common_vendor.index.setStorageSync("imported_playlists", importedPlaylists.value);
console.log("[removePlaylist] 已从导入列表移除并保存,本地存储剩余:", importedPlaylists.value.length, "个");
importedPlaylists.value = [...importedPlaylists.value];
}
} else {
console.log("[removePlaylist] 从自定义歌单中移除");
store_modules_list.listStore.removeUserList([menuPlaylistInfo.value.id]);
refreshCustomPlaylists();
}
closePlaylistMenu();
common_vendor.index.showToast({ title: "已删除", icon: "success" });
}
}
});
};
const simplifySongs = (songs2) => {
if (!songs2 || !Array.isArray(songs2))
return [];
return songs2.map((song) => {
var _a, _b;
const simplified = {
id: song.id,
name: song.name,
singer: song.singer || (song.ar ? song.ar.map((a) => a.name).join("/") : ""),
ar: song.ar || (song.singer ? song.singer.split("/").map((name) => ({ name })) : []),
album: song.album || song.albumName || (song.al ? song.al.name : ""),
duration: song.duration || song.dt || song.interval,
dt: song.dt || song.duration || song.interval,
// 兼容 SongListItem 组件
interval: song.interval || song.dt || song.duration,
// 兼容播放器
source: song.source
};
if (song.songmid)
simplified.songmid = song.songmid;
if (song.hash)
simplified.hash = song.hash;
if (song.copyrightId)
simplified.copyrightId = song.copyrightId;
if (song.img || song.albumPic || ((_a = song.al) == null ? void 0 : _a.picUrl)) {
simplified.img = song.img || song.albumPic || ((_b = song.al) == null ? void 0 : _b.picUrl);
}
return simplified;
});
};
const syncPlaylist = () => {
if (!menuPlaylistInfo.value || menuPlaylistType.value !== "imported")
return;
const currentPlaylist2 = menuPlaylistInfo.value;
if (!currentPlaylist2.link) {
common_vendor.index.showToast({
title: "该歌单没有链接信息,无法同步",
icon: "none"
});
return;
}
common_vendor.index.showModal({
title: "同步歌单",
content: `确定要同步歌单"${currentPlaylist2.name}"吗?
同步操作将会:
• 重新从源头获取最新歌单内容
• 完全覆盖当前歌单
• 清除所有播放进度和收藏状态
请确保您当前的网络连接正常。`,
confirmText: "确定同步",
cancelText: "取消",
success: async (res) => {
var _a, _b, _c, _d, _e, _f, _g, _h;
if (res.confirm) {
console.log("[syncPlaylist] 开始同步歌单:", currentPlaylist2.name, "链接:", currentPlaylist2.link, "平台:", currentPlaylist2.source);
try {
common_vendor.index.showLoading({ title: "正在同步..." });
let result;
const shouldUseBackend = currentPlaylist2.source === "tx";
if (shouldUseBackend) {
console.log("[syncPlaylist] QQ音乐使用后端接口");
result = await utils_api_songlist.getListDetail(currentPlaylist2.source, currentPlaylist2.link, 1);
} else {
console.log("[syncPlaylist] 使用前端直接API:", currentPlaylist2.source);
let targetPlaylistId = currentPlaylist2.link;
if (/^https?:\/\//.test(currentPlaylist2.link)) {
let match = currentPlaylist2.link.match(/[?&]id=(\d+)/);
if (match) {
targetPlaylistId = match[1];
console.log("[syncPlaylist] 从URL查询参数解析出ID:", targetPlaylistId);
} else {
match = currentPlaylist2.link.match(/\/playlist(?:_detail)?\/(\d+)/);
if (match) {
targetPlaylistId = match[1];
console.log("[syncPlaylist] 从URL路径解析出ID:", targetPlaylistId);
} else if (currentPlaylist2.source === "mg" && currentPlaylist2.link.includes("c.migu.cn")) {
console.log("[syncPlaylist] 检测到咪咕短链接,尝试获取真实URL...");
try {
const res2 = await common_vendor.index.request({
url: currentPlaylist2.link,
method: "HEAD",
header: {
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15"
}
});
const location = ((_a = res2.header) == null ? void 0 : _a.Location) || ((_b = res2.header) == null ? void 0 : _b.location);
if (location) {
console.log("[syncPlaylist] 咪咕短链接重定向到:", location);
const idMatch = location.match(/[?&]id=(\d+)/);
if (idMatch) {
targetPlaylistId = idMatch[1];
console.log("[syncPlaylist] 从咪咕重定向URL解析出ID:", targetPlaylistId);
}
}
} catch (err) {
console.error("[syncPlaylist] 获取咪咕短链接失败:", err);
}
}
}
} else {
console.log("[syncPlaylist] 直接使用作为ID:", targetPlaylistId);
}
result = await utils_api_songlistDirect.getListDetailDirect(currentPlaylist2.source, targetPlaylistId, 1);
}
const updatedSongs = result.list || [];
if (updatedSongs.length === 0) {
throw new Error("获取到0首歌曲,可能歌单已删除或无权限访问");
}
const playlistIndex = importedPlaylists.value.findIndex((p) => p.id === currentPlaylist2.id);
if (playlistIndex > -1) {
const simplifiedSongs = simplifySongs(updatedSongs);
importedPlaylists.value[playlistIndex].songs = simplifiedSongs;
importedPlaylists.value[playlistIndex].trackCount = updatedSongs.length;
importedPlaylists.value[playlistIndex].coverImgUrl = ((_c = result.info) == null ? void 0 : _c.img) || result.coverImgUrl || currentPlaylist2.coverImgUrl;
importedPlaylists.value[playlistIndex].name = ((_d = result.info) == null ? void 0 : _d.name) || result.name || currentPlaylist2.name;
if (((_e = result.info) == null ? void 0 : _e.desc) || result.desc) {
importedPlaylists.value[playlistIndex].desc = ((_f = result.info) == null ? void 0 : _f.desc) || result.desc;
}
common_vendor.index.setStorageSync("imported_playlists", importedPlaylists.value);
console.log("[syncPlaylist] 歌单已更新并保存,歌曲数:", updatedSongs.length);
importedPlaylists.value = [...importedPlaylists.value];
if (currentPlaylistId.value === currentPlaylist2.id) {
songs.value = [...updatedSongs];
currentPlaylist2.name = ((_g = result.info) == null ? void 0 : _g.name) || result.name || currentPlaylist2.name;
currentPlaylist2.coverImgUrl = ((_h = result.info) == null ? void 0 : _h.img) || result.coverImgUrl || currentPlaylist2.coverImgUrl;
currentPlaylist2.trackCount = updatedSongs.length;
console.log("[syncPlaylist] 当前歌单已更新,歌曲数:", updatedSongs.length);
}
}
closePlaylistMenu();
common_vendor.index.showToast({
title: `同步成功(${updatedSongs.length}首)`,
icon: "success"
});
} catch (error) {
console.error("[syncPlaylist] 同步失败:", error);
let errorMessage = "同步失败";
if (error.message) {
if (error.message.includes("404") || error.message.includes("not found")) {
errorMessage = "歌单不存在或已删除";
} else if (error.message.includes("403") || error.message.includes("forbidden")) {
errorMessage = "没有权限访问该歌单";
} else if (error.message.includes("network") || error.message.includes("网络")) {
errorMessage = "网络连接失败";
} else {
errorMessage = `同步失败: ${error.message}`;
}
}
common_vendor.index.showToast({
title: errorMessage,
icon: "none"
});
} finally {
common_vendor.index.hideLoading();
}
}
}
});
};
const toggleAutoUpdate = () => {
if (!menuPlaylistInfo.value || menuPlaylistType.value !== "imported")
return;
const currentPlaylist2 = menuPlaylistInfo.value;
const newAutoUpdateState = !currentPlaylist2.autoUpdate;
const playlistIndex = importedPlaylists.value.findIndex((p) => p.id === currentPlaylist2.id);
if (playlistIndex > -1) {
importedPlaylists.value[playlistIndex].autoUpdate = newAutoUpdateState;
common_vendor.index.setStorageSync("imported_playlists", importedPlaylists.value);
console.log("[toggleAutoUpdate] 自动更新状态已更新:", newAutoUpdateState);
importedPlaylists.value = [...importedPlaylists.value];
menuPlaylistInfo.value.autoUpdate = newAutoUpdateState;
common_vendor.index.showToast({
title: newAutoUpdateState ? "已开启自动更新" : "已关闭自动更新",
icon: "success"
});
}
};
const batchAutoUpdatePlaylists = async () => {
console.log("[batchAutoUpdatePlaylists] 开始批量自动更新检查");
const importedList = importedPlaylists.value;
const autoUpdatePlaylists = importedList.filter((p) => p.autoUpdate && p.canAutoUpdate);
console.log("[batchAutoUpdatePlaylists] 开启自动更新的歌单数量:", autoUpdatePlaylists.length);
if (autoUpdatePlaylists.length === 0) {
console.log("[batchAutoUpdatePlaylists] 没有开启自动更新的歌单,跳过");
return;
}
for (const playlist of autoUpdatePlaylists) {
if (autoUpdatedPlaylists.value.has(playlist.id)) {
console.log("[batchAutoUpdatePlaylists] 歌单已更新过,跳过:", playlist.name);
continue;
}
console.log("[batchAutoUpdatePlaylists] 开始自动更新歌单:", playlist.name);
showAutoUpdateToast.value = true;
autoUpdatePlaylistName.value = playlist.name;
try {
autoUpdatedPlaylists.value.add(playlist.id);
await autoUpdatePlaylist(playlist, false);
console.log("[batchAutoUpdatePlaylists] 歌单自动更新成功:", playlist.name);
} catch (error) {
console.error("[batchAutoUpdatePlaylists] 歌单自动更新失败:", playlist.name, error);
autoUpdatedPlaylists.value.delete(playlist.id);
}
await new Promise((resolve) => setTimeout(resolve, 1e3));
}
console.log("[batchAutoUpdatePlaylists] 批量自动更新完成");
showAutoUpdateToast.value = false;
autoUpdatePlaylistName.value = "";
};
const autoUpdatePlaylist = async (playlistData, showToast = true) => {