-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathService.py
More file actions
561 lines (548 loc) · 18.2 KB
/
Service.py
File metadata and controls
561 lines (548 loc) · 18.2 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
#-*-coding:utf-8-*-
import sys
import time
from flask import Flask,jsonify
app = Flask(__name__)
appJSON={
"controller":{
"title":"Speed Dial Squared Up",
"rightButton":{
"title":"请求",
"click":"${()=>{$dispatch('fetchData')}}"
}
},
"lifeCircle":{
"viewDidMount":"${()=>{$dispatch('fetchData')}}",
},
"components":[
{
"id":"header",
"type":"View",
"style":{
"position":"`{{2,0},{${UI.screenW-2},200}}`",
"backgroundColor":"rgb(255,255,255)",
},
"components":[
{
"id":"nameLabel",
"type":"TextView",
"style":{
"position":"`{{6,6},{${UI.screenW-12},264}}`",
"backgroundColor":"`rgb(255,255,255)`",
"text":" 相信大家肯定有这样的烦恼,因为各式各样的需求,每次app更新版本都需要编码->测试->打包->提交app store 审核,这样花费的时间太多,又或者你会想到这不是有现成的解决方案嘛,ReactNative就可以,并且可以热更新(不同于JSPatch)。是的,但是我不想因为简单的需求就引入那么多文件,更增加了app体积。JSONRenderKit核心就只有几个.h.m文件。\n\n 同时一个非常好玩的库,不用重新command+R,只要改动JSON就可以看到新的UI效果。之所以说他好玩,因为它可以做很多彩蛋,给用户惊喜。\n\n并且我也已经正式放进项目-(”掌上理工大 “app store 可以搜索)里面使用啦,并且抽出代码,详细注释做成了Demo放在github。你也可以修改源代码并扩展新组件后放进的你自己的项目,重要的是你也可以参考JavaScript是怎样和OC进行交互的,代码里面有详细的注释。要是有兴趣,你可以自己将他打造成为一个有用的工具。",
"textColor":"rgb(132,132,132)",
"cornerRadius":4,
"borderColor":"rgb(244,244,244)",
"borderWidth":1,
"allowEdit":0,
"fontSize":14.0,
},
},
]
},
{
"id":"listbox",
"type":"ListView",
"style":{
"position":"`{{0,270},{${UI.screenW},270}}`",
"itemSize":"`{${UI.screenW/3},90}`",
"itemVMarign":0,
"itemHMarign":0,
"scrollDirection":"vertical",
},
"itemStyle":{
"separatorDirection":"right|bottom",
"separatorColor":"rgb(240,240,240)",
},
"clickItem":"${(index)=>{UI.alert('you pressed',$props.apps[index].name)}}",
"item":[
{
"id":"appname",
"type":"Label",
"style":{
"position":"`{{0,60},{${UI.screenW/3},30}}`",
"text":"标签",
"align":"center",
"fontSize":14,
"textColor":"rgb(130,130,130)",
},
},
{
"id":"appicon",
"type":"ImageView",
"style":{
"position":"{{48,30},{26,26}}",
"image":"https://static.wutnews.net/icon/calendar/2x.png?2",
"imageMode":"aspectfit",
},
},
],
}
],
"props":{
"testIndex":1,
"apps":[],
},
"actions":{
"fetchData":{
"viewId":"listbox",
"URLRequest":{
"type":"GET",
"url":"http://palmwhut.sinaapp.com/member/get_app?timestamp=0&platform=ios",
"check":"${(json)=>{return json.status == '200';}}",
"failure":"${(desc)=>{UI.alert('信息获取失败',desc)}}",
"extractData":"${(json)=>{$props.apps=$props.apps.concat(json.data);return json.data;}}",
"itemToStyleTemplate":{
"subStyles":[
{
"viewId":"appname",
"style":{
"text":"`${item.name}`",
}
},
{
"viewId":"appicon",
"style":{
"image":"`${item.icon['3x']}`",#item.icon.3x 语法格式不正确
}
},
]
},
"render":"${(data)=>{$getView('listbox').setDataArray([]).addDatas(data).reloadData()}}",
},
},
}
}
translation={
"controller":{
"title":"translation",
},
"components":[
{
"id":"searchField",
"type":"TextField",
"style":{
"position":"`{{6,6},{${UI.screenW-80},36}}`",
"textColor":"rgb(80,80,80)",
"borderStyle":"none",
"backgroundColor":"rgb(240,240,240)",
"cornerRadius":4,
"placeholder":"请输入你要翻译的单词",
}
},
{
"id":"searchButton",
"type":"Button",
"style":{
"position":"`{{${UI.screenW-68},4},{68,40}}`",
"titleColor":"rgb(40,40,40)",
"title":"search"
},
"click":"${()=>{$dispatch('transAction');}}"
},
{
"id":"resultList",
"type":"ListView",
"style":{
"position":"`{{0,60},{${UI.screenW},${UI.screenH-60}}}`",
"itemSize":"`{${UI.screenW},54}`",
"itemVMarign":0,
"scrollDirection":"vertical",
},
"itemStyle":{
"separatorDirection":"bottom",
"separatorColor":"rgb(240,240,240)",
},
"item":[
{
"id":"fixLabel",
"type":"Label",
"style":{
"position":"`{{13,8},{${UI.screenW-13},20}}`",
"fontSize":12,
"textColor":"rgb(200,200,200)",
}
},
{
"id":"descLabel",
"type":"Label",
"style":{
"position":"`{{13,30},{${UI.screenW-13},20}}`",
"fontSize":14,
"textColor":"rgb(80,80,80)",
}
},
],
"dataArray":[
{
"subStyles":[
{
"viewId":"fixLabel",
"style":{
"text":"译文",
},
},
{
"viewId":"descLabel",
"style":{
"text":"Who am I?",
},
},
]
},
{
"subStyles":[
{
"viewId":"fixLabel",
"style":{
"text":"译文",
},
},
{
"viewId":"descLabel",
"style":{
"text":"Who are you?",
},
},
]
},
]
}
],
"props":{
"transResults":[]
},
"actions":{
"transAction":{
"viewId":"resultList",
"URLRequest":{
"type":"get",
"url":"`https://dict.bing.com.cn/api/http/v2/4154AA7A1FC54ad7A84A0236AA4DCAF3/zh-cn/en-us/?q=${$getView('searchField').text}&format=application/json`",
"check":"${(json)=>{return true}}", #进行检查 必须返回一个布尔值
"failure":"${(desc)=>{UI.alert('信息获取失败',desc)}}",
# "success":"${(data)=>{$props.apps=$props.apps.concat(data);}}", #将结果进行保存
"extractData":"${(json)=>{return json.LEX.C_DEF[1].SEN}}",
"willRender":"",
"willSend":"${()=>{UI.showIndicator('gray');}}",
"itemToStyleTemplate":{
"subStyles":[
{
"viewId":"descLabel",
"style":{
"text":"`${item.D}`",#item.icon.3x 语法格式不正确
}
},
{
"viewId":"fixLabel",
"style":{
"text":"译文",#item.icon.3x 语法格式不正确
}
},
]
},
"render":"${(renderData)=>{$getView('resultList').setDataArray([]).addDatas(renderData).reloadData()}}",
"didRender":"${()=>{UI.hideIndicatorDelay(0.618)}}",
},
},
}
}
todo={
"controller":{
"title":"todo",
},
"components":[
{
"id":"addField",
"type":"TextField",
"style":{
"position":"`{{6,6},{${UI.screenW-80},36}}`",
"textColor":"rgb(80,80,80)",
"borderStyle":"none",
"backgroundColor":"rgb(240,240,240)",
"cornerRadius":4,
"placeholder":"请输入项目",
}
},
{
"id":"addButton",
"type":"Button",
"style":{
"position":"`{{${UI.screenW-68},4},{68,40}}`",
"titleColor":"rgb(40,40,40)",
"title":"add"
},
"click":"${()=>{$dispatch('addToDo');}}"
},
{
"id":"todoList",
"type":"ListView",
"style":{
"position":"`{{0,60},{${UI.screenW},${UI.screenH-60-64}}}`",
"itemSize":"`{${UI.screenW},60}`",
"itemVMarign":0,
"scrollDirection":"vertical",
},
"itemStyle":{
"separatorDirection":"bottom",
"separatorColor":"rgb(240,240,240)",
"itemHighlightColor":"rgb(220,220,220)",
},
"item":[
{
"id":"nameLabel",
"type":"Label",
"style":{
"position":"`{{13,8},{${UI.screenW/2-13},20}}`",
"fontSize":18,
"textColor":"rgb(20,20,20)",
"adjustTextFont":1,
}
},
{
"id":"deleteLabel",
"type":"Label",
"style":{
"position":"`{{13,30},{${UI.screenW/2-13},20}}`",
"fontSize":14,
"textColor":"rgb(90,90,90)",
"adjustTextFont":1,
}
},
],
"clickItem":"${(index)=>{$props.selectedIndex=index;$dispatch('removeToDo')}}",
"dataArray":[
{
"subStyles":[
{
"viewId":"nameLabel",
"style":{
"text":"apple",
},
},
{
"viewId":"deleteLabel",
"style":{
"text":"tap to delete",
},
},
]
},
{
"subStyles":[
{
"viewId":"nameLabel",
"style":{
"text":"orange",
},
},
{
"viewId":"deleteLabel",
"style":{
"text":"tap to delete",
},
},
]
},
]
}],
"props":{
"selectedIndex":-1,
"toDoItemStyle":{
"subStyles":[
{
"viewId":"nameLabel",
"style":{
"text":"`${$getView('addField').text}`",
},
},
{
"viewId":"deleteLabel",
"style":{
"text":"tap to delete",
},
},
]
},
},
"actions":{
"removeToDo":{
"viewId":"todoList",
"valKey":"dataArray",
"reduce":"${(oldVal)=>{return oldVal.removeAtIndex($props.selectedIndex);}}",
},
"addToDo":{
"viewId":"todoList",
"valKey":"dataArray",
"reduce":"${(oldVal)=>{oldVal.push($props.getCopy('toDoItemStyle'));return oldVal;}}",
}
}
}
newApi = {
"controller":{
"title":"swipe the banner",
},
"components":[
{
"id":"imageLists",
"type":"ListView",
"style":{
"position":"`{{0,0},{${UI.screenW},${220}}}`",
"itemSize":"`{${UI.screenW},220}`",
"itemHMarign":0,
"itemVMarign":0,
"scrollDirection":"horizontal",
"backgroundColor":"rgb(255,255,255)",
"splitPage":1,
"infiniteScroll":1,
"showHBar":0
},
"clickItem":"${(index)=>{UI.log(index)}}",
"item":[
{
"id":"image",
"type":"ImageView",
"style":{
"position":"`{{0,0},{${UI.screenW},220}}`",
}
},
],
"dataArray":[
{
"subStyles":[
{
"viewId":"image",
"style":{
"image":"`https://unsplash.it/${UI.screenW*2}/440/?image=210`",
},
},
]
},
{
"subStyles":[
{
"viewId":"image",
"style":{
"image":"`https://unsplash.it/${UI.screenW*2}/440/?image=211`",
},
},
]
},
{
"subStyles":[
{
"viewId":"image",
"style":{
"image":"`https://unsplash.it/${UI.screenW*2}/440/?image=223`",
},
},
]
},
]
},
{
"id":"UIToolLists",
"type":"ListView",
"style":{
"position":"`{{0,220},{${UI.screenW},${UI.screenH-220-64}}}`",
"itemSize":"`{${UI.screenW},50}`",
"itemVMarign":0,
"scrollDirection":"vertical",
"backgroundColor":"rgb(255,255,255)",
},
"clickItem":"${(index)=>{$props.runFuncs(index)}}",
"itemStyle":{
"separatorDirection":"bottom",
"separatorColor":"rgb(220,220,220)",
},
"item":[
{
"id":"toolLabel",
"type":"Label",
"style":{
"position":"`{{14,8},{${UI.screenW-14},40}}`",
"fontSize":18,
"textColor":"rgb(20,20,20)",
}
},
],
"dataArray":[
{
"subStyles":[
{
"viewId":"toolLabel",
"style":{
"text":"showActionSheet",
},
},
]
},
{
"subStyles":[
{
"viewId":"toolLabel",
"style":{
"text":"showActionAlert",
},
},
]
},
{
"subStyles":[
{
"viewId":"toolLabel",
"style":{
"text":"alertDeviceScreenSize",
},
},
]
},
{
"subStyles":[
{
"viewId":"toolLabel",
"style":{
"text":"showIndicator",
},
},
]
},
{
"subStyles":[
{
"viewId":"toolLabel",
"style":{
"text":"hideIndicatorDelay",
},
},
]
},
]
},
],
"props":{
"$runFunctions":[
"${()=>{UI.showSheetView('sheetView标题','点击非标题列表按钮,index=-1',['apple','orange','litchi'],(index)=>{UI.log('你点击了'+index)});}}",
"${()=>{UI.alertTitles('alert标题','点击非标题列表按钮,index=-1',['banana','grape'],(index)=>{UI.log('你点击了'+index)});}}",
"${()=>{let info = `设备宽:${UI.screenW} \n 设备高:${UI.screenH}`;UI.alert('设备屏幕详情',info);}}",
"${()=>{UI.showIndicator();}}",
"${()=>{UI.hideIndicatorDelay(0);}}"
]
}
}
@app.route('/')
def hello_world():
return 'JSON render Hello World!'
@app.route('/appjson', methods=['GET'])
def get_appjson():
return jsonify(appJSON)
@app.route('/trans', methods=['GET'])
def get_translation():
return jsonify(translation)
@app.route('/todo', methods=['GET'])
def get_todo():
return jsonify(todo)
@app.route('/newApi', methods=['GET'])
def get_newApi():
return jsonify(newApi)
if __name__ == '__main__':
app.run()