forked from flwfdd/MergeMusic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
870 lines (800 loc) · 24.9 KB
/
index.html
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
<!DOCTYPE HTML>
<html>
<head>
<!--2020-云南师大附中学联网络部 版权所有-->
<!--Code by. 范滇东-->
<!--想小苏~-->
<title>MergeMusic</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Material+Icons" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/font/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-clipboard.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-router.min.js"></script>
<!--引入思源字体-->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto+Serif+SC:100,300,400,500,700,900">
<style>
#app {
font-family: Noto Serif SC;
font-style: normal;
font-weight: 500;
}
#title {
animation: change 10s linear 0s infinite;
text-decoration: none;
outline: none;
border: none;
text-align: center;
font-weight: 500;
font-size: 2.5em;
}
@keyframes change {
0% {
color: #4cf;
}
50% {
color: #fac;
}
100% {
color: #4cf;
}
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
font-family: Noto Serif SC;
font-style: normal;
font-weight: 500;
}
#bgimg {
position: fixed;
height: 100%;
width: 100%;
background-size: cover;
background-position: center center;
opacity: 0.7;
z-index: 0;
filter: blur(5px);
}
#sand {
font-size: small;
color: #aaa;
text-align: center;
}
.op {
background-color: rgba(255, 255, 255, 0.75) !important;
}
.op0,
.v-tabs-bar,
.v-tabs-items {
background-color: rgba(255, 255, 255, 0) !important;
}
.translist-move {
transition: all 0.3s;
}
.translist-enter-active,
.translist-leave-active {
transition: all 0.3s;
}
.translist-enter,
.translist-leave-to
/* .list-leave-active for below version 2.1.8 */
{
opacity: 0;
transform: translateY(30px);
}
::selection {
color: #fff;
background: #00bcd4;
}
</style>
</head>
<body>
<div id="bgimg"></div>
<div id="app">
<v-app class="op0">
<v-container fluid>
<v-row justify="center">
<v-col class="pa-0" xl=6 lg=7 md=8 sm=10 xs=12>
<v-card class="op" justify="center" outlined>
<!-- <p class="ma-0 mb-n4" id="sand">云南师大附中学联网络部 版权所有</p> -->
<v-container class="mb-n3">
<v-row justify="center">
<v-chip color="pink lighten-3" small outlined
href="https://space.bilibili.com/27482524" target="_blank">
<v-icon small>mdi-television-classic</v-icon>bilibili@范滇东
</v-chip>
<v-chip color="cyan lighten-3" small outlined
href="https://github.com/flwfdd/MergeMusic" target="_blank">
<v-icon small>mdi-github</v-icon>Github
</v-chip>
</v-row>
</v-container>
<h1 id="title">MergeMusic</h1>
<p class="blue-grey--text text--darken-2 mx-2 mb-0" style="text-align: center;">{{hitokoto}}
</p>
<v-row class="ma-2" justify="center">
<v-col class="pa-0" cols=12>
<v-text-field outlined dense hide-details color="cyan" label="搜索" v-model="name"
append-icon="search" @click:append="off=0;Search();"
@keyup.13="off=0;Search();">
</v-text-field>
</v-col>
<v-col class="px-0 pr-1" cols=6>
<v-select outlined dense hide-details color="cyan" item-color="cyan" label="平台"
v-model="platform" :items="platforms"></v-select>
</v-col>
<v-col class="px-0 pl-1" cols=6>
<v-select outlined dense hide-details color="cyan" item-color="cyan" label="类型"
v-model="type" :items="types">
</v-select>
</v-col>
<v-col class="pa-0 pr-1 pb-2" cols=4>
<v-btn block outlined @click="looptype=(looptype+1)%3">{{looptypes[looptype].text}}
</v-btn>
</v-col>
<v-col class="pa-0 px-1 pb-2" cols=4>
<v-btn block outlined @click="PlayNext()">下一首</v-btn>
</v-col>
<v-col class="pa-0 pl-1 pb-2" cols=4>
<v-btn block outlined :disabled="!nowmusic.mid"
@click="dialog_data=nowmusic;dialog_open=true;">详情</v-btn>
</v-col>
<audio style="width:100%;outline: medium;" ref="player" id="player"
:src="nowmusic.src?nowmusic.src:''" controls="controls" autoplay="autoplay"></audio>
<v-col cols=12 class="pa-0">
<p class="blue-grey--text text--darken-2 ma-1"
style="text-align: center;font-size:1.5em">{{nowmusic.name}}</p>
</v-col>
<v-col cols=12 class="pa-0">
<p class="blue-grey--text text--darken-2 ma-1 mb-0"
style="text-align: center;font-size:1.25em">{{nowlrc}}</p>
</v-col>
<v-col cols=12 class="pa-0">
<p class="blue-grey--text text--darken-2 mx-1 my-0"
style="text-align: center;font-size:1em">{{nowtlrc}}</p>
</v-col>
</v-row>
</v-card>
<v-card class="op">
<v-tabs grow v-model="tab" color="cyan">
<v-tab v-for="i in tabs" :key="i.tab">{{i.text}}</v-tab>
</v-tabs>
<v-tabs-items v-model="tab">
<v-tab-item key="search">
<v-container>
<v-row>
<v-col class="pa-0 px-1" cols=6>
<v-btn outlined block @click="AddAll('replace')">播放全部</v-btn>
</v-col>
<v-col class="pa-0 px-1" cols=6>
<v-btn outlined block @click="AddAll('back')">添加全部</v-btn>
</v-col>
</v-row>
</v-container>
<v-expand-transition>
<v-list class="op0" two-line>
<v-list-item-group>
<music-list v-for="(item,index) in search_list" :music="item"
:key="index" :index="index"></music-list>
</v-list-item-group>
</v-list>
</v-expand-transition>
<v-btn block color="cyan lighten-4" @click="Search()" :loading="searching"
:disabled="end">
{{end?'木有了...':'加载更多'}}
</v-btn>
</v-tab-item>
<v-tab-item key="list">
<v-container>
<v-row>
<v-col class="pa-0 px-1" cols=6>
<v-btn outlined block @click="ClearPlayList()">清空列表</v-btn>
</v-col>
<v-col class="pa-0 px-1" cols=6>
<v-btn outlined block @click="ChangeSaveList()">
保存列表:{{save_list?"开":"关"}}
</v-btn>
</v-col>
</v-row>
</v-container>
<v-list class="op0" two-line>
<v-list-item-group>
<transition-group name="translist">
<play-music-list v-for="(item,index) in play_list" :music="item"
:key="item.mid" :index="index"></play-music-list>
</transition-group>
</v-list-item-group>
</v-list>
</v-tab-item>
</v-tabs-items>
</v-card>
</v-col>
</v-row>
<v-dialog v-model="dialog_open">
<v-card v-if="dialog_open">
<v-card-title>{{dialog_data.name}} - {{dialog_data.artist.join(" | ")}}</v-card-title>
<v-container>
<v-row justify="center">
<v-col v-if="dialog_data.type=='music' || dialog_data.type=='p'" cols=11>
<p class="ma-0">
mid:{{dialog_data.mid}}
</p>
</v-col>
<v-col cols=11>
<p class="ma-0">专辑:
<v-chip small outlined v-if="dialog_data.album.name" :color="dialog_data.color"
@click="StartSearch(dialog_data.album.name)">
{{dialog_data.album.name}}</v-chip>
</p>
</v-col>
<v-col cols=11>
<p class="ma-0">作者:
<v-chip small outlined v-for="i in dialog_data.artist" :key="i"
:color="dialog_data.color" @click="StartSearch(i)">{{i}}</v-chip>
</p>
</v-col>
<v-col cols=11>
<v-btn rounded outlined class="my-1" :color="dialog_data.color"
v-if="['music','p','list','fav','up'].indexOf(dialog_data.type)!=-1"
@click="AddMusic(dialog_data,'replace')">
<v-icon left>play_arrow</v-icon>
替换播放
</v-btn>
<v-btn rounded outlined class="my-1" :color="dialog_data.color"
v-if="['music','p','list','fav','up'].indexOf(dialog_data.type)!=-1"
@click="AddMusic(dialog_data,'back')">
<v-icon left>add</v-icon>
添加播放
</v-btn>
<v-btn rounded outlined class="my-1" :color="dialog_data.color"
v-if="dialog_data.type=='music'" @click="Download(dialog_data.mid,'music')">
<v-icon left>file_download</v-icon>
下载歌曲
</v-btn>
<v-btn rounded outlined class="my-1" :color="dialog_data.color"
v-if="dialog_data.type=='music'" @click="Download(dialog_data.mid,'lrc')">
<v-icon left>receipt</v-icon>
复制歌词
</v-btn>
<v-btn rounded outlined class="my-1" :color="dialog_data.color"
v-if="dialog_data.type=='music'" @click="Download(dialog_data.mid,'img')">
<v-icon left>image</v-icon>
封面图片
</v-btn>
<v-btn rounded outlined class="my-1" :color="dialog_data.color"
v-if="dialog_data.type=='music'" @click="Download(dialog_data.mid,'share')">
<v-icon left>share</v-icon>
分享链接
</v-btn>
</v-col>
</v-row>
</v-container>
</v-card>
</v-dialog>
<v-dialog v-model="clip_dialog">
<v-card>
<v-card-title>点击复制到剪贴板</v-card-title>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="green darken-1" text v-clipboard:copy="clip_tmp"
v-clipboard:success="ClipSuccess" v-clipboard:error="">复制</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="save_list_dialog" persistent>
<v-card>
<v-card-title>请选择要保留的列表
<v-btn block color="cyan" text @click="SaveListDialogCallback(0)">使用保存的列表覆盖当前列表</v-btn>
<v-btn block color="cyan" text @click="SaveListDialogCallback(1)">使用当前列表覆盖保存的列表</v-btn>
</v-card-title>
</v-card>
</v-dialog>
<v-snackbar v-model="snackbar">
{{snackbar_msg}}
<template v-slot:action="{attrs}">
<v-btn color="pink" text v-bind="attrs" @click="snackbar=false">
Close
</v-btn>
</template>
</v-snackbar>
</v-container>
</v-app>
</div>
<script>
VueClipboard.config.autoSetContainer = true
const routes = []
const router = new VueRouter({
routes // (缩写) 相当于 routes: routes
})
//搜索列表组件
Vue.component("music-list", {
props: ["music", "index"],
data() {
return {
"list": []
};
},
template: `
<div>
<v-list-item @click="music.type=='music'?_this.PlayMusic(music.mid):GetList()" :color="music.color">
<v-list-item-avatar>
<v-chip outlined :color="music.color">{{index+1}}</v-chip>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{music.name}}</v-list-item-title>
<v-list-item-subtitle>
<template v-if="music.album.name">{{music.album.name}} - </template>
{{music.artist.join(" | ")}}
</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon :color="music.color" @click.stop="OpenDialog()">
<v-icon :color="music.color">more_vert</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
<v-expand-transition>
<v-list class="op0" v-if="list.length" two-line>
<v-divider></v-divider>
<v-list-item-group>
<music-list v-for="(item,index) in list" :music="item" :key="index" :index="index"></music-list>
</v-list-item-group>
<v-divider></v-divider>
</v-list>
</v-expand-transition>
</div>
`,
methods: {
GetList() {
if (this.list.length) {
this.list = [];
return;
}
axios.get(_this.apiurl + "/music/", {
params: {
mid: this.music.mid,
type: this.music.type,
}
})
.then((r) => {
this.list = r.data;
});
},
OpenDialog() {
_this.dialog_data = this.music;
_this.dialog_open = true;
}
},
watch: {
list() {
//for(i in this.list)this.list[i].color="#00A1D6";
for (i in this.list) this.list[i].color = _this.colors[this.music.mid[0]];
},
music() {
this.list = [];
}
}
});
//播放列表组件
Vue.component("play-music-list", {
props: ["music", "index"],
template: `
<div>
<v-list-item @click="_this.AddMusic(music,'front')" :color="music.color">
<v-list-item-avatar>
<v-chip outlined :color="music.color">{{index+1}}</v-chip>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{music.name}}</v-list-item-title>
<v-list-item-subtitle>
<v-btn icon small :color="music.color" @click.stop="GoUp()">
<v-icon>arrow_upward</v-icon>
</v-btn>
<v-btn icon small :color="music.color" @click.stop="GoDown()">
<v-icon>arrow_downward</v-icon>
</v-btn>
<v-btn icon small :color="music.color" @click.stop="Delete()">
<v-icon>delete</v-icon>
</v-btn>
<template v-if="music.album.name">{{music.album.name}} - </template>
{{music.artist.join(" | ")}}
</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon :color="music.color" @click.stop="OpenDialog()">
<v-icon :color="music.color">more_vert</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
</div>
`,
methods: {
GoUp() {
key = this.index;
pl = _this.play_list.concat();
if (key == 0) return;
key2 = (key - 1 + pl.length) % pl.length;
Vue.set(_this.play_list, key, pl[key2]);
Vue.set(_this.play_list, key2, pl[key]);
},
GoDown() {
key = this.index;
pl = _this.play_list.concat();
if (key == pl.length - 1) return;
key2 = (key + 1 + pl.length) % pl.length;
Vue.set(_this.play_list, key, pl[key2]);
Vue.set(_this.play_list, key2, pl[key]);
},
Delete() {
_this.play_list.splice(this.index, 1);
},
OpenDialog() {
_this.dialog_data = this.music;
_this.dialog_open = true;
}
}
});
var vm = new Vue({ //主应用
vuetify: new Vuetify(),
el: "#app",
router,
data: {
// apiurl: "http://127.0.0.1:9000",
apiurl:"https://service-6xbkkinf-1255944436.cd.apigw.tencentcs.com/release",
name: "",
platform: "C",
type: "music",
off: 0,
lim: 20,
end: false,
searching: false,
nowmusic: {},
nowlrc: "",
nowtlrc: "如提示错误可能为服务器压力过大或为VIP音乐,本站当前不会支持VIP音乐,请尊重版权♪(´▽`)",
looptype: 0,
hitokoto: "",
show_play_list: false,
dialog_open: false,
dialog_data: {},
clip_tmp: "",
clip_dialog: false,
snackbar: false,
snackbar_msg: "",
tab: 0,
tabs: [
{ text: "搜索", tab: "search" },
{ text: "列表", tab: "list" },
],
platforms: [
{ "text": "网易云", "value": "C" },
{ "text": "QQ", "value": "Q" },
{ "text": "bilibili", "value": "B" },
// { "text": "SakuraCloud", "value": "S" }
],
types: [
{ "text": "歌曲", "value": "music" },
{ "text": "歌单", "value": "list" },
{ "text": "用户|UP主", "value": "user" },
{ "text": "歌词", "value": "lrc" }
],
looptypes: [
{ "text": "顺序", "value": "0" },
{ "text": "单曲", "value": "1" },
{ "text": "随机", "value": "2" }
],
colors: {
"C": "#C20C0C",
"Q": "#68D9A3",
"B": "#FCA6BF",
"S": "#F9D2E0"
},
search_list: [],
play_list: [],
auto_save: true,
save_list: true,
save_list_dialog: false,
},
methods: {
Search() { //搜索
this.show_play_list = false;
this.tab = 0;
this.dialog_open = false;
//if(this.searching)return;
//console.log(this.platform+this.type+this.name);
this.searching = true;
color = this.colors[this.platform];
axios.get(this.apiurl + "/search/", {
params: {
platform: this.platform,
keyword: encodeURIComponent(this.name),
type: this.type,
offset: this.off,
limit: this.lim
}
}).then((r) => {
r = r.data;
if (this.off == 0) this.end = false, this.search_list = []; //搜索归零
if (r.length == 0) this.end = true;
if (!this.end) {
for (i in r) r[i].color = color;
this.search_list = this.search_list.concat(r);
if (r.length < this.lim) this.end = true;
}
this.off++;
this.searching = false;
});
},
PlayMusic(mid) { //播放音乐
axios.get(this.apiurl + "/music/", {
params: {
mid: mid,
type: "music",
}
}).then((response) => {
let mmusic=JSON.parse(JSON.stringify(response.data));
this.nowmusic = response.data
document.querySelector("#bgimg").style.backgroundImage = "url(" + this.nowmusic.img + ")";
this.nowlrc = this.nowtlrc = ""
this.nowmusic.lrcs = this.DecodeLrc(response.data.lrc);
if (response.data.tlrc) this.nowmusic.tlrcs = this.DecodeLrc(response.data.tlrc);
if (this.nowmusic.src == "") {
this.nowmusic.name = "出错了Orz将移除此歌";
setTimeout(this.Delete, 3000, this.nowmusic.mid);
}
delete mmusic.src;
delete mmusic.img;
delete mmusic.lrc;
delete mmusic.tlrc;
this.AddList([mmusic], "front");
});
},
DecodeLrc(s) { //歌词解码
l = s.split("\n");
ls = [];
for (i = 0; i < l.length; i++) {
if (l[i] == "") continue;
time_str = l[i].slice(1, l[i].search("]"));
t = time_str.split(":")[0] * 60 + time_str.split(":")[1] * 1.0;
ls.push([t, l[i].slice(l[i].search("]") + 1)]);
}
return ls;
},
Delete(mid) { //从播放列表删除歌曲
for (i in this.play_list) {
if (this.play_list[i].mid == mid) {
this.play_list.splice(i, 1);
break;
}
}
},
UpLrc() { //歌词更新
if (!this.nowmusic.lrcs) return;
t = this.$refs["player"].currentTime;
for (i = this.nowmusic.lrcs.length - 1; i >= 0; i--) {
if (t >= this.nowmusic.lrcs[i][0]) {
this.nowlrc = this.nowmusic.lrcs[i][1];
break;
}
}
if (!this.nowmusic.tlrcs) return;
t = this.$refs["player"].currentTime;
for (i = this.nowmusic.tlrcs.length - 1; i >= 0; i--) {
if (t >= this.nowmusic.tlrcs[i][0]) {
this.nowtlrc = this.nowmusic.tlrcs[i][1];
break;
}
}
},
PlayNext() { //下一首
au = this.$refs['player'];
if (this.looptype == 0) {
if (this.play_list.length) {
this.play_list.push(this.play_list.shift());
if (this.play_list.length == 1) au.currentTime = 0, au.play();
}
else {
this.nowmusic.src = "";
}
}
if (this.looptype == 2) {
if (this.play_list.length) {
ind = Math.floor(Math.random() * this.play_list.length)
if (ind == 0) au.currentTime = 0, au.play();
else this.play_list.unshift(this.play_list.splice(ind, 1)[0]);
}
else {
this.nowmusic.src = "";
}
}
if (this.looptype == 1) {
au.currentTime = 0;
au.play();
}
},
StartSearch(s) { //新建搜索
this.name = s;
this.off = 0;
this.type = "music";
this.Search();
},
Download(mid, type) { //下载
if (type == 'share') {
this.clip_tmp = window.location.origin + window.location.pathname + "#/?mid=" + mid;
this.clip_dialog = true;
return;
}
axios.get(this.apiurl + "/music/", {
params: {
mid: mid,
type: "music",
}
})
.then((r) => {
if (type == "music") {
window.open(r.data.src, "_blank");
}
if (type == "lrc") {
this.clip_tmp = r.data.lrc + "\n\n" + r.data.tlrc;
this.clip_dialog = true;
}
if (type == "img") {
window.open(r.data.img, "_blank");
}
})
},
AddMusic(music, type) { //添加歌曲或歌单到播放列表
if (music.type == "music") this.AddList([music], type);
else { //如果是歌单什么的就要先获取歌曲列表(解包)
axios.get(this.apiurl + "/music/", {
params: {
mid: music.mid,
type: music.type,
}
}).then((r) => {
this.AddList(r.data, type);
}).catch((e) => { }).then(() => { this.Delete(music.mid); });
}
},
AddList(list, type) { //添加数个音乐到播放列表
if (type == "replace") { //替换
this.play_list = list.concat();
this.tab = 1;
}
else {
music_list = [];
if (type == "front") { //添加到前部 需要去重
for (i in list) music_list.push(list[i].mid);
for (i in this.play_list) if (music_list.indexOf(this.play_list[i].mid) != -1) this.play_list.splice(i, 1);
this.play_list = list.concat(this.play_list);
}
else { //添加到尾部
for (i in this.play_list) music_list.push(this.play_list[i].mid);
for (i in list) if (music_list.indexOf(list[i].mid) != -1) list.splice(i, 1);
this.play_list = this.play_list.concat(list);
this.Msg("已添加到列表(・∀・)");
}
}
},
AddAll(type) { //把搜索列表中的添加到播放列表
this.AddList(this.search_list.concat(), type);
},
UpHitokoto() { //更新一言
axios.get("https://v1.hitokoto.cn/")
.then((res) => {
this.hitokoto = res.data.hitokoto + " ——" + res.data.from;
})
},
ClipSuccess(e) { //剪贴板回调
this.clip_dialog = false;
this.Msg("复制成功");
},
ClearPlayList() { //清空播放列表
this.play_list = [];
this.nowmusic = {};
document.querySelector("#bgimg").style.backgroundImage = "url()";
this.nowlrc = this.nowtlrc = "";
},
ChangeSaveList() { //更改同步列表状态
this.save_list = !this.save_list;
if (this.save_list == true && localStorage.getItem("play_list")) {
this.save_list_dialog = true;
}
},
SaveListDialogCallback(method) {
if (method == 0) {
this.play_list = JSON.parse(localStorage.getItem("play_list"));
}
if (method == 1) {
localStorage.setItem("play_list", JSON.stringify(this.play_list));
}
this.save_list_dialog = false;
},
Msg(msg) { //提示框
this.snackbar_msg = msg;
this.snackbar = true;
}
},
watch: {
play_list() {
//同步
if (this.save_list) {
localStorage.setItem("play_list", JSON.stringify(this.play_list));
}
//添加颜色
for (i in this.play_list) {
this.play_list[i].color = this.colors[this.play_list[i].mid.substr(0, 1)];
}
//播放列表第一个
if (this.play_list.length) {
let mmusic = this.play_list[0];
if (this.nowmusic.mid != mmusic.mid) {
if (mmusic.type == "music") this.PlayMusic(mmusic.mid);
else {
this.AddMusic(mmusic, 'front');
}
}
}
else {
this.nowmusic = {};
}
},
save_list(){
localStorage.setItem("save_list",JSON.parse(this.save_list));
}
},
created() {
_this = this;
axios.interceptors.response.use(response => {
// 2xx 范围内的状态码都会触发该函数。
// 对响应数据做点什么
return response;
}, error => {
// 超出 2xx 范围的状态码都会触发该函数。
// 对响应错误做点什么
this.Msg("出错啦QwQ");
return Promise.reject(error);
});
setInterval(this.UpLrc, 100);
this.UpHitokoto();
setInterval(this.UpHitokoto, 10000);
setTimeout(() => {
this.$refs["player"].addEventListener('ended', () => {
this.PlayNext();
});
}, 1000)
if(localStorage.getItem("save_list"))
{
this.save_list=JSON.parse(localStorage.getItem("save_list"));
}
if (this.save_list && localStorage.getItem("play_list")) {
this.play_list = JSON.parse(localStorage.getItem("play_list"));
this.tab = 1;
}
if (this.$route.query.mid) {
this.show_play_list = true;
this.tab = 1;
this.PlayMusic(this.$route.query.mid);
}
this.Msg("欢迎来到Ours-MergeMusic~");
}
});
</script>
<script>
var _hmt = _hmt || [];
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?f2df3b6029c8fc35e1d4f5986f53b914";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</body>
</html>