| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- 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<curDatas.length;i++){
- if(id==curDatas[i].id){
- rowData = curDatas[i];
- break;
- }
- }
- return rowData;
- }
- function showPopup4Common(title,callback,area,divId,offset){
- if(!area) area='auto';
- if(!divId) divId='#form-div';
- if(!offset) offset='auto';
- //添加常量页面
- return layer.open({
- type: 1,
- area: area,
- title: title,
- closeBtn: 1,
- shadeClose: true,
- offset: offset,
- skin: 'layui-layer-lan',
- content: $(divId),
- btn: '保存',
- btnAlign: 'c', //按钮居中
- shade: 0 ,//不显示遮罩
- yes: function(index){
- if(callback!=false){
- callback();
- }
- layer.close(index);
- }
- });
- }
- function deleteItem4Common(id,url,okCb,offset){
- if(!offset) offset='auto';
- //询问框
- layer.confirm('确定删除记录?', {
- btn: ['删除','取消'], //按钮
- offset:offset
- }, function(){
- var param ={"id":id};
- no_return_common_service(url, param, function(data) {
- okCb();//重新加载表格数据
- layer.msg(data, {
- time: 2000//20s后自动关闭
- });
- }, function(error) {
- alert(error);
- });
- }, function(index){
- layer.close(index);
- });
- }
- function addOrUpdateItem4Common(param,url,okCb){
- no_return_common_service(url, param, function(data) {
- if(okCb) okCb();//重新加载表格数据
- layer.msg(data, {
- time: 2000//20s后自动关闭
- });
- }, function(error) {
- alert(error);
- });
- }
- function setFeSelect(div,selectId){
- get_common_service("/dept/getAllFs",null,function(data){
- var optStr = '<option value="">全部</option>';
- for(var i in data) {
- if(data[i].deptid==selectId)
- optStr += '<option value="'+data[i].deptid+'" selected="selected">'+data[i].name+'</option>';
- else
- optStr += '<option value="'+data[i].deptid+'">'+data[i].name+'</option>';
- }
- $(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 += '<option value="'+data[i].id+'" selected="selected">'+data[i].name+'</option>';
- else
- optStr += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
- }
- $(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 += '<option value="'+data[i].id+'" selected="selected">'+data[i].truename+'</option>';
- else
- optStr += '<option value="'+data[i].id+'">'+data[i].truename+'</option>';
- }
- $(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+= '<a href="javascript:void(0)" onclick="showClientImg('+fileSrc+')"><img src="'+fileSrc+'" style="height:55px;margin:5px;"></a>';
- }else{
- optionStr+= '<a href="'+fileSrc+'" target="_blank"><img src="'+fileSrc+'" style="height:55px;margin:5px;"></a>';
- }
- }else if(fileSrc.endWith("doc")|| fileSrc.endWith("docx")){
- if(ISCLIENT) {
- optionStr+= '<a href="javascript:void(0)" onclick="downloadClientfile('+fileSrc+')"><i class="icon icon-file-word icon-4x" style="vertical-align: middle"></a>';
- }else{
- optionStr+= '<a href="'+fileSrc+'" target="_blank"><i class="icon icon-file-word icon-4x" style="vertical-align: middle"></a>';
- }
- }else if(fileSrc.endWith("txt")){
- if(ISCLIENT) {
- optionStr+= '<a href="javascript:void(0)" onclick="downloadClientfile('+fileSrc+')"><i class="icon icon-file-code icon-4x" style="vertical-align: middle"></a>';
- }else{
- optionStr+= '<a href="'+fileSrc+'" target="_blank"><i class="icon icon-file-code icon-4x" style="vertical-align: middle"></a>';
- }
- }
- }
- 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 += '<option value="'+data[i].id+'" selected="selected">'+data[i].truename+'</option>';
- else
- optStr += '<option value="'+data[i].id+'">'+data[i].truename+'</option>';
- }
- $(div).html('');
- $(div).html(optStr);
- });
- }
|