docs: add comprehensive README.md and fix bugs
- add README.md with usage and deployment guide - fix category sync logic in backend - fix URL overflow in admin services list - fix data caching issues in front-end and back-end - add 'View Front-end' button in admin dashboard
This commit is contained in:
45
app.py
45
app.py
@@ -43,12 +43,15 @@ def api_services():
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 查询时动态获取分类名
|
||||
cursor.execute('''
|
||||
SELECT id, name, url, description, icon, category, sort_order,
|
||||
health_check_enabled
|
||||
FROM services
|
||||
WHERE is_enabled = 1
|
||||
ORDER BY sort_order DESC, id ASC
|
||||
SELECT s.id, s.name, s.url, s.description, s.icon,
|
||||
COALESCE(c.name, s.category) as category,
|
||||
s.sort_order, s.health_check_enabled
|
||||
FROM services s
|
||||
LEFT JOIN categories c ON s.category = c.name
|
||||
WHERE s.is_enabled = 1
|
||||
ORDER BY s.sort_order DESC, s.id ASC
|
||||
''')
|
||||
|
||||
services = [dict(row) for row in cursor.fetchall()]
|
||||
@@ -140,11 +143,14 @@ def api_admin_services():
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 查询时动态获取分类名(如果分类不存在则显示原始值)
|
||||
cursor.execute('''
|
||||
SELECT id, name, url, description, icon, category, is_enabled,
|
||||
sort_order, health_check_url, health_check_enabled
|
||||
FROM services
|
||||
ORDER BY sort_order DESC, id ASC
|
||||
SELECT s.id, s.name, s.url, s.description, s.icon,
|
||||
COALESCE(c.name, s.category) as category,
|
||||
s.is_enabled, s.sort_order, s.health_check_url, s.health_check_enabled
|
||||
FROM services s
|
||||
LEFT JOIN categories c ON s.category = c.name
|
||||
ORDER BY s.sort_order DESC, s.id ASC
|
||||
''')
|
||||
|
||||
services = [dict(row) for row in cursor.fetchall()]
|
||||
@@ -327,16 +333,35 @@ def api_admin_update_category(category_id):
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 先获取旧的分类名
|
||||
cursor.execute('SELECT name FROM categories WHERE id = ?', (category_id,))
|
||||
old_row = cursor.fetchone()
|
||||
if not old_row:
|
||||
conn.close()
|
||||
return jsonify({'error': '分类不存在'}), 404
|
||||
|
||||
old_name = old_row[0]
|
||||
new_name = data.get('name', '')
|
||||
|
||||
# 更新分类表
|
||||
cursor.execute('''
|
||||
UPDATE categories
|
||||
SET name = ?, sort_order = ?
|
||||
WHERE id = ?
|
||||
''', (
|
||||
data.get('name', ''),
|
||||
new_name,
|
||||
data.get('sort_order', 0),
|
||||
category_id
|
||||
))
|
||||
|
||||
# 同步更新 services 表中该分类的服务
|
||||
if old_name != new_name:
|
||||
cursor.execute('''
|
||||
UPDATE services
|
||||
SET category = ?
|
||||
WHERE category = ?
|
||||
''', (new_name, old_name))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user