global.js 2.85 KB
var CODE_SUCCESS = 200;

//html页面之间用来传递参数的对象
var paramObject = {};

var adminPortalUrl = null;

$.ajaxSetup({
	cache : false,
	dataType : "json",
	type : "POST",
	complete : function(XMLHttpRequest, textStatus) {
		$.messager.progress("close");
		var status = XMLHttpRequest.status;
		if (status == 200) {
			return;
		}
		
		var dialog = $("<div>").appendTo($(document.body));
		if (status == 900) {
			//数据库超时
			//$.messageAlert("错误", "查询超时了");
			$(dialog).myDialog({
				modal : true,
				width : 200,
				height : 150,
				title : "错误",
				content : "查询超时了!",
				buttons : [{
					text : "关闭",
					iconCls : "icon-no",
					handler : function() {
						$(dialog).myDialog("destroy");
					}
				}]
			});
		} else if (status == 901) {
			//session超时
			$(dialog).myDialog({
				modal : true,
				width : 200,
				height : 150,
				title : "错误",
				content : "登录超时了!",
				buttons : [{
					text : "重新登录",
					iconCls : "icon-no",
					handler : function() {
						window.top.location.href = "http://java-ufo-platform.test3.ingress.dev.yohocorp.com/ufoPlatform/html/login.html";
					}
				}]
			});
		} else {
			$(dialog).myDialog({
				modal : true,
				width : 200,
				height : 150,
				title : "错误",
				content : "操作失败了!",
				buttons : [{
					text : "关闭",
					iconCls : "icon-no",
					handler : function() {
						$(dialog).myDialog("destroy");
					}
				}]
			});
		}
	}
});

//通用的LoadFilter
function defaultLoadFilter(data) {
	if (!data || data.code != 200) {
		return [];
	}
	return data.data;
}

function utf16to8(str) {
	debugger
	var out, i, len, c;
	out = "";
	len = str.length;
	for(i = 0; i < len; i++) {
		c = str.charCodeAt(i);
		if ((c >= 0x0001) && (c <= 0x007F)) {
			out += str.charAt(i);
		} else if (c > 0x07FF) {
			out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
			out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
			out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
		} else {
			out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
			out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
		}
	}
	return out;}



	function addHead(title1, title2) {
	var str = "<div class='pageheader'>";
	str += "<div class='media'>";
	str += "<div class='pageicon pull-left'>";
	str += "<i class='fa fa-th-list'></i>";
	str += "</div>";
	str += "<div class='media-body' style=\"font-family: 'microsoft yahei'\">";
	str += "<ul class='breadcrumb'>";
	str += "<li><a href=''><i class='glyphicon glyphicon-home'></i></a></li>";
	str += "<li><a href=''>"+ title1 +"</a></li>";
	str += "<li>"+ title2 +"</li>";
	str += "</ul>";
	str += "<div style='margin-top: 4px'>";
	str += "<h4 style='line-height: 30px;font-size: 24px'>";
	str += title2;
	str += "</h4>";
	str += "</div>";
	str += "</div>";
	str += "</div>";
	str += "</div>";
	return str;
}