guanghulab/modules/m-channel/module-loader.js
Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

37 lines
1.2 KiB
JavaScript

// 模块加载器
window.ModuleLoader = {
loadModule: function(moduleName, containerId) {
console.log(`[loader] 加载模块: ${moduleName}`);
const module = ModuleRegistry.get(moduleName);
if (!module) {
console.error(`[loader] 模块 ${moduleName} 未注册`);
return;
}
const container = document.getElementById(containerId);
if (!container) {
console.error(`[loader] 容器 ${containerId} 不存在`);
return;
}
// 如果模块有 init 方法
if (module.init && typeof module.init === 'function') {
module.init(container);
} else {
container.innerHTML = `<div>模块 ${moduleName} 内容</div>`;
}
ModuleLifecycle.onLoad(moduleName);
},
unloadModule: function(moduleName) {
console.log(`[loader] 卸载模块: ${moduleName}`);
const module = ModuleRegistry.get(moduleName);
if (module && module.destroy && typeof module.destroy === 'function') {
module.destroy();
}
ModuleLifecycle.onUnload(moduleName);
}
};