/** * 应用主入口文件 * 根据当前页面自动初始化相应的页面逻辑 */ import { IndexPage, BasicInfoPage } from './pages/index.js'; /** * 应用类 */ class App { constructor() { this.currentPage = null; } /** * 初始化应用 */ init() { // 等待 DOM 完全准备好 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => this.setup()); } else { // DOM 已经准备好,使用 setTimeout 确保在下一个事件循环中执行 setTimeout(() => this.setup(), 0); } } /** * 设置应用 */ setup() { // 检测当前页面并初始化对应的页面逻辑 if (this.isIndexPage()) { console.log('[App] 初始化主页面'); this.currentPage = new IndexPage(); } else if (this.isBasicInfoPage()) { console.log('[App] 初始化基本信息页面'); this.currentPage = new BasicInfoPage(); } else { console.warn('[App] 未知的页面类型'); } } /** * 判断是否为主页面 * @returns {boolean} */ isIndexPage() { return document.getElementById('loanAmount') !== null; } /** * 判断是否为基本信息页面 * @returns {boolean} */ isBasicInfoPage() { return document.getElementById('assetList') !== null; } /** * 销毁应用 */ destroy() { if (this.currentPage) { this.currentPage.destroy(); this.currentPage = null; } } } // 创建应用实例并初始化 const app = new App(); app.init(); // 将应用实例暴露到全局,方便调试 window.__app = app; console.log('[App] 应用入口已加载');