-
Notifications
You must be signed in to change notification settings - Fork 2
/
data.js
190 lines (190 loc) · 6.9 KB
/
data.js
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
var data = {
//
data_song: {},
// 转换后端数据格式
_transform_data: function(obj){
if('vocal' in obj) obj.vocal = obj.vocal.split(',');
if('CreateTime' in obj) obj.CreateTime = obj.CreateTime.substring(0, 10);
obj.CDN = obj.CDN.split(':');
if(obj.CDN.length == 1) obj.CDN.push(obj.CDN[0], obj.CDN[0]);
// 11:12:13 11图片库 12歌曲库 13歌词库
return obj;
},
get_cdn_url: function(id){
return app_config.CDN[id];
},
// 获取mp3地址
get_song_link: function(song_id) {
let song_data = data.get_song(song_id);
return this.get_cdn_url(song_data.CDN[1]) + song_data.music;
},
get_lyric_link: function(song_id) {
let song_data = data.get_song(song_id);
return this.get_cdn_url(song_data.CDN[2]) + song_data.Lyric;
},
get_img_link: function(img_name, song_id) {
let song_data = data.get_song(song_id);
return this.get_cdn_url(song_data.CDN[0]) + song_data.img;
},
get_album_img_link: function(img) {
return app_config.img_path + img;
},
//songs
get_song: function(song_id) {
if(song_id in data.data_song){
// 如果已经请求过则不再请求
return data.data_song[song_id];
}
let res;
$.ajax({
type: "POST",
async: false, // 这里是同步请求,虽然这里最好应该使用异步+回调解决
contentType: 'application/json',
url: "https://vtb.aqua.chat/Music_Manage/music_data/GetTheData",
data: JSON.stringify({ "id": String(song_id)}),
success: function (result) {
let res_data = result['Data'];
console.log('get_song', song_id);
if(res_data == null){
console.error('不存在歌曲', song_id);
return null;
}
res = data.data_song[res_data.Id] = data._transform_data(res_data);
},
error: function() {
console.error('get_song', song_id, 'erro');
info_app.init('获取歌曲失败');
}})
return res;
},
// note: pageIndex 从1开始
get_songs: function(page, per_page_num) {
var res = [];
$.ajax({
type: "POST",
async: false,
contentType: 'application/json',
url: "https://vtb.aqua.chat/Music_Manage/music_data/GetDataList",
data: JSON.stringify({ "pageIndex": page, "pageRows": per_page_num, "SortField": "CreateTime", "SortType": "desc"}),
success: function (result) {
let res_data = result['Data'];
for(let iter in res_data){
let song_data = data._transform_data(res_data[iter]);
if(song_data.Deleted) continue;
data.data_song[res_data[iter].Id] = song_data;
res.push(song_data);
}
app_data.total_song_num = Number(result['Total']);
$('#footer-song-cnt').text(result['Total']);
},
error: function() {
info_app.init('获取歌曲失败');
}})
return res;
},
// 通过歌手获取歌曲
get_song_from_vocal: function(vocal) {
let res = [];
$.ajax({
type: "POST",
async: false,
contentType: 'application/json',
url: "https://vtb.aqua.chat/Music_Manage/music_data/GetDataList",
data: JSON.stringify({ "search": {"condition": "vocal", "keyword": vocal}, "pageIndex": 1, "pageRows": 9999, "SortField": "CreateTime", "SortType": "desc"}),
success: function (result) {
let res_data = result['Data'];
for(let iter in res_data){
let song_data = data._transform_data(res_data[iter]);
if(song_data.Deleted) continue;
data.data_song[res_data[iter].Id] = song_data;
res.push(song_data);
}
},
error: function() {
info_app.init('获取歌曲失败');
}})
return res;
},
// 搜索歌曲
search_song: function(text) {
let songs = [];
$.ajax({
type: "POST",
async: false,
contentType: 'application/json',
url: "https://vtb.aqua.chat/Music_Manage/music_data/GetDataList",
data: JSON.stringify({ "search": {"condition": "name", "keyword": text}, "pageIndex": 1, "pageRows": 9999, "SortField": "CreateTime", "SortType": "desc"}),
success: function (result) {
let res_data = result['Data'];
for(let iter in res_data){
let song_data = data._transform_data(res_data[iter]);
if(song_data.Deleted) continue;
data.data_song[res_data[iter].Id] = song_data;
songs.push(song_data);
}
},
error: function() {
info_app.init('获取歌曲失败');
}})
return songs;
},
//figures
get_figure: function(figure_name) {
return data_data_figures[data.get_figure_index(figure_name)];
},
get_figures: function(page, per_page_num) {
return data_data_figures.slice(per_page_num * (page - 1), per_page_num * page);
},
get_figure_index: function(name) {
for (let item in data_data_figures)
if (data_data_figures[item]['name'] == name) return item;
return -1;
},
search_figure: function(text) {
let figures = [];
for (let i in data_data_figures)
if (data_data_figures[i].name.search(text) != -1 || data_data_figures[i].jpname.search(text) != -1)
figures.push(data_data_figures[i]);
return figures;
},
//albums
get_album: function(album_name) {
return data_data_albums[data.get_album_index(album_name)];
},
get_albums: function(page, per_page_num) {
return data_data_albums.slice(per_page_num * (page - 1), per_page_num * page);
},
get_album_index: function(name) {
for (let item in data_data_figures)
if (data_data_albums[item].name == name) return item;
return -1;
},
get_album_songs_id: function(name) {
return data.get_album(name).songs;
},
// 网页渲染前加载必要数据
load_data: function() {
// load CDN
$.ajax({
type: "POST",
async: false,
contentType: 'application/json',
url: "https://vtb.aqua.chat/CDN_Manage/storage_data/GetDataList",
data: JSON.stringify({ "PageIndex": 1, "PageRows": 9999}),
success: function (result) {
let res_data = result['Data'];
app_config.CDN = {};
for(let i in res_data)
app_config.CDN[res_data[i].name] = res_data[i].url;
},
error: function() {
info_app.init('获取CDN失败');
}})
// 新版上线后最好清除以前的playlist数据
if(Cookies.get('vtb-music-version-20050301') == null){
Cookies.set('vtb-music-version-20050301', true);
app_debug.clear_playlist();
}
app.init();
},
}