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:41:32 +08:00
parent d7dcfb95b6
commit c3a6118387

View File

@@ -34,7 +34,11 @@ window.PATH_CONFIG = PATH_CONFIG;
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]()
if (typeof Controller[CONFIG.ACTION] == "function") {
Controller[CONFIG.ACTION]()
} else {
console.error(`\r\n控制器对应的JS ${CONFIG.CONTROLLER_JS_PATH} 监测异常\r\n当前Js文件中不存在监听 ${CONFIG.ACTION} 方法`)
}
}, function (e) {
console.error(e);
});