const InstallPage = { step: 1, async render() { const status = await API.get('/install/status'); if (status.installed) { location.hash = '#/login'; return ''; } return `
`; }, mount() { this.showStep(1); }, showStep(n) { this.step = n; const ct = document.getElementById('install-steps'); if (n === 1) this.renderDBStep(ct); else if (n === 2) this.renderAdminStep(ct); }, renderDBStep(ct) { ct.innerHTML = `
第1步:数据库配置
如不存在将自动创建
`; document.getElementById('install-db').onsubmit = async e => { e.preventDefault(); const btn = e.target.querySelector('button'); btn.disabled = true; btn.innerHTML = ' 测试中...'; try { await API.post('/install/check-db', { host: document.getElementById('db-host').value, port: document.getElementById('db-port').value, user: document.getElementById('db-user').value, password: document.getElementById('db-pass').value, database: document.getElementById('db-name').value, }); this.dbConfig = { host: document.getElementById('db-host').value, port: document.getElementById('db-port').value, user: document.getElementById('db-user').value, pass: document.getElementById('db-pass').value, name: document.getElementById('db-name').value, }; this.showStep(2); } catch (ex) { document.getElementById('db-err').textContent = ex.message; document.getElementById('db-err').classList.remove('hidden'); btn.disabled = false; btn.innerHTML = ' 测试连接并继续'; } }; }, renderAdminStep(ct) { ct.innerHTML = `
第2步:创建服主账号
注意:安装完成后需要重启服务器才能加载业务路由。请记好账号密码。
`; document.getElementById('install-admin').onsubmit = async e => { e.preventDefault(); const btn = e.target.querySelector('button'); btn.disabled = true; btn.innerHTML = ' 安装中...'; try { await API.post('/install/complete', { ...this.dbConfig, db_host: this.dbConfig.host, db_port: this.dbConfig.port, db_user: this.dbConfig.user, db_pass: this.dbConfig.pass, db_name: this.dbConfig.name, site_name: document.getElementById('ia-sitename').value, site_url: document.getElementById('ia-siteurl').value, admin_username: document.getElementById('ia-username').value, admin_password: document.getElementById('ia-password').value, admin_email: document.getElementById('ia-email').value, admin_game_name: document.getElementById('ia-game').value, admin_game_uid: document.getElementById('ia-uid').value, }); document.getElementById('install-admin').innerHTML = '

安装成功!

系统已就绪,正在刷新并跳转登录...

'; setTimeout(() => location.reload(), 1500); } catch (ex) { document.getElementById('ia-err').textContent = ex.message; document.getElementById('ia-err').classList.remove('hidden'); btn.disabled = false; btn.innerHTML = ' 完成安装'; } }; } };