1. 程式人生 > >通用方法(常規一)

通用方法(常規一)

前言:

function setCookie(c_name, value, expiredays) {
	var exdate = new Date()
	exdate.setDate(exdate.getDate() + expiredays)
	document.cookie = c_name + "=" + escape(value) +
		((expiredays == null) ? "" : "; expires=" + exdate.toGMTString())
}

function getCookie(c_name) {
	if(document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=")
		if(c_start != -1) {
			c_start = c_start + c_name.length + 1
			c_end = document.cookie.indexOf(";", c_start)
			if(c_end == -1) c_end = document.cookie.length
			return unescape(document.cookie.substring(c_start, c_end))
		}
	}
	return ""
}

var SDHF = SDHF || {};
SDHF.showHead = function(theadarr, obj) { //顯示錶頭
	var theadhtml = '';
	for(var i = 0, len = theadarr.length; i < len; i++) {
		theadhtml += '<p class="w' + i + '" title="' + theadarr[i] + '">' + theadarr[i] + '</p> ';
	}
	$(obj).html(theadhtml);
};
SDHF.showHeadind = function(theadarr, obj) { //顯示錶頭綜合分析
	var theadhtml = '';
	for(var i = 0, len = theadarr.length; i < len; i++) {
		theadhtml += '<p class="w' + i + '" title="' + theadarr[i] + '">' + theadarr[i] + '</p> ';
	}
	$(obj).html(theadhtml);
	return theadhtml;
};
SDHF.showload = function() {
	layui.use('layer', function() {
		index = layer.load(2, {
			shade: [0.1, '#fff'] //0.1透明度的白色背景
		});
	})
};
SDHF.hideload = function() {
	layui.use('layer', function() {
		layer.close(index);
	})
};
SDHF.norows = function() {
	var norowshtml = '<tr><td colspan="' + num + '">暫無資料</td></tr>';
	return norowshtml;
};
SDHF.norows2 = function(num) {
	var norowshtml = '<div class="tr"><p  style="width: 100%;"> 暫無資料</p></div>';
	return norowshtml;
};
SDHF.errer = function(text) {
	layui.use('layer', function() {
		layer.msg(text = undefined ? "失敗了~" : text, {
			icon: 5,
			time: 2000
		});
	})
};
SDHF.getRequest = function() {
	var urls = window.location.search;
	var theRequest = new Object();
	if(urls.indexOf("?") != -1) {
		var str = urls.substr(1),
			strs = str.split("&");
		for(var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
};
SDHF.isgetpage = function(totalPage, num) //總頁數,當前頁(返回為true的時候去執行)
{
	var a = true;
	if(GAME.currentpage == num) {
		if(num == 1) {
			layui.use('layer', function() {
				layer.msg("已經是第一頁啦~", {
					icon: 5,
					time: 2000
				});
			})
		} else if(totalPage == num) {
			layui.use('layer', function() {
				layer.msg("已經是最後一頁啦~", {
					icon: 5,
					time: 2000
				});
			})
		} else {
			layui.use('layer', function() {
				layer.msg("已經到當前頁啦~", {
					icon: 5,
					time: 2000
				});
			})
		}
		a = false;
	}

	return a;
}
SDHF.show404 = function() {
	$(".messlistbox").html(`<img src="img/zwsj.png" />`)
}
SDHF.cookie = function() {
	var cookie = false;
	if(getCookie("username") != "") {
		cookie = true;
	}
	return cookie;
}
SDHF.islogin = function() {
	var cookie = false;
	if(sessionStorage.getItem('userid') != null) {
		cookie = true;
	}
	return cookie;
}

SDHF.ischeckUser = function(str) { //賬號
	var a = true;
	var re = /^[a-zA-z]\w{3,15}$/;
	if(!re.test(str)) {
		layer.msg("賬號請輸入字母、數字或下劃線,字母開頭,4-16位", {
			icon: 0,
			time: 6000
		});
		a = false;
	}
	return a;
};
SDHF.iscard = function(str) { //身份證
	var a = true;
	var re = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
	if(!re.test(str)) {
		layer.msg("請輸入正確的身份證格式!", {
			icon: 0,
			time: 1700
		});
		a = false;
	}
	return a;

};
SDHF.nosql = function(str) { //賬號
	var a = true;
	var re = /select|update|delete|exec|count|’|"|=|;|>|<|%|'/i;
	if(re.test(str)) {
		layer.msg("暱稱或賬號不能輸入特殊字元.", {
			icon: 0,
			time: 6000
		});
		a = false;
	}
	return a;
};
SDHF.isemail = function(str) { //郵箱
	var a = true;
	var re = /^(\w-*\.*)
[email protected]
(\w-?)+(\.\w{2,})+$/; if(!re.test(str)) { layer.msg("請輸入正確的郵箱格式", { icon: 0, time: 2000 }); a = false; } return a; }; SDHF.isyesname = function(str) { //姓名 var a = true; var re = /^[\u0391-\uFFE5A-Za-z]+$/; if(!re.test(str)) { layer.msg("請輸入中文或英文名稱", { icon: 0, time: 2000 }); a = false; } return a; }; SDHF.isphone = function(str) { //手機 var a = true; var re = /^1\d{10}$/; if(!re.test(str)) { layer.msg("請輸入以1開頭的11位手機號", { icon: 0, time: 2000 }); a = false; } return a; }; SDHF.istxt = function(name) { //顯示錶頭 if(name == "") { layer.msg("請輸入搜尋內容", { icon: 0, time: 2000 }); return false; } else { return true; } }; SDHF.notxt = function(obj) { //顯示錶頭 $(obj).val(''); }; //SDHF.showHead = function(theadarr) {//顯示錶頭 // var theadhtml=''; // for(var i=0,len=theadarr.length;i<len;i++){ // theadhtml+='<p class="w'+i+'">'+theadarr[i]+'</p> '; // } // $(".thead .tr").html(theadhtml); //}; SDHF.showW = function(warr) { //顯示錶格每一項寬度 for(var i = 0, len = warr.length; i < len; i++) { $(".w" + i).css("width", warr[i] + '%'); } }; SDHF.getAdminbtns = function(arr, txt) { //顯示錶格每一項寬度 var btnsarr = ['', '修改', '檢視', '刪除', '執行', '暫停', '重啟', '禁用', '啟用']; var btnshtml = ''; if(arr.length == 0) { for(var i = 1, len = 7; i < len; i++) { btnshtml += '<span id="' + txt + i + '"> ' + ' <img src="img/pimg/icon' + i + '.png" alt="" /> ' + ' <i>' + btnsarr[i] + '</i> ' + ' </span>'; } } else if(arr.length != 0) { for(var i = 0, len = arr.length; i < len; i++) { btnshtml += '<span id="' + txt + arr[i] + '"> ' + ' <img src="img/pimg/icon' + arr[i] + '.png" alt="" /> ' + ' <i>' + btnsarr[arr[i]] + '</i> ' + ' </span>'; } } return btnshtml; }; SDHF.isNull = function(str) { if(typeof(str) == "undefined" || str == null || str == "null") { return ""; } else { return str; } } SDHF.UrlSearch = function(dataid) { var name, value; var str = dataid; //取得整個位址列 var num = str.indexOf("?") str = str.substr(num + 1); //取得所有引數 stringvar.substr(start [, length ] var arr = str.split("&"); //各個引數放到數組裡 for(var i = 0; i < arr.length; i++) { num = arr[i].indexOf("="); if(num > 0) { name = arr[i].substring(0, num); value = arr[i].substr(num + 1); this[name] = decodeURI(value); } } } SDHF.notbody = function() { $(".tablebox>table>tbody").html(""); }; //SDHF.showHead = function(theadarr,obj) {//顯示錶頭 // var theadhtml=''; // for(var i=0,len=theadarr.length;i<len;i++){ // theadhtml+='<th>'+theadarr[i]+'</th> '; // } // $(obj).html(theadhtml); //}; // 學院班級------start // 顯示學院班級 //var isshow=true; //$(".main").on("click",".jsscclass",function(){ // if(isshow){ // $(".schoolbox").css("width","200px"); // $(".rightitconbox").css("width",'calc(100% - 200px)'); // isshow=false; // }else if(!isshow){ // $(".schoolbox").css("width","44px"); // $(".rightitconbox").css("width",'calc(100% - 44px)'); // isshow=true; // } // $(this).next().toggle(); //}) // 顯示學院班級 //var isshow=true; $(".main").on("mouseover", ".schoolbox", function() { $(this).find(".scclassul").show(); }) $(".main").on("mouseout", ".schoolbox", function() { $(this).find(".scclassul").hide(); }) SDHF.getclassitem = function() { //獲取學院 $.ajax({ type: "post", url: url + "psychoanalysis/getAllCollegeName", async: true, dataType: "json", contentType: "application/json", data: JSON.stringify({}), success: function(data) { if(data.code == 0) { var sd = data.data; var shtml = ''; for(var i = 0, len = sd.length; i < len; i++) { shtml += '<li name = "' + sd[i] + '">' + ' <span>' + sd[i] + '</span>' + ' <div class="clchoose">' + SDHF.getMajorName(sd[i]); + ' </div>' + ' </li>'; } $(".jsscclassul").html(shtml); } } }) }; SDHF.getMajorName = function(txx) { //獲取專業 var ghtml = ''; $.ajax({ type: "post", url: url + "psychoanalysis/getMajorNameByCollegeName", async: false, dataType: "json", contentType: "application/json", data: JSON.stringify({ "collegename": txx }), success: function(data) { if(data.code == 0) { var sd = data.data; if(sd[0] == '') { ghtml = "暫無內容" return false } for(var i = 0, len = sd.length; i < len; i++) { ghtml += '<div class="clitemrow" name ="' + sd[i] + '">' + ' <b>' + sd[i] + '<em>></em></b>' + ' <p>' + SDHF.ClassName(sd[i]) + ' </p>' + '</div>'; } } } }) return ghtml; }; SDHF.ClassName = function(tclass) { //獲取班級 var classnamehtml = ''; $.ajax({ type: "post", url: url + "psychoanalysis/getClassNameByCAndMName", async: false, dataType: "json", contentType: "application/json", data: JSON.stringify({ "majorname": tclass }), success: function(data) { if(data.code == 0) { var sd = data.data; for(var z = 0, len = sd.length; z < len; z++) { classnamehtml += '<span>' + sd[z] + '</span> '; } } } }) return classnamehtml; } // 學院班級------end //綜合查詢========start SDHF.getclassitemsel = function() { //獲取學院 $.ajax({ type: "post", url: url + "psychoanalysis/getAllCollegeName", async: true, dataType: "json", contentType: "application/json", data: JSON.stringify({}), success: function(data) { if(data.code == 0) { var sd = data.data; var shtml = '<option value="">請選擇</option>'; for(var i = 0, len = sd.length; i < len; i++) { shtml += '<option value="' + sd[i] + '">' + sd[i] + '</option>'; } $(".jscollegename").html(shtml); } } }) }; SDHF.getMajorNamesel = function(txx) { //獲取專業 var ghtml = ''; $.ajax({ type: "post", url: url + "psychoanalysis/getMajorNameByCollegeName", async: true, dataType: "json", contentType: "application/json", data: JSON.stringify({ "collegename": txx }), success: function(data) { if(data.code == 0) { var sd = data.data; if(sd[0] == '') { ghtml += '<option value="">請選擇</option>'; } else { ghtml += '<option value="">請選擇</option>'; for(var i = 0, len = sd.length; i < len; i++) { ghtml += '<option value="' + sd[i] + '">' + sd[i] + '</option>'; } } $(".jsmajorname").html(ghtml); } } }) }; SDHF.ClassNamesel = function(tclass) { //獲取班級 var classnamehtml = ''; $.ajax({ type: "post", url: url + "psychoanalysis/getClassNameByCAndMName", async: true, dataType: "json", contentType: "application/json", data: JSON.stringify({ "majorname": tclass }), success: function(data) { if(data.code == 0) { var sd = data.data; classnamehtml += '<option value="">請選擇</option>'; for(var z = 0, len = sd.length; z < len; z++) { classnamehtml += '<option value="' + sd[z] + '">' + sd[z] + '</option>'; } $(".classname").html(classnamehtml); } } }) } SDHF.ClassNamezz = function() { //獲取經濟資助型別 var ClassNamezzhtml = ''; $.ajax({ type: "post", url: url + "psychoanalysis/getSupportType", async: true, dataType: "json", contentType: "application/json", data: JSON.stringify({}), success: function(data) { if(data.code == 0) { var sd = data.data.stypes; ClassNamezzhtml += '<option value="">請選擇</option>'; for(var j = 0, len = sd.length; j < len; j++) { ClassNamezzhtml += '<option value="' + sd[j].id + '">' + sd[j].name + '</option>'; } $(".jsstypeid").html(ClassNamezzhtml); } } }) } SDHF.peopleserchhtml = function() { //獲取查詢方式 var htmlbox = ''; htmlbox += '<p> ' + ' <span>學院:</span> ' + ' <select name="" class="jscollegename"> ' + ' <option value="">請選擇</option> ' + ' </select> ' + ' </p> ' + ' <p> ' + ' <span>專業:</span> ' + ' <select name="" class="jsmajorname"> ' + ' <option value="">請選擇</option> ' + ' </select> ' + ' </p> ' + ' <p> ' + ' <span>班級:</span> ' + ' <select name="" class="classname"> ' + ' <option value="">請選擇</option> ' + ' </select> ' + ' </p> ' + ' <p> ' + ' <span>學號:</span> ' + ' <input type="text" name="" value="" placeholder="" class="jsstudentnum"/> ' + ' </p> ' + ' <p> ' + ' <span>經濟資助型別:</span> ' + ' <select name="" class="jsstypeid"> ' + ' <option value="">請選擇</option> ' + ' <option value="1">請選擇1</option> ' + ' <option value="2">請選擇2</option> ' + ' </select> ' + ' </p> ' + ' <p> ' + ' <span>姓名:</span> ' + ' <input type="text" value="" placeholder="" class="jsname"/> ' + ' </p>'; $(".itserchbox").html(htmlbox); SDHF.getclassitemsel(); //獲取學院 SDHF.ClassNamezz(); } //綜合查詢========end SDHF.getyc = function(data) { //獲取異常情況 var htmlxm = ''; var arr = data.split(","); for(var i = 0, len = arr.length; i < len; i++) { switch(arr[i]) { case '0': htmlxm += '無,' break; case '1': htmlxm += '心裡異常,' break; case '2': htmlxm += '上網時間異常,' break; case '3': htmlxm += '消費異常,' break; case '4': htmlxm += '日常行為異常,' break case '5': htmlxm += '日常行為異常,' break case '6': htmlxm += '社交媒體異常,' break; default: break; } } return htmlxm } SDHF.getdy = function(data) { //嚴重程度對應關係 var htmlxm = ''; switch(data) { case 1: htmlxm += '嚴重' break; case 2: htmlxm += '非常嚴重' break; case 3: htmlxm += '一般' break; default: break; } return htmlxm } function formatDate(now) { now = new Date(now); var year = now.getFullYear(), month = now.getMonth() + 1, date = now.getDate(), hour = now.getHours(), minute = now.getMinutes(), second = now.getSeconds(); minute = checkTime(minute); month = checkTime(month); date = checkTime(date); hour = checkTime(hour); second = checkTime(second); return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second; } function formatDate2() { now = new Date(); var year = now.getFullYear(), month = now.getMonth() + 1, date = now.getDate(), day = now.getDay(), hour = now.getHours(), minute = now.getMinutes(), second = now.getSeconds(); minute = checkTime(minute); month = checkTime(month); date = checkTime(date); hour = checkTime(hour); second = checkTime(second); day = checkday(day) return year + " / " + month + " / " + date + " " + day + " " + hour + ":" + minute + ":" + second; } function checkTime(i) { if(i < 10) { i = "0" + i } return i } function checkday(daynum) { switch(daynum) { case 0: daynum = ' Monday ' break; case 1: daynum = ' Tuesday ' break; case 2: daynum = ' Wednesday ' break; case 3: daynum = ' Thursday ' break; case 4: daynum = ' Friday ' break; case 5: daynum = ' Saturday ' break; case 6: daynum = ' Sunday ' break; default: break; } return daynum } function Chineseyearnum() { //農曆 var CalendarData = new Array(100); var madd = new Array(12); var tgString = "甲乙丙丁戊己庚辛壬癸"; var dzString = "子醜寅卯辰巳午未申酉戌亥"; var numString = "一二三四五六七八九十"; var monString = "正二三四五六七八九十冬臘"; var weekString = "日一二三四五六"; var sx = "鼠牛虎兔龍蛇馬羊猴雞狗豬"; var cYear, cMonth, cDay, TheDate; CalendarData = new Array(0xA4B, 0x5164B, 0x6A5, 0x6D4, 0x415B5, 0x2B6, 0x957, 0x2092F, 0x497, 0x60C96, 0xD4A, 0xEA5, 0x50DA9, 0x5AD, 0x2B6, 0x3126E, 0x92E, 0x7192D, 0xC95, 0xD4A, 0x61B4A, 0xB55, 0x56A, 0x4155B, 0x25D, 0x92D, 0x2192B, 0xA95, 0x71695, 0x6CA, 0xB55, 0x50AB5, 0x4DA, 0xA5B, 0x30A57, 0x52B, 0x8152A, 0xE95, 0x6AA, 0x615AA, 0xAB5, 0x4B6, 0x414AE, 0xA57, 0x526, 0x31D26, 0xD95, 0x70B55, 0x56A, 0x96D, 0x5095D, 0x4AD, 0xA4D, 0x41A4D, 0xD25, 0x81AA5, 0xB54, 0xB6A, 0x612DA, 0x95B, 0x49B, 0x41497, 0xA4B, 0xA164B, 0x6A5, 0x6D4, 0x615B4, 0xAB6, 0x957, 0x5092F, 0x497, 0x64B, 0x30D4A, 0xEA5, 0x80D65, 0x5AC, 0xAB6, 0x5126D, 0x92E, 0xC96, 0x41A95, 0xD4A, 0xDA5, 0x20B55, 0x56A, 0x7155B, 0x25D, 0x92D, 0x5192B, 0xA95, 0xB4A, 0x416AA, 0xAD5, 0x90AB5, 0x4BA, 0xA5B, 0x60A57, 0x52B, 0xA93, 0x40E95); madd[0] = 0; madd[1] = 31; madd[2] = 59; madd[3] = 90; madd[4] = 120; madd[5] = 151; madd[6] = 181; madd[7] = 212; madd[8] = 243; madd[9] = 273; madd[10] = 304; madd[11] = 334; function GetBit(m, n) { return(m >> n) & 1; } function e2c() { TheDate = (arguments.length != 3) ? new Date() : new Date(arguments[0], arguments[1], arguments[2]); var total, m, n, k; var isEnd = false; var tmp = TheDate.getYear(); if(tmp < 1900) { tmp += 1900; } total = (tmp - 1921) * 365 + Math.floor((tmp - 1921) / 4) + madd[TheDate.getMonth()] + TheDate.getDate() - 38; if(TheDate.getYear() % 4 == 0 && TheDate.getMonth() > 1) { total++; } for(m = 0;; m++) { k = (CalendarData[m] < 0xfff) ? 11 : 12; for(n = k; n >= 0; n--) { if(total <= 29 + GetBit(CalendarData[m], n)) { isEnd = true; break; } total = total - 29 - GetBit(CalendarData[m], n); } if(isEnd) break; } cYear = 1921 + m; cMonth = k - n + 1; cDay = total; if(k == 12) { if(cMonth == Math.floor(CalendarData[m] / 0x10000) + 1) { cMonth = 1 - cMonth; } if(cMonth > Math.floor(CalendarData[m] / 0x10000) + 1) { cMonth--; } } } function GetcDateString() { var tmp = ""; tmp += tgString.charAt((cYear - 4) % 10); tmp += dzString.charAt((cYear - 4) % 12); tmp += "("; tmp += sx.charAt((cYear - 4) % 12); tmp += ")年 "; if(cMonth < 1) { tmp += "(閏)"; tmp += monString.charAt(-cMonth - 1); } else { tmp += monString.charAt(cMonth - 1); } tmp += "月"; tmp += (cDay < 11) ? "初" : ((cDay < 20) ? "十" : ((cDay < 30) ? "廿" : "三十")); if(cDay % 10 != 0 || cDay == 10) { tmp += numString.charAt((cDay - 1) % 10); } return tmp; } function GetLunarDay(solarYear, solarMonth, solarDay) { //solarYear = solarYear<1900?(1900+solarYear):solarYear; if(solarYear < 1921 || solarYear > 2020) { return ""; } else { solarMonth = (parseInt(solarMonth) > 0) ? (solarMonth - 1) : 11; e2c(solarYear, solarMonth, solarDay); return GetcDateString(); } } var D = new Date(); var yy = D.getFullYear(); var mm = D.getMonth() + 1; var dd = D.getDate(); var ww = D.getDay(); var ss = parseInt(D.getTime() / 1000); if(yy < 100) yy = "19" + yy; Chineseyear = GetLunarDay(yy, mm, dd) return Chineseyear //console.log(Chineseyear) } function UrlSearch() { var name, value; var str = location.href; //取得整個位址列 var num = str.indexOf("?") str = str.substr(num + 1); //取得所有引數 stringvar.substr(start [, length ] var arr = str.split("&"); //各個引數放到數組裡 for(var i = 0; i < arr.length; i++) { num = arr[i].indexOf("="); if(num > 0) { name = arr[i].substring(0, num); value = arr[i].substr(num + 1); this[name] = decodeURI(value); } } } var Git = new UrlSearch(); //例項化