Files
ulthon_admin/public/static/plugs/ulthon-admin/admin-utils.js

243 lines
7.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function () {
var ua = window.UA_ADMIN;
var { layer, table } = window.UA_CORE;
ua.checkMobile = function () {
return tools.checkMobile();
};
ua.open = function (title, url, width, height, isResize, shadeClose = false) {
isResize = isResize === undefined ? true : isResize;
var index = layer.open({
title: title,
type: 2,
area: [width, height],
content: url,
maxmin: true,
moveOut: true,
shadeClose: shadeClose,
success: function (layero, index) {
var body = layer.getChildFrame('body', index);
if (body.length > 0) {
$.each(body, function (i, v) {
// todo 优化弹出层背景色修改
$(v).before('<style>\n' +
'html, body {\n' +
' background: #ffffff;\n' +
'}\n' +
'</style>');
});
}
},
end: function () {
index = null;
}
});
if (ua.checkMobile() || width === undefined || height === undefined) {
layer.full(index);
}
if (isResize) {
$(window).on("resize", function () {
index && layer.full(index);
});
}
};
ua.getQueryVariable = function (variable, defaultValue) {
if (typeof defaultValue == 'undefined') {
defaultValue = undefined;
}
var query = window.location.search.substring(1);
query = query.replace(/\+/g, ' ');
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return decodeURIComponent(pair[1]);
}
}
return defaultValue;
};
ua.dataBrage = null;
ua.getDataBrage = function (keys, defaultValue) {
if (this.dataBrage == null) {
this.dataBrage = JSON.parse($('#data-brage').text());
}
if (typeof defaultValue == 'undefined') {
defaultValue = undefined;
}
return ua.dataGet(this.dataBrage, keys, defaultValue);
};
ua.dataGet = function (data, keys, defaultValue) {
return (
(!Array.isArray(keys)
? keys.replace(/\[/g, '.').replace(/\]/g, '').split('.')
: keys
).reduce((o, k) => (o || {})[k], data) || defaultValue
);
};
ua.getExtGroupName = function (ext) {
var extGroup = ua.init.extGroup;
var groupName = 'file';
for (const extGroupName in extGroup) {
if (Object.hasOwnProperty.call(extGroup, extGroupName)) {
const extGroupList = extGroup[extGroupName];
if (extGroupList.indexOf(ext) != -1) {
groupName = extGroupName;
break;
}
}
}
return groupName;
};
//js版empty判断变量是否为空
ua.empty = function (r) {
var n, t, e, f = [void 0, null, !1, 0, "", "0"];
for (t = 0, e = f.length; t < e; t++) if (r === f[t]) return !0;
if ("object" == typeof r) {
for (n in r) if (r.hasOwnProperty(n)) return !1;
return !0;
}
return !1;
};
ua.bytes = function (size) {
if (size > 0) {
const kb = 1024;
const unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(size) / Math.log(kb));
const num = (size / Math.pow(kb, i)).toPrecision(3);
const u = unit[i];
return num + u;
}
return '0B';
};
ua.triggerEventReplaceJs = function (name, defaultCallback, replaceCallback) {
var code = $('#event-replace-js-' + name).html();
if (ua.empty(code)) {
defaultCallback();
} else {
replaceCallback(code);
}
};
ua.randdomString = function (len) {
len = len || 32;
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
var maxPos = $chars.length;
var pwd = '';
for (var i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
};
ua.getPageSetting = function (key, defaultValue, global = false) {
if (!global) {
key = window.CONFIG.PAGE_KEY_NAME + '_' + key;
}
return tools.getLocal(key, defaultValue);
};
ua.setPageSetting = function (key, value, global) {
if (!global) {
key = window.CONFIG.PAGE_KEY_NAME + '_' + key;
}
return tools.setLocal(key, value);
};
/**
* 如果不存在则写入,返回有效的值
* 如果不存在则返回新的值,否则返回之前设置的值
*
* @param {string} key
* @param {mixed} value
* @param {boolean} global
* @returns
*/
ua.trySetPageSetting = function (key, value, global) {
var oldValue = ua.getPageSetting(key, undefined, global);
if (!oldValue) {
ua.setPageSetting(key, value, global);
return value;
}
return oldValue;
};
ua.isCurrentIndex = function () {
if (window.pageType && window.pageType == 'index') {
return true;
}
return false;
};
ua.isParentIndex = function () {
try {
if (window.parent && window.parent.pageType && window.parent.pageType == 'index') {
return true;
}
} catch (e) {
return false;
}
return false;
};
ua.findIndexPage = function (findCallback, missCallback) {
if (!findCallback) {
findCallback = function (w) { return w; };
}
if (!missCallback) {
missCallback = function (w) { return w; };
}
if (this.isCurrentIndex()) {
return findCallback(window);
}
var parent = window.parent;
if (parent && parent != window) {
return parent.ua.findIndexPage(findCallback, missCallback);
}
return missCallback(null);
};
ua.getCurrentPageId = function () {
// pageId就是路径加参数
var path = location.pathname;
var params = location.search;
return path + params;
};
ua.findPageId = function (tabId) {
var iframeWindow;
this.findIndexPage(function (window) {
// 查找对应的tab内容区域
var tabContent = window.layui.$('.layui-tab-content .layui-tab-item[lay-id="' + tabId + '"]');
if (tabContent.length > 0) {
var iframe = tabContent.find('iframe')[0];
if (iframe) {
iframeWindow = iframe.contentWindow;
}
}
});
return iframeWindow;
};
ua.getMenuInfoByTabId = function (tabId) {
var menuValue = null;
this.findIndexPage(function (w) {
var menu = w.miniTab.searchMenu(tabId);
if (menu) {
menuValue = menu;
}
});
return menuValue;
};
ua.getMenuTitleByTabId = function (tabId, defaultValue) {
var menuTitle = defaultValue;
var menu = this.getMenuInfoByTabId(tabId);
if (menu) {
menuTitle = menu.title;
}
return menuTitle;
};
})();