forked from sunyymq/JSBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path快递100.js
286 lines (271 loc) · 6.53 KB
/
快递100.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
/**
* 快递100 - 查询快递动态小脚本
* Powered by JSbox
*
* @author AbleCats <[email protected]>
* @public https://t.me/Flow_Script
* @version 20180318A
*
* Using Tips
* 在items上可进行长按/双击操作
* 暂时无法使用上下页功能,稍等下个版本
* widget 需要 JSBox 1.11(117)及以上版本支持
*/
var storied = $cache.get("storied") ? $cache.get("storied") : []
async function scanCode(num) {
num = typeof(num) == "object" ? num[0] : num
return new Promise(resolve => {
$http.get({
url: "https://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text=" + num,
handler: function(resp) {
saveOrder(num)
var data = resp.data
var comCode = data.auto[0].comCode
$http.get({
url: "https://www.kuaidi100.com/query?type=" + comCode + "&postid=" + num,
handler: function(resp) {
var items = []
var data = resp.data
if (data.status == 200)
for (const key in data.data) {
let d = data.data[key]
cnum = " " + num + " "
ctim = d.time
items.push({
num: num,
text: d.context,
time: comCode + cnum + ctim
})
}
else {
items.push({
time: "ERROR " + data.status,
text: "emmm... 出错啦 🌝"
})
data.status==201?delOrder(num):0
}
resolve(items)
}
})
}
})
})
}
function saveOrder(num) {
let length = storied.length
if (length) {
for (const key in storied) {
if (storied[key] == num) break;
else {
if (key == length - 1) {
storied.unshift(num)
$cache.set("storied", storied)
}
}
}
} else {
storied.unshift(num)
$cache.set("storied", storied)
}
}
function delOrder(num) {
for (const key in storied) {
if (storied[key] == num) {
storied.splice(key, 1)
$cache.set("storied", storied)
}
}
}
async function waitData() {
var Code = []
var ct = $clipboard.text
$ui.loading(true)
function orderRun(i) {
$console.log(i)
$ui.alert({
title: "单号操作",
message: "请选择对单号\n" + i + "\n要执行的操作内容",
actions: [{
title: "删除",
handler: function() {
delOrder(i)
waitData()
}
},
{
title: "复制",
handler: function() {
$clipboard.text = i
}
},
{
title: "取消",
handler: function() {
}
}
]
})
}
function CS(ct) {
let length = storied.length
if (length) {
for (const key in storied) {
if (storied[key] == ct) break;
else if (key == length - 1) Alt(ct);
}
} else Alt(ct)
}
function Alt(ct) {
$ui.alert({
title: "单号检测完成",
message: "检测到单号\n" + ct + "\n请选择要执行的操作",
actions: [{
title: "忽略",
handler: function() {
$clipboard.clear()
}
},
{
title: "查看",
handler: function() {
saveOrder(ct)
waitData()
$clipboard.clear()
}
}
]
})
}
function listText(d) {
var T = {
type: "list",
props: {
rowHeight: 120,
data: [{
title: d[0].time,
rows: [{
type: "label",
props: {
lines: 0,
text: d[0].text,
autoFontSize: true,
align: $align.center
},
layout: $layout.fill,
events: {
longPressed: function(sender) {
orderRun(d[0].num)
},
doubleTapped: function() {
waitData()
}
}
}]
}],
footer: {
type: "view",
views: [{
type: "label",
props: {
height: 20,
text: "AbleCats",
textColor: $color("#AAAAAA"),
align: $align.center,
font: $font(12)
},
layout: function(make, view) {
make.center.equalTo(view.super)
WHT = $ui.window.frame.width / 3
make.size.equalTo($size(WHT, 20))
}
}, {
type: "button",
props: {
alpha: 0.5,
radius: 20,
title: "上",
},
layout: function(make, view) {
make.left.inset(5)
WHT = $ui.window.frame.width / 3
make.size.equalTo($size(40, 40))
},
events: {
tapped: function(sender) {
$("vs").page = $("vs").page - 1 >= 0 ? $("vs").page - 1 : storied.length - 1
}
}
}, {
type: "button",
props: {
alpha: 0.5,
radius: 20,
title: "下",
},
layout: function(make, view) {
make.right.inset(5)
WHT = $ui.window.frame.width / 3
make.size.equalTo($size(40, 40))
},
events: {
tapped: function(sender) {
$("vs").page = $("vs").page + 1 <= storied.length - 1 ? $("vs").page + 1 : 0
}
}
}]
},
layout: $layout.fill
}
}
return T;
}
function eText() {
Code.push({
type: "list",
props: {
data: [{
title: "ERROR",
rows: [{
type: "label",
props: {
lines: 0,
text: "没有单号无能无力🌚",
align: $align.center
},
layout: $layout.fill,
events: {
doubleTapped: function() {
waitData()
}
}
}]
}]
},
layout: $layout.fill,
})
}
for (let i of storied) {
if (i) {
d = await scanCode(i)
Code.push(listText(d))
}
}
Code.length ? Code : eText()
$ui.loading(false)
$ui.render({
props: {
title: "快递100"
},
views: [{
type: "gallery",
props: {
id: "vs",
items: Code,
},
layout: $layout.fill
}]
})
var Pass = /[0-9]{10,14}/g
Pass.test(ct) ? CS(ct) : 0
}
waitData()