/* ******* foundation ******* */ /* 1. 由main.html引用 */ /* 2. 其他界面不使用 */ /* ************************** */ function BrowserType() { var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器 var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器 var isEdge = userAgent.indexOf("Windows NT 6.1; WOW64; Trident/7.0;") > -1 && !isIE; //判断是否IE的Edge浏览器 var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器 var isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") == -1; //判断是否Safari浏览器 var isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("Safari") > -1; //判断Chrome浏览器 if (isIE) { var reIE = new RegExp("MSIE (\\d+\\.\\d+);"); reIE.test(userAgent); var fIEVersion = parseFloat(RegExp["$1"]); if(fIEVersion == 7) { return {type: "IE", version: 7};} else if(fIEVersion == 8) { return {type: "IE", version: 8};} else if(fIEVersion == 9) { return {type: "IE", version: 9};} else if(fIEVersion == 10) { return {type: "IE", version: 10};} else if(fIEVersion == 11) { return {type: "IE", version: 11};} else { return {type: "IE", version: 0};}//IE版本过低 }//isIE end if (isFF) { return {type: "FF"};} if (isOpera) { return {type: "Opera"};} if (isSafari) { return {type: "Safari"};} if (isChrome) { return {type: "Chrome"};} if (isEdge) { return {type: "Edge"};} return {type: "IE", version: 0}; } function debug(message, obj) { if (config.isDebug) { if (obj) { console.log(message, obj); } else { console.log(message); } } } /* ********** object ************ */ Object.init = function(config) { if (prototyping) { return; } this.config = config; if (config) { var name = null, value; for (name in config) { value = config[name]; if (typeof value === "function" && typeof value.nodeType !== "number") { this[name] = value; } } } }; Object.subClass = function(properties) { if (!properties) { return; } var clazz = properties.init; delete properties.init; if (!clazz) { clazz = new Function(); } prototyping = true; try { var prototype = new this(); } finally { prototyping = false; } if($) { $.extend(prototype, properties); } clazz.prototype = prototype; clazz.subClass = arguments.callee; return clazz; }; /* ********* control ************* */ Control = Object.subClass({ init: function(config) { if (prototyping) { return; } //0. default settings this.style = config.style = config.style || "A"; this.visible = config.visible; this.sequence = 0; //1. call object create Object.init.call(this, config); //2. create container this.visible = (this.visible === undefined) || this.visible; //3. try create content if (this.create) { this.create(config); return; } //4. create container this.container = this.createContainer(this.visible); //5. append to parent if (config.element == "body") { this.parent = $("body"); } else { this.parent = config.element ? util.getEl(config.element) : $("body"); } this.parent.append(this.container); //6. create items if (this.createContent) { if (this.beforeCreateContent) { this.beforeCreateContent(config); } this.createContent(config); } else if (this.items) { this.createItems(this, this.container, config.items, 1); } }, createContainer: function(visible) { var config = this.config; var template = this.getContainerTemplate(config); var el = $(template); if (config.css) { this.addClass(el, config.css.container); } var container = $("#body", el); if (!container.length) { container = el; } if (this.onCreateContainer) { this.onCreateContainer(container, config); } if (!visible) { container.hide(); } return container; }, getContainerTemplate: function(config) { return config.element; }, setText: function(el, text, css) { if (!el || !el.length) { return; } el.html(text); this.addClass(el, css); }, setImage: function(el, imageURL, imageCss) { if (!el || !el.length) { return; } if (imageURL) { var element = el.get(0); var node = element.nodeName; if (node == "IMG") { el.attr("src", imageURL); } else { el.css({ "background-image": "url(" + imageURL + ")" }); } return; } this.addClass(el, imageCss); }, setIcon: function(el, iconClass, iconCss) { if (!el || !el.length) { return; } this.addClass(el, iconClass); this.addClass(el, iconCss); }, addClass: function(el, css) { if (css) { el.addClass(css); } }, removeClass: function(el, css) { if (css) { el.removeClass(css); } }, setVisible: function(visible) { if (visible) { this.container.show(); } else { this.container.hide(); } }, replaceParameter: function(obj) { for (var name in obj) { var value = obj[name]; if (typeof value == "string") { obj[name] = value.replace("@{style}", this.style); } } }, getTemplate: function(ctrlName, segmentName) { var name = ctrlName + "_Template" + this.config.style; var template = window[name]; if (!segmentName) { return template.join(""); } return template[segmentName].join(""); }, createSequenceValue: function(ctrlName) { this.sequence = this.sequence + 1; return ctrlName + sequence; }, averageTo: function(total, size) { if (size <= 0) { return null; } var result = new Array(size); var max = size - 1; var value = Math.floor(total / size); var sum = 0; for (var i = 0; i < max; i++) { result[i] = value; sum = sum + value; } result[max] = total - sum; return result; } }); Control.subClass = function(properties) { if (!properties.items) { return Object.subClass.call(this, properties); } if (!properties.createItem) { properties.createItem = function(container, option, level) {}; } if (!properties.attachItem) { properties.attachItem = function(container, item) { container.append(item); }; } if (!properties.doAddItem) { properties.doAddItem = function(parentObject, container, option, level) { var item = this.createItem(container, option, level); item.option = option; this.attachItem(container, item); parentObject.items.push(item); return item; }; } if (!properties.deleteItem) { properties.deleteItem = function(item) { item.header.remove(); item.body.remove(); }; } /* if (!properties.createItems) { properties.createItems = function(parentObject, container, itemOptions, level) { parentObject.items = []; if (!itemOptions) { return; } if (this.beforeCreateItems) { this.beforeCreateItems(this.config); } for (var i = 0; i < itemOptions.length; i++) { var option = itemOptions[i]; this.doAddItem(parentObject, container, option, level); }; }; } */ if (!properties.createItems) { properties.createItems = function(parentObject, container, itemOptions, level, item0_) { parentObject.items = []; if (!itemOptions) { return; } if (this.beforeCreateItems) { this.beforeCreateItems(this.config); } for (var i = 0; i < itemOptions.length; i++) { var option = itemOptions[i]; var item_ = this.doAddItem(parentObject, container, option, level); if (!item0_) { item0_ = item_; } }; return item0_; }; } properties.getItemBy = function(name, value) { for (var i = 0; i < this.items.length; i++) { var item = this.items[i]; if (item[name] == value) { return item; } } return null; }; return Object.subClass.call(this, properties); }; /* ******** RootParent ************ */ RootBodyClass = Object.subClass({ init: function() { this.controls = []; this.win = $(window); this.document = $(document); this._width = this.win.width(); this._height = this.win.height(); }, width: function() { return this._width; }, height: function() { return this._height; }, append: function(element) { if (!this.body) { this.body = $('body'); var me = this; this.document.click(function() { me.notifyAll(); }); } this.body.append(element); }, register: function(control) { this.controls.push(control); }, notifyAll: function() { for (var i = 0; i < this.controls.length; i++) { this.notifyOne(this.controls[i]); } }, notifyOne: function(control) { if (control && control.onNotify) { control.onNotify.call(control, "rootClick"); } } }); RootBody = new RootBodyClass(); /* ******** Server ************ */ var ServerClass = Object.subClass({ ajaxRequest: function(url, param, callback, onFail, onSuccess, onError) { var me = this; var headers_ = {}; if (!url) { return; } if (url.substring(0, 8) == "rootact/") { url = config.url_act + url.substring(8); } else if (url.substring(0, 8) == "rootocr/") { url = config.url_ocr + url.substring(8); } else if (url.substring(0, 7) == "worder/") { url = config.url_worder + url.substring(7); } else if (url.substring(0, 7) == "rootjm/") { url = config.url_jmreport + url.substring(7); } else if (url.substring(0, 5) == "http:" || url.substring(0, 6) == "https:") { } else { url = config.url_root + url; } if (!param) { param = {} } var token = ""; if (Root) { token = Root.getToken(); // if(localStorage.getItem("hdtoken") != token) { // window.top.location.href = config.page_timeout; // return // } if (!param.token) { param.token = token; } if (param.type && param.type == "get") { if (url.indexOf("?") > 0) { url = url + "&" + "token=" + token; } else { url = url + "?" + "token=" + token; } } } if(param.headers) { headers_ = clone(param.headers); param.headers = null; } var option = { contentType: param.contentType || "text/plain" , dataType: param.dataType || "json", type: param.type || "post", headers: headers_, responseType: param.responseType || "" } if (param.type == "get") { param = null; } else { param = util.encode(param); } if (config.isupgrading) { // 升级中则退回登录页面 window.top.location.href = config.page_timeout; return } debug("请求:" + url); debug("参数:" + param); try { $.ajax({ url: url, contentType: option.contentType, dataType: option.dataType, type: option.type, headers: option.headers, data: param, xhrFields: { responseType: option.responseType }, success: function(result) { debug("返回:", result); if (result) { if ("timeout" == result.errorcode) { // return window.top.location.href = config.page_timeout; } else if (!result.success) { console.log(result); if (onFail) { onError(onFail, result); } else if(!result.success && result.message) { Root.message({ type: 'error', message: result.message }); } else if (result.errormessage) { var error = util.decode(result.errormessage); try { if (console.log) { console.log("error", error); } } catch (e) {} // console.log("error", error); // alert(error); } else { onSuccess(callback, result); } } else if (result.success){ onSuccess(callback, result); } } }, error: function(d1, error, message) { if (error == "parsererror" && d1.responseText) { var result_ = clone(d1.responseText); console.log(result_); result_ = result_.replace(/[\t\r\n]/g,""); // result_ = result_.replace(/[Null]/g,"null"); if (me.isJson(result_)) { // result_ = JSON.parse(result_); result_ = new Function('return ' + result_)() } else { onSuccess(callback, result_); return } if (result_.success) { onSuccess(callback, result_); return } } console.log("error", error); if (onFail) { onError(onFail, error); } // alert(error); // try { // if (console.log) { // console.log(error); // } // } catch (e) {} } }); } catch (e) {} }, isJson: function(str) { if (typeof str == 'string') { try { var obj = JSON.parse(str); // 等于这个条件说明就是JSON字符串 会返回true if (typeof obj == 'object' && obj) { return true; } else { //不是就返回false return false; } } catch (e) { return false; } } return false; }, call: function(url, param, callback, onFail) { if (!url) { return; } var me = this; var afterRequest = function(doCallback, result) { if (result && result.meta) { var type_ = "form"; if (url.indexOf('getEntitySet') != -1) { type_ = "table"; } result.meta = metaFieldTranslateMyelementField(result.meta, type_); if (result.host_meta) { result.host_meta = metaFieldTranslateMyelementField(result.host_meta, type_); } } if (doCallback) { try { result = util.decode(result); } finally { doCallback(result); } } }; if (!onFail) { onFail = function(errorresult) { console.log("错误信息", errorresult); if (errorresult.messages && errorresult.messages.count && errorresult.messages.count.error) { if (errorresult.messages.list) { var popupObj = { totab: false, // width: "1200px", // height: 800, icon: "icon-product", text: "错误信息", url: "module/tool/page/popup_error_messages.html", data: {}, delta: errorresult.messages.list, callback: function(obj, popupcallback) { if (popupcallback) { popupcallback(); } } }; var callback_ = popupObj.callback; var closecallback_ = popupObj.closecallback; var width_ = popupObj.width ? popupObj.width : "900px"; var height_ = popupObj.height ? popupObj.height : "450px"; var show_close_ = popupObj.show_close ? popupObj.show_close : false; var parames = { width: width_, height: height_, show_close: show_close_,//弹窗时是否隐藏右上角的“×”关闭符号 text: popupObj.text, title: popupObj.title, url: popupObj.url, sceneCode: popupObj.sceneCode, data: popupObj.data, delta: popupObj.delta, disabled: popupObj.disabled, disabledone: popupObj.disabledone, filter: popupObj.filter || "", dataname: popupObj.dataname || "", closecallback: function() { if (closecallback_) { closecallback_(); } }, callback: function(obj, popupcallback) { if (callback_) { callback_(obj); } if (popupcallback) { popupcallback(); } } }; window.top.Root.popupParames = parames; window.top.Root.showPopup(parames); } } else { window.top.Root.message({ type: 'error', message: '请求失败' }); } } } me.ajaxRequest(url, param, callback, onFail, afterRequest, afterRequest); }, upload: function(url, file, onProgress, onSuccess, onError) { var formdata = new FormData(); formdata.append("fileList", file); try { $.ajax({ cache: true, type: "POST", url: serverAddress + url, data: formdata, dataType: "json", processData: false, contentType: false, xhr: function() { var xhr = $.ajaxSettings.xhr(); if (onProgress && xhr.upload) { xhr.upload.addEventListener("progress", onProgress, false); return xhr; } }, error: function(request) { if (onError) { onError(); } }, success: function(data) { data = util.decode(data); if (onSuccess) { onSuccess(data); } } }); } catch (e) { if (onError) { onError(); } } } }); Server = new ServerClass(); /* ******** root ************ */ var RootClass = Object.subClass({ popupParames: {}, popupList: [], userInfo: {}, tab: null, message: null, init: function(config) { Object.call(this, {}); this.tab = config.tab; this.userInfo = config.userInfo; }, setUserInfo: function(userInfo) { this.userInfo = userInfo; }, showSubTab: function(config) { this.tab.showSubItem(config); }, hideSubTab: function(config) { this.tab.hideSubItem(config); }, showPopup: function(config) { config.url = util.buildURL(config.url); this.popupParames = config; var popup = new PopupWindowClass(config); this.popupList.push(popup); popup.show(); }, setPopupWH: function(w, h) { if (!this.popupList.length) { return; } var popup = this.popupList[this.popupList.length - 1]; popup.setSize(w, h); }, setPopupTitle: function(title) { if (!this.popupList.length) { return; } var popup = this.popupList[this.popupList.length - 1]; popup.setTitle(title); }, hidePopup: function(closecallback) { if (!this.popupList.length) { return; } var popup = this.popupList.pop(); if (closecallback) { closecallback() } popup.hide(); }, init_vue: function() { this.confirm = vue.$confirm; this.message = vue.$message; }, getToken: function() { // if(localStorage.getItem("hdtoken") != this.userInfo.token) { if(!this.userInfo.name || localStorage.getItem("HDU" + this.userInfo.name) != this.userInfo.token) { window.top.location.href = config.page_timeout; return } else { return this.userInfo.token; } } }); Root = null; //////////////////////////////FormatCenterClass/////////////// FormatCenterClass = Object.subClass({ init: function() { }, format: function(value, formatterCode) { var formatter = this.itemMap[formatterCode]; if (!formatter) { return value; } var result = formatter(null, null, value); return result; }, load: function() { var itemMap = this.itemMap = {}; itemMap.json = formatter_json; itemMap.formatter_date = formatter_date; itemMap.formatter_money = formatter_money; itemMap.formatter_float = formatter_float; itemMap.formatter_percent = formatter_percent; itemMap.formatter_split = formatter_split; itemMap.formatter_password = formatter_password; itemMap.prefixorunit = formatter_prefixorunit; itemMap.earlyWarning = formatter_earlyWarning; } }); FormatCenter = new FormatCenterClass(); DictionaryClass = Object.subClass({ init: function() { data: {} }, getLabel: function(value, dictCode) { var dict = this.data[dictCode]; if (!dict) { return value; } var result = dict.map[value]; if (!result) { return value; } return result.label; }, getList: function(dictCode) { var dict = this.data[dictCode]; if (!dict) { return []; } return dict.list; }, getMap: function(dictCode) { var dict = this.data[dictCode]; if (!dict) { return {}; } return dict.map; }, load: function(datalist) { if (!(datalist && datalist.length > 0)) { return; } var dataobj_ = {}; var dictionary_list = [ {code: "sysdictionary", value: "字典组名"} ]; var dictionary_map = {code: "sysdictionary", value: "字典组名"}; datalist.map(e=>{ if (e.code == "truefalse") { e.items.map(ed=>{ if (ed.code == "true") { ed.code = true } else if (ed.code == "false") { ed.code = false } }) } var dictionary_ = { code: e.code, value: e.name } dictionary_list.push(dictionary_); dictionary_map[e.code] = dictionary_; if (e.items.length) { dataobj_[e.code] = e.items; } }); var data = {}; data.sysdictionary = { "list": dictionary_list, "map": dictionary_map } for (var prop in dataobj_) { var dict = dataobj_[prop]; var list = dict, map = {}; for (var i = 0; i < list.length; i++) { var item = list[i]; map[item.code] = item.value; } data[prop] = { "list": list, "map": map } } this.data = data; }, addDictionary: function(dictionaryCode, dictionaryList) { var map_ = {}; dictionaryList.map(item=>{ map_[item.code] = item.value; }) this.data[dictionaryCode] = { "list": dictionaryList, "map": map_ } } }); Dictionary = new DictionaryClass(); var PopupWindowClass = Object.subClass({ width: 600, height: 400, template: [ '' ], init: function(config) { config = config ? config : {}; Object.call(this, {}); this.createElement(config); }, createElement: function(config) { // 1. create var el = this.el = $(this.template.join("")); // el.win_background = $("#win_background", el); el.popup_title = $(".popup-title", el); el.popup_body = $(".popup-body", el); el.icon = $("#win_icon", el); el.title = $("#win_title", el); el.btnClose = $("#win_btn_close", el); el.btnClosepopupdiv = $("#win_btn_closepopup_div", el); el.btnClosepopup = $("#win_btn_closepopup", el); el.container = $("#win_container", el); el.body = $("#win_body", el); //2. title if (!config.title && !config.text) { el.popup_title.hide(); el.popup_body.css("top", "0px"); } else { if (config.icon) { el.icon.addClass(config.icon); } if (config.title) { el.title.html(config.title); } else if (config.text) { el.title.html(config.text); } } el.btnClose.click(function() { Root.hidePopup(config.closecallback); }); el.btnClosepopupdiv[0].onmousedown = function(e) { Root.hidePopup(config.closecallback); if(window.event){ // ie 和 谷歌支持阻止冒泡 window.event.cancelBubble = true; } else{ // 火狐和谷歌支持的阻止冒泡 e.preventDefault(); } }; el.btnClosepopup[0].onmousedown = function(e) { Root.hidePopup(config.closecallback); if(window.event){ // ie 和 谷歌支持阻止冒泡 window.event.cancelBubble = true; } else{ // 火狐和谷歌支持的阻止冒泡 e.preventDefault(); } }; // el.btnClosepopup.click(function(e) { // Root.hidePopup(config.closecallback); // if(window.event){ // // ie 和 谷歌支持阻止冒泡 // window.event.cancelBubble = true; // } // else{ // // 火狐和谷歌支持的阻止冒泡 // e.preventDefault(); // } // }); el.btnClose.hide(); if (config.show_close) { el.btnClose.show(); } if (config.hide_close) { el.btnClosepopupdiv.hide(); } // 2. width and height this.width = config.width || this.width; this.height = config.height || this.height; el.container.css({ "width": this.width, "height": this.height }); if (config.url.indexOf("?") > 0) { config.url = config.url + "&t=" + new Date().getTime(); } else { config.url = config.url + "?t=" + new Date().getTime(); } el.body.attr("src", config.url); //弹窗拖拽功能 el[0].style["align-items"] = "center"; el[0].style["justify-content"] = "center"; var callCenterDiv = el.container[0]; callCenterDiv.onmousedown = function (e) { //获取外边框大小 var computedStyle = ""; if (window.getComputedStyle) { computedStyle = getComputedStyle(callCenterDiv, null) } else { computedStyle = div.currentStyle;//兼容IE的写法 } var b_t = computedStyle.borderTop.substring(0, computedStyle.borderTop.lastIndexOf("px")) * 1; var b_l = computedStyle.borderLeft.substring(0, computedStyle.borderLeft.lastIndexOf("px")) * 1; // 记录鼠标到盒子边缘的距离,这个距离在整个拖拽过程中是固定不变的 var disX = e.offsetX, disY = e.offsetY var left_ = e.clientX - disX - b_l; var top_ = e.clientY - disY - b_t; callCenterDiv.style.left = left_ + 'px' callCenterDiv.style.top = top_ + 'px' el[0].style["align-items"] = "stretch"; el[0].style["justify-content"] = "flex-start"; // 只要鼠标在box上按下了,在整个文档里移动都会触发拖拽 document.onmousemove = function (e) { // console.log(456,e) // 鼠标坐标减去鼠标到盒子边缘的距离 var left = e.clientX - disX - b_l; var top = e.clientY - disY - b_t; //边框限制 var b_ = 20; // 判断边界 if (left < (0 - callCenterDiv.offsetWidth + b_)) left = 0 - callCenterDiv.offsetWidth + b_ if (top < 0) top = 0 if (left > window.innerWidth + callCenterDiv.offsetWidth - b_) { left = window.innerWidth + callCenterDiv.offsetWidth - b_ } if (top > window.innerHeight + callCenterDiv.offsetHeight - b_) { top = window.innerHeight + callCenterDiv.offsetHeight - b_ } callCenterDiv.style.left = left + 'px' callCenterDiv.style.top = top + 'px' } // 鼠标离开box,但是仍然会触发document的up事件 document.onmouseup = function () { // 移除move事件 document.onmousemove = null } // 阻止默认拖拽文字 return false } el.popup_body[0].onmouseup = function () { // 移除move事件 document.onmousemove = null } }, show: function(config) { RootBody.append(this.el); this.el.animate({ "margin-left": "0px" }); }, hide: function() { // this.el.hide(); this.el.animate({ "margin-left": "100%" }); var me = this; setTimeout(function (){ me.el.remove(); }, 500); }, setSize: function(w, h) { let w_ = w.substring(0, w.length - 2); let h_ = h; if(h.substring(h.length - 2, h.length) == "px") { h_ = h.substring(0, h.length - 2) * 1 + 42; h_ += "px"; } this.el.container.css({ "width": w, "height": h_, "max-height": "90vh" }); }, setTitle: function(title) { this.el.title.html(title); this.el.popup_title.show(); this.el.popup_body.css("top", "40px"); } }); /* ******** util ************ */ util = {}; util.debug = function(message) { if (RootSetting.isDebug) { console.log(message); } }; util.buildURL = function(url) { if (!url) { return null; } if (url.startsWith("http")) { return url; } if (url.startsWith("/")) { return "/" + RootSetting.appName + url; } url = window.top.config.url_page + url return url; }; util.decode = function(obj) { if (!obj) { return null; } if ($.isArray(obj)) { return this.decodeArray(obj); } else if (typeof obj == "object") { return this.decodeObject(obj); } else if (typeof obj == "string") { try { return decodeURIComponent(obj); } catch (e) { return obj; } } else { return obj; } }; util.decodeArray = function(data) { for (var i = 0; i < data.length; i++) { if (typeof data[i] == 'string') { data[i] = this.decode(data[i]); } else { data[i] = this.decodeObject(data[i]); } } return data; }; util.decodeObject = function(data) { for (var prop in data) { if (data[prop]) { data[prop] = this.decode(data[prop]); } } return data; }; util.encode = function(obj) { if ($.isArray(obj)) { return this.encodeArray(obj); } else if (typeof obj == "object") { return this.encodeObject(obj); } else if (typeof obj == "string") { return "\"" + encodeURI(obj) + "\""; } else if (typeof obj == "boolean") { return String(obj); } else if (typeof obj == "number") { return String(obj); } else if (typeof obj === "function") { return ""; } }; util.encodeArray = function(o) { var a = ["[", ""], len = o.length, i; for (i = 0; i < len; i += 1) { a.push(this.encode(o[i]), ','); } a[a.length - 1] = ']'; return a.join(""); }; util.encodeObject = function(o) { if (!o) { return "null"; } if (o.length) { return "el"; } var a = ["{", ""]; for (var i in o) { if (i == 'parent') { continue; } a.push(this.encode(i), ":", this.encode(o[i]), ','); } a[a.length - 1] = '}'; return a.join(""); }; util.objectToURI = function(object) { if (!object) { return null; } if (typeof object == "String") { return encodeURI(object); } var param = null; for (var prop in object) { if (object[prop] != null) { if (param) { param = param + "&" + prop + "=" + encodeURI(object[prop]); } else { param = prop + "=" + encodeURI(object[prop]); } } } return param; }; util.combine = function(obj1, obj2, override) { if (!obj1) { return obj2; } if (!obj2) { return obj1; } for (var name in obj2) { if (override || obj1[name] === undefined) { obj1[name] = obj2[name]; } } return obj1; }; util.combineObj = function(obj1, obj2, override) { if (!obj1) { return obj2; } if (!obj2) { return obj1; } for (var name in obj2) { //如果1没有该属性 if (override || obj1[name] === undefined) { obj1[name] = obj2[name]; } //如果1存在该属性 else if (typeof(obj1[name]) == "object") { util.combine(obj1[name], obj2[name]); } } return obj1; }; util.setVisible = function(el, visible) { if (visible) { el.show(); } else { el.hide(); } }; util.getEl = function(element) { var type = typeof element; if (type == "string") { if ("#" != element.substring(0, 1)) { element = "#" + element; } var el = $(element); return el; } return element; }; util.pageTo = function(frame, url) { if (!url) { url = frame; frame = null; } if (!url) { return; } //1. root var exists = url && url.lastIndexOf("root/"); if (exists >= 0) { var current = window.top.location.pathname; var pos = current.indexOf("root/"); if (pos >= 0) { url = current.substring(0, pos) + url; } } //2. random if (url.indexOf("?") > 0) { url = url + "&t=" + new Date().getTime(); } else { url = url + "?t=" + new Date().getTime(); } //3. set if (frame) { if(url.substring(0, 7) == "module/") { frame.attr("src", window.top.config.url_page + url); } else if (url.substring(0, 5) == "root/") { frame.attr("src", window.top.config.url_root + url); } else if (url.substring(0, 7) == "rootjm/") { frame.attr("src", window.top.config.url_jmreport + url.substring(7)); } else { frame.attr("src", url); } } else { window.top.location.href = url; } }; // 将meta返回的字段属性转译成组件需要的属性 function metaFieldTranslateMyelementField(metaFields, type) { for (var dataname in metaFields) { if (metaFields[dataname].fields) { metaFields[dataname].fields = doMetaFieldTranslateMyelementField(metaFields[dataname].fields, type, dataname); } } return metaFields; } function doMetaFieldTranslateMyelementField(metaFields, type, dataname) { // type: "table"/"form"; // meta的字段属性:组件的字段属性 var fieldMappng_ = { input_type: "inputtype", field_name: "field", label_chinese: "labelchinese", label_english: "labelenglish", format_pattern: "formatpattern", is_filter: "isfilter", is_not_filter: "isnotfilter", options_key: "optionsgroup", input_type_filter: "inputtypefilter", filter_field: "filterfield", filter_type: "filtertype", filter_control: "isfilterable", filter_operator: "filteroperator", filter_props: "filter_props", options_pattern: "tagtype", is_readonly: "readonly", is_required: "required", validate_regex: "pattern", visible_filter_rule: "visiblefilterrule", hide_filter_rule: "hidefilterrule", is_min_width: "isminwidth", form_group_name: "group_name", table_group_name: "tablegroupname", table_form_group_name: "table_formgroup_name", label_width: "labelwidth", input_keys: "inputkeys", issortable: "issortable", is_tablesum: "istablesum", filter_is_multiple: "ismultiple", } var fieldMappng_table = { list_is_visible: "isshow", } var fieldMappng_form = { form_is_visible: "isshow", } var fieldMappng = fieldMappng_; if (type == "table") { for(var f in fieldMappng_table) { fieldMappng[f] = fieldMappng_table[f] } } else if (type == "form") { for(var f in fieldMappng_form) { fieldMappng[f] = fieldMappng_form[f] } } var metaFields_ = []; var isjoin_ = false; metaFields.map(fieldobj=>{ var field_ = fieldobj.field_name ? fieldobj.field_name : fieldobj.field; if (field_ && field_.indexOf('__') != -1) { isjoin_ = true; } }) metaFields.map(fieldobj=>{ var field_ = {} for (var key in fieldobj) { if (fieldMappng[key]) { field_[fieldMappng[key]] = fieldobj[key] } else { field_[key] = fieldobj[key] } } if (field_.field && field_.field.indexOf('__') == -1 && isjoin_) { field_.basicdataname = dataname } if (field_.issortable) { if (field_.issortable == "T") { field_.issortable = true } else if (field_.issortable == "F") { field_.issortable = false } } // 设置胶囊样式 if (field_.inputtype == 'tag' || field_.inputtype == 'capsuletag') { //从字典获取对应样式 var tagtypeList_ = window.top.Dictionary.getList("tagtype"); var tagtype_ = {}; tagtypeList_.map(tt=>{ tagtype_[tt.code] = tt.value; }) field_.tagtype = tagtype_; } metaFields_.push(field_); }) return metaFields_; } // 根据字段定义数据 // function getDataByFields(formData, formFields) { // var dataobj_ = {}; // if (formData) { // dataobj_ = clone(formData); // } // formFields.map(fieldobj=>{ // var field_ = fieldobj.field; // var field_type_ = fieldobj.inputtype || fieldobj.type; // if (field_type_ == "numberrange") { // if (dataobj_[field_] && dataobj_[field_].length == 2) { // if (dataobj_[field_][0] == null) { // dataobj_[field_][0] = undefined; // } // if (dataobj_[field_][1] == null) { // dataobj_[field_][1] = undefined; // } // } // } // if (typeof (dataobj_[field_]) == 'undefined') { // if (field_type_ == "selectmultiple" || field_type_ == "cascader" || field_type_ == "checkboxobj" || field_type_ == "uploadfilelist") { // dataobj_[field_] = []; // } // else if (field_type_ == "switch") { // dataobj_[field_] = false; // } // else if (field_type_ != "number" && field_type_ != "numberrange") { // dataobj_[field_] = ""; // } // else { // dataobj_[field_] = null; // } // } // }) // return dataobj_; // }; ///////////////////formatter////////////////// ///////////////////具体实现//////////////////// //日期格式转换 function dateFormat(date, fmt) { if (typeof date == 'string') { date = new Date(date); } if (null == date || undefined == date) return ''; var o = { "M+": date.getMonth() + 1, //月份 "d+": date.getDate(), //日 "h+": date.getHours(), //小时 "m+": date.getMinutes(), //分 "s+": date.getSeconds(), //秒 "S": date.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.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 toMoney(num, digit, isnotsymbol) { var symbol = "¥"; if (isnotsymbol) { symbol = ""; } if (digit == null || digit == "" || isNaN(digit)) { digit = 2; } else { digit = typeof digit == 'string' ? digit * 1 : digit } if (num) { if (isNaN(num)) { //alert('金额中含有不能识别的字符'); return; } num = typeof num == 'string' ? parseFloat(num) : num // 判断是否是字符串如果是字符串转成数字 num = num.toFixed(digit); // 保留两位 num = parseFloat(num); // 转成数字 num = num.toLocaleString(); // 转成金额显示模式 // 判断是否有小数 if (num.indexOf('.') === -1) { num = symbol + num + '.00'; } else { // console.log(num.split('.')[1].length) num = num.split('.')[1].length < 2 ? symbol + num + '0' : symbol + num; } return num; // 返回的是字符串23,245.12保留2位小数 } else { return num = null; } }; //数值转率,可设置小数位数 function toPercent(num, digit) { if (digit == null || digit == "" || isNaN(digit)) { digit = 2; } else { digit = typeof digit == 'string' ? digit * 1 : digit } if (num || num == 0) { if (isNaN(num)) { //alert('金额中含有不能识别的字符'); return; } num = typeof num == 'string' ? parseFloat(num) : num // 判断是否是字符串如果是字符串转成数字 num = num.toFixed(digit); // 保留两位 num = parseFloat(num); // 转成数字 num += "%"; return num; // 返回的是字符串23,245.12保留2位小数 } else { return num = null; } }; //数值保留几位小数 function toFloat(num, digit) { if (digit == null || digit == "" || isNaN(digit)) { digit = 2; } else { digit = typeof digit == 'string' ? digit * 1 : digit } if (num) { if (isNaN(num)) { //alert('金额中含有不能识别的字符'); return; } num = typeof num == 'string' ? parseFloat(num) : num // 判断是否是字符串如果是字符串转成数字 num = num.toFixed(digit); // 保留两位 num = parseFloat(num); // 转成数字 return num; // 返回的是字符串23,245.12保留2位小数 } else { return num = null; } }; //数值保留几位小数, 小数值直接截取 function toFloatBySubstring(num, digit) { if (digit == null || digit == "" || isNaN(digit)) { digit = 2; } else { digit = typeof digit == 'string' ? digit * 1 : digit } // 设置小数位数 digit += 1; // 获取小数位数 var max_digit_ = 0; if (num) { if (isNaN(num)) { return; } num = num.toString(); if (num.indexOf(".") != -1) { num = num.substring(0, num.indexOf(".") + digit); } num = parseFloat(num); // 转成数字 return num; // 返回的是字符串23,245.12保留2位小数 } else { return num = null; } }; function toSplit(row, format) { var str_ = ""; //format = "#{name}-{name}%" var treeTxtList_ = []; var treeTxtFormatter_ = []; treeTxtFormatter_ = format.split("{"); treeTxtFormatter_.map(f=>{ if (f.indexOf('}') != -1) { var fa_ = f.split("}"); if (fa_[0]) { if (row[fa_[0]]) { treeTxtList_.push(row[fa_[0]]); } } if (fa_[1]) { treeTxtList_.push(fa_[1]); } } else if (f) { treeTxtList_.push(f); } }) treeTxtList_.map(s=>{ str_ += s; }) return str_; }; /////////////////组件中的formatter/////////////////// //通用formatterjson转换,根据json对应关系显示, function formatter_json(row, column, cellValue, index, json_) { var json = json_; var val = ""; var cellValue_ = null; if (cellValue || cellValue == false || cellValue == 0) { cellValue_ = cellValue.toString() } if (typeof(json_)=="string") { json = JSON.parse(json_); } if (json[cellValue]) { return json[cellValue]; } else if (cellValue && json.othervaldefaultval) { //没有对应关系但是有值,可设置其它数值的显示值 return json.othervaldefaultval; } else if (!cellValue && json.defaultval) { //没有值,可设置默认显示值 return json.defaultval; } else { return cellValue } }; // 字段加密 function formatter_password(row, column, cellValue, index) { return "********"; }; //字段拼接显示 function formatter_split(row, column, cellValue, index, format) { if (cellValue) { return toSplit(row, format); } return cellValue; }; //日期格式化 function formatter_date(row, column, cellValue, index, format) { var format_ = "yyyy-MM-dd"; if (format) { format_ = format; } if (cellValue) { return dateFormat(cellValue, format_); } return cellValue; }; //金额格式化 function formatter_money(row, column, cellValue, index, digit) { if (cellValue) { return toMoney(cellValue, digit); } return cellValue; }; //小数格式化 function formatter_float(row, column, cellValue, index, digit) { if (cellValue) { return toFloat(cellValue, digit); } return cellValue; }; //率转换格式化 function formatter_percent(row, column, cellValue, index, digit) { if (cellValue) { return toPercent(cellValue, digit); } return cellValue; }; //有前缀或后缀的格式化 function formatter_prefixorunit(row, column, cellValue, index, prefix, unit) { if (cellValue != null) { var cellValue_ = cellValue; if (prefix) { cellValue_ = prefix + (cellValue_); } if (unit) { cellValue_ = (cellValue_) + unit; } return cellValue_; } return cellValue; }; ////////////////非通用的格式化//////////////// function formatter_earlyWarning(row, column, cellValue, index) { var d_ = 31; var date_ = Date.parse(new Date()); var closedate_ = Date.parse(new Date(row.closedate)); var d_ = parseInt((closedate_-date_)/ (1000 * 60 * 60 * 24)); return d_; }; FormatCenter.load();