feat: dockerize app and unify query management UI
This commit is contained in:
@@ -5,7 +5,25 @@
|
||||
From repository root:
|
||||
|
||||
```bash
|
||||
python3 -m http.server 8123
|
||||
docker compose up --build -d
|
||||
```
|
||||
|
||||
Optional environment setup:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
Stop:
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
```
|
||||
|
||||
Reset both MySQL and managed raw/index data:
|
||||
|
||||
```bash
|
||||
docker compose down -v
|
||||
```
|
||||
|
||||
Open:
|
||||
@@ -13,14 +31,35 @@ Open:
|
||||
- http://127.0.0.1:8123/web/device_query.html (设备查询)
|
||||
- http://127.0.0.1:8123/web/brand_management.html (数据管理)
|
||||
|
||||
整个功能栈统一运行在 Docker Compose 中,不再依赖本地 Python 或本地 MySQL 直接启动。
|
||||
|
||||
容器启动时会自动完成:
|
||||
|
||||
- 构建 `dist/device_index.json`
|
||||
- 导出 MySQL seed 文件
|
||||
- 加载 MySQL schema 与 seed 数据
|
||||
- 启动 Web 页面与 API 服务
|
||||
|
||||
容器内还会同时启动 MySQL:
|
||||
|
||||
- `127.0.0.1:3306`
|
||||
- database: `mobilemodels`
|
||||
- reader user: `mobilemodels_reader`
|
||||
|
||||
页面顶部有导航条(Gitea 风格):
|
||||
|
||||
- `设备查询`
|
||||
- `数据管理`
|
||||
|
||||
设备查询页顶部额外提供三个页内 tab:
|
||||
|
||||
- `索引查询`
|
||||
- `SQL 查询`
|
||||
- `相关文档`
|
||||
|
||||
## 设备查询
|
||||
|
||||
### Mode A: 客户端上报模式(新增)
|
||||
### 客户端上报模式
|
||||
|
||||
字段按你给的上报方式输入:
|
||||
|
||||
@@ -30,41 +69,25 @@ Open:
|
||||
- iOS
|
||||
- `platform=ios`
|
||||
- `model_raw=utsname.machine`(例如 `iPhone14,2`)
|
||||
- 鸿蒙
|
||||
- HarmonyOS
|
||||
- `platform=harmony`
|
||||
- `model_raw`(如果有就原样填)
|
||||
- `deviceInfo.marketName`(页面里填 `marketName`)
|
||||
- `deviceInfo.osFullName`(页面里填 `osFullName`)
|
||||
- `model_raw`(例如 `NOH-AL00`)
|
||||
|
||||
说明:
|
||||
|
||||
- 鸿蒙模式下,`model_raw` 和 `marketName` 至少填一个。
|
||||
- Android / iOS / HarmonyOS 都直接使用客户端原始上报的 `model_raw`。
|
||||
- 页面会输出完整候选列表,并附带 `report_payload` 方便核对上报值。
|
||||
|
||||
### Mode B: 通用多字段模式(原有)
|
||||
### SQL 查询模式
|
||||
|
||||
`primaryName`:
|
||||
- 直接调用 Compose 内的 API 查询 MySQL 主表 `mobilemodels.mm_device_catalog`
|
||||
- 服务端会先把输入归一化成 `alias_norm`
|
||||
- 页面会显示实际执行的 SQL、结果列表和返回 JSON
|
||||
|
||||
- Put the strongest identifier first, such as `iPhone14,5`, `M2102J2SC`, `L55M5-AD`, `SM-G9910`.
|
||||
### 相关文档
|
||||
|
||||
`extraNames` (one line each):
|
||||
|
||||
- Paste all values you can get from client APIs, for example:
|
||||
|
||||
```text
|
||||
model=SM-G9910
|
||||
device=star2qltechn
|
||||
marketName=Galaxy S21
|
||||
buildProduct=o1qzcx
|
||||
```
|
||||
|
||||
`brand`:
|
||||
|
||||
- Optional. Supports aliases like `苹果`, `samsung`, `huawei`, `小米`.
|
||||
|
||||
`platform`:
|
||||
|
||||
- iOS / Android / HarmonyOS / Unknown
|
||||
- 页面内统一展示主推 SQL、兼容 SQL、归一化规则和文档入口
|
||||
- 可直接跳转查看 `misc/mysql-query-design.md`、`web/README.md`、`README.md`
|
||||
|
||||
## Output
|
||||
|
||||
@@ -103,8 +126,15 @@ buildProduct=o1qzcx
|
||||
- Supports drag-and-drop source ordering.
|
||||
- Ranking weight is higher for sources at the top.
|
||||
- Initial order puts `*_cn.md` before non-`cn` sources.
|
||||
- 原始数据同步(新增):
|
||||
- Available in the third left tab.
|
||||
- Calls the Compose service API to sync upstream `KHwang9883/MobileModels` raw markdown, rebuild `dist/device_index.json`, export MySQL seed, and reload MySQL.
|
||||
- Requires `docker compose up --build -d`.
|
||||
- 索引数据(新增):
|
||||
- Available in the fourth left tab.
|
||||
- Includes index reload and index load status.
|
||||
|
||||
## Notes
|
||||
|
||||
- If browser blocks local file fetch, start HTTP server as above.
|
||||
- You can also manually upload `dist/device_index.json` in the page.
|
||||
- Managed raw data, rebuilt index, and MySQL seed files are persisted in Docker volumes, not written back to the local workspace during runtime.
|
||||
- For production, override `MYSQL_ROOT_PASSWORD` and `MYSQL_READER_PASSWORD` with your own values.
|
||||
|
||||
@@ -117,6 +117,10 @@
|
||||
font-weight: 600;
|
||||
}
|
||||
button.primary { background: var(--brand); color: #fff; }
|
||||
button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.result-head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
@@ -253,6 +257,18 @@
|
||||
.manage-panel.hidden {
|
||||
display: none;
|
||||
}
|
||||
.sync-log {
|
||||
min-height: 240px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
font-size: 12px;
|
||||
line-height: 1.45;
|
||||
background: #f6f8fb;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
}
|
||||
.hidden { display: none; }
|
||||
.modal-backdrop {
|
||||
position: fixed;
|
||||
@@ -305,7 +321,7 @@
|
||||
}
|
||||
.manage-tabs {
|
||||
position: static;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -316,6 +332,7 @@
|
||||
<a href="/web/device_query.html" class="brand">MobileModels</a>
|
||||
<a href="/web/device_query.html" class="item">设备查询</a>
|
||||
<a href="/web/brand_management.html" class="item active">数据管理</a>
|
||||
<a href="/web/device_query.html?view=docs" class="item">相关文档</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@@ -327,6 +344,8 @@
|
||||
<aside class="manage-tabs">
|
||||
<button id="tabBrandBtn" type="button" class="tab-btn active">品牌列表</button>
|
||||
<button id="tabSourceBtn" type="button" class="tab-btn">数据来源</button>
|
||||
<button id="tabSyncBtn" type="button" class="tab-btn">原始数据同步</button>
|
||||
<button id="tabIndexBtn" type="button" class="tab-btn">索引数据</button>
|
||||
</aside>
|
||||
|
||||
<div class="manage-content">
|
||||
@@ -374,6 +393,27 @@
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="syncTabPanel" class="manage-panel hidden">
|
||||
<h3 class="title">原始数据同步</h3>
|
||||
<p class="sub">从上游 `KHwang9883/MobileModels` 拉取原始 markdown 数据,并重建 `dist/device_index.json`、刷新 MySQL。请先使用 `docker compose up --build -d` 启动完整服务。</p>
|
||||
<div class="btns">
|
||||
<button id="syncUpstreamBtn" type="button" class="primary">开始同步原始数据</button>
|
||||
<button id="refreshSyncStatusBtn" type="button">刷新同步状态</button>
|
||||
</div>
|
||||
<div id="syncStatus" class="sub">正在检测同步能力。</div>
|
||||
<pre id="syncLog" class="sync-log mono">暂无同步记录</pre>
|
||||
</section>
|
||||
|
||||
<section id="indexTabPanel" class="manage-panel hidden">
|
||||
<h3 class="title">索引数据</h3>
|
||||
<p class="sub">这里集中显示 `dist/device_index.json` 的加载状态与基础统计,并提供手动重新加载入口。</p>
|
||||
<div class="btns">
|
||||
<button id="reloadIndexBtn" type="button" class="primary">重新加载索引</button>
|
||||
</div>
|
||||
<div id="indexStatus" class="sub">索引尚未加载。</div>
|
||||
<pre id="indexSummary" class="sync-log mono">暂无索引信息</pre>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -420,8 +460,22 @@
|
||||
const sourceOrderListEl = document.getElementById("sourceOrderList");
|
||||
const tabBrandBtnEl = document.getElementById("tabBrandBtn");
|
||||
const tabSourceBtnEl = document.getElementById("tabSourceBtn");
|
||||
const tabSyncBtnEl = document.getElementById("tabSyncBtn");
|
||||
const tabIndexBtnEl = document.getElementById("tabIndexBtn");
|
||||
const brandTabPanelEl = document.getElementById("brandTabPanel");
|
||||
const sourceTabPanelEl = document.getElementById("sourceTabPanel");
|
||||
const syncTabPanelEl = document.getElementById("syncTabPanel");
|
||||
const indexTabPanelEl = document.getElementById("indexTabPanel");
|
||||
const syncStatusEl = document.getElementById("syncStatus");
|
||||
const syncLogEl = document.getElementById("syncLog");
|
||||
const syncUpstreamBtnEl = document.getElementById("syncUpstreamBtn");
|
||||
const refreshSyncStatusBtnEl = document.getElementById("refreshSyncStatusBtn");
|
||||
const reloadIndexBtnEl = document.getElementById("reloadIndexBtn");
|
||||
const indexStatusEl = document.getElementById("indexStatus");
|
||||
const indexSummaryEl = document.getElementById("indexSummary");
|
||||
|
||||
let syncSupported = false;
|
||||
let syncRunning = false;
|
||||
|
||||
function normalizeText(text) {
|
||||
return (text || "").toLowerCase().replace(/[^0-9a-z\u4e00-\u9fff]+/g, "");
|
||||
@@ -436,6 +490,107 @@
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
async function fetchJson(url, options = {}) {
|
||||
const resp = await fetch(url, options);
|
||||
const data = await resp.json().catch(() => ({}));
|
||||
if (!resp.ok) {
|
||||
throw new Error((data && data.error) || `HTTP ${resp.status}`);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function updateSyncButtons() {
|
||||
syncUpstreamBtnEl.disabled = syncRunning || !syncSupported;
|
||||
refreshSyncStatusBtnEl.disabled = syncRunning;
|
||||
}
|
||||
|
||||
function renderIndexStatus(message, details) {
|
||||
indexStatusEl.textContent = message || "索引尚未加载。";
|
||||
indexSummaryEl.textContent = details || "暂无索引信息";
|
||||
}
|
||||
|
||||
function renderSyncLog(data, fallbackTitle) {
|
||||
if (!data) {
|
||||
syncLogEl.textContent = fallbackTitle || "暂无同步记录";
|
||||
return;
|
||||
}
|
||||
|
||||
const lines = [];
|
||||
if (fallbackTitle) lines.push(fallbackTitle);
|
||||
if (data.data_root) lines.push(`数据目录: ${data.data_root}`);
|
||||
if (data.repo_root) lines.push(`应用目录: ${data.repo_root}`);
|
||||
if (data.storage_mode) lines.push(`存储模式: ${data.storage_mode}`);
|
||||
if (data.upstream_repo_url) lines.push(`上游仓库: ${data.upstream_repo_url}`);
|
||||
if (data.upstream_branch) lines.push(`上游分支: ${data.upstream_branch}`);
|
||||
if (data.last_sync_time) lines.push(`最近同步时间: ${data.last_sync_time}`);
|
||||
if (data.last_upstream_commit) lines.push(`最近同步提交: ${data.last_upstream_commit}`);
|
||||
if (data.index_file) lines.push(`索引文件: ${data.index_file}`);
|
||||
if (data.index_mtime) lines.push(`索引更新时间: ${data.index_mtime}`);
|
||||
if (data.mysql_seed_file) lines.push(`MySQL Seed: ${data.mysql_seed_file}`);
|
||||
if (data.mysql_seed_mtime) lines.push(`MySQL Seed 更新时间: ${data.mysql_seed_mtime}`);
|
||||
if (data.mysql_host && data.mysql_port) lines.push(`MySQL 地址: ${data.mysql_host}:${data.mysql_port}`);
|
||||
if (data.mysql_database) lines.push(`MySQL 数据库: ${data.mysql_database}`);
|
||||
if (data.mysql_reader_user) lines.push(`MySQL 只读账号: ${data.mysql_reader_user}`);
|
||||
if (typeof data.mysql_ready === "boolean") lines.push(`MySQL 状态: ${data.mysql_ready ? "ready" : "not ready"}`);
|
||||
if (data.mysql_status) lines.push(`MySQL 详情: ${data.mysql_status}`);
|
||||
if (data.output) {
|
||||
lines.push("");
|
||||
lines.push("同步输出:");
|
||||
lines.push(data.output);
|
||||
}
|
||||
syncLogEl.textContent = lines.join("\n").trim() || "暂无同步记录";
|
||||
}
|
||||
|
||||
async function loadSyncStatus(options = {}) {
|
||||
const preserveLog = !!options.preserveLog;
|
||||
syncStatusEl.textContent = "正在检测同步能力。";
|
||||
try {
|
||||
const data = await fetchJson("/api/status", { cache: "no-store" });
|
||||
syncSupported = !!data.supports_upstream_sync;
|
||||
syncStatusEl.textContent = syncSupported
|
||||
? "已连接 Docker Compose 服务,可以直接从页面同步原始数据、索引和 MySQL。"
|
||||
: "当前服务不支持原始数据同步。";
|
||||
if (!preserveLog) {
|
||||
renderSyncLog(data, "服务状态");
|
||||
}
|
||||
} catch (err) {
|
||||
syncSupported = false;
|
||||
syncStatusEl.textContent = `当前页面未连接支持同步的 Docker Compose 服务:${err.message}`;
|
||||
if (!preserveLog) {
|
||||
syncLogEl.textContent = "请使用 `docker compose up --build -d` 启动完整服务后,再使用这个功能。";
|
||||
}
|
||||
} finally {
|
||||
updateSyncButtons();
|
||||
}
|
||||
}
|
||||
|
||||
async function runUpstreamSync() {
|
||||
if (syncRunning) return;
|
||||
syncRunning = true;
|
||||
updateSyncButtons();
|
||||
syncStatusEl.textContent = "正在同步原始数据、重建索引并刷新 MySQL,请稍候。";
|
||||
syncLogEl.textContent = "同步进行中...";
|
||||
|
||||
try {
|
||||
const data = await fetchJson("/api/sync-upstream", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: "{}",
|
||||
});
|
||||
syncSupported = true;
|
||||
syncStatusEl.textContent = "同步完成,页面索引已刷新。";
|
||||
renderSyncLog(data, "同步完成");
|
||||
await loadIndexFromPath();
|
||||
} catch (err) {
|
||||
syncSupported = false;
|
||||
syncStatusEl.textContent = `同步失败: ${err.message}`;
|
||||
syncLogEl.textContent = `同步失败\n${err.message}`;
|
||||
} finally {
|
||||
syncRunning = false;
|
||||
await loadSyncStatus({ preserveLog: true });
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeAliasList(name, aliases) {
|
||||
const out = [];
|
||||
const seen = new Set();
|
||||
@@ -1031,6 +1186,7 @@
|
||||
|
||||
async function loadIndexFromPath() {
|
||||
try {
|
||||
renderIndexStatus("正在加载 dist/device_index.json ...", "加载中...");
|
||||
const resp = await fetch("../dist/device_index.json", { cache: "no-cache" });
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
indexData = await resp.json();
|
||||
@@ -1039,9 +1195,32 @@
|
||||
rebuildManagedBrandIndexes();
|
||||
renderBrandStats();
|
||||
renderSourceOrder();
|
||||
const sourceCount = Array.isArray(managedSourceConfig && managedSourceConfig.order)
|
||||
? managedSourceConfig.order.length
|
||||
: 0;
|
||||
const brandCount = managedBrandConfig && Array.isArray(managedBrandConfig.brands)
|
||||
? managedBrandConfig.brands.length
|
||||
: 0;
|
||||
const manufacturerCount = managedBrandConfig && Array.isArray(managedBrandConfig.manufacturers)
|
||||
? managedBrandConfig.manufacturers.length
|
||||
: 0;
|
||||
renderIndexStatus(
|
||||
`索引加载成功: records=${indexData.total_records}, lookup=${Object.keys(indexData.lookup || {}).length}`,
|
||||
[
|
||||
`generated_on: ${indexData.generated_on || "(unknown)"}`,
|
||||
`total_records: ${indexData.total_records || 0}`,
|
||||
`lookup_keys: ${Object.keys(indexData.lookup || {}).length}`,
|
||||
`brand_count: ${brandCount}`,
|
||||
`manufacturer_count: ${manufacturerCount}`,
|
||||
`source_count: ${sourceCount}`,
|
||||
].join("\n")
|
||||
);
|
||||
} catch (err) {
|
||||
brandStatsEl.textContent = `索引加载失败: ${err.message}`;
|
||||
sourceOrderStatsEl.textContent = `索引加载失败: ${err.message}`;
|
||||
renderIndexStatus(`索引加载失败: ${err.message}`, `索引加载失败\n${err.message}`);
|
||||
brandStatsEl.textContent = "索引不可用,暂无品牌关系数据。";
|
||||
sourceOrderStatsEl.textContent = "索引不可用,暂无来源数据。";
|
||||
brandRelationBodyEl.innerHTML = `<tr><td colspan="3" class="sub">暂无关系数据</td></tr>`;
|
||||
sourceOrderListEl.innerHTML = `<li class="sub">暂无来源数据</li>`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1052,6 +1231,9 @@
|
||||
document.getElementById("resetSourceOrderBtn").addEventListener("click", resetSourceOrder);
|
||||
brandCountBtnEl.addEventListener("click", openBrandListModal);
|
||||
manufacturerCountBtnEl.addEventListener("click", openManufacturerListModal);
|
||||
syncUpstreamBtnEl.addEventListener("click", runUpstreamSync);
|
||||
refreshSyncStatusBtnEl.addEventListener("click", loadSyncStatus);
|
||||
reloadIndexBtnEl.addEventListener("click", loadIndexFromPath);
|
||||
|
||||
brandModalCancelBtnEl.addEventListener("click", closeBrandModal);
|
||||
brandModalBackdropEl.addEventListener("click", (e) => {
|
||||
@@ -1069,17 +1251,27 @@
|
||||
|
||||
function switchManageTab(tab) {
|
||||
const isBrand = tab === "brand";
|
||||
const isSource = tab === "source";
|
||||
const isSync = tab === "sync";
|
||||
const isIndex = tab === "index";
|
||||
tabBrandBtnEl.classList.toggle("active", isBrand);
|
||||
tabSourceBtnEl.classList.toggle("active", !isBrand);
|
||||
tabSourceBtnEl.classList.toggle("active", isSource);
|
||||
tabSyncBtnEl.classList.toggle("active", isSync);
|
||||
tabIndexBtnEl.classList.toggle("active", isIndex);
|
||||
brandTabPanelEl.classList.toggle("hidden", !isBrand);
|
||||
sourceTabPanelEl.classList.toggle("hidden", isBrand);
|
||||
sourceTabPanelEl.classList.toggle("hidden", !isSource);
|
||||
syncTabPanelEl.classList.toggle("hidden", !isSync);
|
||||
indexTabPanelEl.classList.toggle("hidden", !isIndex);
|
||||
}
|
||||
|
||||
tabBrandBtnEl.addEventListener("click", () => switchManageTab("brand"));
|
||||
tabSourceBtnEl.addEventListener("click", () => switchManageTab("source"));
|
||||
tabSyncBtnEl.addEventListener("click", () => switchManageTab("sync"));
|
||||
tabIndexBtnEl.addEventListener("click", () => switchManageTab("index"));
|
||||
|
||||
switchManageTab("brand");
|
||||
loadIndexFromPath();
|
||||
loadSyncStatus();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
181
web/doc_viewer.html
Normal file
181
web/doc_viewer.html
Normal file
@@ -0,0 +1,181 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>MobileModels 文档查看</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #f5f7fb;
|
||||
--card: #ffffff;
|
||||
--text: #1c2430;
|
||||
--sub: #566173;
|
||||
--line: #d9e0ea;
|
||||
--brand: #0f6fff;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
|
||||
background: radial-gradient(circle at 0 0, #eef4ff 0, var(--bg) 40%), var(--bg);
|
||||
color: var(--text);
|
||||
}
|
||||
.top-nav {
|
||||
background: linear-gradient(180deg, #1f2a3a, #1a2431);
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
.top-nav-inner {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 16px;
|
||||
height: 52px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.top-nav .brand,
|
||||
.top-nav .item {
|
||||
color: #d6e3f7;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
padding: 6px 10px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.top-nav .brand {
|
||||
font-weight: 700;
|
||||
margin-right: 8px;
|
||||
color: #f4f8ff;
|
||||
}
|
||||
.top-nav .item.active {
|
||||
background: rgba(255, 255, 255, 0.16);
|
||||
color: #ffffff;
|
||||
font-weight: 600;
|
||||
}
|
||||
.wrap {
|
||||
max-width: 1200px;
|
||||
margin: 24px auto;
|
||||
padding: 0 16px 32px;
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
.card {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 14px;
|
||||
padding: 14px;
|
||||
box-shadow: 0 6px 18px rgba(36, 56, 89, 0.06);
|
||||
}
|
||||
.title {
|
||||
margin: 0 0 8px;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.sub {
|
||||
margin: 0 0 14px;
|
||||
color: var(--sub);
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.btns {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 12px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 9px 14px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #c8d6ee;
|
||||
background: #f7faff;
|
||||
color: #244775;
|
||||
text-decoration: none;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.btn:hover {
|
||||
background: #eef5ff;
|
||||
}
|
||||
pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
font-size: 13px;
|
||||
line-height: 1.65;
|
||||
background: #f6f8fb;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
padding: 14px;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="top-nav">
|
||||
<div class="top-nav-inner">
|
||||
<a href="/web/device_query.html" class="brand">MobileModels</a>
|
||||
<a href="/web/device_query.html" class="item">设备查询</a>
|
||||
<a href="/web/brand_management.html" class="item">数据管理</a>
|
||||
<a href="/web/device_query.html?view=docs" class="item active">相关文档</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="wrap">
|
||||
<section class="card">
|
||||
<h1 class="title" id="docTitle">文档查看</h1>
|
||||
<p class="sub" id="docPath">正在加载文档...</p>
|
||||
<div class="btns">
|
||||
<a class="btn" href="/web/doc_viewer.html?path=/misc/mysql-query-design.md&title=MySQL%20%E8%AE%BE%E8%AE%A1%E8%AF%B4%E6%98%8E">MySQL 设计说明</a>
|
||||
<a class="btn" href="/web/doc_viewer.html?path=/web/README.md&title=Web%20%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E">Web 使用说明</a>
|
||||
<a class="btn" href="/web/doc_viewer.html?path=/README.md&title=%E9%A1%B9%E7%9B%AE%20README">项目 README</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<pre id="docContent">加载中...</pre>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const ALLOWED_DOCS = new Map([
|
||||
["/misc/mysql-query-design.md", "MySQL 设计说明"],
|
||||
["/web/README.md", "Web 使用说明"],
|
||||
["/README.md", "项目 README"],
|
||||
]);
|
||||
|
||||
async function main() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const path = params.get("path") || "/misc/mysql-query-design.md";
|
||||
const title = params.get("title") || ALLOWED_DOCS.get(path) || "文档查看";
|
||||
const docTitleEl = document.getElementById("docTitle");
|
||||
const docPathEl = document.getElementById("docPath");
|
||||
const docContentEl = document.getElementById("docContent");
|
||||
|
||||
if (!ALLOWED_DOCS.has(path)) {
|
||||
docTitleEl.textContent = "文档不存在";
|
||||
docPathEl.textContent = path;
|
||||
docContentEl.textContent = "当前只允许查看预设文档。";
|
||||
return;
|
||||
}
|
||||
|
||||
document.title = `${title} - MobileModels`;
|
||||
docTitleEl.textContent = title;
|
||||
docPathEl.textContent = path;
|
||||
|
||||
try {
|
||||
const resp = await fetch(path, { cache: "no-store" });
|
||||
if (!resp.ok) {
|
||||
throw new Error(`HTTP ${resp.status}`);
|
||||
}
|
||||
const text = await resp.text();
|
||||
docContentEl.textContent = text;
|
||||
} catch (err) {
|
||||
docContentEl.textContent = `加载失败\n${err.message || err}`;
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user