/******** 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: [
|
'<div id="win_background" role="dialog" aria-modal="true" aria-label="dialog" class="popup-cover">',
|
'<div id="win_container" class="popup-page">',
|
|
'<div id="win_btn_closepopup_div" class="popup-close" style="top: 10px; right: 20px; color: #d55; font-size: 18px; background-color: #fff; border: 1px solid #e38c8c; border-radius: 5px; height: 20px; width: 20px; line-height: 20px; text-align: center;">',
|
// '<i id="win_btn_closepopup" class="el-icon-circle-close"></i>',
|
'<i id="win_btn_closepopup" class="el-icon-close"></i>',
|
'</div>',
|
|
'<div class="popup-close">',
|
'<i id="win_btn_close" class="el-icon-close"></i>',
|
'</div>',
|
|
'<div class="popup-drag" style="width: 100%; height: 0px; background-color: #7b7f7f;">',
|
'</div>',
|
|
'<div class="popup-title">',
|
'<span id="win_icon" class="popup-title-icon icon-font"></span>',
|
'<span id="win_title" class="popup-title-icon icon-font"></span>',
|
'</div>',
|
'<div v-drag class="popup-body">',
|
'<iframe v-drag id="win_body" style="width: 100%; min-height: 100%;" frameborder="0"></iframe>',
|
'</div>',
|
'</div>',
|
'</div>'
|
],
|
|
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 + "&" + new Date().getTime();
|
} else {
|
url = url + "?" + 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;
|
}
|
};
|
|
///////////////////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) {
|
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 = '¥' + num + '.00';
|
} else {
|
// console.log(num.split('.')[1].length)
|
num = num.split('.')[1].length < 2 ? '¥' + num + '0' : '¥' + 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) {
|
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 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();
|