Files
ulthon_admin/public/static/plugs/ulthon-admin/admin-utils.js
augushong 6dda5890e0 refactor(ulthon-admin): 拆分 JS 单文件为多模块架构
将 ulthon-admin.js (3258行) 按职责拆分为 5 个独立模块文件:- admin-core.js (248行): 配置、请求封装、消息提示、权限检查- admin-utils.js (224行): 工具函数(URL参数、页面设置、弹层等)- admin-table.js (1370行): 表格模块(渲染、搜索、工具栏、列模板等)- admin-api.js (687行): API组件(表单提交、上传、编辑器、选择器等)- admin-listen.js (267行): 全局事件监听(按钮、删除、刷新等)

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-05-27 07:51:30 +08:00

243 lines
7.6 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 admin = window.UA_ADMIN;
var { layer, table } = window.UA_CORE;
admin.checkMobile = function () {
return tools.checkMobile();
};
admin.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 (admin.checkMobile() || width === undefined || height === undefined) {
layer.full(index);
}
if (isResize) {
$(window).on("resize", function () {
index && layer.full(index);
});
}
};
admin.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;
};
admin.dataBrage = null;
admin.getDataBrage = function (keys, defaultValue) {
if (this.dataBrage == null) {
this.dataBrage = JSON.parse($('#data-brage').text());
}
if (typeof defaultValue == 'undefined') {
defaultValue = undefined;
}
return admin.dataGet(this.dataBrage, keys, defaultValue);
};
admin.dataGet = function (data, keys, defaultValue) {
return (
(!Array.isArray(keys)
? keys.replace(/\[/g, '.').replace(/\]/g, '').split('.')
: keys
).reduce((o, k) => (o || {})[k], data) || defaultValue
);
};
admin.getExtGroupName = function (ext) {
var extGroup = admin.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判断变量是否为空
admin.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;
};
admin.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';
};
admin.triggerEventReplaceJs = function (name, defaultCallback, replaceCallback) {
var code = $('#event-replace-js-' + name).html();
if (admin.empty(code)) {
defaultCallback();
} else {
replaceCallback(code);
}
};
admin.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;
};
admin.getPageSetting = function (key, defaultValue, global = false) {
if (!global) {
key = window.CONFIG.PAGE_KEY_NAME + '_' + key;
}
return tools.getLocal(key, defaultValue);
};
admin.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
*/
admin.trySetPageSetting = function (key, value, global) {
var oldValue = admin.getPageSetting(key, undefined, global);
if (!oldValue) {
admin.setPageSetting(key, value, global);
return value;
}
return oldValue;
};
admin.isCurrentIndex = function () {
if (window.pageType && window.pageType == 'index') {
return true;
}
return false;
};
admin.isParentIndex = function () {
try {
if (window.parent && window.parent.pageType && window.parent.pageType == 'index') {
return true;
}
} catch (e) {
return false;
}
return false;
};
admin.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);
};
admin.getCurrentPageId = function () {
// pageId就是路径加参数
var path = location.pathname;
var params = location.search;
return path + params;
};
admin.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;
};
admin.getMenuInfoByTabId = function (tabId) {
var menuValue = null;
this.findIndexPage(function (w) {
var menu = w.miniTab.searchMenu(tabId);
if (menu) {
menuValue = menu;
}
});
return menuValue;
};
admin.getMenuTitleByTabId = function (tabId, defaultValue) {
var menuTitle = defaultValue;
var menu = this.getMenuInfoByTabId(tabId);
if (menu) {
menuTitle = menu.title;
}
return menuTitle;
};
})();