function doajax(method, dataurl, data, sucessCallBack, errorCallBack) { var user_key = undefined; var user = $.zui.store.get("user") if (typeof(user) == "undefined" || user == null) { } else { user_key = "XinTong " + (user.token); } if (typeof(user_key) == "undefined" || user_key == null) { $.ajax({ type: method, url: dataurl, contentType: "application/json", dataType: "json", async: true, data: JSON.stringify(data), success: sucessCallBack, error: function(error) { if (HandleError(error)) return; errorCallBack(error); } }) } else { $.ajax({ type: method, url: dataurl, contentType: "application/json", dataType: "json", beforeSend: function(xhr) { xhr.setRequestHeader("token", user_key); }, headers: { 'token': user_key }, async: true, data: JSON.stringify(data), success: sucessCallBack, error: function(error) { if (HandleError(error)) return; errorCallBack(error); } }) } } function ajaxGet(dataurl, data, sucessCallBack, errorCallBack) { doajax("GET", dataurl, data, sucessCallBack, errorCallBack) } function ajaxPost(dataurl, data, sucessCallBack, errorCallBack) { doajax("POST", dataurl, data, sucessCallBack, errorCallBack) } function ajaxPut(dataurl, data, sucessCallBack, errorCallBack) { doajax("PUT", dataurl, data, sucessCallBack, errorCallBack) } function ajaxDelete(dataurl, data, sucessCallBack, errorCallBack) { doajax("DELETE", dataurl, data, sucessCallBack, errorCallBack) } function HandleError(error) { if (typeof(error) != "undefined" && error != null) { if (typeof(error.status) != "undefined" && error.status != null) { if (error.status == 403) { //未登录退出 layer.msg('登陆已经过期,将重新登陆!', { time: 2000, //20s后自动关闭 }, function() { self.location = base_ui_url + UI_USER_LOGIN }) return true; } } } return false; } function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); } return null; } function getItemByIdFromArr(id,curDatas){ var rowData; for(var i=0;i'+data[i].name+''; else optStr += ''; } $(div).html(''); $(div).html(optStr); }); } function setLaneSelect(div,selectId){ var optStr = ''; var data =[]; for(var i =0;i<=8;i++) { if(i==0) data.push({id:i,name:'值机室'}); else data.push({id:i,name:i+'车道'}); } for(var i in data) { if(i==selectId) optStr += ''; else optStr += ''; } $(div).html(''); $(div).html(optStr); } // var ViewMap = new HashMap() // ViewMap.set("/view/mytask/unchecked.html", __inline('/view/mytask/unchecked.html')); // ViewMap.set("/view/mytask/unexamined.html", __inline('/view/mytask/unexamined.html')); // ViewMap.set("/view/mytask/undispatched.html", __inline('/view/mytask/undispatched.html')); // ViewMap.set("/view/mytask/dispatched.html", __inline('/view/mytask/dispatched.html')); // ViewMap.set("/view/constant/constant.html", __inline('/view/constant/constant.html')); /** * @Func 处理长整形时间格式化 * @time long * @format string 有默认值 */ function timeStamp2String(time,format){ if(time == "" || time == null) return ; if(format==undefined || format == "") format = "yyyy/MM/dd hh:mm:ss"; var datetime = new Date(); datetime.setTime(time); return datetime.Format(format); }; /** * @Func 时间格式化 * @FuncName Format * (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 */ Date.prototype.Format = function (fmt) { 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 tip(data,timeout){ if(data==undefined || data=='') return ; layer.msg(data, { time: (timeout!=null)?timeout:2000 //20s后自动关闭 }); } function showPopup4CommonBtns(title,area,divId,btns,callback1,callback2){ if(!area) area='auto'; if(!divId) divId='#form-div'; //添加常量页面 return layer.open({ type: 1, area: area, title: title, closeBtn: 1, shadeClose: true, content: $(divId), btn: btns, btnAlign: 'c', //按钮居中 shade: 0 ,//不显示遮罩 yes: function(index){ if(callback!=false){ callback(); } layer.close(index); } }); } function getCurrentUser() { var user = $.zui.store.get("user") return user; } function hasRole(role){ var user = getCurrentUser(); var roles = user.roles; for(var i in roles){ if(roles[i].name==role) return true; } return false; } function roleContains(role){ var user = getCurrentUser(); var roles = user.roles; for(var i in roles){ if(roles[i].name.indexOf(role) >= 0) return true; } return false; } function setCheckmanSelect(div, selectId, notHaveUserId, callback){ post_common_service("/user/getAllCheckman",null,function(data){ var optStr = ''; for(var i in data) { if(data[i].id==notHaveUserId) continue; if(data[i].id==selectId) optStr += ''; else optStr += ''; } $(div).html(''); $(div).html(optStr); if(callback) callback(); }); } function genAppeaFiles(file_src){ initStringfunc(); var files = file_src.split(","); var optionStr=""; for(var i in files) { var fileSrc = base_image_server_url+files[i]; if(fileSrc.endWith("png") || fileSrc.endWith("jpg")||fileSrc.endWith("ico")){ if(ISCLIENT) { optionStr+= ''; }else{ optionStr+= ''; } }else if(fileSrc.endWith("doc")|| fileSrc.endWith("docx")){ if(ISCLIENT) { optionStr+= ''; }else{ optionStr+= ''; } }else if(fileSrc.endWith("txt")){ if(ISCLIENT) { optionStr+= ''; }else{ optionStr+= ''; } } } return optionStr; } initStringfunc(); function initStringfunc(){ String.prototype.endWith = function(str){ if(str==null || str=="" || this.length == 0 ||str.length > this.length){ return false; } if(this.substring(this.length - str.length) == str){ return true; }else{ return false; } }; String.prototype.startWith = function(str){ if(str == null || str== "" || this.length== 0 || str.length > this.length){ return false; } if(this.substr(0,str.length) == str){ return true; }else{ return false; } }; } function showClientImg(src){ callFunc("showImage", src); } function downloadClientfile(src){ callFunc("downloadfile", src); } function setTeamUserSelect(div,selectId,classId){ post_common_service("/team/getTeamPersonsByUserClassId/"+classId,null,function(data){ var optStr = ''; for(var i in data) { if(data[i].positionid==4) data[i].truename=data[i].truename+'(班长)'; if(data[i].id==selectId) optStr += ''; else optStr += ''; } $(div).html(''); $(div).html(optStr); }); }