v2.2.0 — 删除评分+心愿模块(HTML/JS/CSS/Python)

This commit is contained in:
mac
2026-07-28 19:33:17 +08:00
parent a2f009f986
commit 979e7fd097
5 changed files with 4 additions and 943 deletions

View File

@@ -11,7 +11,7 @@ os.makedirs(DB_DIR, exist_ok=True)
DB_PATH = os.path.join(DB_DIR, 'ziwei_power.db')
# 当前数据库 schema 版本 —— 改表结构时必须 +1 并补迁移逻辑
CURRENT_SCHEMA_VERSION = 4
CURRENT_SCHEMA_VERSION = 2
def get_conn():
@@ -56,26 +56,7 @@ def init_db():
''')
if current < 2:
# v2: 心愿清单
conn.execute('''
CREATE TABLE IF NOT EXISTS wishes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
priority TEXT NOT NULL DEFAULT '',
deadline TEXT NOT NULL DEFAULT '',
done INTEGER NOT NULL DEFAULT 0,
sort_order INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL
)
''')
if current < 3:
# v3: 优先级改为四象限
conn.execute("ALTER TABLE wishes ADD COLUMN quadrant TEXT NOT NULL DEFAULT '重要不紧急'")
conn.execute("UPDATE wishes SET quadrant = CASE priority WHEN '' THEN '重要紧急' WHEN '' THEN '重要不紧急' WHEN '' THEN '不紧急不重要' ELSE '重要不紧急' END WHERE quadrant = '重要不紧急'")
if current < 4:
# v4: 日打卡 → 周打卡
# v2: 日打卡 → 周打卡
# 备份旧表 → 聚合 → 新建周表
existing = conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='checkins'").fetchone()
if existing:
@@ -170,62 +151,6 @@ def get_all_checkins():
return results
# ── 心愿清单 CRUD ──────────────────────────────────
def get_wishes():
"""获取所有心愿,按 sort_order 排序"""
conn = get_conn()
rows = conn.execute('SELECT * FROM wishes ORDER BY sort_order').fetchall()
conn.close()
return [dict(row) for row in rows]
def save_wish(name, quadrant, deadline):
"""新增一条心愿"""
now = datetime.now().isoformat()
conn = get_conn()
max_order = conn.execute('SELECT COALESCE(MAX(sort_order), -1) + 1 AS n FROM wishes').fetchone()['n']
conn.execute(
'INSERT INTO wishes (name, quadrant, deadline, done, sort_order, created_at) VALUES (?, ?, ?, 0, ?, ?)',
(name, quadrant, deadline, max_order, now)
)
conn.commit()
wish_id = conn.execute('SELECT last_insert_rowid()').fetchone()[0]
conn.close()
return wish_id
def update_wish(wish_id, **kwargs):
"""更新心愿字段"""
allowed = ['name', 'quadrant', 'deadline', 'done']
updates = {k: v for k, v in kwargs.items() if k in allowed}
if not updates:
return
conn = get_conn()
sets = ', '.join(f'{k} = ?' for k in updates)
vals = list(updates.values()) + [wish_id]
conn.execute(f'UPDATE wishes SET {sets} WHERE id = ?', vals)
conn.commit()
conn.close()
def delete_wish(wish_id):
"""删除心愿"""
conn = get_conn()
conn.execute('DELETE FROM wishes WHERE id = ?', (wish_id,))
conn.commit()
conn.close()
def reorder_wishes(order_list):
"""批量更新排序order_list = [id1, id2, ...]"""
conn = get_conn()
for idx, wid in enumerate(order_list):
conn.execute('UPDATE wishes SET sort_order = ? WHERE id = ?', (idx, wid))
conn.commit()
conn.close()
def get_weeks_list():
"""返回所有已有打卡记录的周号列表"""
conn = get_conn()