/******** 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); } 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) { 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"); result_ = JSON.parse(result_); 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) {} }, call: function(url, param, callback, onFail) { if (!url) { return; } var me = this; var afterRequest = function(doCallback, result) { if (doCallback) { try { result = util.decode(result); } finally { doCallback(result); } } }; 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) { 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; } }); Dictionary = new DictionaryClass(); var PopupWindowClass = Object.subClass({ width: 600, height: 400, template: [ '