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>
This commit is contained in:
augushong
2026-05-27 07:51:30 +08:00
parent fefe2fe95f
commit 6dda5890e0
5 changed files with 3291 additions and 0 deletions

View File

@@ -0,0 +1,289 @@
(function () {
window.onInitElemStyle = function () {
miniTheme.renderElemStyle();
$('iframe').each(function (index, iframe) {
if (typeof iframe.contentWindow.onInitElemStyle == "function") {
iframe.contentWindow.onInitElemStyle();
}
});
};
window.onInitElemStyle();
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate,
upload = layui.upload,
element = layui.element,
laytpl = layui.laytpl,
util = layui.util;
layer.config({
skin: 'layui-layer-easy'
});
var init = {
tableElem: '#currentTable',
tableRenderId: 'currentTableRenderId',
uploadUrl: 'ajax/upload',
uploadExts: '',
extGroup: {}
};
var table;
table = layui.table;
var extGroup = {
// 图片扩展名数组
'image': ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'ico', 'webp', 'svg'],
// word扩展名数组
'word': ['doc', 'docx'],
// excel扩展名数组
'excel': ['xls', 'xlsx'],
// ppt扩展名数组
'ppt': ['ppt', 'pptx'],
// pdf扩展名数组
'pdf': ['pdf'],
// 压缩文件扩展名数组
'zip': ['zip', 'rar', '7z'],
// 文本文件扩展名数组
'txt': ['txt'],
// 音乐文件扩展名数组
'music': ['mp3', 'wma', 'wav', 'mid', 'm4a'],
// 视频文件扩展名数组
'video': ['mp4', 'avi', 'wmv', '3gp', 'flv'],
// visio扩展名数组
'visio': ['vsd', 'vsdx'],
'file': []
};
var allExtGroup = [];
for (const extGroupName in extGroup) {
if (Object.hasOwnProperty.call(extGroup, extGroupName)) {
const extGroupList = extGroup[extGroupName];
allExtGroup = allExtGroup.concat(extGroupList);
}
}
extGroup['office'] = [].concat(extGroup['word'], extGroup['excel'], extGroup['ppt'], extGroup['pdf']);
extGroup['media'] = [].concat(extGroup['image'], extGroup['music'], extGroup['video']);
init.uploadExts += allExtGroup.join('|');
init.extGroup = extGroup;
var admin = {
init: init,
config: {
shade: [0.02, '#000'],
},
url: function (url) {
var urlPrefixCheck = ['/', 'http://', 'https://'];
for (const index in urlPrefixCheck) {
if (Object.hasOwnProperty.call(urlPrefixCheck, index)) {
const prefix = urlPrefixCheck[index];
if (url.indexOf(prefix) === 0) {
return url;
}
}
}
return '/' + CONFIG.ADMIN + '/' + url;
},
headers: function () {
return { 'X-CSRF-TOKEN': window.CONFIG.CSRF_TOKEN };
},
checkAuth: function (node, elem) {
if (node === '1') {
return true;
}
if (CONFIG.IS_SUPER_ADMIN) {
return true;
}
if ($(elem).attr('data-auth-' + node) === '1') {
return true;
} else {
return false;
}
},
parame: function (param, defaultParam) {
return param !== undefined ? param : defaultParam;
},
request: {
post: function (option, ok, no, ex, complete) {
return admin.request.ajax('post', option, ok, no, ex, complete);
},
get: function (option, ok, no, ex, complete) {
return admin.request.ajax('get', option, ok, no, ex, complete);
},
ajax: function (type, option, ok, no, ex, complete) {
type = type || 'get';
option.url = option.url || '';
option.data = option.data || {};
option.prefix = option.prefix || false;
option.statusName = option.statusName || 'code';
option.statusCode = option.statusCode || 0;
ok = ok || function (res) {};
var originalOk = ok;
ok = function (res) {
originalOk(res);
complete()
}
complete = complete || function () {
};
if (no) {
var originalNo = no;
no = function (res) {
originalNo(res);
complete();
};
} else {
no = function (res) {
var msg = res.msg == undefined ? '返回数据格式有误' : res.msg;
admin.msg.error(msg);
complete();
return false;
};
}
if (ex) {
var originalEx = ex;
ex = function (res) {
originalEx(res);
complete();
};
} else {
ex = function (res) {
complete();
};
}
if (option.url == '') {
admin.msg.error('请求地址不能为空');
return false;
}
if (option.prefix == true) {
option.url = admin.url(option.url);
}
loading.show();
$.ajax({
url: option.url,
type: type,
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
dataType: "json",
headers: admin.headers(),
data: option.data,
timeout: 60000,
success: function (res) {
loading.hide();
if (eval('res.' + option.statusName) == option.statusCode) {
return ok(res);
} else {
return no(res);
}
},
error: function (xhr, textstatus, thrown) {
var errorMsg = '';
if (xhr.responseJSON.message) {
errorMsg = xhr.responseJSON.message;
}
loading.hide();
admin.msg.error('Status:' + xhr.status + '' + xhr.statusText + ',请稍后再试!<br/>' + errorMsg, function () {
ex(this);
});
return false;
},
});
}
},
common: {
parseNodeStr: function (node) {
var array = node.split('/');
$.each(array, function (key, val) {
if (key === 0) {
val = val.split('.');
$.each(val, function (i, v) {
val[i] = admin.common.humpToLine(v.replace(v[0], v[0].toLowerCase()));
});
val = val.join(".");
array[key] = val;
}
});
node = array.join("/");
return node;
},
lineToHump: function (name) {
return name.replace(/\_(\w)/g, function (all, letter) {
return letter.toUpperCase();
});
},
humpToLine: function (name) {
return name.replace(/([A-Z])/g, "_$1").toLowerCase();
},
},
msg: {
// 成功消息
success: function (msg, callback) {
if (callback === undefined) {
callback = function () {
};
}
var index = layer.msg(msg, { icon: 1, shade: admin.config.shade, scrollbar: false, time: 800, shadeClose: true }, callback);
return index;
},
// 失败消息
error: function (msg, callback) {
if (callback === undefined) {
callback = function () {
};
}
var index = layer.msg(msg, { icon: 2, shade: admin.config.shade, scrollbar: false, time: -1, shadeClose: true }, callback);
return index;
},
// 警告消息框
alert: function (msg, callback) {
var index = layer.alert(msg, { end: callback, scrollbar: false });
return index;
},
// 对话框
confirm: function (msg, ok, no) {
var index = layer.confirm(msg, { title: '操作确认', btn: ['确认', '取消'] }, function () {
typeof ok === 'function' && ok.call(this);
}, function () {
typeof no === 'function' && no.call(this);
});
return index;
},
// 消息提示
tips: function (msg, time, callback) {
var index = layer.msg(msg, { time: (time || 0.8) * 1000, shade: this.shade, end: callback, shadeClose: true });
return index;
},
// 加载中提示
loading: function (msg, callback) {
var index = msg ? layer.msg(msg, { icon: 16, scrollbar: false, shade: this.shade, time: 0, end: callback }) : layer.load(2, { time: 0, scrollbar: false, shade: this.shade, end: callback });
return index;
},
// 关闭消息框
close: function (index) {
return layer.close(index);
}
}
};
window.UA_CORE = { form: form, layer: layer, laydate: laydate, upload: upload, element: element, laytpl: laytpl, util: util, table: table };
window.UA_SHARED = { init: init, extGroup: extGroup };
window.UA_ADMIN = admin;
})();