fix(admin-config): ensure required JS loads on DOM ready; add error handling

Moved the RequireJS dynamic load of the controller-specific JavaScript to execute upon
the 'load' event of the window, guaranteeing that all required DOM elements are available
before the script execution begins. Also, added error handling to log any require failures
to the console for easier debugging.
This commit is contained in:
wolfcode
2024-08-20 17:22:54 +08:00
parent 55c4743417
commit d7dcfb95b6

View File

@@ -31,11 +31,13 @@ var PATH_CONFIG = {
window.PATH_CONFIG = PATH_CONFIG;
// 初始化控制器对应的JS自动加载
if ("undefined" != typeof CONFIG.AUTOLOAD_JS && CONFIG.AUTOLOAD_JS) {
require([BASE_URL + CONFIG.CONTROLLER_JS_PATH], function (Controller) {
if (eval('Controller.' + CONFIG.ACTION)) {
eval('Controller.' + CONFIG.ACTION + '()');
}
});
}
window.addEventListener('load', function () {
if ("undefined" != typeof CONFIG.AUTOLOAD_JS && CONFIG.AUTOLOAD_JS) {
require([BASE_URL + CONFIG.CONTROLLER_JS_PATH], function (Controller) {
Controller[CONFIG.ACTION]()
}, function (e) {
console.error(e);
});
}
})