-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
1669 lines (1669 loc) · 66.7 KB
/
Copy pathindex.js
File metadata and controls
1669 lines (1669 loc) · 66.7 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 store_modules_list = require("./store/modules/list.js");
const store_modules_player = require("./store/modules/player.js");
const store_modules_system = require("./store/modules/system.js");
const utils_api_songlist = require("./utils/api/songlist.js");
const utils_api_songlistDirect = require("./utils/api/songlist-direct.js");
const utils_api_music = require("./utils/api/music.js");
const utils_musicUrlCache = require("./utils/musicUrlCache.js");
const utils_lyricCache = require("./utils/lyricCache.js");
const utils_musicParams = require("./utils/musicParams.js");
const utils_i18n = require("./utils/i18n.js");
const utils_system = require("./utils/system.js");
const utils_imageProxy = require("./utils/imageProxy.js");
const utils_playSong = require("./utils/playSong.js");
const composables_usePageLifecycle = require("./composables/usePageLifecycle.js");
const composables_useBottomHeight = require("./composables/useBottomHeight.js");
if (!Array) {
const _easycom_roc_icon_plus2 = common_vendor.resolveComponent("roc-icon-plus");
_easycom_roc_icon_plus2();
}
const _easycom_roc_icon_plus = () => "./uni_modules/roc-icon-plus/components/roc-icon-plus/roc-icon-plus.js";
if (!Math) {
_easycom_roc_icon_plus();
}
const DOUBLE_CLICK_DELAY = 300;
const STATUS_BAR_DOUBLE_CLICK_DELAY = 300;
const _sfc_main = {
__name: "index",
props: {
isActive: {
type: Boolean,
default: false
}
},
setup(__props, { expose: __expose }) {
const props = __props;
const statusBarHeight = common_vendor.ref(utils_system.getStatusBarHeight());
const statusBarStyle = common_vendor.computed(() => ({
height: `${statusBarHeight.value}px`,
width: "100%",
backgroundColor: isDarkMode.value ? "#1f2937" : "transparent"
}));
const currentBannerIndex = common_vendor.ref(0);
const isLoadingMore = common_vendor.ref(false);
const isDarkMode = common_vendor.ref(false);
const isRefreshing = common_vendor.ref(false);
common_vendor.ref(false);
const APP_NAMES = ["拼好歌", "青釉音乐"];
const currentAppNameIndex = common_vendor.ref(0);
const appName = common_vendor.computed(() => APP_NAMES[currentAppNameIndex.value]);
let lastClickTime = 0;
const showMiniPlayer = common_vendor.computed(() => store_modules_player.playerStore.getState().showMiniPlayer);
const { bottomPaddingStyle, bottomMarginStyle, totalBottomHeight, isMiniPlayerVisible, checkMiniPlayerStatus: checkMiniPlayerStatusFromComposable } = composables_useBottomHeight.useBottomHeight();
const scrollViewStyle = common_vendor.computed(() => {
console.log("[Index] scrollViewStyle 计算:", { totalBottomHeight: totalBottomHeight.value, isMiniPlayerVisible: isMiniPlayerVisible.value });
return {};
});
const safeBottomStyle = common_vendor.computed(() => {
return {
height: `${totalBottomHeight.value}px`
};
});
const banners = common_vendor.ref([]);
const recommendPlaylists = common_vendor.ref([]);
const newSongs = common_vendor.ref([]);
const newAlbums = common_vendor.ref([]);
const topArtists = common_vendor.ref([]);
const isTablet = common_vendor.ref(false);
const showBannerNav = common_vendor.ref(false);
const showPlaylistNav = common_vendor.ref(false);
const showArtistNav = common_vendor.ref(false);
const playlistScrollLeft = common_vendor.ref(0);
const artistScrollLeft = common_vendor.ref(0);
const canScrollPlaylistLeft = common_vendor.ref(false);
const canScrollPlaylistRight = common_vendor.ref(false);
const canScrollArtistLeft = common_vendor.ref(false);
const canScrollArtistRight = common_vendor.ref(false);
common_vendor.ref(null);
common_vendor.ref(null);
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;
const newIsTablet = aspectRatio >= TABLET_ASPECT_RATIO && width >= TABLET_MIN_WIDTH;
if (isTablet.value !== newIsTablet) {
console.log("[Index] checkIsTablet - 状态变化:", isTablet.value, "->", newIsTablet, `尺寸:${width}x${height} 比值:${aspectRatio.toFixed(2)}`);
isTablet.value = newIsTablet;
}
return isTablet.value;
} catch (e) {
isTablet.value = false;
return false;
}
};
const handleTabletModeChanged = (newIsTablet) => {
console.log("[Index] 收到平板模式变化事件:", newIsTablet, "当前值:", isTablet.value);
if (isTablet.value !== newIsTablet) {
isTablet.value = newIsTablet;
console.log("[Index] 平板模式已更新为:", newIsTablet);
}
};
const decodeName = (str) => {
if (!str)
return "";
return str.replace(/'/g, "'").replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/'/g, "'").replace(/ /g, " ").replace(/ /g, " ");
};
const checkDarkMode = () => {
const storedDarkMode = common_vendor.index.getStorageSync("darkMode") === "true";
const followSystem = common_vendor.index.getStorageSync("followSystem");
const isFollowSystem = followSystem !== "false" && followSystem !== false;
if (isFollowSystem) {
const systemInfo = common_vendor.index.getSystemInfoSync();
if (systemInfo && systemInfo.theme) {
isDarkMode.value = systemInfo.theme === "dark";
} else {
isDarkMode.value = storedDarkMode;
}
} else {
isDarkMode.value = storedDarkMode;
}
if (!isFollowSystem) {
const theme = isDarkMode.value ? "dark" : "light";
utils_system.setAppTheme(theme);
}
console.log("[Index] checkDarkMode - 暗黑模式:", isDarkMode.value, "isFollowSystem:", isFollowSystem);
};
const checkScrollStatus = () => {
setTimeout(() => {
if (recommendPlaylists.value.length > 3) {
canScrollPlaylistRight.value = true;
}
if (topArtists.value.length > 4) {
canScrollArtistRight.value = true;
}
console.log("[Index] 初始化滚动状态 - 推荐歌单:", canScrollPlaylistRight.value, "热门歌手:", canScrollArtistRight.value);
}, 100);
};
const checkMiniPlayerStatus = () => {
console.log("[Index] checkMiniPlayerStatus - 开始检查");
if (checkMiniPlayerStatusFromComposable) {
checkMiniPlayerStatusFromComposable();
}
const currentSong = store_modules_player.playerStore.getState().currentSong;
console.log("[Index] checkMiniPlayerStatus - 当前歌曲:", (currentSong == null ? void 0 : currentSong.name) || "无");
console.log("[Index] checkMiniPlayerStatus - 当前底部高度:", {
totalBottomHeight: totalBottomHeight.value,
isMiniPlayerVisible: isMiniPlayerVisible.value
});
};
const fetchData = async () => {
try {
await Promise.all([
fetchBanners(),
fetchRecommendPlaylists(),
fetchNewSongs(),
fetchNewAlbums(),
fetchTopArtists()
]);
checkScrollStatus();
} catch (error) {
console.error("获取首页数据失败:", error);
common_vendor.index.showToast({
title: "获取数据失败,请重试",
icon: "none"
});
}
};
composables_usePageLifecycle.usePageLifecycle(
() => props.isActive,
{
onInit: () => {
console.log("[Index] 页面初始化");
fetchData();
},
onActivated: () => {
console.log("[Index] 页面激活");
checkDarkMode();
checkMiniPlayerStatus();
console.log("[Index] 页面激活完成 - 底部高度:", totalBottomHeight.value);
},
onDeactivated: () => {
console.log("[Index] 页面停用");
}
}
);
common_vendor.onMounted(() => {
initAppName();
checkIsTablet();
common_vendor.index.$on("themeChanged", handleThemeChanged);
common_vendor.index.$on("systemThemeChange", handleSystemThemeChange);
common_vendor.index.$on("tabletModeChanged", handleTabletModeChanged);
console.log("[Index] 已注册监听: themeChanged, systemThemeChange, tabletModeChanged");
setTimeout(() => {
checkScrollStatus();
}, 1e3);
});
common_vendor.onUnmounted(() => {
common_vendor.index.$off("themeChanged", handleThemeChanged);
common_vendor.index.$off("systemThemeChange", handleSystemThemeChange);
common_vendor.index.$off("tabletModeChanged", handleTabletModeChanged);
console.log("[Index] 已移除监听: themeChanged, systemThemeChange, tabletModeChanged");
});
const handleThemeChanged = (data) => {
console.log("[Index] 收到主题变化事件 (themeChanged):", data);
isDarkMode.value = data.isDark;
common_vendor.index.$emit("themeLogAdded", { log: `[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] [Index] 收到主题变化: ${JSON.stringify(data)}` });
};
const handleSystemThemeChange = (data) => {
console.log("[Index] 收到系统主题变化事件 (systemThemeChange):", data);
isDarkMode.value = data.isDark;
common_vendor.index.$emit("themeLogAdded", { log: `[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] [Index] 收到系统主题变化: ${JSON.stringify(data)}` });
};
const fetchBanners = async () => {
try {
const savedMaxPage = common_vendor.index.getStorageSync("kw_banner_max_page");
let targetPage = 1;
const rn = 10;
if (savedMaxPage && savedMaxPage > 0) {
targetPage = Math.floor(Math.random() * savedMaxPage) + 1;
console.log("[Banner] 使用保存的页码范围:", savedMaxPage, "随机选择页码:", targetPage);
} else {
console.log("[Banner] 首次打开,使用第1页");
}
const url = `http://wapi.kuwo.cn/api/pc/classify/playlist/getRcmPlayList?loginUid=0&loginSid=0&appUid=76039576&pn=${targetPage}&rn=${rn}&order=hot`;
const res = await common_vendor.index.request({
url,
method: "GET",
header: {
"Referer": "https://servicewechat.com/wx2d02f54a4e4c4027/devtools/page-frame.html"
}
});
if (res.statusCode !== 200 || res.data.code !== 200) {
throw new Error("获取歌单数据失败");
}
const total = res.data.data.total || 0;
const list = res.data.data.data || [];
const maxPage = Math.ceil(total / rn) || 1;
common_vendor.index.setStorageSync("kw_banner_max_page", maxPage);
console.log("[Banner] 酷我推荐歌单总数:", total, "计算总页数:", maxPage, "本次获取:", list.length, "当前页码:", targetPage);
const bannerList = [];
const usedIndices = [];
while (bannerList.length < 5 && usedIndices.length < list.length) {
const randomIndex = Math.floor(Math.random() * list.length);
if (!usedIndices.includes(randomIndex)) {
usedIndices.push(randomIndex);
const item = list[randomIndex];
let imgUrl = item.img ? item.img.trim().replace(/`/g, "") : "";
if (imgUrl && !imgUrl.endsWith(".jpg") && !imgUrl.endsWith(".png") && !imgUrl.endsWith(".webp")) {
imgUrl = imgUrl + ".jpg";
}
imgUrl = utils_imageProxy.proxyImageUrl(imgUrl);
bannerList.push({
imageUrl: imgUrl,
targetType: 1,
targetId: `digest-${item.digest}__${item.id}`,
titleColor: "red",
typeTitle: decodeName(item.name),
subtitle: decodeName(item.desc) || "精选歌单推荐",
url: "",
source: "kw",
playCount: item.listencnt,
total: item.total
});
}
}
if (bannerList.length < 5) {
const fallbackBanners = [
{
imageUrl: "https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?q=80&w=1470&auto=format&fit=crop",
targetType: 1,
targetId: "digest-8__2886046289",
titleColor: "red",
typeTitle: "夏日特辑",
subtitle: "清凉一夏,畅享音乐",
url: "",
source: "kw"
},
{
imageUrl: "https://images.unsplash.com/photo-1507838153414-b4b713384a76?q=80&w=1470&auto=format&fit=crop",
targetType: 1,
targetId: "digest-8__2847251561",
titleColor: "blue",
typeTitle: "古典新声",
subtitle: "感受古典音乐的魅力",
url: "",
source: "kw"
},
{
imageUrl: "https://images.unsplash.com/photo-1470225620780-dba8ba36b745?q=80&w=1470&auto=format&fit=crop",
targetType: 1,
targetId: "digest-8__2736267853",
titleColor: "red",
typeTitle: "电音节拍",
subtitle: "夏夜狂欢,尽情舞动",
url: "",
source: "kw"
},
{
imageUrl: "https://images.unsplash.com/photo-1493225457124-a3eb161ffa5f?q=80&w=1470&auto=format&fit=crop",
targetType: 1,
targetId: "digest-8__2829883282",
titleColor: "blue",
typeTitle: "轻音乐精选",
subtitle: "放松身心,享受宁静",
url: "",
source: "kw"
},
{
imageUrl: "https://images.unsplash.com/photo-1514525253161-7a46d19cd819?q=80&w=1474&auto=format&fit=crop",
targetType: 1,
targetId: "digest-8__2829816742",
titleColor: "red",
typeTitle: "流行热歌",
subtitle: "当下最热门的流行音乐",
url: "",
source: "kw"
}
];
while (bannerList.length < 5) {
bannerList.push(fallbackBanners[bannerList.length]);
}
}
banners.value = bannerList;
console.log("[Banner] 轮播图数据:", bannerList);
} catch (error) {
console.error("[Banner] 获取轮播图失败:", error);
common_vendor.index.removeStorageSync("kw_banner_max_page");
console.log("[Banner] 请求失败,已清除保存的页码,下次将使用第1页");
banners.value = [
{
imageUrl: "https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?q=80&w=1470&auto=format&fit=crop",
targetType: 1,
targetId: "digest-8__2886046289",
titleColor: "red",
typeTitle: "夏日特辑",
subtitle: "清凉一夏,畅享音乐",
url: "",
source: "kw"
},
{
imageUrl: "https://images.unsplash.com/photo-1507838153414-b4b713384a76?q=80&w=1470&auto=format&fit=crop",
targetType: 1,
targetId: "digest-8__2847251561",
titleColor: "blue",
typeTitle: "古典新声",
subtitle: "感受古典音乐的魅力",
url: "",
source: "kw"
},
{
imageUrl: "https://images.unsplash.com/photo-1470225620780-dba8ba36b745?q=80&w=1470&auto=format&fit=crop",
targetType: 1,
targetId: "digest-8__2736267853",
titleColor: "red",
typeTitle: "电音节拍",
subtitle: "夏夜狂欢,尽情舞动",
url: "",
source: "kw"
}
];
}
};
const fetchRecommendPlaylists = async () => {
var _a, _b;
try {
const savedMaxPage = common_vendor.index.getStorageSync("kw_recommend_max_page");
let targetPage = 1;
const rn = 15;
if (savedMaxPage && savedMaxPage > 0) {
targetPage = Math.floor(Math.random() * savedMaxPage) + 1;
console.log("[Recommend] 使用保存的页码范围:", savedMaxPage, "随机选择页码:", targetPage);
} else {
console.log("[Recommend] 首次打开,使用第1页");
}
const res = await common_vendor.index.request({
url: "http://wapi.kuwo.cn/api/pc/classify/playlist/getRcmPlayList",
method: "GET",
data: {
loginUid: 0,
loginSid: 0,
appUid: 76039576,
pn: targetPage,
rn,
order: "hot"
},
header: {
"Referer": "https://servicewechat.com/wx2d02f54a4e4c4027/devtools/page-frame.html"
}
});
if (res.statusCode !== 200 || res.data.code !== 200) {
throw new Error("获取推荐歌单失败");
}
const total = ((_a = res.data.data) == null ? void 0 : _a.total) || 0;
const list = ((_b = res.data.data) == null ? void 0 : _b.data) || [];
const maxPage = Math.ceil(total / rn) || 1;
common_vendor.index.setStorageSync("kw_recommend_max_page", maxPage);
console.log("[Recommend] 酷我推荐歌单总数:", total, "计算总页数:", maxPage, "本次获取:", list.length, "当前页码:", targetPage);
recommendPlaylists.value = list.map((item) => ({
id: item.id,
name: decodeName(item.name),
coverImgUrl: utils_imageProxy.proxyImageUrl(item.img),
playCount: item.listencnt,
source: "kw",
author: "",
digest: item.digest
}));
console.log("[Index] 推荐歌单数量:", recommendPlaylists.value.length);
} catch (error) {
console.error("[Index] 获取推荐歌单失败:", error);
common_vendor.index.removeStorageSync("kw_recommend_max_page");
console.log("[Recommend] 请求失败,已清除保存的页码,下次将使用第1页");
recommendPlaylists.value = [];
}
};
const fetchNewSongs = async () => {
var _a, _b, _c;
try {
const res = await common_vendor.index.request({
url: "https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/querycontentbyId.do",
method: "GET",
data: {
columnId: "27553319",
needAll: 0
},
header: {
"User-Agent": "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36",
"Referer": "https://app.c.nf.migu.cn/",
"channel": "0146921"
}
});
if (res.statusCode !== 200 || ((_a = res.data) == null ? void 0 : _a.code) !== "000000") {
console.error("[Index] 咪咕新歌接口返回:", res.data);
throw new Error("获取咪咕新歌失败");
}
const contents = (_c = (_b = res.data) == null ? void 0 : _b.columnInfo) == null ? void 0 : _c.contents;
if (!contents || !Array.isArray(contents)) {
throw new Error("咪咕新歌无数据");
}
newSongs.value = contents.slice(0, 6).map((item) => {
var _a2, _b2;
const info = item.objectInfo || item;
return {
id: info.songId || info.id,
name: decodeName(info.songName || info.name),
singer: decodeName(info.singerName || info.singer),
album: decodeName(info.albumName || info.album),
img: ((_b2 = (_a2 = info.albumImgs) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.img) || info.landscapImg || "",
source: "mg"
};
});
console.log("[Index] 新歌数量:", newSongs.value.length);
} catch (error) {
console.error("[Index] 获取新歌失败:", error);
newSongs.value = [];
}
};
const fetchNewAlbums = async () => {
try {
newAlbums.value = [];
console.log("[Index] 新碟上架功能暂未实现");
} catch (error) {
console.error("[Index] 获取新碟上架失败:", error);
newAlbums.value = [];
}
};
const fetchTopArtists = async () => {
var _a, _b, _c;
try {
const res = await common_vendor.index.request({
url: "https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/querycontentbyId.do",
method: "GET",
data: {
columnId: "27186466",
needAll: 0
},
header: {
"User-Agent": "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36",
"Referer": "https://app.c.nf.migu.cn/",
"channel": "0146921"
}
});
if (res.statusCode !== 200 || ((_a = res.data) == null ? void 0 : _a.code) !== "000000") {
console.error("[Index] 咪咕热歌榜接口返回:", res.data);
throw new Error("获取咪咕热歌榜失败");
}
const contents = (_c = (_b = res.data) == null ? void 0 : _b.columnInfo) == null ? void 0 : _c.contents;
if (!contents || !Array.isArray(contents)) {
throw new Error("咪咕热歌榜无数据");
}
console.log("[TopArtists] 咪咕热歌榜歌曲数量:", contents.length);
const artistMap = /* @__PURE__ */ new Map();
for (const item of contents) {
const info = item.objectInfo || item;
let singerName = info.singerName || info.singer || "";
if (!singerName)
continue;
singerName = singerName.split(/[,,/&]/)[0].trim();
const singerId = info.singerId || "";
let imgUrl = "";
if (info.landscapImg) {
imgUrl = info.landscapImg;
} else if (info.albumImgs && info.albumImgs.length > 0) {
imgUrl = info.albumImgs[0].img || "";
}
if (!artistMap.has(singerName)) {
artistMap.set(singerName, {
id: singerId || singerName,
name: singerName,
picUrl: imgUrl || "https://images.unsplash.com/photo-1470229722913-7c0e2dbbafd3?q=80&w=1470&auto=format&fit=crop"
});
}
if (artistMap.size >= 10) {
break;
}
}
const artistList = Array.from(artistMap.values());
console.log("[TopArtists] 提取的热门歌手数量:", artistList.length);
if (artistList.length < 10) {
const fallbackArtists = [
{ id: "1", name: "薛之谦", picUrl: "https://images.unsplash.com/photo-1470229722913-7c0e2dbbafd3?q=80&w=1470&auto=format&fit=crop" },
{ id: "2", name: "周杰伦", picUrl: "https://images.unsplash.com/photo-1514525253161-7a46d19cd819?q=80&w=1474&auto=format&fit=crop" },
{ id: "3", name: "林俊杰", picUrl: "https://images.unsplash.com/photo-1470225620780-dba8ba36b745?q=80&w=1470&auto=format&fit=crop" },
{ id: "4", name: "邓紫棋", picUrl: "https://images.unsplash.com/photo-1516450360452-9312f5e86fc7?q=80&w=1470&auto=format&fit=crop" },
{ id: "5", name: "张学友", picUrl: "https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?q=80&w=1470&auto=format&fit=crop" },
{ id: "6", name: "刘德华", picUrl: "https://images.unsplash.com/photo-1507838153414-b4b713384a76?q=80&w=1470&auto=format&fit=crop" },
{ id: "7", name: "陈奕迅", picUrl: "https://images.unsplash.com/photo-1493225457124-a3eb161ffa5f?q=80&w=1470&auto=format&fit=crop" },
{ id: "8", name: "五月天", picUrl: "https://images.unsplash.com/photo-1549213783-8284d0336c4f?q=80&w=1470&auto=format&fit=crop" },
{ id: "9", name: "毛不易", picUrl: "https://images.unsplash.com/photo-1598387993281-cecf8b71a8f8?q=80&w=1476&auto=format&fit=crop" },
{ id: "10", name: "李荣浩", picUrl: "https://images.unsplash.com/photo-1501386761578-eac5c94b800a?q=80&w=1470&auto=format&fit=crop" }
];
while (artistList.length < 10) {
const fallback = fallbackArtists[artistList.length];
if (!artistMap.has(fallback.name)) {
artistList.push(fallback);
} else {
break;
}
}
}
topArtists.value = artistList;
} catch (error) {
console.error("[TopArtists] 获取热门歌手失败:", error);
topArtists.value = [
{ id: "1", name: "薛之谦", picUrl: "https://images.unsplash.com/photo-1470229722913-7c0e2dbbafd3?q=80&w=1470&auto=format&fit=crop" },
{ id: "2", name: "周杰伦", picUrl: "https://images.unsplash.com/photo-1514525253161-7a46d19cd819?q=80&w=1474&auto=format&fit=crop" },
{ id: "3", name: "林俊杰", picUrl: "https://images.unsplash.com/photo-1470225620780-dba8ba36b745?q=80&w=1470&auto=format&fit=crop" },
{ id: "4", name: "邓紫棋", picUrl: "https://images.unsplash.com/photo-1516450360452-9312f5e86fc7?q=80&w=1470&auto=format&fit=crop" },
{ id: "5", name: "张学友", picUrl: "https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?q=80&w=1470&auto=format&fit=crop" },
{ id: "6", name: "刘德华", picUrl: "https://images.unsplash.com/photo-1507838153414-b4b713384a76?q=80&w=1470&auto=format&fit=crop" },
{ id: "7", name: "陈奕迅", picUrl: "https://images.unsplash.com/photo-1493225457124-a3eb161ffa5f?q=80&w=1470&auto=format&fit=crop" },
{ id: "8", name: "五月天", picUrl: "https://images.unsplash.com/photo-1549213783-8284d0336c4f?q=80&w=1470&auto=format&fit=crop" },
{ id: "9", name: "毛不易", picUrl: "https://images.unsplash.com/photo-1598387993281-cecf8b71a8f8?q=80&w=1476&auto=format&fit=crop" },
{ id: "10", name: "李荣浩", picUrl: "https://images.unsplash.com/photo-1501386761578-eac5c94b800a?q=80&w=1470&auto=format&fit=crop" }
];
}
};
const initAppName = () => {
const savedIndex = common_vendor.index.getStorageSync("appNameIndex");
if (savedIndex !== "" && savedIndex !== null && savedIndex !== void 0) {
currentAppNameIndex.value = parseInt(savedIndex, 10) || 0;
} else {
currentAppNameIndex.value = 0;
}
console.log("[Index] 初始化APP名称:", appName.value, "索引:", currentAppNameIndex.value);
};
const handleAppLogoClick = () => {
const currentTime = Date.now();
const timeDiff = currentTime - lastClickTime;
console.log("[Index] APP Logo被点击,时间差:", timeDiff);
if (timeDiff > 0 && timeDiff < DOUBLE_CLICK_DELAY) {
console.log("[Index] 检测到双击,准备切换APP名称");
const newIndex = (currentAppNameIndex.value + 1) % APP_NAMES.length;
currentAppNameIndex.value = newIndex;
common_vendor.index.setStorageSync("appNameIndex", newIndex);
console.log("[Index] 切换APP名称成功:", appName.value);
common_vendor.index.showToast({
title: `已切换为"${appName.value}"`,
icon: "none",
duration: 1500
});
lastClickTime = 0;
} else {
lastClickTime = currentTime;
console.log("[Index] 检测到单击,记录时间:", lastClickTime);
}
};
let statusBarLastClickTime = 0;
const handleStatusBarClick = () => {
const currentTime = Date.now();
const timeDiff = currentTime - statusBarLastClickTime;
console.log("[Index] 状态栏被点击,时间差:", timeDiff);
if (timeDiff > 0 && timeDiff < STATUS_BAR_DOUBLE_CLICK_DELAY) {
console.log("[Index] 检测到状态栏双击,切换全屏");
statusBarLastClickTime = 0;
} else {
statusBarLastClickTime = currentTime;
}
};
const onRefresh = async () => {
console.log("[Index] 下拉刷新开始");
if (isRefreshing.value)
return;
isRefreshing.value = true;
try {
banners.value = [];
recommendPlaylists.value = [];
newSongs.value = [];
newAlbums.value = [];
topArtists.value = [];
await fetchData();
common_vendor.index.showToast({
title: "刷新成功",
icon: "success",
duration: 1500
});
} catch (error) {
console.error("[Index] 下拉刷新失败:", error);
common_vendor.index.showToast({
title: "刷新失败",
icon: "none",
duration: 1500
});
} finally {
isRefreshing.value = false;
console.log("[Index] 下拉刷新结束");
}
};
const formatPlayCount = (count) => {
if (count < 1e4) {
return count.toString();
} else if (count < 1e8) {
return Math.floor(count / 1e4) + "万";
} else {
return Math.floor(count / 1e8) + "亿";
}
};
const formatArtists = (artists) => {
return artists.map((artist) => artist.name).join(" / ");
};
const playSong = (song) => {
const songWithoutUrl = {
...song,
url: "",
playUrl: ""
};
store_modules_player.playerStore.playSong(songWithoutUrl);
};
const showSongOptions = (song) => {
common_vendor.index.showActionSheet({
itemList: ["添加到播放列表", "下一首播放", "收藏到歌单", "分享", "歌手:" + formatArtists(song.artists), "专辑:" + song.album.name],
success: (res) => {
switch (res.tapIndex) {
case 0:
store_modules_player.playerStore.addToPlaylist(song);
common_vendor.index.showToast({
title: "已添加到播放列表",
icon: "none"
});
break;
case 1:
store_modules_player.playerStore.addToPlaylistAsNext(song);
common_vendor.index.showToast({
title: "已添加到下一首播放",
icon: "none"
});
break;
case 2:
common_vendor.index.showToast({
title: "收藏功能开发中",
icon: "none"
});
break;
case 3:
common_vendor.index.share({
provider: "weixin",
scene: "WXSceneSession",
type: 0,
title: song.name,
summary: formatArtists(song.artists),
imageUrl: song.album.picUrl,
success: function(res2) {
console.log("分享成功:" + JSON.stringify(res2));
},
fail: function(err) {
console.log("分享失败:" + JSON.stringify(err));
}
});
break;
case 4:
common_vendor.index.showToast({ title: "歌手详情功能暂未开放", icon: "none" });
break;
case 5:
common_vendor.index.showToast({ title: "专辑详情功能暂未开放", icon: "none" });
break;
}
}
});
};
const playNewSong = async (song, index) => {
console.log("[Index] 播放新歌:", song.name, "索引:", index);
if (!song || !song.id) {
console.error("[Index] 歌曲对象无效:", song);
common_vendor.index.showToast({
title: "歌曲信息无效",
icon: "none"
});
return;
}
await utils_playSong.playSongCommon(song, {
addToDefaultList: true,
source: song.source || "mg"
});
};
const formatDuration = (duration) => {
if (!duration || duration <= 0)
return "00:00";
const minutes = Math.floor(duration / 60);
const seconds = Math.floor(duration % 60);
return `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
};
const handleBannerClick = (banner) => {
console.log("[Banner] 点击轮播图:", banner);
if (banner.source === "kw" && banner.targetId) {
const queryParams = [
`id=${banner.targetId}`,
`source=kw`,
`fromName=index`,
`name=${encodeURIComponent(banner.typeTitle || "")}`,
`picUrl=${encodeURIComponent(banner.imageUrl || "")}`,
`playCount=${banner.playCount || ""}`,
`link=${encodeURIComponent(banner.targetId)}`
].join("&");
navigateTo(`/pages/sharelist/index?${queryParams}`);
return;
}
switch (banner.targetType) {
case 1:
common_vendor.index.showToast({
title: "播放歌曲ID: " + banner.targetId,
icon: "none"
});
break;
case 10:
common_vendor.index.showToast({ title: "专辑详情功能暂未开放", icon: "none" });
break;
case 1e3:
common_vendor.index.showToast({ title: "歌单详情功能暂未开放", icon: "none" });
break;
case 1004:
common_vendor.index.showToast({ title: "MV功能暂未开放", icon: "none" });
break;
case 3e3:
if (banner.url) {
common_vendor.index.showToast({
title: "外链暂不支持",
icon: "none"
});
}
break;
default:
if (banner.targetId) {
const queryParams = [
`id=${banner.targetId}`,
`source=kw`,
`fromName=index`,
`name=${encodeURIComponent(banner.typeTitle || "")}`,
`picUrl=${encodeURIComponent(banner.imageUrl || "")}`,
`playCount=${banner.playCount || ""}`,
`link=${encodeURIComponent(banner.targetId)}`
].join("&");
navigateTo(`/pages/sharelist/index?${queryParams}`);
} else {
common_vendor.index.showToast({
title: "未知类型",
icon: "none"
});
}
}
};
const playBanner = async (banner) => {
var _a, _b;
console.log("[Banner] 播放按钮点击:", banner);
if (banner.source === "kw" && banner.targetId) {
common_vendor.index.showLoading({
title: "加载歌单中...",
mask: true
});
try {
const playlistDetail = await utils_api_songlistDirect.getListDetailDirect("kw", banner.targetId, 1);
console.log("[Banner] 获取到歌单详情,歌曲数量:", (_a = playlistDetail.list) == null ? void 0 : _a.length);
if (!playlistDetail.list || playlistDetail.list.length === 0) {
throw new Error("歌单为空");
}
store_modules_list.listStore.clearTempList();
const playlistId = `banner_${Date.now()}`;
const originalPlaylistId = banner.targetId ? String(banner.targetId) : playlistId;
store_modules_list.listStore.setTempList(
playlistId,
playlistDetail.list,
{
id: playlistId,
source: "kw",
name: banner.typeTitle || "歌单推荐",
link: originalPlaylistId
}
);
store_modules_list.listStore.setPlayerListId(store_modules_list.LIST_IDS.TEMP);
const firstSong = playlistDetail.list[0];
const quality = store_modules_system.systemStore.getState().audioQuality || "128k";
const songSource = firstSong.source || "kw";
let playUrl = await utils_musicUrlCache.getCachedMusicUrl(firstSong.id, quality, songSource);
let lyricData = null;
if (!playUrl) {
const requestData = utils_musicParams.buildMusicRequestParams({
...firstSong,
source: "kw"
}, quality);
if (!requestData) {
throw new Error("构建请求参数失败");
}
const musicUrlData = await utils_api_music.getMusicUrl(requestData);
playUrl = musicUrlData == null ? void 0 : musicUrlData.url;
if (playUrl) {
await utils_musicUrlCache.setCachedMusicUrl(firstSong.id, quality, playUrl, songSource);
lyricData = {
lyric: musicUrlData.lyric || "",
tlyric: musicUrlData.tlyric || "",
rlyric: musicUrlData.rlyric || "",
lxlyric: musicUrlData.lxlyric || ""
};
}
} else {
store_modules_player.playerStore.setUsingCachedUrl(true);
const cachedLyric = await utils_lyricCache.getCachedLyric(firstSong.id, "kw");
if (cachedLyric) {
lyricData = {
lyric: cachedLyric.lyric || "",
tlyric: cachedLyric.tlyric || "",
rlyric: cachedLyric.rlyric || "",
lxlyric: cachedLyric.lxlyric || ""
};
}
}
if (!playUrl) {
throw new Error("无法获取播放链接");
}
const musicInfo = {
...firstSong,
url: playUrl,
playUrl,
lyric: (lyricData == null ? void 0 : lyricData.lyric) || "",
tlyric: (lyricData == null ? void 0 : lyricData.tlyric) || "",
rlyric: (lyricData == null ? void 0 : lyricData.rlyric) || "",
lxlyric: (lyricData == null ? void 0 : lyricData.lxlyric) || ""
};
store_modules_list.listStore.setPlayMusicInfo(store_modules_list.LIST_IDS.TEMP, musicInfo, false);
store_modules_player.playerStore.playSong(musicInfo);
store_modules_player.playerStore.addToListHistory({
id: originalPlaylistId,
name: banner.typeTitle || "歌单推荐",
source: "kw",
coverUrl: banner.imageUrl || "",
trackCount: ((_b = playlistDetail.list) == null ? void 0 : _b.length) || 0,
link: originalPlaylistId
});
common_vendor.index.showToast({
title: `正在播放: ${banner.typeTitle}`,
icon: "none",
duration: 2e3
});
} catch (error) {
console.error("[Banner] 播放失败:", error);
common_vendor.index.showToast({
title: error.message || "播放失败",
icon: "none",
duration: 2e3
});
} finally {
common_vendor.index.hideLoading();
}
} else {
common_vendor.index.showToast({
title: "暂不支持该类型",
icon: "none"
});
}
};
const simplifySongs = (songs) => {
if (!songs || !Array.isArray(songs))
return [];
return songs.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,
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 getPlatformName = (source) => {
const platformMap = {
"kw": "酷我音乐",
"tx": "QQ音乐",
"kg": "酷狗音乐",
"wy": "网易云音乐",
"mg": "咪咕音乐"
};
return platformMap[source] || "未知平台";
};
const collectBanner = async (banner) => {
console.log("[Banner] 收藏按钮点击:", banner);
if (!banner.targetId) {
common_vendor.index.showToast({
title: "歌单信息不完整",
icon: "none"
});
return;
}
const sourceListId = banner.targetId;
const source = banner.source || "kw";
let importedList = common_vendor.index.getStorageSync("imported_playlists") || [];
const existsIndex = importedList.findIndex((p) => p.sourceListId === sourceListId);
if (existsIndex !== -1) {
common_vendor.index.showToast({
title: "歌单已收藏",
icon: "none"
});
return;
}
common_vendor.index.showModal({
title: "收藏歌单",
content: `是否将「${banner.typeTitle}」收藏到我的歌单?`,
confirmText: "收藏",
cancelText: "取消",
success: async (res) => {
var _a, _b, _c;
if (res.confirm) {
common_vendor.index.showLoading({ title: "获取歌单中..." });
try {
console.log("[Banner] 开始获取歌单详情, source:", source, "id:", sourceListId);
let result;
if (source === "kw" && sourceListId.includes("digest-")) {
result = await utils_api_songlistDirect.getListDetailDirect("kw", sourceListId, 1);
} else if (source === "mg") {
result = await utils_api_songlistDirect.getListDetailDirect("mg", sourceListId, 1);
} else {
result = await utils_api_songlist.getListDetail(source, sourceListId, 1);
}
console.log("[Banner] 获取歌单详情结果:", result);
if (!result || !result.list || result.list.length === 0) {
common_vendor.index.showToast({
title: "获取歌单失败",
icon: "none"
});
common_vendor.index.hideLoading();
return;
}
const simplifiedSongs = simplifySongs(result.list);
console.log("[Banner] 精简后歌曲数量:", simplifiedSongs.length, "首");
const importedPlaylist = {
id: sourceListId,
name: banner.typeTitle || result.name || "未知歌单",
coverImgUrl: banner.imageUrl || ((_a = result.info) == null ? void 0 : _a.coverImgUrl),
trackCount: result.list.length,
source,
sourceListId,
link: sourceListId,
platform: getPlatformName(source),
songs: simplifiedSongs,
importedAt: Date.now(),
playCount: banner.playCount || ((_b = result.info) == null ? void 0 : _b.playCount) || 0,
description: banner.subtitle || ((_c = result.info) == null ? void 0 : _c.description) || "",
isFromImport: false,
canAutoUpdate: false,
autoUpdate: false
};
importedList.unshift(importedPlaylist);
common_vendor.index.setStorageSync("imported_playlists", importedList);
common_vendor.index.$emit("imported-playlists-changed");