panchengyong
10 days ago b2d3f7caf927e5b83ec52efb74f1f818dbb15236
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
/*
* 技术支持:老狼孩科技
* 老狼孩科技官网:http://42.193.53.121/
* 联系方式:QQ1:2029491180  QQ2:2985539603 QQ3:2241819424
* 源码、工具、干货、脚本下载地址:https://wwe.lanzoui.com/b01i7fcmb 密码:7cyj
* 各类图色工具下载地址:https://wwe.lanzoui.com/b01iro0xe 密码:5rqv
* 自动化辅助脚本下载地址:https://wwe.lanzoui.com/b01iv9zbg  密码:9nsj
* 版本:v1.0.4
*/
 
var version = JSON.parse(readIECFileAsString("update.json")).version;
var width = device.getScreenWidth();
var height = device.getScreenHeight();
 
// const EASYCLICKSDK = (function(){
    function EASYCLICKSDK(){
        //初始化EC
        this.init();
    }
    /*
    * 功能:到底到顶判断
    * fyTepy 判断类型
    * nodeIDValue 节点ID值
    * return 布尔类型,返回结果
    */
    EASYCLICKSDK.prototype.到底到顶判断 = function(fyTepy,nodeIDValue) {
        //DOWN 到底 UP 到顶
        let  res = false;
        let selectors = id(nodeIDValue);
        if(selectors && isScrollEnd(fyTepy,selectors)){
            res = true;
        }
        return res;
    }
 
 
    /*
    * 功能:控件翻页
    * attr 节点属性,如id,直接写id,而不是"id",不能加双引号
    * attrValue 节点属性值
    */
    EASYCLICKSDK.prototype.控件翻页 = function(attr,attrValue) {
        let node = attr(attrValue).scrollable(true).getOneNodeInfo(100);
        if(node) {
            node.scrollForward();
            this.msg("开始翻页1", 100);
        }
        sleep(1000);
        // swipeToPoint(width / 2,height - 400 ,width / 2,100,1500);
    }
 
    /*
    * 功能:坐标翻页
    * x1 起点x坐标
    * y1 起点y坐标
    * x2 终点x坐标
    * y2 终点y坐标
    * fyTime 滑动时间,单位毫秒
    */
    EASYCLICKSDK.prototype.坐标翻页 = function(x1,y1,x2,y2,fyTime) {
        this.msg("开始翻页1", 100);
        swipeToPoint(x1,y1,x2,y2,fyTime);
        sleep(1000);
    }
 
 
    /*
    * 功能:自动启动服务
    * time 启动服务超时次数
    * return 布尔类型,返回结果
    */
    EASYCLICKSDK.prototype.autoServiceStart = function(time) {
        for (let i = 0; i < time; i++) {
            if (isServiceOk()) {
                return true;
            }
            let started = startEnv();
            logd("第" + (i + 1) + "次启动服务结果: " + started);
            if (isServiceOk()) {
                return true;
            }
        }
        return isServiceOk();
    }
 
    
    /*
    * 功能:初始化EC
    */
    EASYCLICKSDK.prototype.init = function() {
        let res = startEnv();
        let daEnvRs = daemonEnv(true);
        this.msg('启动服务:' + res);
        this.msg('守护自动化环境:' + daEnvRs);
 
        //如果自动化服务正常
        if (!this.autoServiceStart(3)) {
            this.msg("自动化服务启动失败,无法执行脚本");
            exit();
            return;
        }
 
        
        let result = hasFloatViewPermission();
        if(!result){
            result = requestFloatViewPermission(10000);
            if(!result){
                this.msg("申请悬浮权限失败");
                exit();
                return;
            }
        }
 
        
        let req = image.requestScreenCapture(10000,0);
        if (!req) {
            req = image.requestScreenCapture(10000,0);
        }
        if (!req) {
            this.msg("申请截图权限失败");
            exit();
            return;
        }
 
        let d = image.initOpenCV();
        this.msg("图色环境:" + d,200);
        this.msg("初始化完成");
    }
 
    
    /*
    * 功能:信息显示
    * msgValue 显示内容
    * sleepTime 显示时间,单位毫秒
    */
    EASYCLICKSDK.prototype.msg = function(msgValue,sleepTime) {
        if(sleepTime == undefined){
            sleepTime = 1000;
        }
        logd(msgValue + version);
        toast(msgValue + version);
        sleep(sleepTime);
    }
 
    /*
    * 功能:无节点输入内容
    * text 输入内容
    */
    EASYCLICKSDK.prototype.无节点输入内容 = function(text) {
        imeInputText(null,text);
        sleep(1000);
    }
 
    
    /*
    * 功能:查找节点或点击
    * way 查找节点方式
    * str 查找节点属性值
    * depth 查找节点深度
    * isClick 是否点击
    * isProFind 是否强化识别,默认true
    * isFWClick 是否范围点击,默认false
    * isClickOne 是否点击,默认true
    * timeOut 查找超时时间,单位毫秒,默认0
    * return 布尔类型,返回识别结果
    */
    EASYCLICKSDK.prototype.findNode = function(way,str,depth,isClick,isProFind,isFWClick,isClickOne,timeOut) {
        // this.msg("请稍等...",0);
 
        if(isFWClick == undefined){
            isFWClick = false
        }
 
        if(timeOut  == undefined){
            timeOut = 1
        }
        if(isClickOne  == undefined){
            isClickOne = true
        }
        if(isProFind == undefined){
            isProFind = true
        }
        
        let result = false //点击结果
        let object;
        if(way == "text"){
            if(isProFind){
                object = text(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = text(str).getOneNodeInfo(timeOut);
            }
 
        } else if(way == "desc"){
            if(isProFind){
                object = desc(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = desc(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "id"){
            if(isProFind){
                object = id(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = id(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "clz"){
            if(isProFind){
                object = clz(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = clz(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "pkg"){
            if(isProFind){
                object = pkg(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = pkg(str).getOneNodeInfo(timeOut);
            }
 
        } else if(way == "textMatch"){
            if(isProFind){
                object = textMatch(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = textMatch(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "idMatch"){
            if(isProFind){
                object = idMatch(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = idMatch(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "clzMatch"){ //textStartsWith
            if(isProFind){
                object = clzMatch(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = clzMatch(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "pkgMatch"){ //textStartsWith
            if(isProFind){
                object = pkgMatch(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = pkgMatch(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "descMatch"){ //textStartsWith
            if(isProFind){
                object = descMatch(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = descMatch(str).getOneNodeInfo(timeOut);
            }
        }
        else{
            logd("Error:组件参数不正确");
        }
 
        if(object != null){
            try{
                // object.refresh();
                if(isClick){
                    //    //{"top":1578,"bottom":1734,"left":888,"right":1044}
                    let x1 = parseInt(object.bounds.top);
                    let y1 = parseInt(object.bounds.bottom);
                    let w1 = parseInt(object.bounds.left);
                    let h1 = parseInt(object.bounds.right);
                    // l,top,r,b
 
                    if(isFWClick){
                        if(w1 >= 0 && x1 >= 400 && h1 <= width &&  y1 <= height - 400){
                            if(isClickOne){ //单击
                                result = object.clickCenter();
                            }else{ //双击
                                for (i = 1; i < 3; i++) {
                                    result = object.clickCenter();
                                    sleep(100);
                                }
                            }
                        }else {
                            this.msg("控件不在指定区域内",10);
                        }
 
                    }else {
                        if(isClickOne){ //单击
                            result = object.clickCenter();
                        }else{ //双击
                            for (i = 1; i < 3; i++) {
                                result = object.clickCenter();
                                sleep(100);
                            }
                        }
                    }
 
                }else{
                    result = true
                }
            }catch(err){
                logd(err);
            }
        }
        // else{
        //     logd("Error:组件不存在/没找到");
        // }
 
        return result;
    }
 
 
    /*
    * 功能:获取节点属性值
    * way 查找节点方式
    * str 查找节点属性值
    * depth 查找节点深度
    * isProFind 是否强化识别
    * timeOut 查找超时时间,单位毫秒
    * wayType 获取节点属性方式
    * return 布尔类型,返回识别结果
    */
    EASYCLICKSDK.prototype.getNodeAttr = function(way,str,depth,isProFind,timeOut,wayType){
        let object = null;
        let res = "";
 
        if(way == "text"){
            if(isProFind){
                object = text(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = text(str).getOneNodeInfo(timeOut);
            }
 
        } else if(way == "desc"){
            if(isProFind){
                object = desc(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = desc(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "id"){
            if(isProFind){
                object = id(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = id(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "clz"){
            if(isProFind){
                object = clz(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = clz(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "pkg"){
            if(isProFind){
                object = pkg(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = pkg(str).getOneNodeInfo(timeOut);
            }
 
        } else if(way == "textMatch"){
            if(isProFind){
                object = textMatch(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = textMatch(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "idMatch"){
            if(isProFind){
                object = idMatch(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = idMatch(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "clzMatch"){ //textStartsWith
            if(isProFind){
                object = clzMatch(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = clzMatch(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "pkgMatch"){ //textStartsWith
            if(isProFind){
                object = pkgMatch(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = pkgMatch(str).getOneNodeInfo(timeOut);
            }
 
        }else if(way == "descMatch"){ //textStartsWith
            if(isProFind){
                object = descMatch(str).depth(depth).getOneNodeInfo(timeOut);
            }else{
                object = descMatch(str).getOneNodeInfo(timeOut);
            }
        }
        else{
            logd("Error:组件参数不正确");
        }
 
        if(object != null){
            if(wayType == "selected"){
                res = object.selected;
            }else if(wayType == "text"){
                res = object.text;
            } else if(wayType == "desc"){
                res = object.desc;
            }
 
        }else{
            logd("Error:组件不存在/没找到");
        }
        return res;
    }
 
    
    /*
    * 功能:倒计时
    * endTime 倒计时时间,单位秒
    */
    EASYCLICKSDK.prototype.倒计时 = function(endTime){
        for (let i=0; i< endTime; i++)
        {
            this.是否暂停脚本()
            this.msg((endTime - i) + "秒后开始下一个任务!");
        }
    }
 
    /*
    * 功能:对节点输入内容
    * node 节点信息
    * inpText 输入内容
    */
    EASYCLICKSDK.prototype.nodeInputText = function(node,inpText) {
        if(node){
            node.inputText(inpText)
            sleep(1000);
        }
    }
 
 
    /*
    * 功能:删除字符串左右两端的空格
    * str 字符串
    * return 删除两端空格后的字符串
    */
    EASYCLICKSDK.prototype.trim = function(str){ 
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }
 
 
    /*
    * 功能:热更新_检测心跳
    * rgxOutTime 热更新超时时间
    */
    EASYCLICKSDK.prototype.热更新_检测心跳 = function(rgxOutTime) {
        // let version = JSON.parse(readIECFileAsString("update.json")).version;
        while (true){
            try{
                // toast("Hello World -> "+version);
                //请求服务器是否有新版本
                let updateResult = hotupdater.updateReq();
                // logd("请求更新是否有: "+updateResult);
 
                if (!updateResult) {
                    // logw("请求失败错误信息: "+hotupdater.getErrorthis.msg());
                }else{
                    // logd("请求数据: "+hotupdater.getUpdateResp());
                    //有更新得情况下进行下载新的版本
                    let path = hotupdater.updateDownload();
                    // logd("下载路径为: "+path);
                    if (!path) {
                        // logw("下载IEC文件错误信息: "+hotupdater.getErrorthis.msg());
                    }else{
                        //存储数据
                        // storage.putBoolean("isUP",true);
                        restartScript(path,true,3)
                        return;
                    }
                }
            }catch(e){
                logd("网络异常,稍后再试");
            }
            rgxOutTime = new Date();
            sleep(3 * 60 * 1000);
        }
    }
 
    /*
    * 功能:是否暂停脚本
    * isStop 是否暂停脚本
    */
    EASYCLICKSDK.prototype.是否暂停脚本 = function(isStop){
        while (isStop){
            sleep(1000);
        }
    }
 
    /*
    * 功能:初始化节点
    */
    EASYCLICKSDK.prototype.初始化节点 = function(){
        //刷新节点
        removeNodeFlag(0);
        //释放节点锁
        releaseNode();
        //锁住节点,界面刷新也不动
        lockNode();
    }
 
 
    /*
    * 功能:多点找色
    * colorArr 多点颜色数组
    * return 布尔类型,返回查找结果
    */
    EASYCLICKSDK.prototype.多点找色 = function(colorArr,isClick) {
        if (device.getScreenWidth() != width) {
            restartScript(null,true,1);
            width = device.getScreenWidth();
        }
 
        let res = false;
        let points = image.findMultiColorEx(colorArr[0], colorArr[1], colorArr[2], colorArr[3], colorArr[4], colorArr[5], colorArr[6], colorArr[7],colorArr[8]);
        if(points && points.length > 0){
            if(isClick){
                clickPoint(points[0].x,points[0].y);
                sleep(1000);
            }
            res = true;
        }
        return res;
    }
 
    /*
    * 功能:找图
    * imgPath 图片路径
    * isClick 是否点击
    * imgBoundsArr 查找范围,如[1017,540,1044,619]
    * return 布尔类型,返回查找结果
    */
    EASYCLICKSDK.prototype.找图 = function(imgPath,isClick,imgBoundsArr) {
        let res = false;
 
        if (device.getScreenWidth() != width) {
            restartScript(null,true,1);
            width = device.getScreenWidth();
        }
 
        if(imgBoundsArr == undefined){
            imgBoundsArr = [0,0,width,height];
        }
        let sms=readResAutoImage(imgPath);
        //在当前屏幕中查找,并且限制只查找一个
        let points = image.findImageEx(sms,imgBoundsArr[0],imgBoundsArr[1],imgBoundsArr[2],imgBoundsArr[3],0.7, 0.9, 21, 5);
        if(points && points.length > 0){
            let x = parseInt((points[0].left + points[0].right)/2)
            let y = parseInt((points[0].top + points[0].bottom)/2)
            //点击坐标
            if(isClick){
                clickPoint(x,y);
                sleep(1000);
            }
            res = true;
        }
        //图片要回收
        image.recycle(sms)
 
        // let sms=readResAutoImage(imgPath);
        // let aimage = image.captureFullScreen();
        // logd("aimage "+aimage);
        // if (aimage != null) {
        //     //在图片中查找
        //     let points = image.findImage(aimage, sms,imgBoundsArr[0],imgBoundsArr[1],imgBoundsArr[2],imgBoundsArr[3],0.7, 0.9, 21, 5);
        //     if(points && points.length > 0){
        //         if(isClick){
        //             let x = parseInt((points[0].left + points[0].right)/2)
        //             let y = parseInt((points[0].top + points[0].bottom)/2)
        //             //点击坐标
        //             clickPoint(x,y);
        //             sleep(1000);
        //         }
        //         res = true;
        //     }
        //     //图片要回收
        //     image.recycle(aimage)
        // }
        // //图片要回收
        // image.recycle(sms)
 
        return res;
    }
    
    // return EASYCLICKSDK;
// })();
module.exports = new EASYCLICKSDK();
// module.exports = { EASYCLICKSDK  }