diff --git a/app.py b/app.py index e028271..6b4a685 100644 --- a/app.py +++ b/app.py @@ -473,6 +473,71 @@ def api_delete_knowledge(knowledge_id): return jsonify({'success': True}) +# ============ 动态分类数据API ============ + +@app.route('/api/items/') +def api_items(category_id): + """获取分类下的数据列表""" + items_file = DATA_DIR / f'items_{category_id}.json' + items = load_data(items_file) + return jsonify(items) + +@app.route('/api/items//') +def api_item_detail(category_id, item_id): + """获取单个数据详情""" + items_file = DATA_DIR / f'items_{category_id}.json' + items = load_data(items_file) + item = next((i for i in items if i['id'] == item_id), None) + + if not item: + return jsonify({'error': 'Item not found'}), 404 + + return jsonify(item) + +@app.route('/api/items/', methods=['POST']) +def api_create_item(category_id): + """创建新数据""" + data = request.get_json() + items_file = DATA_DIR / f'items_{category_id}.json' + items = load_data(items_file) + + import uuid + data['id'] = uuid.uuid4().hex[:12] + data['category_id'] = category_id + data['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + + items.append(data) + save_data(items_file, items) + + return jsonify(data) + +@app.route('/api/items//', methods=['PUT']) +def api_update_item(category_id, item_id): + """更新数据""" + data = request.get_json() + items_file = DATA_DIR / f'items_{category_id}.json' + items = load_data(items_file) + + item = next((i for i in items if i['id'] == item_id), None) + if not item: + return jsonify({'error': 'Item not found'}), 404 + + item.update(data) + item['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + save_data(items_file, items) + + return jsonify(item) + +@app.route('/api/items//', methods=['DELETE']) +def api_delete_item(category_id, item_id): + """删除数据""" + items_file = DATA_DIR / f'items_{category_id}.json' + items = load_data(items_file) + items = [i for i in items if i['id'] != item_id] + save_data(items_file, items) + + return jsonify({'success': True}) + if __name__ == '__main__': print("=" * 50) print("ParamHub - 参数百科") diff --git a/data/categories.json b/data/categories.json index cd95bc8..efe26f5 100644 --- a/data/categories.json +++ b/data/categories.json @@ -1,8 +1,42 @@ [ - {"id": "ai-models", "name": "AI模型", "icon": "ri-robot-line", "color": "blue", "description": "大语言模型、图像模型等AI模型参数", "order": 1}, - {"id": "gpus", "name": "GPU显卡", "icon": "ri-cpu-line", "color": "green", "description": "NVIDIA、AMD等GPU显卡规格参数", "order": 2}, - {"id": "cpus", "name": "CPU处理器", "icon": "ri-memory-line", "color": "purple", "description": "Intel、AMD等CPU处理器参数", "order": 3}, - {"id": "phones", "name": "手机", "icon": "ri-smartphone-line", "color": "orange", "description": "各品牌手机参数规格", "order": 4}, - {"id": "laptops", "name": "电脑", "icon": "ri-macbook-line", "color": "teal", "description": "笔记本电脑、台式机参数", "order": 5}, - {"id": "cars", "name": "汽车", "icon": "ri-car-line", "color": "red", "description": "新能源汽车、燃油车参数", "order": 6} + { + "id": "ai-models", + "name": "AI模型", + "icon": "ri-robot-line", + "color": "blue", + "description": "大语言模型、图像模型等AI模型参数", + "order": 1 + }, + { + "id": "gpus", + "name": "GPU显卡", + "icon": "ri-cpu-line", + "color": "green", + "description": "NVIDIA、AMD等GPU显卡规格参数", + "order": 2 + }, + { + "id": "cpus", + "name": "CPU处理器", + "icon": "ri-memory-line", + "color": "purple", + "description": "Intel、AMD等CPU处理器参数", + "order": 3 + }, + { + "id": "phones", + "name": "手机", + "icon": "ri-smartphone-line", + "color": "orange", + "description": "各品牌手机参数规格", + "order": 4 + }, + { + "id": "laptops", + "name": "电脑", + "icon": "ri-macbook-line", + "color": "teal", + "description": "笔记本电脑、台式机参数", + "order": 5 + } ] \ No newline at end of file diff --git a/templates/admin.html b/templates/admin.html index b53815e..3ea5389 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -23,31 +23,8 @@
后台管理