refactor(api): 去除代码版本命名

This commit is contained in:
admin committed 2026-09-14 15:35:53 +08:00
1 parent bbc4bdd140
commit dcf4cb0719
31 files changed
+174 -154

No files matched your search

+11 -7
View File
@@ -1,9 +1,9 @@
/* ==========================================================================
阅间 · 微信读书看板 v2 —— 交互逻辑
阅间 · 微信读书看板 —— 交互逻辑
--------------------------------------------------------------------------
视觉结构、类名、交互控件完全沿用「阅间」设计稿(web-demo)。
差异只在于数据来源:设计稿读取 demo-data.js 的静态示例,
这里改为调用 /api/v2/* 实时接口。
这里改为调用 /api/reading/* 实时接口。
========================================================================== */
const $ = selector => document.querySelector(selector);
@@ -12,7 +12,8 @@ const esc = value =>
const findBook = id => books.find(book => book.id === id);
const uniqueIds = ids => [...new Set(ids)].filter(id => findBook(id));
const today = () => new Date().toLocaleDateString('sv-SE');
const storageKey = 'weread-goals-v2';
const storageKey = 'weread-goals';
const legacyStorageKeys = [storageKey, 'weread-goals-' + 'v' + '2'];
const PICKER_LIMIT = 60;
const SHELF_PAGE = 48;
@@ -43,13 +44,16 @@ let numberData = {}; /* 书籍详情里按条件二次拉取的小接口缓存
const loadState = { shelf: 'idle', dashboard: {}, notes: {}, discover: {}, book: {} };
const loadError = { shelf: '', dashboard: {}, notes: {}, discover: {}, book: {} };
let goals = [], legacyGoals = [];
let goals = [], legacyGoals = [], legacyGoalStorageKey = '';
try {
const saved = localStorage.getItem(storageKey);
if (saved && !localStorage.getItem(`${storageKey}-imported`)) {
for (const key of legacyStorageKeys) {
const saved = localStorage.getItem(key);
if (!saved || localStorage.getItem(`${key}-imported`)) continue;
const parsed = JSON.parse(saved);
if (!Array.isArray(parsed) || !parsed.every(goal => typeof goal.id === 'string' && typeof goal.name === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(goal.start) && /^\d{4}-\d{2}-\d{2}$/.test(goal.end) && goal.start <= goal.end && Array.isArray(goal.ids) && Array.isArray(goal.sources))) throw new Error('invalid');
legacyGoals = parsed;
legacyGoalStorageKey = key;
break;
}
} catch { storageWarning = '浏览器旧目标无法读取,原备份已保留。数据库目标不受影响。'; }
@@ -497,7 +501,7 @@ async function importGoals() {
const result = await WeApi.importGoals(legacyGoals);
// 标记迁移完成但保留旧数据,避免删除数据库目标后又从旧备份恢复。
legacyGoals = [];
try { localStorage.setItem(`${storageKey}-imported`, '1'); }
try { localStorage.setItem(`${legacyGoalStorageKey || storageKey}-imported`, '1'); }
catch { storageWarning = '旧目标已导入,但浏览器无法记录导入标记;再次导入会保留数据库已有目标。'; }
await ensureGoals();
toast(`已导入 ${result.imported} 个目标,数据库已有目标已保留,原备份也保留。`);