refactor: 整体迁移控制面至MySQL + 替换UI框架为Element Plus

1. 移除naive-ui依赖,迁移前端至Element Plus
2. 重构后端数据库层,切换为MySQL替代SQLite
3. 调整项目部署架构,停止exe打包改为源码部署
4. 新增设备上报接口与相关数据库模型
5. 优化配置路径与SQL语法,替换为MySQL占位符格式
6. 调整站点名称与文案,统一为「37du 插件管理平台」
7. 新增SQLite到MySQL迁移脚本
This commit is contained in:
2026-09-16 15:58:45 +08:00
parent 4363116e31
commit 84d3e103ec
54 changed files with 5542 additions and 1890 deletions
+39 -9
View File
@@ -22,7 +22,7 @@ router = APIRouter()
def _account_disabled(acct: str) -> bool:
"""账号是否已停用(停用后机器侧一律不给插件/授权)。"""
with _db() as conn:
row = conn.execute("SELECT status FROM accounts WHERE account = ?", (acct,)).fetchone()
row = conn.execute("SELECT status FROM accounts WHERE account = %s", (acct,)).fetchone()
return bool(row) and not bool(row["status"])
@@ -49,7 +49,7 @@ def plugins(account: str = Query(default="", description="账号(旧底座按此
SELECT p.id, p.name, p.latest_version AS version
FROM plugins p
JOIN account_plugins ap ON ap.plugin_id = p.id
WHERE ap.account = ?
WHERE ap.account = %s
ORDER BY p.id
""",
(acct,),
@@ -72,7 +72,7 @@ def platforms_allowed(account: str = Query(default="", description="账号(旧
return {"account": acct, "allowed": []}
with _db() as conn:
rows = conn.execute(
"SELECT platform_id FROM account_platforms WHERE account = ? ORDER BY platform_id",
"SELECT platform_id FROM account_platforms WHERE account = %s ORDER BY platform_id",
(acct,),
).fetchall()
return {"account": acct, "allowed": [dict(r)["platform_id"] for r in rows]}
@@ -112,7 +112,7 @@ def pkg(plugin_id: str, version: str,
_check_token(x_api_token)
with _db() as conn:
row = conn.execute(
"SELECT filename FROM plugin_versions WHERE plugin_id = ? AND version = ?",
"SELECT filename FROM plugin_versions WHERE plugin_id = %s AND version = %s",
(plugin_id, version),
).fetchone()
if not row:
@@ -147,9 +147,9 @@ def me_license(account: str = Query(...), device: str = Query(default=""),
rows = conn.execute(
"""
SELECT g.plugin_id, g.can_download, g.can_run, p.name, p.status, p.latest_version
FROM plugin_grants g
FROM account_plugins g
JOIN plugins p ON p.id = g.plugin_id
WHERE g.account = ?
WHERE g.account = %s
""",
(account.strip(),),
).fetchall()
@@ -199,10 +199,10 @@ def download_ticket(plugin_id: str, version: str,
raise HTTPException(400, "account 不能为空")
with _db() as conn:
row = conn.execute(
"SELECT can_download FROM plugin_grants WHERE account = ? AND plugin_id = ?",
"SELECT can_download FROM account_plugins WHERE account = %s AND plugin_id = %s",
(account.strip(), plugin_id)).fetchone()
ver = conn.execute(
"SELECT filename, sha256 FROM plugin_versions WHERE plugin_id = ? AND version = ?",
"SELECT filename, sha256 FROM plugin_versions WHERE plugin_id = %s AND version = %s",
(plugin_id, version)).fetchone()
if not ver:
raise HTTPException(404, f"未找到插件包 {plugin_id}@{version}")
@@ -243,12 +243,42 @@ def runtime_report(b: schemas.RuntimeReportIn,
with _db() as conn:
conn.execute(
"INSERT INTO runtime_reports(account, device_id, plugin_id, version, status, msg, duration_sec, at) "
"VALUES (?,?,?,?,?,?,?,?)",
"VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",
(b.account, b.device_id, b.plugin_id, b.version, b.status, b.msg, b.duration_sec, _now()))
conn.commit()
return {"ok": True}
@router.post("/api/device/report")
def device_report(b: schemas.DeviceReportIn,
x_api_token: str = Header(default="", alias="X-API-Token")) -> dict:
"""执行机心跳/环境上报(含 Chrome 检测结果):按 device_id 幂等 upsert 设备记录。
供壳(执行机底座)启动/定时上报本机环境;last_seen 与 status 由中心机统一维护
在线态(status 由调用方按心跳状态传,离线清理逻辑在管理端查询侧)。
"""
_check_token(x_api_token)
device_id = (b.device_id or "").strip()
if not device_id:
raise HTTPException(400, "device_id 不能为空")
with _db() as conn:
conn.execute(
"INSERT INTO devices(device_id, account, hostname, os, ip, "
"chrome_installed, chrome_version, chrome_ok, last_seen, status) "
"VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) "
"ON DUPLICATE KEY UPDATE "
"account = VALUES(account), hostname = VALUES(hostname), os = VALUES(os), "
"ip = VALUES(ip), chrome_installed = VALUES(chrome_installed), "
"chrome_version = VALUES(chrome_version), chrome_ok = VALUES(chrome_ok), "
"last_seen = VALUES(last_seen), status = VALUES(status)",
(device_id, (b.account or "").strip(), (b.hostname or "").strip(),
(b.os or "").strip(), (b.ip or "").strip(),
int(bool(b.chrome_installed)), (b.chrome_version or "").strip(),
int(bool(b.chrome_ok)), _now(), int(bool(b.status))))
conn.commit()
return {"ok": True, "device_id": device_id}
# ==================== 壳子(执行机主程序)自动更新 ====================
# shell/version.json 约定:{"version": "1.0.0", "filename": "setup-37du-host-1.0.0.exe",
# "sha256": "<可选,安装包校验值>", "notes": "<可选,更新说明>"}