v1.1.0 — 心愿清单
- 新增 wishes 表 (schema v2),含名称/优先级/截止时间/完成状态 - API: GET/POST/PUT/DELETE /api/wishes + PUT /api/wishes/reorder - 侧边栏心愿清单面板:checklist + 新增表单 - 完成勾选 → 删除线;优先级标签(红/黄/灰) - HTML5 原生拖拽排序,松开即保存 - 编辑模式切换:默认隐藏新增/删除按钮
This commit is contained in:
54
app.py
54
app.py
@@ -6,7 +6,7 @@ from datetime import timedelta
|
||||
from functools import wraps
|
||||
from flask import Flask, render_template, request, jsonify, session, redirect, url_for
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from database import init_db, get_checkin, save_checkin, delete_checkin, get_all_checkins
|
||||
from database import init_db, get_checkin, save_checkin, delete_checkin, get_all_checkins, get_wishes, save_wish, update_wish, delete_wish, reorder_wishes
|
||||
|
||||
app = Flask(__name__)
|
||||
# 固定密钥确保 gunicorn 多 worker 下 session 可互通
|
||||
@@ -115,9 +115,11 @@ def compute_stats():
|
||||
def index():
|
||||
import json
|
||||
stats = compute_stats()
|
||||
wishes = [dict(w) for w in get_wishes()]
|
||||
return render_template('index.html',
|
||||
username=session.get('display_name', session.get('username', '')),
|
||||
initial_stats=json.dumps(stats, ensure_ascii=False))
|
||||
initial_stats=json.dumps(stats, ensure_ascii=False),
|
||||
initial_wishes=json.dumps(wishes, ensure_ascii=False))
|
||||
|
||||
|
||||
# ── API ──────────────────────────────────────────────
|
||||
@@ -175,6 +177,54 @@ def api_user():
|
||||
})
|
||||
|
||||
|
||||
# ── 心愿清单 API ──────────────────────────────
|
||||
|
||||
@app.route('/api/wishes', methods=['GET'])
|
||||
@login_required
|
||||
def api_get_wishes():
|
||||
wishes = [dict(w) for w in get_wishes()]
|
||||
return jsonify({'ok': True, 'data': wishes})
|
||||
|
||||
|
||||
@app.route('/api/wishes', methods=['POST'])
|
||||
@login_required
|
||||
def api_create_wish():
|
||||
body = request.get_json(force=True)
|
||||
name = body.get('name', '').strip()
|
||||
if not name:
|
||||
return jsonify({'ok': False, 'error': '名称不能为空'}), 400
|
||||
priority = body.get('priority', '中')
|
||||
deadline = body.get('deadline', '')
|
||||
wid = save_wish(name, priority, deadline)
|
||||
return jsonify({'ok': True, 'id': wid})
|
||||
|
||||
|
||||
@app.route('/api/wishes/<int:wish_id>', methods=['PUT'])
|
||||
@login_required
|
||||
def api_update_wish(wish_id):
|
||||
body = request.get_json(force=True)
|
||||
update_wish(wish_id, **body)
|
||||
return jsonify({'ok': True})
|
||||
|
||||
|
||||
@app.route('/api/wishes/<int:wish_id>', methods=['DELETE'])
|
||||
@login_required
|
||||
def api_delete_wish(wish_id):
|
||||
delete_wish(wish_id)
|
||||
return jsonify({'ok': True})
|
||||
|
||||
|
||||
@app.route('/api/wishes/reorder', methods=['PUT'])
|
||||
@login_required
|
||||
def api_reorder_wishes():
|
||||
body = request.get_json(force=True)
|
||||
order = body.get('order', [])
|
||||
if not isinstance(order, list):
|
||||
return jsonify({'ok': False, 'error': 'order 必须是列表'}), 400
|
||||
reorder_wishes(order)
|
||||
return jsonify({'ok': True})
|
||||
|
||||
|
||||
# ── 启动 ──────────────────────────────────────────────
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user