feat: v1.2.0 新增网站配置管理功能

新功能:
- 后台管理新增'网站配置'菜单
- 支持配置:网站名称、副标题、备案号、联系邮箱、GitHub、页脚文字
- 前台页面自动读取配置显示
- 页脚支持备案号链接

配置存储在 data/config.json
This commit is contained in:
2026-04-11 02:27:21 +08:00
parent 7a2b1da9ff
commit 74be7688c9
4 changed files with 153 additions and 9 deletions

41
app.py
View File

@@ -25,6 +25,7 @@ GPUS_FILE = DATA_DIR / 'gpus.json'
CPUS_FILE = DATA_DIR / 'cpus.json'
CATEGORIES_FILE = DATA_DIR / 'categories.json'
KNOWLEDGE_FILE = DATA_DIR / 'knowledge.json'
CONFIG_FILE = DATA_DIR / 'config.json'
# 大模型配置
LLM_CONFIG = {
@@ -33,6 +34,27 @@ LLM_CONFIG = {
'model': 'auto',
}
# 默认网站配置
DEFAULT_CONFIG = {
'site_name': 'ParamHub',
'site_subtitle': '参数百科',
'footer_text': 'ParamHub - AI大模型与硬件参数速查平台',
'icp_number': '',
'copyright_year': '2024',
'contact_email': '',
'github_url': '',
}
def load_config():
"""加载网站配置"""
if CONFIG_FILE.exists():
return json.loads(CONFIG_FILE.read_text(encoding='utf-8'))
return DEFAULT_CONFIG.copy()
def save_config(config):
"""保存网站配置"""
CONFIG_FILE.write_text(json.dumps(config, ensure_ascii=False, indent=2), encoding='utf-8')
def load_data(file_path):
"""加载JSON数据"""
if file_path.exists():
@@ -863,9 +885,26 @@ def api_toggle_item_visible(category_id, item_id):
return jsonify({'success': True, 'visible': item['visible']})
# ============ 网站配置API ============
@app.route('/api/config')
def api_get_config():
"""获取网站配置"""
return jsonify(load_config())
@app.route('/api/config', methods=['PUT'])
def api_update_config():
"""更新网站配置"""
data = request.get_json()
config = load_config()
config.update(data)
config['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
save_config(config)
return jsonify(config)
if __name__ == '__main__':
print("=" * 50)
print("ParamHub - 参数百科 v1.1.0")
print("ParamHub - 参数百科 v1.2.0")
print("=" * 50)
print(f"访问地址: http://localhost:19010")
print(f"后台管理: http://localhost:19010/admin")