You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

529 lines
16 KiB

  1. function GetFileName(filename) {
  2. var startPos = filename.lastIndexOf("/");
  3. var ext = filename.substr(startPos + 1);
  4. return ext;
  5. }
  6. function GenerateRandom() {
  7. var retstr = "";
  8. var date = new Date();
  9. retstr = date.getFullYear().toString() + "-" + date.getMonth().toString() + "-" + date.getDate().toString() + "-" + date.getUTCHours().toString() + "-" + date.getUTCMinutes() + "-" + date.getUTCSeconds().toString();
  10. var Num = "";
  11. for(var i = 0; i < 6; i++) {
  12. Num += Math.floor(Math.random() * 10);
  13. }
  14. return retstr + Num;
  15. }
  16. function getImage() {
  17. var c = plus.camera.getCamera();
  18. c.captureImage(function(e) {
  19. plus.io.resolveLocalFileSystemURL(e, function(entry) {
  20. var s = entry.toLocalURL();
  21. var bitmap = new plus.nativeObj.Bitmap("bighead");
  22. bitmap.load(s, function() {
  23. bitmap.save("_doc/" + GenerateRandom() + ".jpg", {
  24. overwrite: true,
  25. format: "jpg",
  26. quality: 100
  27. },
  28. function(event) {
  29. var target = event.target;
  30. var width = event.width; // 保存后图片的实际宽度,单位为px
  31. var height = event.height; // 保存后图片的实际高度,单位为px
  32. //裁剪
  33. mui.openWindow({
  34. url: '/User/SelectHead.html',
  35. id: 'SelectHead',
  36. extras: {
  37. headsrc: target,
  38. realwidth: width,
  39. realheight: height
  40. },
  41. show: {
  42. aniShow: 'pop-in'
  43. }
  44. });
  45. bitmap.clear();
  46. },
  47. function(exc) {
  48. console.log("save Bitmap error" + exc.message + " " + exc.code);
  49. });
  50. }, function(ex) {
  51. console.log("load Bitmap error" + ex.message);
  52. });
  53. }, function(e) {
  54. console.log("读取拍照文件错误:" + e.message);
  55. });
  56. }, function(s) {
  57. console.log("error" + s.message);
  58. }, {
  59. filename: "_doc/" + GenerateRandom() + ".jpg"
  60. });
  61. }
  62. function galleryImg() {
  63. plus.gallery.pick(function(a) {
  64. plus.io.resolveLocalFileSystemURL(a, function(entry) {
  65. var s = entry.toLocalURL();
  66. var bitmap = new plus.nativeObj.Bitmap("bighead");
  67. bitmap.load(s, function() {
  68. bitmap.save("_doc/" + GenerateRandom() + ".jpg", {
  69. overwrite: true,
  70. format: "jpg",
  71. quality: 100
  72. },
  73. function(event) {
  74. var target = event.target;
  75. var width = event.width; // 保存后图片的实际宽度,单位为px
  76. var height = event.height; // 保存后图片的实际高度,单位为px
  77. //裁剪
  78. mui.openWindow({
  79. url: '/User/SelectHead.html',
  80. id: 'SelectHead',
  81. extras: {
  82. headsrc: target,
  83. realwidth: width,
  84. realheight: height
  85. },
  86. show: {
  87. aniShow: 'pop-in'
  88. }
  89. });
  90. bitmap.clear();
  91. },
  92. function(exc) {
  93. console.log("save Bitmap error" + exc.message + " " + exc.code);
  94. });
  95. }, function(ex) {
  96. console.log("load Bitmap error" + ex.message);
  97. });
  98. }, function(e) {
  99. console.log("读取拍照文件错误:" + e.message);
  100. });
  101. }, function(a) {}, {
  102. filter: "image"
  103. })
  104. }
  105. function ChangeCurrentTab(tabid) {
  106. var ucenterTab = document.getElementById(tabid);
  107. //模拟点击
  108. mui.trigger(ucenterTab, 'tap');
  109. //切换选项卡高亮
  110. var current = document.querySelector(".web-tool>.active");
  111. if(defaultTab !== current) {
  112. current.classList.remove('active');
  113. ucenterTab.classList.add('active');
  114. }
  115. }
  116. function ReloadAllTabs() {
  117. if(plus.webview.currentWebview().opener() != undefined && plus.webview.currentWebview().opener() != null) {
  118. plus.webview.currentWebview().opener().reload(true);
  119. if(plus.webview.currentWebview().opener().opener() != undefined && plus.webview.currentWebview().opener().opener() != null)
  120. plus.webview.currentWebview().opener().opener().reload(true);
  121. } else
  122. plus.webview.currentWebview().reload(true);
  123. var subpages = ['index.html', 'message.html', 'kcb.html', 'kq.html', 'ucenter.html'];
  124. for(var i = 0; i < 5; i++) {
  125. plus.webview.getWebviewById(subpages[i]).reload(true);
  126. }
  127. }
  128. Date.prototype.Format = function(fmt) { //author: meizz
  129. var o = {
  130. "M+": this.getMonth() + 1, //月份
  131. "d+": this.getDate(), //日
  132. "h+": this.getHours(), //小时
  133. "m+": this.getMinutes(), //分
  134. "s+": this.getSeconds(), //秒
  135. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  136. "S": this.getMilliseconds() //毫秒
  137. };
  138. if(/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  139. for(var k in o)
  140. if(new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  141. return fmt;
  142. }
  143. function formatDateTime(date) {
  144. var myyear = date.getFullYear();
  145. var mymonth = date.getMonth() + 1;
  146. var myweekday = date.getDate();
  147. var myHours = date.getHours();
  148. var myMinutes = date.getMinutes();
  149. var mySeconds = date.getSeconds();
  150. if(mymonth < 10) {
  151. mymonth = "0" + mymonth;
  152. }
  153. if(myweekday < 10) {
  154. myweekday = "0" + myweekday;
  155. }
  156. if(myHours < 10) {
  157. myHours = "0" + myHours;
  158. }
  159. if(myMinutes < 10) {
  160. myMinutes = "0" + myMinutes;
  161. }
  162. if(mySeconds < 10) {
  163. mySeconds = "0" + mySeconds;
  164. }
  165. return(myyear + "-" + mymonth + "-" + myweekday + " " + myHours + ":" + myMinutes + ":" + mySeconds);
  166. }
  167. function formatDate(date) {
  168. var myyear = date.getFullYear();
  169. var mymonth = date.getMonth() + 1;
  170. var myweekday = date.getDate();
  171. var myHours = date.getHours();
  172. var myMinutes = date.getMinutes();
  173. var mySeconds = date.getSeconds();
  174. if(mymonth < 10) {
  175. mymonth = "0" + mymonth;
  176. }
  177. if(myweekday < 10) {
  178. myweekday = "0" + myweekday;
  179. }
  180. if(myHours < 10) {
  181. myHours = "0" + myHours;
  182. }
  183. if(myMinutes < 10) {
  184. myMinutes = "0" + myMinutes;
  185. }
  186. if(mySeconds < 10) {
  187. mySeconds = "0" + mySeconds;
  188. }
  189. return(myyear + "-" + mymonth + "-" + myweekday);
  190. }
  191. function jsonDateFormatDateTime(strDate) { //json日期格式转换为正常格式
  192. if(strDate != undefined && strDate != null) {
  193. var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
  194. function(a) {
  195. return parseInt(a, 10) - 1;
  196. }).match(/\d+/g) + ')');
  197. return formatDateTime(date);
  198. } else {
  199. return '';
  200. }
  201. }
  202. function jsonDateFormatDate(strDate) { //json日期格式转换为正常格式
  203. if(strDate != undefined && strDate != null) {
  204. var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
  205. function(a) {
  206. return parseInt(a, 10) - 1;
  207. }).match(/\d+/g) + ')');
  208. return formatDate(date);
  209. } else {
  210. return '';
  211. }
  212. }
  213. function UpdateUserColumns(columns, where) {
  214. var xhr = new plus.net.XMLHttpRequest();
  215. xhr.responseType = "json";
  216. xhr.onreadystatechange = function() {
  217. switch(xhr.readyState) {
  218. case 4:
  219. if(xhr.status == 200) {
  220. if(xhr.response.Statu == 1) {
  221. plus.nativeUI.toast('修改成功。');
  222. plus.nativeUI.closeWaiting();
  223. plus.webview.currentWebview().reload();
  224. } else {
  225. plus.nativeUI.toast('出错了,请稍候再试。');
  226. plus.nativeUI.closeWaiting();
  227. }
  228. } else {
  229. plus.nativeUI.closeWaiting();
  230. plus.nativeUI.toast('您的网络不给力');
  231. }
  232. break;
  233. default:
  234. break;
  235. }
  236. }
  237. xhr.open("POST", serverdomain + "/Account/UpdateUserColumns");
  238. var data = "columns=" + columns + "&where=" + where + "";
  239. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  240. xhr.send(data);
  241. plus.nativeUI.showWaiting("加载中...");
  242. }
  243. /**
  244. * 获取本地是否安装客户端
  245. **/
  246. function isAppInstalled(id) {
  247. if(id === 'qihoo' && mui.os.plus) {
  248. return true;
  249. }
  250. if(mui.os.android) {
  251. var main = plus.android.runtimeMainActivity();
  252. var packageManager = main.getPackageManager();
  253. var PackageManager = plus.android.importClass(packageManager)
  254. var packageName = {
  255. "qq": "com.tencent.mobileqq",
  256. "weixin": "com.tencent.mm",
  257. "sinaweibo": "com.sina.weibo"
  258. }
  259. try {
  260. return packageManager.getPackageInfo(packageName[id], PackageManager.GET_ACTIVITIES);
  261. } catch(e) {}
  262. } else {
  263. switch(id) {
  264. case "qq":
  265. var TencentOAuth = plus.ios.import("TencentOAuth");
  266. return TencentOAuth.iphoneQQInstalled();
  267. case "weixin":
  268. var WXApi = plus.ios.import("WXApi");
  269. return WXApi.isWXAppInstalled()
  270. case "sinaweibo":
  271. var SinaAPI = plus.ios.import("WeiboSDK");
  272. return SinaAPI.isWeiboAppInstalled()
  273. default:
  274. break;
  275. }
  276. }
  277. }
  278. /*获取指定字典的列表*/
  279. function GetDictionaryData(userPicker, dicttypecode) {
  280. // var xhr = new plus.net.XMLHttpRequest();
  281. // xhr.responseType = "json";
  282. // xhr.onreadystatechange = function() {
  283. // switch(xhr.readyState) {
  284. // case 4:
  285. // if(xhr.status == 200) {
  286. // console.log(JSON.stringify(xhr.response.msg));
  287. // userPicker.setData(ChangeJsonObjectPropertyToValueText(xhr.response.msg, "dict"));
  288. // } else {}
  289. // break;
  290. // default:
  291. // break;
  292. // }
  293. // }
  294. // xhr.open("GET", encodeURI(serverdomain + "/WebService/UserService.ashx?Action=dicEntry&content={'dictypeid':'" + dicttypecode + "'}"));
  295. // xhr.send();
  296. mui.post(api+'/user/getdataitem',{data:dicttypecode},function(res){
  297. if(res.code=="200"){
  298. console.log(JSON.stringify(res.data))
  299. userPicker.setData(ChangeJsonObjectPropertyToValueText(res.data, "dict"))
  300. }
  301. })
  302. }
  303. function GetDictionaryDataBySource(userPicker, dicttypecode) {
  304. mui.post(api+'/user/getCultureInfo',{data:dicttypecode},function(res){//
  305. if(res.code=="200"){
  306. userPicker.setData(ChangeJsonObjectPropertyToValueText(res.data, "dict"))
  307. }
  308. },'json')
  309. }
  310. /*获取校区的列表*/
  311. function GetSchoolData(userPicker) {
  312. // var xhr = new plus.net.XMLHttpRequest();
  313. // xhr.responseType = "json";
  314. // xhr.onreadystatechange = function() {
  315. // switch(xhr.readyState) {
  316. // case 4:
  317. // if(xhr.status == 200) {
  318. // console.log(JSON.stringify(xhr.response.msg));
  319. // userPicker.setData(ChangeJsonObjectPropertyToValueText(xhr.response.msg, "school"));
  320. // } else {}
  321. // break;
  322. // default:
  323. // break;
  324. // }
  325. // }
  326. // xhr.open("GET", encodeURI(serverdomain + "/WebService/UserService.ashx?Action=getSchoolArea&content={'app':'1'}"));
  327. // xhr.send();
  328. mui.get(api+'/user/getcompany',{},function(res){
  329. if(res.code=="200"){
  330. userPicker.setData(ChangeJsonObjectPropertyToValueText(res.data, "school"))
  331. }
  332. })
  333. }
  334. /*获取专业列表*/
  335. function GetDepartData(userPicker, schoolid, whcdid) {
  336. //plus.nativeUI.showWaiting("加载中...");
  337. // var xhrdepart = new plus.net.XMLHttpRequest();
  338. // xhrdepart.responseType = "json";
  339. // xhrdepart.onreadystatechange = function() {
  340. // switch(xhrdepart.readyState) {
  341. // case 4:
  342. // if(xhrdepart.status == 200) {
  343. // plus.nativeUI.closeWaiting();
  344. // userPicker.setData(ChangeJsonObjectPropertyToValueText(xhrdepart.response.msg, "depart"));
  345. // } else {
  346. // plus.nativeUI.closeWaiting();
  347. // }
  348. // break;
  349. // default:
  350. // break;
  351. // }
  352. // }
  353. // xhrdepart.open("GET", encodeURI(serverdomain + "/WebService/UserService.ashx?Action=getDepartsByName&content={'school':'" + schoolid + "','culture':'" + whcdid + "','app':'1'}"));
  354. // xhrdepart.send();
  355. console.log(schoolid)
  356. mui.post(api+'/user/getmajor',{data:schoolid},function(res){
  357. plus.nativeUI.closeWaiting()
  358. if(res.code=="200"){
  359. console.log(JSON.stringify(res.data));
  360. userPicker.setData(ChangeJsonObjectPropertyToValueText(res.data, "depart"));
  361. }
  362. },'json');
  363. }
  364. /*返回字典数据重新组装*/
  365. function ChangeJsonObjectPropertyToValueText(oldjsonlist, typename) {
  366. var newlist = new Array();
  367. if(oldjsonlist.length > 0) {
  368. for(var iobj in oldjsonlist) {
  369. var newobj = {};
  370. if(typename == "dict") {
  371. newobj.value = oldjsonlist[iobj].dicentryid;
  372. newobj.text = oldjsonlist[iobj].name;
  373. }
  374. if(typename == "school") {
  375. newobj.value = oldjsonlist[iobj].schoolID;
  376. newobj.text = oldjsonlist[iobj].school;
  377. }
  378. if(typename == "depart") {
  379. newobj.value = oldjsonlist[iobj].departID;
  380. newobj.text = oldjsonlist[iobj].depart;
  381. }
  382. if(typename == "province") {
  383. newobj.value = oldjsonlist[iobj].ProID;
  384. newobj.text = oldjsonlist[iobj].name;
  385. }
  386. if(typename == "city") {
  387. newobj.value = oldjsonlist[iobj].CityID;
  388. newobj.text = oldjsonlist[iobj].name;
  389. }
  390. if(typename == "area") {
  391. newobj.value = oldjsonlist[iobj].Id;
  392. newobj.text = oldjsonlist[iobj].name;
  393. }
  394. newlist.push(newobj);
  395. }
  396. }
  397. return newlist;
  398. }
  399. function isIdCardNo(num) {
  400. num = num.toUpperCase(); //身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X。
  401. if(!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) {
  402. //alert('输入的身份证号长度不对,或者号码不符合规定!\n15位号码应全为数字,18位号码末位可以为数字或X。');
  403. alert('身份证号长度不正确或不符合规定!');
  404. return false;
  405. }
  406. //验证前2位,城市符合
  407. var aCity = {
  408. 11: "北京",
  409. 12: "天津",
  410. 13: "河北",
  411. 14: "山西",
  412. 15: "内蒙古",
  413. 21: "辽宁",
  414. 22: "吉林",
  415. 23: "黑龙江 ",
  416. 31: "上海",
  417. 32: "江苏",
  418. 33: "浙江",
  419. 34: "安徽",
  420. 35: "福建",
  421. 36: "江西",
  422. 37: "山东",
  423. 41: "河南",
  424. 42: "湖北",
  425. 43: "湖南",
  426. 44: "广东",
  427. 45: "广西",
  428. 46: "海南",
  429. 50: "重庆",
  430. 51: "四川",
  431. 52: "贵州",
  432. 53: "云南",
  433. 54: "西藏",
  434. 61: "陕西",
  435. 62: "甘肃",
  436. 63: "青海",
  437. 64: "宁夏",
  438. 65: "新疆",
  439. 71: "台湾",
  440. 81: "香港",
  441. 82: "澳门",
  442. 91: "国外"
  443. };
  444. if(aCity[parseInt(num.substr(0, 2))] == null) {
  445. alert('身份证号不正确或不符合规定!');
  446. return false;
  447. }
  448. //alert('城市:'+aCity[parseInt(num.substr(0,2))]);
  449. //下面分别分析出生日期和校验位
  450. var len, re;
  451. len = num.length;
  452. if(len == 15) {
  453. re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
  454. var arrSplit = num.match(re); //检查生日日期是否正确
  455. var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
  456. var bGoodDay;
  457. bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
  458. if(!bGoodDay) {
  459. alert('身份证号的出生日期不对!');
  460. return false;
  461. } else { //将15位身份证转成18位 //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  462. var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
  463. var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
  464. var nTemp = 0,
  465. i;
  466. num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);
  467. for(i = 0; i < 17; i++) {
  468. nTemp += num.substr(i, 1) * arrInt[i];
  469. }
  470. num += arrCh[nTemp % 11];
  471. return true;
  472. }
  473. }
  474. if(len == 18) {
  475. re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
  476. var arrSplit = num.match(re); //检查生日日期是否正确
  477. var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
  478. var bGoodDay;
  479. bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
  480. if(!bGoodDay) {
  481. //alert(dtmBirth.getYear());
  482. //alert(arrSplit[2]);
  483. alert('身份证号的出生日期不对!');
  484. return false;
  485. } else { //检验18位身份证的校验码是否正确。 //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  486. var valnum;
  487. var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
  488. var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
  489. var nTemp = 0,
  490. i;
  491. for(i = 0; i < 17; i++) {
  492. nTemp += num.substr(i, 1) * arrInt[i];
  493. }
  494. valnum = arrCh[nTemp % 11];
  495. if(valnum != num.substr(17, 1)) {
  496. //alert('18位身份证的校验码不正确!应该为:' + valnum);
  497. alert('18位身份证号的校验码不正确!');
  498. return false;
  499. }
  500. return true;
  501. }
  502. }
  503. return false;
  504. }