feat: dockerize app and unify query management UI
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user