//服务器地址 var base_url = 'http://116.255.224.148:8083'; //var base_url = 'http://192.168.31.87:8084'; var reqdata = function (url) { if (url.indexof('http:') < 0 && url.indexof('https:') < 0) { this.url = base_url + url; } else { this.url = url; } }; /** * 异步加载数据 */ reqdata.prototype = { constructor: reqdata, loaddata: function (callback) { $.ajax({ type: 'post', url: this.url, datatype: 'json', xhrfields: { withcredentials: true }, success: function (r) { callback(r) }, error: function (xhr, type) { //登录失效 // login(); callback(false, ""); } }); }, postdata: function (data, callback) { $.ajax({ type: 'post', url: this.url, contenttype: 'application/json', data: data, datatype: 'json', xhrfields: { withcredentials: true }, success: function (r) { callback(r) }, error: function (xhr, type) { //登录失效 // login(); // callback(false,xhr.status); } }); } }; //从服务器加载数据并执行渲染数据方法 function loaddata(url, callback) { //加载数据 let p1 = new reqdata(url); p1.loaddata(function (item) { if (item.code == 200 || item.code == 0) { callback(item); } else if (item.msg) { //返回错误提示 // showalert(item.msg); } }); } function postformdata(url, data, callback) { let p1 = new reqdata(url); p1.postdata(data, function (item) { if (item.code == 200 || item.code == 0) { callback(true, item); } else if (item.msg) { //showalert(item.msg) } }); } function postdata(url, callback) { //加载数据 let p1 = new reqdata(url); p1.loaddata(function (item) { if (item.code == 200 || item.code == 0) { callback(item); } else if (item.msg) { // showalert(item.msg); } }); } //跳转到登录页面 function login() { window.location = '/login'; } function getarray(array) { let jo = {}; let array_name; array.foreach(function (item) { if (jo[item.name] !== undefined) { if (!jo[item.name].push) { jo[item.name] = [jo[item.name]]; } jo[item.name].push(item.value || ''); } else { if (item.name.indexof('[') > -1 && item.name.indexof(']') > -1) { let name = item.name.substring(0, item.name.indexof('[')); if (array_name != name) { array_name = name; let ja = getattacharray(array_name, array); if (ja.length > 0) { let oja = [] ja.foreach(function (sub) { for (let k in sub) { if (k.indexof('[') > 0) { oja.push({'name': k, 'value': sub[k]}) delete sub[k] } } }) if (oja.length > 0) { let ojo = getarray(oja) ja[0] = object.assign({}, ja[0], ojo) } jo[array_name] = ja; } } } else if (item.name.indexof('.') > -1) { let name = item.name.substring(0, item.name.indexof('.')); jo[name] = getobjectbyname(name,array) } else { jo[item.name] = item.value || ''; } } }) return jo } function getattacharray(name, array) { let ja = []; let line = 0; let dto = {}; array = getarraybyname(name, array) array.foreach(function (item, idx) { if (item.name.indexof('[') != -1 && item.name.indexof(']') != -1) { let l1 = item.name.indexof('['); let l2 = item.name.indexof(']'); let array_name = item.name.substring(0, l1); if (array_name == name) { let array_val = item.name.substring(l1 + 1, l2); if (number(array_val) != line) { if ($.isemptyobject(dto) != true) { ja.push(dto); } line = array_val; dto = {}; } if (item.value) { let po_name = item.name.substring(l2 + 2); dto[po_name] = item.value; } } } }) if ($.isemptyobject(dto) != true) { ja.push(dto); } return ja; } function getarraybyname(name, array) { let ja = []; array.foreach(function (d, i) { if (d.name.indexof(name) > -1) { let fn = name.substr(0, name.indexof('[')) d.name = d.name.substr(d.name.indexof(fn)) ja.push(d) } }); return ja; } function getobjectbyname(name, array) { let jo = {}; array.foreach(function (d, i) { if (d.name.indexof(name) > -1) { d.name = d.name.substr(d.name.indexof('.')+1) jo[d.name] = d.value } }); return jo; } //表单序列化支持附件 $.fn.tojson = function (t) { var o = {}; var a = this.serializearray(); var array_name; $.each(a, function () { if (o[this.name] !== undefined) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { if (this.name.indexof('[') == -1 || this.name.indexof(']') == -1){ o[this.name] = this.value || ''; }else{ var name = this.name.substring(0, this.name.indexof('[')); if (array_name != name) { array_name = name; var ja = getattacharray(array_name, a); if (ja.length > 0) { o[array_name] = ja; } } } } }); if (!t) { return json.stringify(o); } else { return o; } }; //数据回显表单不支持附件 $.fn.toform = function (jsonvalue, dis) { let obj = this; $.each(jsonvalue, function (name, val) { let $oinput = obj.find("input[name=" + name + "]"); if ($oinput.attr("type") == "checkbox") { if (val !== null) { let checkboxobj = $("[name=" + name + "]"); let checkarray = val.split(","); for (let i = 0; i < checkboxobj.length; i++) { for (let j = 0; j < checkarray.length; j++) { if (checkboxobj[i].value == checkarray[j]) { checkboxobj[i].click(); } } } } } else if ($oinput.attr("type") == "radio") { $oinput.each(function () { let radioobj = $("[name=" + name + "]"); for (let i = 0; i < radioobj.length; i++) { if (radioobj[i].value == val) { radioobj[i].click(); } } }); } else if ($oinput.attr("type") == "textarea") { obj.find("[name=" + name + "]").html(val); } else { obj.find("[name=" + name + "]").val(val); } }); if (dis) { this.find('input,textarea').attr('readonly', true); this.find('input:radio').attr('disabled', true); this.find('input:checkbox').attr('disabled', true); this.find("select").each(function () { $("#" + this.id).attr("disabled", true); }); } }; function encrypt(param) { let encrypt = new jsencrypt(); encrypt.setpublickey("migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqcmkihq4wssazwi1ptya3/gxvh1zeih/gbwd1vlq2bnxzixbayzzw+v+xylfkogzeaa/lmadh3+ivlx5f6zktyqfhltlyxplc9ptwvvp4yhanpehja0hb3vz0odmmndmocbo9h6jkcpvqphpzld6l1orqdz6dqp7fmmmu3iy2xhwqidaqab"); return encrypt.encrypt(param) } function download(url, name) { const elt = document.createelement('a'); elt.setattribute('href', url); if (name) { elt.setattribute('download', name); } elt.style.display = 'none'; document.body.appendchild(elt); elt.click(); document.body.removechild(elt); } function uploadfile(ipt, callback) { $('#' + ipt).fileupload({ url: "/system/upload/save", datatype: 'json', add: function (e, data) { data.submit(); }, done: function (e, data) { let r = data.result if (r.code != 200) { showalert('上传失败') return } callback({'filename': r.data.filename, 'filepath': r.data.filepath}); } }); } function toindex(){ window.top.location.href='../index.html' } function settopheight(){ parent.setiframeheight(document.body.scrollheight) parent.parent.setiframeheight(parent.document.body.scrollheight) } function setparentheight(){ parent.setiframeheight(document.body.scrollheight) } function timetostr(datetime){ let timestamp = new date(datetime.replace(/-/g,'/')).gettime(); let date = new date(timestamp) var year = date.getfullyear(); var month = date.getmonth() + 1; var day = date.getdate() ; let time = year + '-' + month + '-'+ day return time ; }