/* * 技术支持:老狼孩科技 * 老狼孩科技官网: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 }