// +---------------------------------------------------------------------- require __DIR__ . '/Installer.php'; $installer = new Installer(); // 已安装检测 if ($installer->isInstalled() && !isset($_GET['action'])) { header('Content-Type: text/html; charset=utf-8'); echo '' . '系统已安装' . '

系统已安装

' . '

检测到安装锁文件 install.lock,系统已完成安装。

' . '

如需重新安装,请先删除项目根目录下的 install.lock 并清空数据库,再访问本向导。

' . '
'; exit; } $action = (string) ($_GET['action'] ?? ($_POST['action'] ?? '')); if ($action === 'env') { header('Content-Type: application/json; charset=utf-8'); echo json_encode(['ok' => true, 'items' => $installer->checkEnv()]); exit; } if ($action === 'dbtest') { header('Content-Type: application/json; charset=utf-8'); echo json_encode($installer->testDb($installer->getDbConfig($_POST))); exit; } if ($action === 'install') { header('Content-Type: application/json; charset=utf-8'); $cfg = $installer->getDbConfig($_POST); $test = $installer->testDb($cfg); if (!$test['ok']) { echo json_encode(['ok' => false, 'msg' => '数据库连接失败:' . ($test['msg'] ?? '')]); exit; } try { $installer->importSql($cfg); $installer->createAdmin($cfg, [ 'account' => $_POST['admin_account'] ?? '', 'password' => $_POST['admin_password'] ?? '', 'nickname' => $_POST['admin_nickname'] ?? '', 'email' => $_POST['admin_email'] ?? '', 'mobile' => $_POST['admin_mobile'] ?? '', ]); $installer->writeEnv($cfg); $installer->makeLock(); echo json_encode(['ok' => true, 'msg' => '安装完成']); } catch (\Throwable $e) { echo json_encode(['ok' => false, 'msg' => '安装失败:' . $e->getMessage()]); } exit; } // 默认:展示前端向导页 header('Content-Type: text/html; charset=utf-8'); include __DIR__ . '/index.html';