Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
850b356f89 | ||
|
|
c85a43f542 | ||
|
|
116ee34b6f |
@@ -0,0 +1,764 @@
|
||||
# ParamHub API 能力文档
|
||||
|
||||
> 本文档记录系统所有 API 能力,变更时请及时更新
|
||||
>
|
||||
> 最后更新:2026-07-11
|
||||
|
||||
---
|
||||
|
||||
## 基础信息
|
||||
|
||||
- **基础地址**: `http://localhost:16041`
|
||||
- **认证方式**: Session Cookie(登录后获取)
|
||||
- **认证要求**: 所有 POST/PUT/DELETE 请求需先登录
|
||||
|
||||
---
|
||||
|
||||
## 1. 认证 API
|
||||
|
||||
### 1.1 登录
|
||||
```
|
||||
POST /login
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"password": "admin123"
|
||||
}
|
||||
|
||||
响应:
|
||||
{
|
||||
"success": true,
|
||||
"redirect": "/admin"
|
||||
}
|
||||
```
|
||||
|
||||
### 1.2 登出
|
||||
```
|
||||
GET /logout
|
||||
```
|
||||
|
||||
### 1.3 检查登录状态
|
||||
```
|
||||
GET /api/config (未登录返回 401)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. 分类管理 API
|
||||
|
||||
### 2.1 获取分类列表
|
||||
```
|
||||
GET /api/categories
|
||||
GET /api/categories?all=1 (包含隐藏分类)
|
||||
```
|
||||
|
||||
### 2.2 获取分类详情
|
||||
```
|
||||
GET /api/categories/{category_id}
|
||||
```
|
||||
|
||||
### 2.3 创建分类
|
||||
```
|
||||
POST /api/categories
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"name": "分类名称",
|
||||
"icon": "ri-icon-name",
|
||||
"order": 0,
|
||||
"visible": true,
|
||||
"fields": ["field1", "field2"] // 动态字段配置
|
||||
}
|
||||
```
|
||||
|
||||
### 2.4 更新分类
|
||||
```
|
||||
PUT /api/categories/{category_id}
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:同创建
|
||||
```
|
||||
|
||||
### 2.5 删除分类
|
||||
```
|
||||
DELETE /api/categories/{category_id}
|
||||
```
|
||||
|
||||
### 2.6 切换分类显示/隐藏
|
||||
```
|
||||
POST /api/categories/{category_id}/visible
|
||||
```
|
||||
|
||||
### 2.7 导出分类
|
||||
```
|
||||
GET /api/categories/export // 导出所有分类
|
||||
GET /api/categories/export/{category_id} // 导出单个分类
|
||||
```
|
||||
|
||||
### 2.8 导入分类
|
||||
```
|
||||
POST /api/categories/import?mode=merge|replace
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"categories": [...]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. AI模型 API
|
||||
|
||||
### 3.1 获取模型列表
|
||||
```
|
||||
GET /api/models
|
||||
GET /api/models?all=1 // 包含隐藏模型
|
||||
GET /api/models?q=关键词 // 搜索
|
||||
GET /api/models?sort=name&order=desc // 排序
|
||||
```
|
||||
|
||||
### 3.2 获取模型详情
|
||||
```
|
||||
GET /api/models/{model_id}
|
||||
```
|
||||
|
||||
### 3.3 创建模型
|
||||
```
|
||||
POST /api/models
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"name": "模型名称",
|
||||
"organization": "组织",
|
||||
"parameters": "70B",
|
||||
"context_length": 4096,
|
||||
"mmlu": 85.5,
|
||||
"publish_date": "2024-01-01",
|
||||
"visible": true,
|
||||
"is_pinned": false
|
||||
}
|
||||
```
|
||||
|
||||
### 3.4 更新模型
|
||||
```
|
||||
PUT /api/models/{model_id}
|
||||
```
|
||||
|
||||
### 3.5 删除模型
|
||||
```
|
||||
DELETE /api/models/{model_id}
|
||||
```
|
||||
|
||||
### 3.6 切换显示/隐藏
|
||||
```
|
||||
POST /api/models/{model_id}/visible
|
||||
```
|
||||
|
||||
### 3.7 置顶/取消置顶
|
||||
```
|
||||
POST /api/models/{model_id}/pin
|
||||
```
|
||||
|
||||
### 3.8 增加阅读数
|
||||
```
|
||||
POST /api/models/{model_id}/view
|
||||
```
|
||||
|
||||
### 3.9 导出模型
|
||||
```
|
||||
GET /api/models/export
|
||||
```
|
||||
|
||||
### 3.10 导入模型
|
||||
```
|
||||
POST /api/models/import?mode=merge|replace
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"type": "models",
|
||||
"items": [...]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. GPU API
|
||||
|
||||
### 4.1 获取GPU列表
|
||||
```
|
||||
GET /api/gpus
|
||||
GET /api/gpus?all=1
|
||||
GET /api/gpus?q=关键词
|
||||
GET /api/gpus?sort=memory_gb&order=desc
|
||||
```
|
||||
|
||||
### 4.2 获取GPU详情
|
||||
```
|
||||
GET /api/gpus/{gpu_id}
|
||||
```
|
||||
|
||||
### 4.3 创建GPU
|
||||
```
|
||||
POST /api/gpus
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"name": "GPU名称",
|
||||
"manufacturer": "NVIDIA",
|
||||
"memory_gb": 80,
|
||||
"cuda_cores": 10752,
|
||||
"tensor_cores": 336,
|
||||
"price_usd": 30000,
|
||||
"release_year": 2024,
|
||||
"visible": true,
|
||||
"is_pinned": false
|
||||
}
|
||||
```
|
||||
|
||||
### 4.4 更新GPU
|
||||
```
|
||||
PUT /api/gpus/{gpu_id}
|
||||
```
|
||||
|
||||
### 4.5 删除GPU
|
||||
```
|
||||
DELETE /api/gpus/{gpu_id}
|
||||
```
|
||||
|
||||
### 4.6 切换显示/隐藏
|
||||
```
|
||||
POST /api/gpus/{gpu_id}/visible
|
||||
```
|
||||
|
||||
### 4.7 置顶/取消置顶
|
||||
```
|
||||
POST /api/gpus/{gpu_id}/pin
|
||||
```
|
||||
|
||||
### 4.8 增加阅读数
|
||||
```
|
||||
POST /api/gpus/{gpu_id}/view
|
||||
```
|
||||
|
||||
### 4.9 导出GPU
|
||||
```
|
||||
GET /api/gpus/export
|
||||
```
|
||||
|
||||
### 4.10 导入GPU
|
||||
```
|
||||
POST /api/gpus/import?mode=merge|replace
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. CPU API
|
||||
|
||||
### 5.1 获取CPU列表
|
||||
```
|
||||
GET /api/cpus
|
||||
GET /api/cpus?all=1
|
||||
GET /api/cpus?q=关键词
|
||||
GET /api/cpus?sort=cores&order=desc
|
||||
```
|
||||
|
||||
### 5.2 获取CPU详情
|
||||
```
|
||||
GET /api/cpus/{cpu_id}
|
||||
```
|
||||
|
||||
### 5.3 创建CPU
|
||||
```
|
||||
POST /api/cpus
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"name": "CPU名称",
|
||||
"manufacturer": "AMD",
|
||||
"cores": 64,
|
||||
"threads": 128,
|
||||
"base_clock": 2.4,
|
||||
"boost_clock": 3.7,
|
||||
"price_usd": 8000,
|
||||
"visible": true,
|
||||
"is_pinned": false
|
||||
}
|
||||
```
|
||||
|
||||
### 5.4 更新CPU
|
||||
```
|
||||
PUT /api/cpus/{cpu_id}
|
||||
```
|
||||
|
||||
### 5.5 删除CPU
|
||||
```
|
||||
DELETE /api/cpus/{cpu_id}
|
||||
```
|
||||
|
||||
### 5.6 切换显示/隐藏
|
||||
```
|
||||
POST /api/cpus/{cpu_id}/visible
|
||||
```
|
||||
|
||||
### 5.7 置顶/取消置顶
|
||||
```
|
||||
POST /api/cpus/{cpu_id}/pin
|
||||
```
|
||||
|
||||
### 5.8 增加阅读数
|
||||
```
|
||||
POST /api/cpus/{cpu_id}/view
|
||||
```
|
||||
|
||||
### 5.9 导出CPU
|
||||
```
|
||||
GET /api/cpus/export
|
||||
```
|
||||
|
||||
### 5.10 导入CPU
|
||||
```
|
||||
POST /api/cpus/import?mode=merge|replace
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. 动态分类数据 API
|
||||
|
||||
### 6.1 获取分类数据列表
|
||||
```
|
||||
GET /api/items/{category_id}
|
||||
GET /api/items/{category_id}?all=1
|
||||
GET /api/items/{category_id}?sort=price&order=desc
|
||||
```
|
||||
|
||||
### 6.2 获取数据详情
|
||||
```
|
||||
GET /api/items/{category_id}/{item_id}
|
||||
```
|
||||
|
||||
### 6.3 创建数据
|
||||
```
|
||||
POST /api/items/{category_id}
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"name": "名称",
|
||||
"visible": true,
|
||||
"is_pinned": false,
|
||||
// ... 其他动态字段
|
||||
}
|
||||
```
|
||||
|
||||
### 6.4 更新数据
|
||||
```
|
||||
PUT /api/items/{category_id}/{item_id}
|
||||
```
|
||||
|
||||
### 6.5 删除数据
|
||||
```
|
||||
DELETE /api/items/{category_id}/{item_id}
|
||||
```
|
||||
|
||||
### 6.6 切换显示/隐藏
|
||||
```
|
||||
POST /api/items/{category_id}/{item_id}/visible
|
||||
```
|
||||
|
||||
### 6.7 置顶/取消置顶
|
||||
```
|
||||
POST /api/items/{category_id}/{item_id}/pin
|
||||
```
|
||||
|
||||
### 6.8 增加阅读数
|
||||
```
|
||||
POST /api/items/{category_id}/{item_id}/view
|
||||
```
|
||||
|
||||
### 6.9 导出分类数据
|
||||
```
|
||||
GET /api/items/{category_id}/export
|
||||
```
|
||||
|
||||
### 6.10 导入分类数据
|
||||
```
|
||||
POST /api/items/{category_id}/import?mode=merge|replace
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. 知识库 API
|
||||
|
||||
### 7.1 获取知识库列表
|
||||
```
|
||||
GET /api/knowledge
|
||||
GET /api/knowledge?all=1
|
||||
GET /api/knowledge?q=关键词
|
||||
GET /api/knowledge?category=分类名
|
||||
```
|
||||
|
||||
### 7.2 获取知识详情
|
||||
```
|
||||
GET /api/knowledge/{knowledge_id}
|
||||
```
|
||||
|
||||
### 7.3 创建知识
|
||||
```
|
||||
POST /api/knowledge
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"title": "标题",
|
||||
"content": "内容",
|
||||
"category": "分类",
|
||||
"order": 0,
|
||||
"visible": true
|
||||
}
|
||||
```
|
||||
|
||||
### 7.4 更新知识
|
||||
```
|
||||
PUT /api/knowledge/{knowledge_id}
|
||||
```
|
||||
|
||||
### 7.5 删除知识
|
||||
```
|
||||
DELETE /api/knowledge/{knowledge_id}
|
||||
```
|
||||
|
||||
### 7.6 切换显示/隐藏
|
||||
```
|
||||
POST /api/knowledge/{knowledge_id}/visible
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8. 审核系统 API
|
||||
|
||||
### 8.1 获取待审核列表
|
||||
```
|
||||
GET /api/reviews
|
||||
GET /api/reviews?status=pending // 待审核
|
||||
GET /api/reviews?status=approved // 已通过
|
||||
GET /api/reviews?status=rejected // 已拒绝
|
||||
GET /api/reviews?status=all // 全部
|
||||
```
|
||||
|
||||
### 8.2 获取待审核数量
|
||||
```
|
||||
GET /api/reviews/count
|
||||
```
|
||||
|
||||
### 8.3 获取审核详情
|
||||
```
|
||||
GET /api/reviews/{review_id}
|
||||
```
|
||||
|
||||
### 8.4 通过审核
|
||||
```
|
||||
POST /api/reviews/{review_id}/approve
|
||||
```
|
||||
|
||||
### 8.5 拒绝审核
|
||||
```
|
||||
POST /api/reviews/{review_id}/reject
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"reason": "拒绝原因"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 9. 通知系统 API
|
||||
|
||||
### 9.1 获取通知列表
|
||||
```
|
||||
GET /api/notifications
|
||||
GET /api/notifications?unread=1 // 仅未读
|
||||
GET /api/notifications?limit=20
|
||||
```
|
||||
|
||||
### 9.2 获取未读数量
|
||||
```
|
||||
GET /api/notifications/unread-count
|
||||
```
|
||||
|
||||
### 9.3 标记已读
|
||||
```
|
||||
POST /api/notifications/{notification_id}/read
|
||||
```
|
||||
|
||||
### 9.4 全部标记已读
|
||||
```
|
||||
POST /api/notifications/read-all
|
||||
```
|
||||
|
||||
### 9.5 删除通知
|
||||
```
|
||||
DELETE /api/notifications/{notification_id}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 10. 智能解析 API
|
||||
|
||||
### 10.1 获取解析提示词模板
|
||||
```
|
||||
POST /api/parse-prompt
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"category_type": "model|gpu|cpu|dynamic",
|
||||
"category_id": "分类ID",
|
||||
"subcategory_id": "子分类ID"
|
||||
}
|
||||
```
|
||||
|
||||
### 10.2 图片解析
|
||||
```
|
||||
POST /api/parse-images
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"text": "附加文本描述",
|
||||
"images": ["图片URL或Base64"],
|
||||
"category_type": "model|gpu|cpu|dynamic",
|
||||
"subcategory_id": "子分类ID",
|
||||
"custom_prompt": "自定义提示词"
|
||||
}
|
||||
|
||||
响应:
|
||||
{
|
||||
"success": true,
|
||||
"count": 1,
|
||||
"products": [解析结果]
|
||||
}
|
||||
```
|
||||
|
||||
### 10.3 智能添加 - AI模型
|
||||
```
|
||||
POST /api/models/smart-add
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"text": "文本描述",
|
||||
"images": ["图片URL"],
|
||||
"subcategory_id": "子分类ID",
|
||||
"custom_prompt": "自定义提示词"
|
||||
}
|
||||
```
|
||||
|
||||
### 10.4 智能添加 - GPU
|
||||
```
|
||||
POST /api/gpus/smart-add
|
||||
```
|
||||
|
||||
### 10.5 智能添加 - CPU
|
||||
```
|
||||
POST /api/cpus/smart-add
|
||||
```
|
||||
|
||||
### 10.6 智能添加 - 动态分类
|
||||
```
|
||||
POST /api/items/{category_id}/smart-add
|
||||
```
|
||||
|
||||
### 10.7 智能补充 - AI模型
|
||||
```
|
||||
POST /api/models/{model_id}/smart-update
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"text": "补充信息文本",
|
||||
"images": ["图片URL"]
|
||||
}
|
||||
|
||||
响应:
|
||||
{
|
||||
"success": true,
|
||||
"updated_fields": ["field1", "field2"],
|
||||
"model": 更新后的模型数据
|
||||
}
|
||||
```
|
||||
|
||||
### 10.8 智能补充 - GPU
|
||||
```
|
||||
POST /api/gpus/{gpu_id}/smart-update
|
||||
```
|
||||
|
||||
### 10.9 智能补充 - CPU
|
||||
```
|
||||
POST /api/cpus/{cpu_id}/smart-update
|
||||
```
|
||||
|
||||
### 10.10 智能补充 - 动态分类
|
||||
```
|
||||
POST /api/items/{category_id}/{item_id}/smart-update
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 11. 搜索与统计 API
|
||||
|
||||
### 11.1 全局搜索
|
||||
```
|
||||
GET /api/search?q=关键词
|
||||
|
||||
响应:
|
||||
{
|
||||
"models": [...],
|
||||
"gpus": [...],
|
||||
"cpus": [...]
|
||||
}
|
||||
```
|
||||
|
||||
### 11.2 显存计算
|
||||
```
|
||||
GET /api/calculate/vram?params=7&precision=fp16
|
||||
|
||||
参数:
|
||||
- params: 模型参数量(单位:B)
|
||||
- precision: 精度 (fp32|fp16|int8|int4)
|
||||
|
||||
响应:
|
||||
{
|
||||
"model_vram": 14.0, // 模型显存需求(GB)
|
||||
"total_vram": 18.2, // 总显存需求(含30%余量)
|
||||
"suitable_gpus": [...] // 适用GPU列表
|
||||
}
|
||||
```
|
||||
|
||||
### 11.3 统计数据
|
||||
```
|
||||
GET /api/stats
|
||||
|
||||
响应:
|
||||
{
|
||||
"models_count": 10,
|
||||
"gpus_count": 5,
|
||||
"cpus_count": 8,
|
||||
"categories_count": 3,
|
||||
"knowledge_count": 20,
|
||||
"latest_models": [...]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 12. 网站配置 API
|
||||
|
||||
### 12.1 获取配置
|
||||
```
|
||||
GET /api/config
|
||||
|
||||
响应:
|
||||
{
|
||||
"site_name": "ParamHub",
|
||||
"admin_password": "admin123",
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
### 12.2 更新配置
|
||||
```
|
||||
PUT /api/config
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"site_name": "新名称",
|
||||
"admin_password": "新密码"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 13. 图片上传 API
|
||||
|
||||
### 13.1 上传图片(文件)
|
||||
```
|
||||
POST /api/upload/image
|
||||
Content-Type: multipart/form-data
|
||||
|
||||
请求体:
|
||||
- file: 图片文件
|
||||
|
||||
响应:
|
||||
{
|
||||
"success": true,
|
||||
"filename": "abc123_1234567890.png",
|
||||
"url": "/static/uploads/abc123_1234567890.png"
|
||||
}
|
||||
```
|
||||
|
||||
### 13.2 上传图片(Base64)
|
||||
```
|
||||
POST /api/upload/image/base64
|
||||
Content-Type: application/json
|
||||
|
||||
请求体:
|
||||
{
|
||||
"image": "data:image/png;base64,xxxxx...",
|
||||
"ext": "png"
|
||||
}
|
||||
```
|
||||
|
||||
### 13.3 删除图片
|
||||
```
|
||||
DELETE /api/upload/image/delete/{filename}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 错误响应
|
||||
|
||||
所有 API 错误响应格式:
|
||||
```json
|
||||
{
|
||||
"error": "错误信息"
|
||||
}
|
||||
```
|
||||
|
||||
常见错误码:
|
||||
- `400` - 请求参数错误
|
||||
- `401` - 未登录
|
||||
- `404` - 资源不存在
|
||||
- `500` - 服务器错误
|
||||
|
||||
---
|
||||
|
||||
## 审核模式说明
|
||||
|
||||
当系统开启审核模式(`REQUIRE_REVIEW = True`)时:
|
||||
|
||||
1. 创建产品(POST /api/models, /api/gpus, /api/cpus, /api/items/{category_id})时:
|
||||
- 数据不会直接入库
|
||||
- 而是提交到审核队列
|
||||
- 返回 `{ "success": true, "message": "已提交审核", "review_id": "xxx" }`
|
||||
|
||||
2. 管理员需通过审核 API 确认:
|
||||
- `POST /api/reviews/{review_id}/approve` - 通过
|
||||
- `POST /api/reviews/{review_id}/reject` - 拒绝
|
||||
|
||||
---
|
||||
|
||||
## 变更日志
|
||||
|
||||
| 日期 | 变更内容 |
|
||||
|------|----------|
|
||||
| 2026-07-11 | 初始版本,记录所有 API 能力 |
|
||||
@@ -54,18 +54,27 @@ param-hub-python/
|
||||
|
||||
## API接口
|
||||
|
||||
| 接口 | 方法 | 说明 |
|
||||
|------|------|------|
|
||||
| `/api/models` | GET | 获取模型列表 |
|
||||
| `/api/models/<id>` | GET | 获取模型详情 |
|
||||
| `/api/gpus` | GET | 获取GPU列表 |
|
||||
| `/api/gpus/<id>` | GET | 获取GPU详情 |
|
||||
| `/api/cpus` | GET | 获取CPU列表 |
|
||||
| `/api/cpus/<id>` | GET | 获取CPU详情 |
|
||||
| `/api/search` | GET | 全局搜索 |
|
||||
| `/api/calculate/vram` | GET | 显存计算 |
|
||||
| `/api/stats` | GET | 统计数据 |
|
||||
完整 API 能力文档请查看 [API.md](API.md)
|
||||
|
||||
### 快速参考
|
||||
|
||||
| 模块 | 主要接口 |
|
||||
|------|----------|
|
||||
| 认证 | `/login`, `/logout` |
|
||||
| 分类 | `/api/categories` CRUD + 导入导出 |
|
||||
| AI模型 | `/api/models` CRUD + 置顶 + 热度 + 导入导出 |
|
||||
| GPU | `/api/gpus` CRUD + 置顶 + 热度 + 导入导出 |
|
||||
| CPU | `/api/cpus` CRUD + 置顶 + 热度 + 导入导出 |
|
||||
| 动态分类 | `/api/items/{category_id}` CRUD |
|
||||
| 知识库 | `/api/knowledge` CRUD |
|
||||
| 审核 | `/api/reviews` 审核通过/拒绝 |
|
||||
| 通知 | `/api/notifications` 通知管理 |
|
||||
| 智能解析 | `/api/parse-images`, `/api/*/smart-add`, `/api/*/smart-update` |
|
||||
| 搜索统计 | `/api/search`, `/api/calculate/vram`, `/api/stats` |
|
||||
| 配置 | `/api/config` |
|
||||
| 图片上传 | `/api/upload/image` |
|
||||
|
||||
## 版本
|
||||
|
||||
- v2.0.0 - 产品审核发布 + 后台通知系统 + 完整API能力
|
||||
- v0.1.0 - 初始版本
|
||||
+226
-16
@@ -324,12 +324,13 @@
|
||||
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">产品名称</th>
|
||||
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">分类</th>
|
||||
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">来源</th>
|
||||
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">提交者</th>
|
||||
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">提交时间</th>
|
||||
<th class="px-4 py-3 text-left text-sm font-medium text-gray-600">状态</th>
|
||||
<th class="px-4 py-3 text-center text-sm font-medium text-gray-600">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="reviewsTable"><tr><td colspan="6" class="text-center text-gray-400 py-8">加载中...</td></tr></tbody>
|
||||
<tbody id="reviewsTable"><tr><td colspan="7" class="text-center text-gray-400 py-8">加载中...</td></tr></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
@@ -479,6 +480,22 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 审核详情弹窗 -->
|
||||
<div id="reviewDetailModal" class="fixed inset-0 bg-black/50 z-50 hidden flex items-center justify-center">
|
||||
<div class="bg-white rounded-xl max-w-4xl w-full mx-4 max-h-[90vh] overflow-auto">
|
||||
<div class="p-6 border-b flex justify-between items-center sticky top-0 bg-white z-10">
|
||||
<h2 class="text-xl font-bold text-gray-800"><i class="ri-file-search-line mr-2 text-blue-600"></i>审核详情</h2>
|
||||
<button onclick="closeReviewDetailModal()" class="text-gray-400 hover:text-gray-600"><i class="ri-close-line text-2xl"></i></button>
|
||||
</div>
|
||||
<div id="reviewDetailContent" class="p-6">
|
||||
<!-- 动态内容 -->
|
||||
</div>
|
||||
<div id="reviewDetailActions" class="p-6 border-t flex justify-end gap-4 sticky bottom-0 bg-white">
|
||||
<!-- 操作按钮 -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 参数字段编辑弹框 -->
|
||||
<div id="fieldModal" class="fixed inset-0 bg-black/50 z-50 hidden flex items-center justify-center">
|
||||
<div class="bg-white rounded-xl max-w-lg w-full mx-4">
|
||||
@@ -3194,7 +3211,7 @@
|
||||
|
||||
if (reviews.length === 0) {
|
||||
document.getElementById('reviewsTable').innerHTML = `
|
||||
<tr><td colspan="6" class="text-center text-gray-400 py-8">暂无数据</td></tr>
|
||||
<tr><td colspan="7" class="text-center text-gray-400 py-8">暂无数据</td></tr>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
@@ -3207,20 +3224,34 @@
|
||||
|
||||
const html = reviews.map(r => {
|
||||
const catName = categories.find(c => c.id === r.category_id)?.name || r.category_id;
|
||||
// 提取关键参数预览
|
||||
const data = r.data || {};
|
||||
const previewFields = [];
|
||||
['organization', 'model_type', 'parameters', 'context_length', 'release_year'].forEach(key => {
|
||||
if (data[key]) previewFields.push(`<span class="text-gray-500">${data[key]}</span>`);
|
||||
});
|
||||
const preview = previewFields.length > 0 ? previewFields.slice(0, 3).join(' · ') : '-';
|
||||
|
||||
return `
|
||||
<tr class="border-b hover:bg-gray-50">
|
||||
<td class="px-4 py-3 font-medium text-gray-800">${r.data?.name || '-'}</td>
|
||||
<tr class="border-b hover:bg-gray-50 ${r.status === 'pending' ? 'bg-orange-50/30' : ''}">
|
||||
<td class="px-4 py-3">
|
||||
<div class="font-medium text-gray-800">${r.data?.name || '-'}</div>
|
||||
<div class="text-xs text-gray-400 mt-1">${preview}</div>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-gray-600">${catName}</td>
|
||||
<td class="px-4 py-3 text-sm">
|
||||
${r.source === 'api' ? '<span class="text-indigo-600">API</span>' : '<span class="text-gray-500">网页</span>'}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-sm">
|
||||
${r.submitter ? `<span class="text-gray-600">${r.submitter}</span>` : '<span class="text-gray-400">匿名</span>'}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-sm text-gray-500">${r.created_at}</td>
|
||||
<td class="px-4 py-3">${statusLabels[r.status] || r.status}</td>
|
||||
<td class="px-4 py-3 text-center">
|
||||
${r.status === 'pending' ? `
|
||||
<button onclick="approveReview('${r.id}')" class="text-green-600 hover:text-green-800 mr-2" title="通过"><i class="ri-check-line"></i></button>
|
||||
<button onclick="viewReviewDetail('${r.id}')" class="text-blue-600 hover:text-blue-800 mr-2" title="查看详情"><i class="ri-eye-line"></i></button>
|
||||
<button onclick="approveReview('${r.id}')" class="text-green-600 hover:text-green-800 mr-1" title="通过"><i class="ri-check-line"></i></button>
|
||||
<button onclick="rejectReview('${r.id}')" class="text-red-600 hover:text-red-800" title="拒绝"><i class="ri-close-line"></i></button>
|
||||
<button onclick="viewReviewDetail('${r.id}')" class="text-blue-600 hover:text-blue-800 ml-2" title="查看详情"><i class="ri-eye-line"></i></button>
|
||||
` : `
|
||||
<button onclick="viewReviewDetail('${r.id}')" class="text-blue-600 hover:text-blue-800" title="查看详情"><i class="ri-eye-line"></i></button>
|
||||
`}
|
||||
@@ -3232,7 +3263,7 @@
|
||||
document.getElementById('reviewsTable').innerHTML = html;
|
||||
} catch (e) {
|
||||
document.getElementById('reviewsTable').innerHTML = `
|
||||
<tr><td colspan="6" class="text-center text-red-500 py-8">加载失败: ${e.message}</td></tr>
|
||||
<tr><td colspan="7" class="text-center text-red-500 py-8">加载失败: ${e.message}</td></tr>
|
||||
`;
|
||||
}
|
||||
}
|
||||
@@ -3279,26 +3310,205 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 当前审核详情ID
|
||||
let currentReviewId = '';
|
||||
|
||||
// 查看审核详情
|
||||
async function viewReviewDetail(reviewId) {
|
||||
currentReviewId = reviewId;
|
||||
try {
|
||||
const res = await fetch(`/api/reviews/${reviewId}`);
|
||||
const review = await res.json();
|
||||
|
||||
let html = '<div class="space-y-4">';
|
||||
html += `<div><span class="text-gray-500">状态:</span> ${review.status}</div>`;
|
||||
html += `<div><span class="text-gray-500">分类:</span> ${review.category_id}</div>`;
|
||||
html += `<div><span class="text-gray-500">来源:</span> ${review.source}</div>`;
|
||||
html += `<div><span class="text-gray-500">提交时间:</span> ${review.created_at}</div>`;
|
||||
html += '<div class="border-t pt-4"><h3 class="font-medium mb-2">产品数据:</h3>';
|
||||
html += '<pre class="bg-gray-50 p-3 rounded text-sm overflow-auto max-h-60">' + JSON.stringify(review.data, null, 2) + '</pre>';
|
||||
html += '</div></div>';
|
||||
const catName = categories.find(c => c.id === review.category_id)?.name || review.category_id;
|
||||
const statusLabels = {
|
||||
pending: '<span class="px-3 py-1 bg-orange-100 text-orange-700 rounded-full text-sm">待审核</span>',
|
||||
approved: '<span class="px-3 py-1 bg-green-100 text-green-700 rounded-full text-sm">已通过</span>',
|
||||
rejected: '<span class="px-3 py-1 bg-red-100 text-red-700 rounded-full text-sm">已拒绝</span>'
|
||||
};
|
||||
|
||||
alert(html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim());
|
||||
let html = `
|
||||
<div class="space-y-6">
|
||||
<!-- 基本信息 -->
|
||||
<div class="bg-gray-50 rounded-lg p-4">
|
||||
<h3 class="text-sm font-semibold text-gray-500 mb-3"><i class="ri-information-line mr-1"></i>基本信息</h3>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div><span class="text-gray-400 text-sm">状态:</span>${statusLabels[review.status] || review.status}</div>
|
||||
<div><span class="text-gray-400 text-sm">分类:</span><span class="font-medium text-gray-800">${catName}</span></div>
|
||||
<div><span class="text-gray-400 text-sm">来源:</span><span class="text-gray-800">${review.source === 'api' ? 'API提交' : '网页提交'}</span></div>
|
||||
<div><span class="text-gray-400 text-sm">提交者:</span><span class="text-gray-800">${review.submitter || '匿名'}</span></div>
|
||||
<div class="col-span-2"><span class="text-gray-400 text-sm">提交时间:</span><span class="text-gray-800">${review.created_at}</span></div>
|
||||
</div>
|
||||
${review.status === 'rejected' && review.reject_reason ? `
|
||||
<div class="mt-3 pt-3 border-t border-gray-200">
|
||||
<span class="text-gray-400 text-sm">拒绝原因:</span>
|
||||
<span class="text-red-600">${review.reject_reason}</span>
|
||||
</div>
|
||||
` : ''}
|
||||
${review.status === 'approved' ? `
|
||||
<div class="mt-3 pt-3 border-t border-gray-200">
|
||||
<span class="text-gray-400 text-sm">审核通过时间:</span>
|
||||
<span class="text-green-600">${review.approved_at || '-'}</span>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
|
||||
<!-- 产品数据 -->
|
||||
<div class="border rounded-lg p-4">
|
||||
<h3 class="text-sm font-semibold text-gray-500 mb-3"><i class="ri-database-2-line mr-1"></i>产品数据</h3>
|
||||
<div class="space-y-3">
|
||||
${renderProductData(review.data, review.category_id)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.getElementById('reviewDetailContent').innerHTML = html;
|
||||
|
||||
// 操作按钮
|
||||
let actionsHtml = '';
|
||||
if (review.status === 'pending') {
|
||||
actionsHtml = `
|
||||
<button onclick="closeReviewDetailModal()" class="px-4 py-2 bg-gray-200 text-gray-600 rounded-lg hover:bg-gray-300">关闭</button>
|
||||
<button onclick="rejectReviewFromModal()" class="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700"><i class="ri-close-line mr-1"></i>拒绝</button>
|
||||
<button onclick="approveReviewFromModal()" class="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700"><i class="ri-check-line mr-1"></i>通过</button>
|
||||
`;
|
||||
} else {
|
||||
actionsHtml = `<button onclick="closeReviewDetailModal()" class="px-4 py-2 bg-gray-200 text-gray-600 rounded-lg hover:bg-gray-300">关闭</button>`;
|
||||
}
|
||||
document.getElementById('reviewDetailActions').innerHTML = actionsHtml;
|
||||
|
||||
document.getElementById('reviewDetailModal').classList.remove('hidden');
|
||||
} catch (e) {
|
||||
alert('加载失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染产品数据(格式化显示)
|
||||
function renderProductData(data, categoryId) {
|
||||
if (!data) return '<div class="text-gray-400">无数据</div>';
|
||||
|
||||
// 获取分类的字段配置
|
||||
const cat = categories.find(c => c.id === categoryId);
|
||||
const fields = cat ? (cat.fields || []) : [];
|
||||
|
||||
// 排序字段:名称放第一
|
||||
const sortedFields = [...fields].sort((a, b) => {
|
||||
if (a.key === 'name') return -1;
|
||||
if (b.key === 'name') return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
let html = '';
|
||||
|
||||
// 先显示有字段配置的值
|
||||
sortedFields.forEach(field => {
|
||||
const value = data[field.key];
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
html += renderFieldRow(field, value);
|
||||
}
|
||||
});
|
||||
|
||||
// 再显示其他没有字段配置的值
|
||||
Object.keys(data).forEach(key => {
|
||||
if (!fields.find(f => f.key === key)) {
|
||||
const value = data[key];
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
html += `<div class="flex py-2 border-b border-gray-100 last:border-0">
|
||||
<div class="w-1/3 text-gray-500 text-sm">${key}</div>
|
||||
<div class="w-2/3 text-gray-800">${formatValue(value)}</div>
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return html || '<div class="text-gray-400">无数据</div>';
|
||||
}
|
||||
|
||||
// 渲染单个字段行
|
||||
function renderFieldRow(field, value) {
|
||||
const label = field.label || field.key;
|
||||
const type = field.type || 'text';
|
||||
let displayValue = formatValue(value, type);
|
||||
|
||||
return `<div class="flex py-2 border-b border-gray-100 last:border-0">
|
||||
<div class="w-1/3 text-gray-500 text-sm">${label}</div>
|
||||
<div class="w-2/3 text-gray-800">${displayValue}</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// 格式化值
|
||||
function formatValue(value, type = 'text') {
|
||||
if (value === null || value === undefined) return '-';
|
||||
if (typeof value === 'boolean') return value ? '<span class="text-green-600">是</span>' : '<span class="text-gray-400">否</span>';
|
||||
if (typeof value === 'object') {
|
||||
if (Array.isArray(value)) {
|
||||
if (value.length === 0) return '-';
|
||||
// 如果是图片数组
|
||||
if (typeof value[0] === 'string' && (value[0].startsWith('http') || value[0].startsWith('/'))) {
|
||||
return value.map(url => `<img src="${url}" class="inline-block w-16 h-16 object-cover rounded mr-2 cursor-pointer hover:opacity-80" onclick="window.open('${url}', '_blank')">`).join('');
|
||||
}
|
||||
return value.join(', ');
|
||||
}
|
||||
return `<pre class="bg-gray-50 p-2 rounded text-xs overflow-auto">${JSON.stringify(value, null, 2)}</pre>`;
|
||||
}
|
||||
if (type === 'url' || (typeof value === 'string' && value.startsWith('http'))) {
|
||||
return `<a href="${value}" target="_blank" class="text-blue-600 hover:underline">${value}</a>`;
|
||||
}
|
||||
return String(value);
|
||||
}
|
||||
|
||||
// 关闭审核详情弹窗
|
||||
function closeReviewDetailModal() {
|
||||
document.getElementById('reviewDetailModal').classList.add('hidden');
|
||||
currentReviewId = '';
|
||||
}
|
||||
|
||||
// 从弹窗中通过审核
|
||||
async function approveReviewFromModal() {
|
||||
if (!currentReviewId) return;
|
||||
if (!confirm('确认通过该产品审核?')) return;
|
||||
try {
|
||||
const res = await fetch(`/api/reviews/${currentReviewId}/approve`, {method: 'POST'});
|
||||
const data = await res.json();
|
||||
if (data.error) {
|
||||
alert('操作失败: ' + data.error);
|
||||
} else {
|
||||
alert('审核通过,产品已发布!');
|
||||
closeReviewDetailModal();
|
||||
loadReviews();
|
||||
loadNotificationCounts();
|
||||
loadOverview();
|
||||
}
|
||||
} catch (e) {
|
||||
alert('操作失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 从弹窗中拒绝审核
|
||||
async function rejectReviewFromModal() {
|
||||
if (!currentReviewId) return;
|
||||
const reason = prompt('请输入拒绝原因(可选):');
|
||||
if (reason === null) return; // 用户取消
|
||||
try {
|
||||
const res = await fetch(`/api/reviews/${currentReviewId}/reject`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({reason})
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.error) {
|
||||
alert('操作失败: ' + data.error);
|
||||
} else {
|
||||
alert('已拒绝该产品!');
|
||||
closeReviewDetailModal();
|
||||
loadReviews();
|
||||
loadNotificationCounts();
|
||||
}
|
||||
} catch (e) {
|
||||
alert('操作失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
</script>
|
||||
|
||||
+130
-3
@@ -56,8 +56,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 搜索结果区域 -->
|
||||
<div id="searchResults" class="hidden mb-8">
|
||||
<h2 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2">
|
||||
<i class="ri-search-line text-indigo-600"></i>
|
||||
搜索结果
|
||||
<span id="searchKeyword" class="text-sm text-gray-500"></span>
|
||||
</h2>
|
||||
<div id="searchContent">
|
||||
<!-- 动态填充 -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 热门模型 -->
|
||||
<div class="bg-white rounded-xl shadow-sm p-6">
|
||||
<div id="hotModels" class="bg-white rounded-xl shadow-sm p-6">
|
||||
<h2 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2">
|
||||
<i class="ri-cpu-line text-indigo-600"></i>
|
||||
热门模型
|
||||
@@ -241,8 +253,123 @@
|
||||
// 搜索
|
||||
async function search() {
|
||||
const keyword = document.getElementById('searchInput').value.trim();
|
||||
if (!keyword) return;
|
||||
window.location.href = `/models?q=${encodeURIComponent(keyword)}`;
|
||||
if (!keyword) {
|
||||
// 清空搜索时恢复原页面
|
||||
document.getElementById('searchResults').classList.add('hidden');
|
||||
document.getElementById('hotModels').classList.remove('hidden');
|
||||
document.getElementById('statsCards').classList.remove('hidden');
|
||||
document.getElementById('categoryCards').parentElement.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用全局搜索 API
|
||||
const res = await fetch(`/api/search?q=${encodeURIComponent(keyword)}`);
|
||||
const data = await res.json();
|
||||
|
||||
// 显示搜索结果区域
|
||||
document.getElementById('searchResults').classList.remove('hidden');
|
||||
document.getElementById('searchKeyword').textContent = `"${keyword}"`;
|
||||
document.getElementById('hotModels').classList.add('hidden');
|
||||
|
||||
// 渲染搜索结果
|
||||
renderSearchResults(data, keyword);
|
||||
}
|
||||
|
||||
// 渲染搜索结果
|
||||
function renderSearchResults(data, keyword) {
|
||||
const models = data.models || [];
|
||||
const gpus = data.gpus || [];
|
||||
const cpus = data.cpus || [];
|
||||
const total = models.length + gpus.length + cpus.length;
|
||||
|
||||
if (total === 0) {
|
||||
document.getElementById('searchContent').innerHTML = `
|
||||
<div class="bg-white rounded-xl shadow-sm p-8 text-center">
|
||||
<i class="ri-search-line text-4xl text-gray-300 mb-4"></i>
|
||||
<p class="text-gray-500">未找到与 "${keyword}" 相关的结果</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
let html = `<div class="bg-white rounded-xl shadow-sm p-4 mb-4 text-sm text-gray-600">找到 ${total} 条结果</div>`;
|
||||
|
||||
// AI模型结果
|
||||
if (models.length > 0) {
|
||||
html += `
|
||||
<div class="bg-white rounded-xl shadow-sm p-6 mb-4">
|
||||
<h3 class="font-semibold text-gray-800 mb-4 flex items-center gap-2">
|
||||
<i class="ri-robot-line text-blue-500"></i>
|
||||
AI模型 (${models.length})
|
||||
</h3>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
${models.map(m => `
|
||||
<a href="/models" class="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition">
|
||||
<div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center text-blue-600 font-bold text-sm">
|
||||
${m.name.substring(0, 2)}
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<div class="font-medium text-gray-800">${m.name}</div>
|
||||
<div class="text-xs text-gray-500">${m.organization || ''}</div>
|
||||
</div>
|
||||
</a>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// GPU结果
|
||||
if (gpus.length > 0) {
|
||||
html += `
|
||||
<div class="bg-white rounded-xl shadow-sm p-6 mb-4">
|
||||
<h3 class="font-semibold text-gray-800 mb-4 flex items-center gap-2">
|
||||
<i class="ri-cpu-line text-green-500"></i>
|
||||
GPU显卡 (${gpus.length})
|
||||
</h3>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
${gpus.map(g => `
|
||||
<a href="/gpus" class="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition">
|
||||
<div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center text-green-600 font-bold text-sm">
|
||||
${g.name.substring(0, 2)}
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<div class="font-medium text-gray-800">${g.name}</div>
|
||||
<div class="text-xs text-gray-500">${g.manufacturer || ''} | ${g.memory_gb || ''}GB</div>
|
||||
</div>
|
||||
</a>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// CPU结果
|
||||
if (cpus.length > 0) {
|
||||
html += `
|
||||
<div class="bg-white rounded-xl shadow-sm p-6 mb-4">
|
||||
<h3 class="font-semibold text-gray-800 mb-4 flex items-center gap-2">
|
||||
<i class="ri-cpu-line text-purple-500"></i>
|
||||
CPU处理器 (${cpus.length})
|
||||
</h3>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
${cpus.map(c => `
|
||||
<a href="/cpus" class="flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition">
|
||||
<div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center text-purple-600 font-bold text-sm">
|
||||
${c.name.substring(0, 2)}
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<div class="font-medium text-gray-800">${c.name}</div>
|
||||
<div class="text-xs text-gray-500">${c.manufacturer || ''} | ${c.cores || ''}核</div>
|
||||
</div>
|
||||
</a>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
document.getElementById('searchContent').innerHTML = html;
|
||||
}
|
||||
|
||||
// 初始化
|
||||
|
||||
Reference in New Issue
Block a user