From c3a611838750a32379f2f08eb009074a7325e736 Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Tue, 20 Aug 2024 17:41:32 +0800 Subject: [PATCH] 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. --- public/static/config-admin.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/static/config-admin.js b/public/static/config-admin.js index cb640f8..addbee9 100644 --- a/public/static/config-admin.js +++ b/public/static/config-admin.js @@ -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); });