From d7dcfb95b6e1819d0adcfd4804f38c027331bf6f Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Tue, 20 Aug 2024 17:22:54 +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 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/public/static/config-admin.js b/public/static/config-admin.js index 87944b0..cb640f8 100644 --- a/public/static/config-admin.js +++ b/public/static/config-admin.js @@ -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); + }); + } +})