mirror of
https://github.com/KingHWJ/WeReadBoard.git
synced 2026-11-03 18:24:58 +08:00
刷新按钮支持数据同步:调用 /api/sync 拉取最新数据
- app.py 新增 /api/sync POST 接口:运行 fetch_data.py + migrate_to_mysql.py - refreshShelf() 先调用 /api/sync 同步数据,再重新加载书架 - 按钮文案三阶段:同步中... → 加载中... → 刷新 - CSS 增加 min-width 防止按钮宽度抖动 - launchd plist 和 start_server.sh 均配置 WEREAD_API_KEY 环境变量
This commit is contained in:
1 parent
e8552a9a4c
commit
7bc02075bd
5 files changed
+112
-2
No files matched your search
@@ -776,6 +776,8 @@ body {
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
white-space: nowrap;
|
||||
min-width: 96px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.shelf-refresh-btn:hover:not(:disabled) {
|
||||
|
||||
+14
-1
@@ -324,10 +324,23 @@ async function refreshShelf() {
|
||||
const btn = document.getElementById("shelfRefreshBtn");
|
||||
btn.disabled = true;
|
||||
btn.classList.add("loading");
|
||||
btn.textContent = "↻ 刷新中...";
|
||||
btn.textContent = "↻ 同步中...";
|
||||
|
||||
try {
|
||||
// Step 1: 从微信读书 API 同步数据到 MySQL
|
||||
const resp = await fetch(API_BASE + "/api/sync", { method: "POST" });
|
||||
const syncResult = await resp.json();
|
||||
if (!syncResult.ok) {
|
||||
throw new Error(syncResult.error || "同步失败");
|
||||
}
|
||||
|
||||
// Step 2: 重新加载分类和书架
|
||||
btn.textContent = "↻ 加载中...";
|
||||
await loadShelfCategories();
|
||||
await loadShelf(1);
|
||||
} catch (e) {
|
||||
console.error("刷新失败:", e);
|
||||
alert("刷新失败: " + (e.message || "未知错误"));
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.classList.remove("loading");
|
||||
|
||||
Reference in new issue
Block a user