common.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. var issOnlineUrl = "http://127.0.0.1:24010/ZKIDROnline";
  2. var browserFlag = getBrowserType();
  3. /*
  4. $().ready(function(){
  5. $(document).off("DOMNodeInserted","#cert_message_type");
  6. $("#cert_message_type").on("DOMNodeInserted",function(e){
  7. openMessage($("#cert_message_type").text(), $("#cert_message").text());
  8. });
  9. });
  10. */
  11. //身份证
  12. //includeScript("baseISSObject.js", function(){
  13. //includeScript("baseISSOnline.js", function(){
  14. var setting = {
  15. Cert : {
  16. callBack : function(result){
  17. setCertificateData(result);
  18. },
  19. select : "#button_readID"
  20. },
  21. Methods : {
  22. showMessage : function(type,message){
  23. $("#cert_message").text(message);
  24. $("#cert_message_type").text(msgType[type]);
  25. },
  26. downloadDrive : function(){
  27. $.jBox.closeTip();
  28. messageBox({messageType: "confirm", text: "请安装相关硬件驱动!点击确定下载驱动。",
  29. callback: function(result){
  30. if(result)
  31. {
  32. window.location.href = "middleware/ZKIDROnline.exe";
  33. }
  34. closeMessage();
  35. }});
  36. }
  37. }
  38. }
  39. createISSonlineDevice(setting);
  40. //});
  41. //});
  42. function setCertificateData(result)
  43. {
  44. //$("#birthDay").val(result.Certificate.Birthday.replace(/\./g,"-").substr(0,10));
  45. var birthday=result.Certificate.Birthday;
  46. $("#birthDay").val(birthday.substring(0,4)+"-"+birthday.substring(4,6)+"-"+birthday.substring(6));
  47. var returnAge=jsGetAge($("#birthDay").val());
  48. $("#age").val(returnAge);
  49. $("#idCard").val(result.Certificate.IDNumber);
  50. //$("#idIssued").val(result.Certificate.IDIssued);
  51. //$("#issuedValidDate").val(result.Certificate.IssuedData+"-"+result.Certificate.ValidDate);
  52. // imgData =result.Certificate.Base64Photo;
  53. // $("#id_img_pers").attr("src","data:image/jpg;base64,"+imgData);
  54. // $("#personIdPhoto").val(imgData);
  55. // $("#personPhoto").val("");
  56. $("#userName").val(result.Certificate.Name);
  57. if(result.Certificate.Sex=="男"){
  58. $("#gender").val(1);
  59. $('#gender').selectpicker('refresh');
  60. }else if(result.Certificate.Sex=="女"){
  61. $("#gender").val(2);
  62. $('#gender').selectpicker('refresh');
  63. }
  64. //$("#nation").val(result.Certificate.Nation);
  65. $("#address").val(result.Certificate.Address);
  66. }
  67. function getRandomNum()
  68. {
  69. var random = parseInt(Math.random() * 10000);
  70. return random;
  71. }
  72. //消息控件的使用类型的类
  73. var msgType =
  74. {
  75. info : "info",
  76. success : "success",
  77. warning : "warning",
  78. error : "error",
  79. loading : "loading"
  80. };
  81. function getBrowserType()
  82. {
  83. var browserFlag = "";
  84. //是否支持html5的cors跨域
  85. if (typeof(Worker) !== "undefined")
  86. {
  87. browserFlag = "html5";
  88. }
  89. //此处判断ie8、ie9
  90. else if(navigator.userAgent.indexOf("MSIE 7.0")>0||navigator.userAgent.indexOf("MSIE 8.0")>0 || navigator.userAgent.indexOf("MSIE 9.0")>0)
  91. {
  92. browserFlag = "simple";
  93. }
  94. else
  95. {
  96. browserFlag = "upgradeBrowser";//当前浏览器不支持该功能,请升级浏览器
  97. }
  98. return browserFlag;
  99. }
  100. function openMessage(type, text, ptimeout)
  101. {
  102. text = (text == "" ? null : text);
  103. var timeout = 1000;
  104. if(type == msgType.warning || type == msgType.info)//警告
  105. {
  106. timeout = 3000;
  107. }
  108. else if(type == msgType.success)//成功
  109. {
  110. text = (text && text != null ? text : "操作成功");//${common_op_succeed}:操作成功
  111. var num = strlen(text)/30;
  112. num = num > 8 ? 8 : num;
  113. timeout = Math.ceil(num) * timeout;//动态判断显示字符数的长度来延长显示时间
  114. }
  115. else if(type == msgType.error)//失败
  116. {
  117. text = (text && text != null) ? text : "操作失败";//${common_op_failed}:操作失败,程序出现异常
  118. timeout = 3000;
  119. }
  120. else if(type == msgType.loading)//处理中
  121. {
  122. timeout = 0;//当为'loading'时,timeout值会被设置为0,表示不会自动关闭。
  123. text = text && text != null ? text : "处理中";//${common_op_processing}:处理中
  124. }
  125. var width = strlen(text) * 6.1 + 45;//按字符计算宽度
  126. timeout = ptimeout ? ptimeout : timeout;
  127. $.jBox.tip(text, type,{timeout: timeout, width: (width > 400 ? 400 : "auto")});//设定最大宽度为400
  128. }
  129. function closeMessage(timeout)
  130. {
  131. timeout = timeout ? timeout : 1000;
  132. window.setTimeout("$.jBox.closeTip();", timeout);//设定最小等待时间
  133. }
  134. function strlen(str)
  135. {
  136. var len = 0;
  137. if(str != null)
  138. {
  139. for (var i=0; i<str.length; i++)
  140. {
  141. var c = str.charCodeAt(i);
  142. if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f))
  143. {
  144. len++;
  145. }
  146. else
  147. {
  148. len+=2;
  149. }
  150. }
  151. }
  152. return len;
  153. }
  154. function messageBox(paramsJson)
  155. {
  156. this.messageType = paramsJson.messageType ? $.trim(paramsJson.messageType) : "confirm";
  157. this.types = "";
  158. if(paramsJson.type)
  159. {
  160. this.typeArray = paramsJson.type.split(" ");
  161. for(var i=0; i<this.typeArray.length; i++)
  162. {
  163. this.types += this.typeArray[i]+" ";
  164. }
  165. }
  166. switch(this.messageType)
  167. {
  168. case "confirm":
  169. $.jBox.confirm(paramsJson.text, "提示", function(v, h, f) {
  170. if (v == "ok")
  171. {
  172. paramsJson.callback(true);
  173. }
  174. });
  175. break;
  176. }
  177. }
  178. /**
  179. * 根据出生日期算出年龄
  180. * @param strBirthday
  181. * @returns {number}
  182. */
  183. function jsGetAge(strBirthday) {
  184. var returnAge;
  185. var strBirthdayArr = strBirthday.split("-");
  186. var birthYear = strBirthdayArr[0];
  187. var birthMonth = strBirthdayArr[1];
  188. var birthDay = strBirthdayArr[2];
  189. d = new Date();
  190. var nowYear = d.getFullYear();
  191. var nowMonth = d.getMonth() + 1;
  192. var nowDay = d.getDate();
  193. if (nowYear == birthYear) {
  194. returnAge = 0;//同年 则为0岁
  195. }
  196. else {
  197. var ageDiff = nowYear - birthYear; //年之差
  198. if (ageDiff > 0) {
  199. if (nowMonth == birthMonth) {
  200. var dayDiff = nowDay - birthDay;//日之差
  201. if (dayDiff < 0) {
  202. returnAge = ageDiff - 1;
  203. }
  204. else {
  205. returnAge = ageDiff;
  206. }
  207. }
  208. else {
  209. var monthDiff = nowMonth - birthMonth;//月之差
  210. if (monthDiff < 0) {
  211. returnAge = ageDiff - 1;
  212. }
  213. else {
  214. returnAge = ageDiff;
  215. }
  216. }
  217. }
  218. else {
  219. returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天
  220. }
  221. }
  222. return returnAge;//返回周岁年龄
  223. }