fix: 修复前端空白页与API调用错误,统一创作流程

- 前端
  - topics.html: 恢复结构并修复Vue初始化问题
  - 调整创作按钮逻辑:仅已发布选题禁用
  - 修正API端点与payload格式(generate/optimizer/publishing使用topic_ids数组)
  - 移除ElementPlus图标模块依赖,使用全局构建
  - admin.html: 回退至Options API版本,解决this上下文错误
- 后端
  - 注册/api/generate/run路由
  - 简化generate逻辑:允许非已发布选题重创作,更新状态为“待审查”
  - 统一logs查询接口支持query参数
  - 修复admin用户管理字段引用
  - 系统概览返回{ stats }结构
- 静态资源整理
  - 删除冗余element-plus-icons、重复CSS/JS、图标文件
  - 正确放置Vue和ElementPlus全局文件
- 数据库与数据
  - 补充30个案例
  - 更新选题状态与初始数据

验证:所有页面可访问,API认证与端点正常工作。
This commit is contained in:
lt
2026-05-06 21:44:56 +08:00
parent bd381ff65a
commit 8920a337e0
29 changed files with 159 additions and 138169 deletions
+7 -1
View File
@@ -12,7 +12,8 @@ from ..models import Topic, Article
from ..schemas import SystemStatus
from ..core.generator import run_creator
from ..core.optimizer import run_optimizer
from ..core.sync import sync_topic_to_db, sync_all_topics
from ..core.sync import sync_all_topics
from ..core.scheduler import scheduler
PROJECT_ROOT = Path(__file__).resolve().parents[4]
if os.getenv('PROJECT_ROOT'):
@@ -151,3 +152,8 @@ def refresh_all():
return {"message": "Refresh completed"}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("/scheduler/status", dependencies=[Depends(get_current_user)])
def get_scheduler_status():
"""获取定时任务状态"""
return {"jobs": scheduler.get_jobs()}
+7 -3
View File
@@ -6,7 +6,7 @@ import os
logger = logging.getLogger(__name__)
# 计算项目根目录(从本文件位置上升4层)
PROJECT_ROOT = Path(__file__).resolve().parents[1]
PROJECT_ROOT = Path(__file__).resolve().parents[4]
# 允许环境变量覆盖(适合容器部署)
if os.getenv('PROJECT_ROOT'):
PROJECT_ROOT = Path(os.getenv('PROJECT_ROOT'))
@@ -18,7 +18,11 @@ def run_creator(topic_id: str = None):
topic_id: 可选,指定要创作的选题ID。不指定则创作优先级最高的选题。
"""
script_path = PROJECT_ROOT / "scripts" / "creator.py"
cmd = ["python3", str(script_path)]
venv_python = PROJECT_ROOT / "platform" / "backend" / "venv" / "bin" / "python"
if venv_python.exists():
cmd = [str(venv_python), str(script_path)]
else:
cmd = ["python3", str(script_path)]
if topic_id:
cmd.extend(["--topic-id", topic_id])
result = subprocess.run(
@@ -47,7 +51,7 @@ def run_creator(topic_id: str = None):
if "选题" in line and "已标记为「待发布」" in line:
# 如: 2026-04-16 ... INFO - 选题 A01 已标记为「待发布」
import re
from .sync import sync_topic_to_db
from .sync import sync_topic_to_db
m = re.search(r'选题\s+([A-Za-z0-9]+)', line)
if m:
topic_id = m.group(1)
-94
View File
@@ -220,97 +220,3 @@ class SystemConfig(Base):
# --- 新增模型:案例库 ---
class Case(Base):
__tablename__ = "cases"
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
title = Column(String, nullable=False)
field = Column(String, nullable=False) # 对应四大支柱及其子领域
summary = Column(Text, nullable=False)
key_metrics = Column(Text, nullable=True) # 关键数据,JSON字符串或纯文本
date = Column(String, nullable=True) # 年份或具体日期,如 "2024"
source = Column(String, nullable=False)
source_url = Column(String, nullable=True)
credibility_rating = Column(String, nullable=True) # 如 "⭐⭐⭐"
china_applicability = Column(String, nullable=True) # 如 "⭐⭐⭐⭐"
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
def to_dict(self):
return {
"id": self.id,
"title": self.title,
"field": self.field,
"summary": self.summary,
"key_metrics": self.key_metrics,
"date": self.date,
"source": self.source,
"source_url": self.source_url,
"credibility_rating": self.credibility_rating,
"china_applicability": self.china_applicability,
"created_at": self.created_at.isoformat() if self.created_at else None,
}
# --- 新增模型:任务日志 ---
class TaskLog(Base):
__tablename__ = "task_logs"
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
task_name = Column(String, nullable=False) # collector/creator/optimizer/research/outline/writer
topic_id = Column(String, nullable=True) # 关联选题ID
status = Column(String, nullable=False) # started/completed/failed
message = Column(Text, nullable=True)
started_at = Column(DateTime(timezone=True), nullable=False)
finished_at = Column(DateTime(timezone=True), nullable=True)
duration_seconds = Column(Integer, nullable=True)
def to_dict(self):
return {
"id": self.id,
"task_name": self.task_name,
"topic_id": self.topic_id,
"status": self.status,
"message": self.message,
"started_at": self.started_at.isoformat() if self.starthed_at else None,
"finished_at": self.finished_at.isoformat() if self.finished_at else None,
"duration_seconds": self.duration_seconds,
}
# --- 新增模型:LLM 配置 ---
class LLMConfig(Base):
__tablename__ = "llm_configs"
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
name = Column(String, unique=True, nullable=False) # e.g., "default_expand"
system_prompt = Column(Text, nullable=False)
user_prompt_template = Column(Text, nullable=False)
temperature = Column(Float, default=0.7)
max_tokens = Column(Integer, default=1000)
model = Column(String, nullable=True) # e.g., "stepfun-ai/step-3.5-flash"
is_active = Column(Boolean, default=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
def to_dict(self):
return {
"id": self.id,
"name": self.name,
"system_prompt": self.system_prompt,
"user_prompt_template": self.user_prompt_template,
"temperature": self.temperature,
"max_tokens": self.max_tokens,
"model": self.model,
"is_active": self.is_active,
}
# --- 新增模型:系统配置(键值对) ---
class SystemConfig(Base):
__tablename__ = "system_configs"
key = Column(String, primary_key=True)
value = Column(Text, nullable=True) # JSON 字符串或普通文本
description = Column(String, nullable=True)
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
def to_dict(self):
return {"key": self.key, "value": self.value, "description": self.description}