|
楼主 |
发表于 2017-6-27 09:33:11
|
显示全部楼层
请问,我想在页面的button的onclick事件中单独调取
- Device.prototype.startFun = function()
- {
- //创建设备
- var device = new Device();
- var myDevice = device.createDevice("Cert");
- //显示提示信息
- myDevice.setMessage();
- setting.Methods.checkWebServer(myDevice);
- };
复制代码
我该怎么写这段。另外,我是参考http://doc.wex5.com/?p=4222 来引用外部JS的,如- var $ = require("jquery");
- var justep = require("$UI/system/lib/justep");
- var baseISSOnline = require("./baseISSOnline");
- var baseISSObject = require("./baseISSObject");
- var jquery = require("./jquery-1.4.2.min");
- var common = require("./common");
复制代码
那请问:
- Model.prototype.button7Click = function(event){
-
-
- };
复制代码
这个我应该怎么写?有没的范例可学习的?
外部JS如下代码:
- var Device = function()
- {
- message : ""
- };
- function createISSonlineDevice(setting)
- {
- var ISSOnline = "ZKIDROnline";
- var browserFlag = getBrowserType() || "";
- //刷卡信息返回默认方法
- if(typeof setting.Methods == "object")
- {
- if(typeof setting.Methods.showMessage != "function")
- {
- setting.Methods.showMessage = function(type,message)
- {
- $("#cert_message").text(message);
- $("#cert_message_type").text(msgType[type]);
- }
- }
- //检查驱动安装默认方法
- if(typeof setting.Methods.checkWebServer != "function")
- {
- setting.Methods.checkWebServer = function(myDevice)
- {
- var ISSVersion = function(){};
- ZK.extend(ISSVersion, Device, {
- message : "",
- url : "/info",
- interfaceResult :
- {
- 0:{mean:"成功",message:"二代身份证读取成功!",type:"success",notShow:true}
- },
- dealDeviceData:function(result){
- var existVersion = result.data.server_version;//2.7.1
- var curVersion = "${application['fpDriver.version']}";//3.5.2
- var existVersionArr = existVersion.split(".");
- var curVersionArr = curVersion.split(".");
- var isLast = true;
- var len = existVersionArr.length;
- for(var i=len;i>0;i--)
- {
- var existVersionTemp = parseInt(existVersionArr[i-1]);
- var curVersionTemp = parseInt(curVersionArr[i-1]);
- if(existVersionTemp<curVersionTemp)
- {
- isLast = false;
- }
- else if(existVersionTemp>curVersionTemp)
- {
- isLast = true;
- }
- else
- {
- }
- }
-
- //if(result.data.server_version >= "${application['fpDriver.version']}")
- if(isLast)
- {
- if(typeof setting.Methods.detectSuccess == "function")
- {
- setting.Methods.detectSuccess();
- }
- if(typeof myDevice == "object")
- {
- //连接设备,处理返回信息
- setTimeout(function(){
- myDevice.accessDevice();
- },100);
- }
- }
- else
- {
- if(typeof setting.Methods.detectWarning == "function")
- {
- setting.Methods.detectWarning();
- }
- if(typeof myDevice == "object")
- {
- //连接设备,处理返回信息
- setTimeout(function(){
- myDevice.accessDevice();
- },100);
- }
- else
- {
- if(typeof setting.Methods.notInstall == "function")
- {
- setting.Methods.notInstall();
- }
- }
- }
- },
- installDrive:function(){
- if(typeof setting.Methods.detectError == "function")
- {
- setting.Methods.detectError();
- }
- if(typeof myDevice == "object")
- {
- closeMessage();
- //驱动未安装
- setting.Methods.downloadDrive();
- }
- else
- {
- if(typeof setting.Methods.notInstall == "function")
- {
- setting.Methods.notInstall();
- }
- }
-
- return false;
- }
- });
-
- var version = new ISSVersion();
- version.accessDevice();
- }
- }
- //下载驱动默认方法
- if(typeof setting.Methods.downloadDrive != "function")
- {
- setting.Methods.downloadDrive = function()
- {
- messageBox({messageType: "confirm", text: "请安装相关硬件驱动!点击确定下载驱动。",
- callback: function(result){
- if(result)
- {
- window.location.href = "middleware/ZKIDROnline.exe";
- }
- closeMessage();
- }});
- }
- }
- }
- /**
- * 设备
- */
-
- var buttonNames = {"Cert":"","Scanner":"","Barcode":""};
- if(typeof setting.Cert == "object")
- {
- buttonNames.Cert = setting.Cert.select;
- //身份证阅读器
- var Cert = function(){};
- ZK.extend(Cert, Device, {
- //提示信息
- message : "请将二代身份证放到读卡区域...",
- //服务url
- url : "/ScanReadIdCardInfo?OP-DEV=1&CMD-URL=4&common=1" + "&random=" + getRandomNum(),
- //接口返回值
- interfaceResult :
- {
- 0:{mean:"成功",message:"二代身份证读取成功!",type:"success"},
- 1:{mean:"端口打开失败",message:"未检测到二代身份证阅读器!",type:"warning"},
- 2:{mean:"数据传输超时",message:"未检测到二代身份证阅读器!",type:"error"},
- 10:{mean:"没有找到卡",message:"未读取到身份证,请重新刷卡!",type:"warning"},
- 11:{mean:"读卡操作失败",message:"未检测到二代身份证阅读器!",type:"error"},
- 20:{mean:"自检失败",message:"二代身份证读取失败!",type:"error"},
- 30:{mean:"其他错误",message:"二代身份证读取失败!",type:"error"},
- 40:{mean:"相片解码失败",message:"二代身份证读取失败!",type:"error"},
- 100:{mean:"超时",message:"未读取到身份证,请重新刷卡!",type:"warning"},
- 200:{mean:"GetBase64PhotoData",message:"二代身份证读取失败!",type:"error"}
- },
- dealDeviceData:setting.Cert.callBack
- });
- }
-
- //工厂
- var DeviceFactory =
- {
- createDevice : function(button){
- var device;
- switch(button){
- case "Cert":
- device = new Cert();
- break;
- case "Scanner":
- device = new Scanner();
- break;
- case "Barcode":
- default:
- device = new BarcodeScanner();
- break;
- }
- return device;
- }
- }
-
- //设备通信,得到硬件返回的数据
- Device.prototype.accessDevice = function()
- {
- $("#iss").css("width","25%");
- if(browserFlag == "html5"||browserFlag == "simple")
- {
- this.ajaxAccess(this.url);
- }
- else if(browserFlag == "simple")
- {
- this.xDomainAccess(this.url);
- }
- else
- {
- if(window.console)
- {
- console.error("browserFlag is missing");
- }
- }
- };
-
- Device.prototype.startFun = function()
- {
- //创建设备
- var device = new Device();
- var myDevice = device.createDevice("Cert");
- //显示提示信息
- myDevice.setMessage();
- setting.Methods.checkWebServer(myDevice);
- };
- /*
- $.each(buttonNames, function(key, value){
- if(value)
- {
- $(document).off("click",value);
- $(document).on("click",value,function(e){
- $(value).blur();
- //创建设备
- var device = new Device();
- var myDevice = device.createDevice(key);
- //显示提示信息
- myDevice.setMessage();
- setting.Methods.checkWebServer(myDevice);
- });
- }
-
- });
- */
- setting.Methods.checkWebServer();
- }
复制代码 |
|