PageSourceSearch

http://ids.ahpu.edu.cn/authserver/ahpu-gorgeous/static/common/utils.js?v=20260821.152009

js ahpu.edu.cn collected 2026-10-02 15:10:23 UTC 13,229 bytes, 427 lines download raw bytes

1window.onload = function(){
2	//用于处理ajax请求时如果后台登录失效被拦截了,然后302无法跳转登录问题
3	$.ajaxSetup({
4	    contentType: "application/x-www-form-urlencoded;charset=utf-8",
5	    complete: function(XMLHttpRequest, textStatus) {
6	    	if(XMLHttpRequest && XMLHttpRequest.responseJSON){
7	    		var response = XMLHttpRequest.responseJSON;
8	    		if(response.errCode && response.errCode == 206302){
9	    			window.location.reload();
10	    		}
11	    	}
12	    }
13	});
14};
15
16$(function(){
17	// 7.2.1.SP4从window.onload移入 需要在该文件加载前加载toastr.js
18	// 初始化 totast
19	// 使用方式:toastr.success('Hello world!', 'Toastr fun!');
20	//success 、 error、info、warning 第二个参数为标题可以省略
21	if(typeof(toastr) != 'undefined'){
22		toastr.options = {
23			closeButton: false,
24			debug: false,
25			progressBar: false,
26			positionClass: 'toast-top-center',
27			onclick: null,
28			showDuration: '300',
29			hideDuration: '1000',
30			timeOut: '4000',
31			extendedTimeOut: '1000',
32			showEasing: 'swing',
33			hideEasing: 'linear',
34			showMethod: 'fadeIn',
35			hideMethod: 'fadeOut'
36		};
37	}
38	//因内容过长会截取,所以需设置title用于显示完成内容(只能显示一行)
39	$(".lang_text_ellipsis").each(function(index){
40		$(this).attr("title", $(this).text());
41		var ellipsis_css = "text-overflow:ellipsis;" +
42			"overflow:hidden;" +
43			"white-space:nowrap;" +
44			"display:-moz-inline-box;" +
45			"word-wrap:break-word;"
46		var display = $(this).css("display");
47		if(display && display == 'none'){
48			ellipsis_css = ellipsis_css +"display:none;"
49		}else{
50			ellipsis_css = ellipsis_css +"display:inline-block;"
51		}
52		utils.addCss(this, ellipsis_css);
53	});
54
55	//因内容过长会截取,所以需设置title用于显示完成内容(通过后面数字显示多少行,例显示5行num-text-ellipsis-5)
56	$("*[class*=num-text-ellipsis]").each(function(index){
57		var webkitLine = 1;
58		var className = $(this)[0].className;
59		$.each(className.split(" "), function(index, obj){
60			if(obj.indexOf("num-text-ellipsis-") >= 0){
61				webkitLine = obj.replace("num-text-ellipsis-", "");
62			}
63		});
64		$(this).attr("title", $(this).text());
65		var ellipsis_css = "text-overflow:ellipsis;" +
66			"overflow:hidden;" +
67			"white-space:inherit;" +
68			"word-wrap:break-word;" +
69			"display:-webkit-box;" +
70			"-webkit-line-clamp:"+webkitLine+";" +
71			"-webkit-box-orient:vertical;";
72		var display = $(this).css("display");
73		if(display && display == "none"){
74			ellipsis_css = ellipsis_css + "display:none";
75		}else{
76			ellipsis_css = ellipsis_css + "display:-webkit-box";
77		}
78		utils.addCss(this, ellipsis_css);
79	});
80
81	//input框只能输入数字,如手机号
82	$(".only-input-number").each(function(){
83		$(this).keyup(function(){
84			$(this).val($(this).val().replace(/[^\d]/g,''));
85		})
86	});
87});
88
89//清除帐号激活和找回密码存入localStorage的临时数据service
90localStorage.removeItem("accountActivation");
91localStorage.removeItem("retrievePassword");
92
93//禁止页面输入框自动填入
94function reloadInput(){
95	$(".no-auto-input").each(function(index){
96		// $(this).val('');
97		//因IE对autocomplete兼容性不支持,会出现输入框点击2次才能输入,所以如果IE就不加该属性
98		if (!(window.ActiveXObject || "ActiveXObject" in window)){
99			$(this).attr('readonly','readonly');
100			$(this).attr('autocomplete','off');
101		}
102	});
103	setTimeout(function(){
104		$(".no-auto-input").each(function(index){
105			// $(this).val('');
106			$(this).removeAttr("readonly");
107		});
108	},1500);
109}
110
111var utils = {
112	disabledBtnCss: {},
113	//全局提示信息显示时长
114	defaultShowMsgTime: 4000,
115	//全局提示信息显示长度(防止字符过长显示不美观)
116	defaultShowMsgLength: 100,
117	// 检查对象元素是否存在
118	isNull: function(data) {
119		if (data == null || data == undefined || $(data).length <= 0) {
120			return true;
121		}
122		return false;
123	},
124
125	// 检查字符串是否为空(包括空格字符串)
126	isEmptyStr: function(data) {
127        if (data == null || data == undefined || data == ""  || $.trim(data) == "") {
128            return true;
129		}
130		return false;
131	},
132	isNotEmptyStr: function(data) {
133		return !this.isEmptyStr(data);
134	},
135	subStr: function(data, num) {
136		if(!num || num==0){
137			num = this.defaultShowMsgLength;
138		}
139		var locale = this.getCookie("org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE");
140		if(this.isNotEmptyStr(locale) && locale.indexOf("en") != -1){
141			num = 2 * num;//英文字符就多截取
142		}
143		if(this.isEmptyStr(data) || num<=0 || data.length<=num){
144			return data;
145		}
146		return data.substring(0,num)+"...";
147	},
148	// null和defined转为"",defaultVal为默认值
149	toStr: function(data, defaultVal) {
150		if (this.isEmptyStr(defaultVal)) {
151			return this.isEmptyStr(data) ? "" : data;
152		} else {
153			return this.isEmptyStr(data) ? defaultVal : data;
154		}
155	},
156	
157	//给A标签href属性url拼接参数(注意paramName参数符号 & or ?)
158	setUrlParam: function(id, paramName, paramValue){
159		var eltObj = document.getElementById(id);
160		if(!eltObj || this.isEmptyStr(paramName) || this.isEmptyStr(paramValue)){
161			return;
162		}
163		if(eltObj.nodeName == "A" || eltObj.nodeName == "a"){
164			//a标签
165			eltObj.href = eltObj.href+paramName+"="+paramValue;
166		}else if(eltObj.nodeName == "FORM" || eltObj.nodeName == "form"){
167			//form标签
168			eltObj.action = eltObj.action+paramName+"="+paramValue;
169		}
170	},
171	
172	//统一input输入校验提示
173	requireInput: function(that, minLength, maxLength, msgThat, errorMsg, requireObj,needFocus){
174		var isRequire = false;
175		if(this.isNull(that)){
176			this.alertBox("代码错误!", 3000);
177			return true;
178		}
179		
180		if(!requireObj){
181			requireObj = that;
182		}
183		//页面输入框校验
184		var thatVal = $(that).val();
185		if(thatVal != undefined){
186			thatVal = thatVal.replace(/(^\s*)|(\s*$)/g, "");//正则去空格
187			$(that).val(thatVal);
188			if(thatVal.length <= minLength || thatVal.length > maxLength){
189				isRequire = true;
190				this.addClass(requireObj, "required");
191				this.showMsg(msgThat,errorMsg);
192				if(needFocus==undefined||needFocus=="true"){
193					$(that).focus();
194				}
195				$(msgThat).show();
196			}else{
197				isRequire = false;
198				this.removeClass(requireObj, "required");
199				this.showMsg(msgThat,"");
200			}
201		}
202		return isRequire;
203	},
204	//清除requrie样式
205	cleanRequire: function(requireObj, showErrorObj){
206		$(requireObj).find(".required").each(function(){
207			utils.removeClass($(this), "required");
208		});
209		$(showErrorObj).empty();
210	},
211	
212	//统一input输入校验插件弹框提示
213	toastRequireInput: function(that, minLength, maxLength, errorMsg){
214		var isRequire = false;
215		if(this.isNull(that)){
216			this.alertBox("代码错误!", 3000);
217			return true;
218		}
219		//页面输入框校验
220		var thatVal = $(that).val();
221		if(thatVal != undefined){
222			thatVal = thatVal.replace(/(^\s*)|(\s*$)/g, "");//正则去空格
223			$(that).val(thatVal);
224			if(thatVal.length <= minLength || thatVal.length > maxLength){
225				isRequire = true;
226				this.addClass(that, "required");
227				this.alertBox(errorMsg);
228			}else{
229				isRequire = false;
230				this.removeClass(that, "required");
231			}
232		}
233		return isRequire;
234	},
235	
236	//弹窗显示提示信息
237	alertBox: function(msg, mTime, mLength) {
238		if(!mTime || mTime<=0){
239			//默认显示时长
240			mTime = this.defaultShowMsgTime;
241		}
242		if(msg){
243			msg = msg.replace(/(^\s*)|(\s*$)/g, "");//正则去空格
244		}else{
245			return false;
246		}
247		//防止提示信息过长
248		var mssg = this.subStr(msg, mLength);
249	    // 防止连续点击造成的多个提示框
250	    if (document.querySelector("#alert-box")) {
251	        document.body.removeChild(document.querySelector("#alert-box"));
252	    }
253		var alertBox = document.createElement("div");
254		alertBox.id = "alert-box";
255		alertBox.title = msg;
256	    
257	    var clientWidth = document.body.clientWidth;
258	    if(clientWidth > 1000){
259	    	//PC端
260	    	clientWidth = clientWidth * 0.3;
261	    }else{
262	    	//移动端
263	    	clientWidth = clientWidth * 0.6;
264	    }
265		alertBox.style.cssText = "" +
266			"min-width:120px;" +
267			"max-width:"+clientWidth+"px;" +
268			"min-height:120px;" +
269			"background:#121212;" +
270			"color:#FFFFFF;" +
271			"font-size:16px;" +
272			"text-align:center;" +
273			"border-radius:5px;" +
274			"opacity: 0.8;" +
275			"z-index:999;" +
276			"padding:21px 14px;" +
277			"-webkit-box-sizing: border-box;" +
278			"-moz-box-sizing: border-box;" +
279			"box-sizing: border-box;" +
280			"display:inline-block;" +
281			"word-wrap: break-word;" +
282			"overflow: hidden;" +
283			"text-overflow:ellipsis;" +
284			"position:absolute;" +
285			"top:35%;" +
286			"left:50%;" +
287			"transform: translate(-50%, -50%);";
288
289	    //设置弹框提示图标
290		var img = document.createElement("img");
291		img.src = "/authserver/default/static/common/images/error-tip.png";
292		img.style.cssText = "width: 48px;
292height: 48px;margin: 0px 0px 8px 0px;";
293		alertBox.appendChild(img)
294		//设置提示语
295		var msgDiv = document.createElement("div");
296		msgDiv.style.cssText = "width: 100%;" +
297			"text-overflow: ellipsis;" +
298			"overflow: hidden;" +
299			"white-space: inherit;" +
300			"overflow-wrap: break-word;" +
301			"-webkit-line-clamp: 3;" +
302			"-webkit-box-orient: vertical;" +
303			"display: -webkit-box;";
304		msgDiv.innerHTML = mssg;
305		alertBox.appendChild(msgDiv)
306	    document.body.appendChild(alertBox);
307	    var bhAlertBox = document.querySelector("#alert-box");
308	    setTimeout(function () {
309	        // 防止前面提示框丢弃之后导致js报错
310	        if (bhAlertBox.parentNode != null) {
311	            document.body.removeChild(bhAlertBox);
312	        }
313	    }, mTime)
314	},
315	
316	//指定页面位置展示提示信息
317	showMsg: function(msgObj, msg, msTime, mLength){
318		if(this.isNull(msgObj)){
319			return;
320		}
321		if(this.isEmptyStr(msg)){
322			return;
323		}
324		msg = msg.replace(/(^\s*)|(\s*$)/g, "");//正则去空格
325		$(msgObj)[0].title=msg;
326		$(msgObj)[0].innerHTML=this.subStr(msg, mLength);
327		//提示信息多久时间后消失
328		if(msTime != undefined){
329			if(msTime <= 0){
330				msTime = this.defaultShowMsgTime;
331			}
332			$(msgObj).show().delay(msTime).hide("slow")
333		}
334		return;
335	},
336
337	//指定页面位置展示提示信息
338	showDelayMsg: function(msgObj, msg, msTime, mLength){
339		if(this.isNull(msgObj)){
340			return;
341		}
342		if(this.isEmptyStr(msg)){
343			return;
344		}
345		msg = msg.replace(/(^\s*)|(\s*$)/g, "");//正则去空格
346		$(msgObj)[0].innerHTML=this.subStr(msg, mLength);
347		//提示信息多久时间后消失
348		if(msTime != undefined){
349			if(msTime <= 0){
350				msTime = this.defaultShowMsgTime;
351			}
352			$(msgObj).show().delay(msTime).hide("slow")
353		}
354		return;
355	},
356
357	//JS原生方式-添加元素指定样式
358	addCss: function(that, cssJson){
359		if(this.isNull(that)){
360			return;
361		}
362		//$(that).css(cssJson);
363		//var obj = document.getElementById("btnB");
364		$(that)[0].style.cssText += ";"+cssJson;
365	},
366	//JS原生方式-添加元素指定样式
367	addClass: function(that, cls){
368		if(this.isNull(that)){
369			return;
370		}
371		//$(that).addClass("required");//IE不支持jquery.addClass()方法
372		$(that)[0].className += " "+cls;
373	},
374	
375	//JS原生方式-删除元素指定样式
376	removeClass: function removeClass(that, cls){
377		if(this.isNull(that)){
378			return;
379		}
380		var obj = $(that)[0];
381		removed = obj.className.replace(new RegExp(cls,"gm"), '');
382		removed = removed.replace(/(^\s+)|(\s+$)/g, '');//去掉首尾空格
383	    obj.className = removed;//替换原来的 class.
384	},
385	
386	//设置浏览器cookie
387	setCookie: function(_3a,_3b){
388	    var secure = window.location.protocol;
389	    if (secure == 'https:') {
390	        document.cookie=_3a+"="+escape(_3b)+";path=/"+";secure;SameSite=None;expires="+(new Date(2099,12,31)).toGMTString();
391	    }else {
392	        document.cookie=_3a+"="+escape(_3b)+";path=/"+";expires="+(new Date(2099,12,31)).toGMTString();
393	    }
394	},
395
396	//获取浏览器cookie
397	getCookie: function(cookie_name) {
398	    var allcookies = document.cookie;
399	    var cookie_pos = allcookies.indexOf(cookie_name);
400	    if (cookie_pos != -1) {
401	        cookie_pos += cookie_name.length + 1;
402	        var cookie_end = allcookies.indexOf(";", cookie_pos);
403	        if (cookie_end == -1) {
404	            cookie_end = allcookies.length;
405	        }
406	        var value = unescape(allcookies.substring(cookie_pos, cookie_end));
407	    }
408	    return value;
409	},
410
411	//统一按钮点击置灰
412	disabledBtn: function(that, flag){
413		if(flag){
414			//按钮置灰不可点击
415			this.disabledBtnCss[$(that).attr("class")] = $(that).css("background-color");
416			$(that).attr("disabled",true);
417			$(that).css("background-color","#cccfd2");
418			$(that).css("cursor","not-allowed");
419			$(that).css("pointer-events","none");
420		}else{
421			$(that).attr("disabled",false);
422			$(that).css("background-color",this.disabledBtnCss[$(that).attr("class")]);
423			$(that).css("pointer-events","");
424			$(that).css("cursor","pointer");
425		}
426	}
427}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.