|
- function GetFileName(filename) {
- var startPos = filename.lastIndexOf("/");
- var ext = filename.substr(startPos + 1);
- return ext;
- }
-
- function GenerateRandom() {
- var retstr = "";
- var date = new Date();
- retstr = date.getFullYear().toString() + "-" + date.getMonth().toString() + "-" + date.getDate().toString() + "-" + date.getUTCHours().toString() + "-" + date.getUTCMinutes() + "-" + date.getUTCSeconds().toString();
- var Num = "";
- for(var i = 0; i < 6; i++) {
- Num += Math.floor(Math.random() * 10);
- }
- return retstr + Num;
- }
-
- function ChangeCurrentTab(tabid) {
- var ucenterTab = document.getElementById(tabid);
- //模拟点击
- mui.trigger(ucenterTab, 'tap');
- //切换选项卡高亮
- var current = document.querySelector(".web-tool>.active");
- if(defaultTab !== current) {
- current.classList.remove('active');
- ucenterTab.classList.add('active');
- }
- }
-
- function ReloadAllTabs() {
- if(plus.webview.currentWebview().opener() != undefined && plus.webview.currentWebview().opener() != null) {
- plus.webview.currentWebview().opener().reload(true);
- if(plus.webview.currentWebview().opener().opener() != undefined && plus.webview.currentWebview().opener().opener() != null)
- plus.webview.currentWebview().opener().opener().reload(true);
- } else
- plus.webview.currentWebview().reload(true);
- var subpages = ['index.html', 'message.html', 'kcb.html', 'kq.html', 'ucenter.html'];
- for(var i = 0; i < 5; i++) {
- plus.webview.getWebviewById(subpages[i]).reload(true);
- }
- }
- Date.prototype.Format = function(fmt) { //author: meizz
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if(/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for(var k in o)
- if(new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
-
- function formatDateTime(date) {
- var myyear = date.getFullYear();
- var mymonth = date.getMonth() + 1;
- var myweekday = date.getDate();
- var myHours = date.getHours();
- var myMinutes = date.getMinutes();
- var mySeconds = date.getSeconds();
-
- if(mymonth < 10) {
- mymonth = "0" + mymonth;
- }
- if(myweekday < 10) {
- myweekday = "0" + myweekday;
- }
- if(myHours < 10) {
- myHours = "0" + myHours;
- }
- if(myMinutes < 10) {
- myMinutes = "0" + myMinutes;
- }
- if(mySeconds < 10) {
- mySeconds = "0" + mySeconds;
- }
- //return(myyear + "-" + mymonth + "-" + myweekday + " " + myHours + ":" + myMinutes + ":" + mySeconds);
- return(myyear + "-" + mymonth + "-" + myweekday );
- }
-
- function formatDate(date) {
- var myyear = date.getFullYear();
- var mymonth = date.getMonth() + 1;
- var myweekday = date.getDate();
- var myHours = date.getHours();
- var myMinutes = date.getMinutes();
- var mySeconds = date.getSeconds();
-
- if(mymonth < 10) {
- mymonth = "0" + mymonth;
- }
- if(myweekday < 10) {
- myweekday = "0" + myweekday;
- }
- if(myHours < 10) {
- myHours = "0" + myHours;
- }
- if(myMinutes < 10) {
- myMinutes = "0" + myMinutes;
- }
- if(mySeconds < 10) {
- mySeconds = "0" + mySeconds;
- }
- return(myyear + "-" + mymonth + "-" + myweekday);
- }
-
- function jsonDateFormatDateTime(strDate) { //json日期格式转换为正常格式
- if(strDate != undefined && strDate != null) {
- var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
- function(a) {
- return parseInt(a, 10) - 1;
- }).match(/\d+/g) + ')');
- return formatDateTime(date);
- } else {
- return '';
- }
- }
-
- function jsonDateFormatDate(strDate) { //json日期格式转换为正常格式
- if(strDate != undefined && strDate != null) {
- var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
- function(a) {
- return parseInt(a, 10) - 1;
- }).match(/\d+/g) + ')');
- return formatDate(date);
- } else {
- return '';
- }
- }
-
- function getImage() {
- var c = plus.camera.getCamera();
- c.captureImage(function(e) {
- plus.io.resolveLocalFileSystemURL(e, function(entry) {
- var s = entry.toLocalURL();
- var bitmap = new plus.nativeObj.Bitmap("bighead");
- bitmap.load(s, function() {
- bitmap.save("_doc/" + GenerateRandom() + ".jpg", {
- overwrite: true,
- format: "jpg",
- quality: 100
- },
- function(event) {
- var target = event.target;
- var width = event.width; // 保存后图片的实际宽度,单位为px
- var height = event.height; // 保存后图片的实际高度,单位为px
- //裁剪
- mui.openWindow({
- url: '/User/SelectHead.html',
- id: 'SelectHead',
- extras: {
- headsrc: target,
- realwidth: width,
- realheight: height
- },
- show: {
- aniShow: 'pop-in'
- }
- });
- bitmap.clear();
- },
- function(exc) {
- console.log("save Bitmap error" + exc.message + " " + exc.code);
- });
- }, function(ex) {
- console.log("load Bitmap error" + ex.message);
- });
- }, function(e) {
- console.log("读取拍照文件错误:" + e.message);
- });
- }, function(s) {
- console.log("error" + s.message);
- }, {
- filename: "_doc/" + GenerateRandom() + ".jpg"
- });
- }
-
- function galleryImg() {
- plus.gallery.pick(function(a) {
- plus.io.resolveLocalFileSystemURL(a, function(entry) {
- var s = entry.toLocalURL();
- var bitmap = new plus.nativeObj.Bitmap("bighead");
- bitmap.load(s, function() {
- bitmap.save("_doc/" + GenerateRandom() + ".jpg", {
- overwrite: true,
- format: "jpg",
- quality: 100
- },
- function(event) {
- var target = event.target;
- var width = event.width; // 保存后图片的实际宽度,单位为px
- var height = event.height; // 保存后图片的实际高度,单位为px
- //裁剪
- mui.openWindow({
- url: '/User/SelectHead.html',
- id: 'SelectHead',
- extras: {
- headsrc: target,
- realwidth: width,
- realheight: height
- },
- show: {
- aniShow: 'pop-in'
- }
- });
- bitmap.clear();
- },
- function(exc) {
- console.log("save Bitmap error" + exc.message + " " + exc.code);
- });
- }, function(ex) {
- console.log("load Bitmap error" + ex.message);
- });
- }, function(e) {
- console.log("读取拍照文件错误:" + e.message);
- });
- }, function(a) {}, {
- filter: "image"
- })
- }
-
- function UpdateUserColumns(columns, where) {
- var xhr = new plus.net.XMLHttpRequest();
- xhr.responseType = "json";
- xhr.onreadystatechange = function() {
- switch(xhr.readyState) {
- case 4:
- if(xhr.status == 200) {
- if(xhr.response.Statu == 1) {
- plus.nativeUI.toast('修改成功。');
- plus.nativeUI.closeWaiting();
- plus.webview.currentWebview().reload();
- } else {
- plus.nativeUI.toast('出错了,请稍候再试。');
- plus.nativeUI.closeWaiting();
- }
- } else {
- plus.nativeUI.closeWaiting();
- plus.nativeUI.toast('您的网络不给力');
- }
- break;
- default:
- break;
- }
- }
- xhr.open("POST", serverdomain + "/Account/UpdateUserColumns");
- var data = "columns=" + columns + "&where=" + where + "";
- xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- xhr.send(data);
- plus.nativeUI.showWaiting("加载中...");
- }
-
- /**
- * 获取本地是否安装客户端
- **/
- function isAppInstalled(id) {
- if(id === 'qihoo' && mui.os.plus) {
- return true;
- }
- if(mui.os.android) {
- var main = plus.android.runtimeMainActivity();
- var packageManager = main.getPackageManager();
- var PackageManager = plus.android.importClass(packageManager)
- var packageName = {
- "qq": "com.tencent.mobileqq",
- "weixin": "com.tencent.mm",
- "sinaweibo": "com.sina.weibo"
- }
- try {
- return packageManager.getPackageInfo(packageName[id], PackageManager.GET_ACTIVITIES);
- } catch(e) {}
- } else {
- switch(id) {
- case "qq":
- var TencentOAuth = plus.ios.import("TencentOAuth");
- return TencentOAuth.iphoneQQInstalled();
- case "weixin":
- var WXApi = plus.ios.import("WXApi");
- return WXApi.isWXAppInstalled()
- case "sinaweibo":
- var SinaAPI = plus.ios.import("WeiboSDK");
- return SinaAPI.isWeiboAppInstalled()
- default:
- break;
- }
- }
- }
-
- /*获取指定字典的列表*/
- function GetDictionaryData(userPicker, dicttypecode) {
- mui.post(api+'/user/getdataitem',{data:dicttypecode},function(res){
- if(res.code=="200"){
- userPicker.setData(ChangeJsonObjectPropertyToValueText(res.data, "dict"))
- }
- })
- }
-
- function GetDictionaryDataBySource(userPicker, dicttypecode) {
-
- mui.post(api+'/user/getCultureInfo',{data:dicttypecode},function(res){//
- if(res.code=="200"){
-
- userPicker.setData(ChangeJsonObjectPropertyToValueText(res.data, "dict"))
- }
- },'json')
- }
- /*获取校区的列表*/
- function GetSchoolData(userPicker) {
- mui.get(api+'/user/getcompany',{},function(res){
- if(res.code=="200"){
-
- userPicker.setData(ChangeJsonObjectPropertyToValueText(res.data, "school"))
- }
- })
- }
-
- /*获取专业列表*/
- function GetDepartData(userPicker, schoolid, whcdid) {
- plus.nativeUI.showWaiting("加载中...");
- mui.post(api+'/user/getmajor',{data:schoolid},function(res){
- plus.nativeUI.closeWaiting()
- if(res.code=="200"){
- userPicker.setData(ChangeJsonObjectPropertyToValueText(res.data, "depart"));
- }else{
- plus.nativeUI.toast("该校区无专业。");
- userPicker.setData(null);
- }
- },'json');
- }
- /*返回字典数据重新组装*/
- function ChangeJsonObjectPropertyToValueText(oldjsonlist, typename) {
- var newlist = new Array();
- if(oldjsonlist.length > 0) {
- for(var iobj in oldjsonlist) {
- var newobj = {};
- if(typename == "dict") {
- newobj.value = oldjsonlist[iobj].dicentryid;
- newobj.text = oldjsonlist[iobj].name;
- }
- if(typename == "school") {
- newobj.value = oldjsonlist[iobj].schoolID;
- newobj.text = oldjsonlist[iobj].school;
- }
- if(typename == "depart") {
- newobj.value = oldjsonlist[iobj].departID;
- newobj.text = oldjsonlist[iobj].depart;
- }
- if(typename == "province") {
- newobj.value = oldjsonlist[iobj].ProID;
- newobj.text = oldjsonlist[iobj].name;
- }
- if(typename == "city") {
- newobj.value = oldjsonlist[iobj].CityID;
- newobj.text = oldjsonlist[iobj].name;
- }
- if(typename == "area") {
- newobj.value = oldjsonlist[iobj].Id;
- newobj.text = oldjsonlist[iobj].name;
- }
- newlist.push(newobj);
- }
- }
-
- return newlist;
- }
-
- function isIdCardNo(num) {
- num = num.toUpperCase(); //身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X。
- if(!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) {
- //alert('输入的身份证号长度不对,或者号码不符合规定!\n15位号码应全为数字,18位号码末位可以为数字或X。');
- alert('身份证号长度不正确或不符合规定!');
- return false;
- }
- //验证前2位,城市符合
- var aCity = {
- 11: "北京",
- 12: "天津",
- 13: "河北",
- 14: "山西",
- 15: "内蒙古",
- 21: "辽宁",
- 22: "吉林",
- 23: "黑龙江 ",
- 31: "上海",
- 32: "江苏",
- 33: "浙江",
- 34: "安徽",
- 35: "福建",
- 36: "江西",
- 37: "山东",
- 41: "河南",
- 42: "湖北",
- 43: "湖南",
- 44: "广东",
- 45: "广西",
- 46: "海南",
- 50: "重庆",
- 51: "四川",
- 52: "贵州",
- 53: "云南",
- 54: "西藏",
- 61: "陕西",
- 62: "甘肃",
- 63: "青海",
- 64: "宁夏",
- 65: "新疆",
- 71: "台湾",
- 81: "香港",
- 82: "澳门",
- 91: "国外"
- };
- if(aCity[parseInt(num.substr(0, 2))] == null) {
- alert('身份证号不正确或不符合规定!');
- return false;
- }
- //alert('城市:'+aCity[parseInt(num.substr(0,2))]);
-
- //下面分别分析出生日期和校验位
- var len, re;
- len = num.length;
- if(len == 15) {
- re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
- var arrSplit = num.match(re); //检查生日日期是否正确
- var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
- var bGoodDay;
- bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
- if(!bGoodDay) {
- alert('身份证号的出生日期不对!');
- return false;
- } else { //将15位身份证转成18位 //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
- var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
- var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
- var nTemp = 0,
- i;
- num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);
- for(i = 0; i < 17; i++) {
- nTemp += num.substr(i, 1) * arrInt[i];
- }
- num += arrCh[nTemp % 11];
- return true;
- }
- }
- if(len == 18) {
- re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
- var arrSplit = num.match(re); //检查生日日期是否正确
- var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
- var bGoodDay;
- bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
- if(!bGoodDay) {
- //alert(dtmBirth.getYear());
- //alert(arrSplit[2]);
- alert('身份证号的出生日期不对!');
- return false;
- } else { //检验18位身份证的校验码是否正确。 //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
- var valnum;
- var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
- var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
- var nTemp = 0,
- i;
- for(i = 0; i < 17; i++) {
- nTemp += num.substr(i, 1) * arrInt[i];
- }
- valnum = arrCh[nTemp % 11];
- if(valnum != num.substr(17, 1)) {
- //alert('18位身份证的校验码不正确!应该为:' + valnum);
- alert('18位身份证号的校验码不正确!');
- return false;
- }
- return true;
- }
- }
- return false;
- }
|