-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path鼠绘漫画.js
288 lines (255 loc) · 6.99 KB
/
鼠绘漫画.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
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
// 主界面
$ui.render({
views: [{
type: "list",
props: {
rowHeight: 80,
id: "index",
template: [{
type: "image",
props: {
id: "image"
},
layout: (make, view) => {
make.left.top.bottom.inset(5);
make.width.equalTo(view.height);
}
},
{
type: "label",
props: {
id: "label",
font: $font("bold", 17),
lines: 0
},
layout: make => {
make.left.equalTo($("image").right).offset(10);
make.top.bottom.equalTo(0);
make.right.inset(10);
}
}
],
actions: [{
title: "Share",
handler: (sender, indexPath) => {
var data = sender.object(indexPath);
$share.sheet([data.url, data.label.text]);
}
}]
},
layout: $layout.fill,
events: {
didSelect: (sender, indexPath, data) => {
episodePage(data.animeID);
},
pulled: getAllComics
}
}]
});
// ====================================================================
// 主界面相关
// ====================================================================
// 获取漫画清单
function getAllComics(page = 1, allpage = -1, alldata = []) {
if (page == allpage + 1) {
$console.info(alldata);
renderIndex(alldata);
return;
} else {
$http.get({
url: `https://prod-api.ishuhui.com/ver/d1472853/comics/list?pageSize=24&toView=true&.json&page=${page}`,
handler: function (resp) {
// $console.info(page);
// $console.info(resp.data.data.data);
page++;
allpage = resp.data.data.totalPages;
for (var i = 0; i < resp.data.data.data.length; i++) {
alldata.push(resp.data.data.data[i]);
}
renderIndex(alldata);
return getAllComics(page = page, allpage = allpage, alldata = alldata);
}
});
}
}
// 渲染主界面
function renderIndex(items) {
$("index").data = items.map(item => {
return {
label: {
// text: $text.HTMLUnescape(item.animeName)
text: $text.HTMLUnescape(item.title)
},
image: {
src: item.thumb
},
animeID: item.animeID
}
});
$("index").endRefreshing();
}
// 补齐位数--->又特么递归,迟早会死翘翘!!!!
// 还没谁能把漫画更新到99999话,五位数足够了
function toSameLength(indexKey) {
newIndexKey = indexKey;
if (indexKey.length == 5) {
return newIndexKey;
} else {
newIndexKey = "0" + newIndexKey;
return toSameLength(newIndexKey);
}
}
// ====================================================================
// 章节页
// ====================================================================
// 显示所有章节
function showAllEpisode(id) {
$http.get({
url: `https://prod-api.ishuhui.com/ver/82383992/anime/detail?id=${id}&type=comics&.json`,
handler: function (resp) {
var items = resp.data.data.comicsIndexes["1"].nums; // 包含所有EpisodeGroup的Obeject
$console.info(items);
// 对分组进行升序排列
temp = []; // 暂存所有的章节
EpisodeID = 1 // 序号索引,因为自带的ID属性有问题
rawEpisodeGroup = Object.keys(items).sort(); // EpisodeGroup的Key值
// 重新建立键值对对应关系
orderEpisodeGroup = {}; // 暂存修改了Key的EpisodeGroup
indexEpisodeGroup = 0; // EpisodeGroup的key值
for (var i in rawEpisodeGroup) {
ii = toSameLength(rawEpisodeGroup[i].split("-")[0])
orderEpisodeGroup[ii] = rawEpisodeGroup[i];
}
orderGroupIndex = Object.keys(orderEpisodeGroup).sort()
for (var episodeGroup in orderGroupIndex) {
group = orderEpisodeGroup[orderGroupIndex[episodeGroup]];
groupDetail = items[group];
sortEpisodeIndex = Object.keys(groupDetail).sort()
newsortEpisode = {}
for (var i in sortEpisodeIndex) {
ii = toSameLength(sortEpisodeIndex[i])
newsortEpisode[ii] = sortEpisodeIndex[i];
}
sortEpisodeIndex = Object.keys(newsortEpisode).sort()
for (var episodeIndex in sortEpisodeIndex) {
episodeIndex = newsortEpisode[sortEpisodeIndex[episodeIndex]];
items[group][episodeIndex][0]["index"] = EpisodeID;
temp.push(items[group][episodeIndex]);
EpisodeID += 1;
}
}
// $console.info(Object.keys(tem).length, "as");
// $console.info(tem);
renderEpisode(temp);
temp = [];
}
});
}
// 章节数据渲染
function renderEpisode(items) {
var episode = $("episodeList");
episode.data = items.map(item => {
return {
A: {
text: $text.HTMLUnescape(`第${item[0].index}话\t\t${item[0].title}`)
},
detailID: item[0].id,
detailName: item[0].title
}
});
episode.endRefreshing();
}
// 章节页
function episodePage(id) {
$console.info(id);
showAllEpisode(id);
$ui.push({
props: {
title: "asd",
},
views: [{
type: "list",
props: {
id: "episodeList",
rowHeight: 25,
template: [{
type: "label",
props: {
id: "A",
font: $font("bold", 17),
lines: 0
},
layout: (make, view) => {
// make.left.top.bottom.right.inset(5);
make.width.equalTo(view.width);
}
}]
},
layout: $layout.fill,
events: {
didSelect: (sender, indexPath, data) => {
seeAllpic(data.detailID, data.detailName);
}
}
}]
});
}
// ==========================================================
// 漫画显示页
// ==========================================================
// 获取某个漫画下的所有图片地址
function getAllPic(detailID) {
// $console.info(detailID);
$http.get({
url: `https://prod-api.ishuhui.com/comics/detail?id=${detailID}`,
handler: function (resp) {
var allimg = resp.data.data.contentImg;
renderPicData(allimg);
$console.info(allimg)
}
});
}
// 渲染数据
function renderPicData(items) {
// items = items[1, items.length-2]
$("a").data = items.map(item => {
return {
image: {
src: item.url
}
}
})
$console.info($("a"));
}
// getAllPic()
// 漫画显示页
function seeAllpic(detailID, detailName) {
getAllPic(detailID)
$ui.push({
props: {
title: detailName
},
views: [{
type: "list",
props: {
id: "a",
rowHeight: $device.info.screen.height,
template: [{
type: "image",
props: {
id: "image"
},
layout: (make, view) => {
// make.left.top.bottom.inset(5);
// view.width =
make.width.equalTo($device.info.screen.width);
make.height.equalTo($device.info.screen.height)
},
}, ],
},
layout: $layout.fill,
}]
});
}
// 首次进入刷新
getAllComics();