feat: 创作工作台统一 + AI味检测/白标 + 移动端补全 + 合规发布闭环
- 新增创作工作台 studio.html:合并选题/内容工厂/文章管理为单一 tab 入口(iframe embed 模式) - 新增 AI味检测模块(ai_slop API + 页面,合规软硬问题分级) - 新增白标品牌配置(branding API + 页面 + deploy 私有化交付包) - 发布闭环:publishing 放宽至 editor + records/mark-published 接口 - 移动端响应式补全(admin/calendar/ai-slop 表格卡片兜底) - 修复菜单幂等播种缺陷(按 path 对齐,避免功能页孤立) - 新增短视频脚本 shortvideo.py 与 2026 市场调研简报
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Depends, Body
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import User, Topic, Article
|
||||
from .auth import get_current_user, org_filter
|
||||
|
||||
router = APIRouter(prefix="/api/ai-slop", tags=["ai-slop"])
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[4]
|
||||
SCRIPTS_DIR = PROJECT_ROOT / "scripts"
|
||||
if not SCRIPTS_DIR.exists():
|
||||
SCRIPTS_DIR = PROJECT_ROOT.parent / "scripts"
|
||||
sys.path.insert(0, str(SCRIPTS_DIR))
|
||||
|
||||
check_article = None
|
||||
polish_with_llm = None
|
||||
clean_html_content = None
|
||||
strip_ai_preface = None
|
||||
strip_thinking_html = None
|
||||
try:
|
||||
from compliance_checker import check_article
|
||||
except Exception:
|
||||
check_article = None
|
||||
try:
|
||||
from compliance_optimizer import polish_with_llm
|
||||
except Exception:
|
||||
polish_with_llm = None
|
||||
try:
|
||||
from content_cleaner import clean_html_content, strip_ai_preface, strip_thinking_html
|
||||
except Exception:
|
||||
clean_html_content = None
|
||||
strip_ai_preface = None
|
||||
strip_thinking_html = None
|
||||
|
||||
HARD_ISSUE_TYPES = ("敏感词", "法律法规", "平台规则", "品牌规范", "资源合规")
|
||||
|
||||
|
||||
class IssueItem(BaseModel):
|
||||
type: str
|
||||
category: str = ""
|
||||
detail: str = ""
|
||||
suggestion: str = ""
|
||||
severity: str = "medium"
|
||||
|
||||
|
||||
class PlatformReport(BaseModel):
|
||||
platform: str
|
||||
score: int
|
||||
passed: bool
|
||||
issues: List[IssueItem]
|
||||
html_preview: str = ""
|
||||
|
||||
|
||||
class ReportResponse(BaseModel):
|
||||
topic_id: str
|
||||
platforms: List[PlatformReport]
|
||||
|
||||
|
||||
class PurifyRequest(BaseModel):
|
||||
topic_id: str
|
||||
platform: str
|
||||
|
||||
|
||||
class PurifyResponse(BaseModel):
|
||||
ok: bool
|
||||
platform: str
|
||||
score_before: Optional[int] = None
|
||||
score_after: Optional[int] = None
|
||||
issues_before: List[IssueItem] = []
|
||||
issues_after: List[IssueItem] = []
|
||||
preview: str = ""
|
||||
message: str = ""
|
||||
|
||||
|
||||
def _normalize_issues(issues: list) -> List[IssueItem]:
|
||||
result = []
|
||||
for i in issues or []:
|
||||
itype = i.get("type", "")
|
||||
severity = "high" if itype in HARD_ISSUE_TYPES else "medium"
|
||||
detail = i.get("detail") or i.get("suggestion") or i.get("word") or i.get("tag") or i.get("pattern") or ""
|
||||
result.append(IssueItem(
|
||||
type=itype,
|
||||
category=i.get("category", ""),
|
||||
detail=detail,
|
||||
suggestion=i.get("suggestion", ""),
|
||||
severity=severity,
|
||||
))
|
||||
return result
|
||||
|
||||
|
||||
def _extract_title(html: str) -> str:
|
||||
import re
|
||||
m = re.search(r"<title>\s*([^<]+?)\s*</title>", html, re.IGNORECASE)
|
||||
if not m:
|
||||
m = re.search(r"<h1[^>]*>\s*([^<]+?)\s*</h1>", html, re.IGNORECASE)
|
||||
return m.group(1).strip() if m else ""
|
||||
|
||||
|
||||
def _extract_content(html: str) -> str:
|
||||
import re
|
||||
text = re.sub(r"<style.*?</style>", "", html, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r"<script.*?</script>", "", text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r"<[^>]+>", "", text)
|
||||
return re.sub(r"\s+", " ", text).strip()
|
||||
|
||||
|
||||
def _load_topic_data(db, topic_id: str) -> dict:
|
||||
topic = db.query(Topic).filter(Topic.id == topic_id).first()
|
||||
if not topic:
|
||||
return {}
|
||||
return {
|
||||
"topic": {
|
||||
"title": getattr(topic, "title", "") or "",
|
||||
"field": getattr(topic, "field", "") or "",
|
||||
"core_concept": getattr(topic, "core_concept", "") or "",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@router.get("/report", response_model=ReportResponse)
|
||||
def get_report(topic_id: str, current_user: User = Depends(get_current_user), db=Depends(get_db)):
|
||||
if check_article is None:
|
||||
raise HTTPException(status_code=503, detail="合规检测模块不可用")
|
||||
topic = db.query(Topic).filter(Topic.id == topic_id).first()
|
||||
if not topic:
|
||||
raise HTTPException(status_code=404, detail="选题不存在")
|
||||
of = org_filter(current_user, Topic)
|
||||
if of is not True and topic.org_id != current_user.org_id:
|
||||
raise HTTPException(status_code=404, detail="选题不存在")
|
||||
topic_data = _load_topic_data(db, topic_id)
|
||||
from db_helper import get_articles_by_topic
|
||||
articles = get_articles_by_topic(topic_id)
|
||||
platforms = []
|
||||
for art in articles:
|
||||
platform = art.get("platform")
|
||||
html = art.get("html_content") or ""
|
||||
if not html:
|
||||
continue
|
||||
res = check_article(html, platform, topic_data=topic_data)
|
||||
platforms.append(PlatformReport(
|
||||
platform=platform,
|
||||
score=res.get("score", 0),
|
||||
passed=res.get("passed", False),
|
||||
issues=_normalize_issues(res.get("issues", [])),
|
||||
html_preview=html[:600],
|
||||
))
|
||||
return ReportResponse(topic_id=topic_id, platforms=platforms)
|
||||
|
||||
|
||||
@router.post("/purify", response_model=PurifyResponse)
|
||||
def purify(req: PurifyRequest, current_user: User = Depends(get_current_user), db=Depends(get_db)):
|
||||
if check_article is None:
|
||||
raise HTTPException(status_code=503, detail="合规检测模块不可用")
|
||||
topic = db.query(Topic).filter(Topic.id == req.topic_id).first()
|
||||
if not topic:
|
||||
raise HTTPException(status_code=404, detail="选题不存在")
|
||||
of = org_filter(current_user, Topic)
|
||||
if of is not True and topic.org_id != current_user.org_id:
|
||||
raise HTTPException(status_code=404, detail="选题不存在")
|
||||
from db_helper import get_articles_by_topic, save_article
|
||||
articles = get_articles_by_topic(req.topic_id)
|
||||
target = next((a for a in articles if a.get("platform") == req.platform), None)
|
||||
if not target or not target.get("html_content"):
|
||||
raise HTTPException(status_code=404, detail=f"未找到 {req.platform} 平台的文章")
|
||||
html = target["html_content"]
|
||||
topic_data = _load_topic_data(db, req.topic_id)
|
||||
|
||||
before = check_article(html, req.platform, topic_data=topic_data)
|
||||
issues_before = _normalize_issues(before.get("issues", []))
|
||||
raw_issues = before.get("issues", [])
|
||||
|
||||
polished_html, log_msg = (html, None)
|
||||
if polish_with_llm is not None:
|
||||
polished_html, log_msg = polish_with_llm(html, req.platform, remaining_issues=raw_issues)
|
||||
|
||||
cleaned = polished_html
|
||||
if clean_html_content is not None:
|
||||
cleaned = clean_html_content(cleaned)
|
||||
if strip_ai_preface is not None:
|
||||
cleaned = strip_ai_preface(cleaned)
|
||||
if strip_thinking_html is not None:
|
||||
cleaned = strip_thinking_html(cleaned)
|
||||
|
||||
title = _extract_title(cleaned)
|
||||
content = _extract_content(cleaned)
|
||||
save_article(req.topic_id, req.platform, cleaned, title=title, content=content, db=db)
|
||||
|
||||
after = check_article(cleaned, req.platform, topic_data=topic_data)
|
||||
issues_after = _normalize_issues(after.get("issues", []))
|
||||
|
||||
message = "净化完成" + (f"({log_msg})" if log_msg else "(仅执行清洗,未调用 LLM)")
|
||||
return PurifyResponse(
|
||||
ok=True,
|
||||
platform=req.platform,
|
||||
score_before=before.get("score"),
|
||||
score_after=after.get("score"),
|
||||
issues_before=issues_before,
|
||||
issues_after=issues_after,
|
||||
preview=cleaned[:600],
|
||||
message=message,
|
||||
)
|
||||
@@ -0,0 +1,80 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import SystemConfig
|
||||
from .auth import get_current_admin
|
||||
|
||||
router = APIRouter(prefix="/api/branding", tags=["branding"])
|
||||
|
||||
BRAND_KEYS = {
|
||||
"brand_name": "宇之然内容创作平台",
|
||||
"brand_logo": "",
|
||||
"brand_primary_color": "#2563eb",
|
||||
"brand_support_email": "",
|
||||
}
|
||||
|
||||
PUBLIC_RESP_DESC = "白标实例公开信息(供前端运行时应用品牌)"
|
||||
|
||||
|
||||
class BrandingResponse(BaseModel):
|
||||
brand_name: str
|
||||
brand_logo: str
|
||||
brand_primary_color: str
|
||||
brand_support_email: str
|
||||
version: str
|
||||
|
||||
|
||||
class BrandingUpdate(BaseModel):
|
||||
brand_name: Optional[str] = None
|
||||
brand_logo: Optional[str] = None
|
||||
brand_primary_color: Optional[str] = None
|
||||
brand_support_email: Optional[str] = None
|
||||
|
||||
|
||||
def _get(db: Session, key: str) -> str:
|
||||
cfg = db.query(SystemConfig).filter(SystemConfig.key == key).first()
|
||||
if not cfg or cfg.value is None:
|
||||
return BRAND_KEYS.get(key, "")
|
||||
return cfg.value
|
||||
|
||||
|
||||
@router.get("", response_model=BrandingResponse)
|
||||
def get_branding(db: Session = Depends(get_db)):
|
||||
"""公开接口:返回当前实例的白标配置(无需登录),用于前端运行时渲染品牌"""
|
||||
try:
|
||||
from ..main import app
|
||||
version = getattr(app, "version", "0.1.0")
|
||||
except Exception:
|
||||
version = "0.1.0"
|
||||
return BrandingResponse(
|
||||
brand_name=_get(db, "brand_name"),
|
||||
brand_logo=_get(db, "brand_logo"),
|
||||
brand_primary_color=_get(db, "brand_primary_color"),
|
||||
brand_support_email=_get(db, "brand_support_email"),
|
||||
version=version,
|
||||
)
|
||||
|
||||
|
||||
@router.put("", response_model=BrandingResponse)
|
||||
def update_branding(
|
||||
payload: BrandingUpdate,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user=Depends(get_current_admin),
|
||||
):
|
||||
"""管理员接口:更新白标配置(品牌名/Logo/主色/支持邮箱)"""
|
||||
data = payload.model_dump(exclude_unset=True)
|
||||
for key, value in data.items():
|
||||
if key not in BRAND_KEYS:
|
||||
continue
|
||||
if value is None:
|
||||
continue
|
||||
cfg = db.query(SystemConfig).filter(SystemConfig.key == key).first()
|
||||
if cfg:
|
||||
cfg.value = str(value)
|
||||
else:
|
||||
db.add(SystemConfig(key=key, value=str(value), description="白标配置"))
|
||||
db.commit()
|
||||
return get_branding(db)
|
||||
@@ -1,4 +1,10 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import desc
|
||||
from typing import Optional
|
||||
@@ -6,10 +12,18 @@ from datetime import datetime, timezone
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import ExternalProduct, PromotionCampaign, CampaignKeyword, SEOAudit, KeywordRanking, OptimizationTask, User
|
||||
from .auth import get_current_user, org_filter
|
||||
from .auth import get_current_user, get_current_admin, org_filter
|
||||
|
||||
router = APIRouter(prefix="/api/external", tags=["external_promotion"])
|
||||
|
||||
PROJECT_ROOT = Path(__file__).parent.parent.parent.parent.parent
|
||||
SEO_AUDITOR_PATH = PROJECT_ROOT / "scripts" / "seo_auditor.py"
|
||||
|
||||
|
||||
class AuditRunRequest(BaseModel):
|
||||
product_id: Optional[str] = None
|
||||
url: Optional[str] = None
|
||||
|
||||
|
||||
def _org_filtered_query(db, model, current_user):
|
||||
query = db.query(model)
|
||||
@@ -467,3 +481,44 @@ def external_overview(
|
||||
"type_breakdown": type_breakdown,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# ===== Run SEO Audit (delegate to scripts/seo_auditor.py) =====
|
||||
|
||||
@router.post("/audit/run")
|
||||
def run_audit(
|
||||
body: AuditRunRequest,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_admin),
|
||||
):
|
||||
cmd = [sys.executable, str(SEO_AUDITOR_PATH)]
|
||||
if body.product_id:
|
||||
cmd += ["--product-id", str(body.product_id)]
|
||||
elif body.url:
|
||||
cmd += ["--url", body.url]
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail="product_id 或 url 至少提供一个")
|
||||
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
|
||||
except subprocess.TimeoutExpired:
|
||||
raise HTTPException(status_code=408, detail="SEO 审计超时")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"审计执行失败: {str(e)}")
|
||||
|
||||
if result.returncode != 0:
|
||||
raise HTTPException(
|
||||
status_code=502,
|
||||
detail={
|
||||
"message": "SEO 审计脚本返回错误",
|
||||
"stderr": result.stderr,
|
||||
"stdout": result.stdout,
|
||||
},
|
||||
)
|
||||
|
||||
return {
|
||||
"ok": True,
|
||||
"stdout": result.stdout,
|
||||
"stderr": result.stderr,
|
||||
"returncode": result.returncode,
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
"""发布管理 API"""
|
||||
from fastapi import APIRouter, HTTPException, Depends, Request
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from datetime import datetime, timezone, timedelta, date
|
||||
from typing import Optional, List
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import Topic, PublishRecord, User
|
||||
from sqlalchemy.orm import Session
|
||||
from .auth import get_current_admin, org_filter
|
||||
from .auth import get_current_user, org_filter
|
||||
from ..core.audit_logger import audit_log
|
||||
|
||||
router = APIRouter(prefix="/api/publishing", tags=["publishing"])
|
||||
@@ -40,9 +40,9 @@ async def create_publish_record(
|
||||
req: MultiPublishRequest,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_admin)
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""多平台发布选题(管理员)"""
|
||||
"""多平台发布选题(运营/管理员,按组织隔离)"""
|
||||
try:
|
||||
q = db.query(Topic).filter(Topic.id == req.topic_id)
|
||||
of = org_filter(current_user, Topic)
|
||||
@@ -66,17 +66,17 @@ async def create_publish_record(
|
||||
record = PublishRecord(
|
||||
topic_id=req.topic_id,
|
||||
platform=platform,
|
||||
action='publish',
|
||||
status='success',
|
||||
action='stage',
|
||||
status='pending_manual',
|
||||
operator=operator,
|
||||
description=f"选题 {req.topic_id} 发布到 {PLATFORM_LABELS.get(platform, platform)}",
|
||||
description=f"选题 {req.topic_id} 已生成 {PLATFORM_LABELS.get(platform, platform)} 发布稿,待人工校验后发布",
|
||||
org_id=topic.org_id
|
||||
)
|
||||
db.add(record)
|
||||
results.append(PublishResult(
|
||||
platform=platform,
|
||||
platform_label=PLATFORM_LABELS.get(platform, platform),
|
||||
status='success'
|
||||
status='pending_manual'
|
||||
))
|
||||
except Exception as e:
|
||||
results.append(PublishResult(
|
||||
@@ -86,16 +86,17 @@ async def create_publish_record(
|
||||
error_msg=str(e)
|
||||
))
|
||||
|
||||
topic.status = '已发布'
|
||||
# 诚实状态流转:本项目无真实自动发布器(且按《AI生成内容标识办法》AI 稿需真人把关),
|
||||
# 故仅将选题置为「待人工发布」,待运营在对应平台校验声明后手动发布。
|
||||
topic.status = 'pending_publish'
|
||||
_now = datetime.now(timezone(timedelta(hours=8)))
|
||||
topic.updated_at = _now
|
||||
topic.published_at = _now.date()
|
||||
db.commit()
|
||||
db.expire_all()
|
||||
db.refresh(topic)
|
||||
|
||||
audit_log(
|
||||
action="publish",
|
||||
action="publish_stage",
|
||||
user=current_user,
|
||||
resource_type="topic",
|
||||
resource_id=req.topic_id,
|
||||
@@ -105,15 +106,104 @@ async def create_publish_record(
|
||||
db=db
|
||||
)
|
||||
|
||||
success_count = sum(1 for r in results if r.status == 'success')
|
||||
staged = sum(1 for r in results if r.status == 'pending_manual')
|
||||
return MultiPublishResponse(
|
||||
ok=success_count > 0,
|
||||
ok=staged == len(results),
|
||||
topic_id=req.topic_id,
|
||||
results=results,
|
||||
message=f"选题 {req.topic_id} 发布完成({success_count}/{len(results)} 平台成功)"
|
||||
message=(
|
||||
f"选题 {req.topic_id} 已生成 {staged}/{len(results)} 个平台的发布稿并置为「待人工发布」。"
|
||||
f"AI 生成内容须由真人校验声明后手动发布,系统不代发。"
|
||||
)
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/records")
|
||||
def list_publish_records(
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""列出发布记录(按组织隔离),用于运营查看「待人工发布 / 已发布」状态"""
|
||||
q = db.query(PublishRecord)
|
||||
of = org_filter(current_user, PublishRecord)
|
||||
if of is not True:
|
||||
q = q.filter(of)
|
||||
recs = q.order_by(PublishRecord.created_at.desc()).all()
|
||||
result = []
|
||||
for r in recs:
|
||||
topic = db.query(Topic).filter(Topic.id == r.topic_id).first()
|
||||
result.append({
|
||||
"id": r.id,
|
||||
"topic_id": r.topic_id,
|
||||
"topic_title": topic.title if topic else None,
|
||||
"platform": r.platform,
|
||||
"action": r.action,
|
||||
"status": r.status,
|
||||
"operator": r.operator,
|
||||
"description": r.description,
|
||||
"url": r.url,
|
||||
"created_at": r.created_at.isoformat() if r.created_at else None,
|
||||
"updated_at": r.updated_at.isoformat() if r.updated_at else None,
|
||||
})
|
||||
return {"records": result}
|
||||
|
||||
|
||||
class MarkPublishedResponse(BaseModel):
|
||||
ok: bool
|
||||
topic_id: str
|
||||
message: str
|
||||
|
||||
|
||||
@router.post("/{topic_id}/mark-published", response_model=MarkPublishedResponse)
|
||||
def mark_published(
|
||||
topic_id: str,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""运营在对应平台手动发布后,回填「已发布」闭环状态"""
|
||||
q = db.query(Topic).filter(Topic.id == topic_id)
|
||||
of = org_filter(current_user, Topic)
|
||||
if of is not True:
|
||||
q = q.filter(of)
|
||||
topic = q.first()
|
||||
if not topic:
|
||||
raise HTTPException(status_code=404, detail=f"选题 {topic_id} 不存在")
|
||||
if topic.status != 'pending_publish':
|
||||
raise HTTPException(status_code=400, detail=f"选题 {topic_id} 当前状态为「{topic.status}」,无需标记发布")
|
||||
|
||||
_now = datetime.now(timezone(timedelta(hours=8)))
|
||||
topic.status = 'published'
|
||||
topic.published_at = date.today()
|
||||
topic.updated_at = _now
|
||||
|
||||
recs = db.query(PublishRecord).filter(
|
||||
PublishRecord.topic_id == topic_id,
|
||||
PublishRecord.status == 'pending_manual'
|
||||
)
|
||||
for r in recs:
|
||||
r.status = 'published'
|
||||
r.updated_at = _now
|
||||
|
||||
db.commit()
|
||||
audit_log(
|
||||
action="publish_confirm",
|
||||
user=current_user,
|
||||
resource_type="topic",
|
||||
resource_id=topic_id,
|
||||
details={"operator": current_user.username},
|
||||
ip_address=request.client.host if request.client else None,
|
||||
user_agent=request.headers.get("user-agent", ""),
|
||||
db=db
|
||||
)
|
||||
return MarkPublishedResponse(
|
||||
ok=True,
|
||||
topic_id=topic_id,
|
||||
message=f"选题 {topic_id} 已标记为「已发布」,发布记录同步更新。"
|
||||
)
|
||||
|
||||
@@ -25,8 +25,7 @@ def _get_cmd(topic_ids: List[str] = None):
|
||||
cmd = [str(venv_python), str(script_path)] if venv_python.exists() else ["python3", str(script_path)]
|
||||
if topic_ids:
|
||||
cmd.extend(["--topic-ids", ','.join(topic_ids)])
|
||||
else:
|
||||
cmd.append("--today-only")
|
||||
# 不再使用 --today-only,避免三平台串行撰写时小红书文章错过审查窗口
|
||||
return cmd
|
||||
|
||||
def run_optimizer(topic_ids: List[str] = None):
|
||||
|
||||
@@ -58,6 +58,7 @@ MODULES = {
|
||||
"scheduled_task_monitor": {"name": "⏰ 任务监控", "cron": "*"},
|
||||
"scheduled_rank_tracker": {"name": "🔍 搜索排名追踪", "cron": "07:00"},
|
||||
"scheduled_geo_tracker": {"name": "🌐 AI 搜索引用追踪", "cron": "07:30"},
|
||||
"scheduled_shortvideo": {"name": "🎬 短视频拆条", "cron": "08:00"},
|
||||
}
|
||||
|
||||
LOG_FILE_MAP = {
|
||||
@@ -71,6 +72,7 @@ LOG_FILE_MAP = {
|
||||
"scheduled_task_monitor": "task_monitor",
|
||||
"scheduled_rank_tracker": "rank_tracker",
|
||||
"scheduled_geo_tracker": "geo_tracker",
|
||||
"scheduled_shortvideo": "shortvideo",
|
||||
}
|
||||
|
||||
def _log_to_file(module_id: str, status: str, message: str = None, error_trace: str = None):
|
||||
@@ -188,6 +190,7 @@ class TaskScheduler:
|
||||
("scheduled_reset_search_usage", self._run_reset_search_usage, "搜索用量重置"),
|
||||
("scheduled_rank_tracker", self._run_rank_tracker, "搜索排名追踪"),
|
||||
("scheduled_geo_tracker", self._run_geo_tracker, "AI 搜索引用追踪"),
|
||||
("scheduled_shortvideo", self._run_shortvideo, "短视频拆条"),
|
||||
]
|
||||
|
||||
for module_id, fn, name in MODULE_JOBS:
|
||||
@@ -418,41 +421,48 @@ class TaskScheduler:
|
||||
count = 0
|
||||
for topic in topics:
|
||||
platform_urls = topic.platform_urls or {}
|
||||
zhihu_url = platform_urls.get("zhihu", "")
|
||||
if not zhihu_url:
|
||||
continue
|
||||
m = re.search(r'zhuanlan\.zhihu\.com/p/(\d+)', zhihu_url)
|
||||
if not m:
|
||||
continue
|
||||
post_id = m.group(1)
|
||||
api_url = f"https://zhuanlan.zhihu.com/api/posts/{post_id}"
|
||||
try:
|
||||
resp = http_requests.get(api_url, headers={"User-Agent": ua}, timeout=10)
|
||||
if resp.status_code != 200:
|
||||
for platform, url in platform_urls.items():
|
||||
if not url:
|
||||
continue
|
||||
if platform == "zhihu":
|
||||
m = re.search(r'zhuanlan\.zhihu\.com/p/(\d+)', url)
|
||||
if not m:
|
||||
continue
|
||||
post_id = m.group(1)
|
||||
api_url = f"https://zhuanlan.zhihu.com/api/posts/{post_id}"
|
||||
try:
|
||||
resp = http_requests.get(api_url, headers={"User-Agent": ua}, timeout=10)
|
||||
if resp.status_code != 200:
|
||||
continue
|
||||
raw = resp.json()
|
||||
existing = db.query(ContentMetrics).filter(
|
||||
ContentMetrics.topic_id == topic.id,
|
||||
ContentMetrics.platform == "zhihu"
|
||||
).first()
|
||||
metric_data = {
|
||||
"views": raw.get("voteup_count", raw.get("views_count", 0)),
|
||||
"likes": raw.get("voteup_count", 0),
|
||||
"favorites": raw.get("favorite_count", 0),
|
||||
"comments": raw.get("comment_count", raw.get("comments_count", 0)),
|
||||
"shares": raw.get("share_count", 0),
|
||||
"last_fetched": datetime.now(),
|
||||
"publish_url": url,
|
||||
"data_snapshot": raw,
|
||||
}
|
||||
if existing:
|
||||
for k, v in metric_data.items():
|
||||
setattr(existing, k, v)
|
||||
else:
|
||||
db.add(ContentMetrics(topic_id=topic.id, platform="zhihu", **metric_data))
|
||||
count += 1
|
||||
except Exception:
|
||||
continue
|
||||
elif platform in ("wechat_mp", "xiaohongshu"):
|
||||
logger.info("平台 %s 无公开指标 API,跳过", platform)
|
||||
continue
|
||||
raw = resp.json()
|
||||
existing = db.query(ContentMetrics).filter(
|
||||
ContentMetrics.topic_id == topic.id,
|
||||
ContentMetrics.platform == "zhihu"
|
||||
).first()
|
||||
metric_data = {
|
||||
"views": raw.get("voteup_count", raw.get("views_count", 0)),
|
||||
"likes": raw.get("voteup_count", 0),
|
||||
"favorites": raw.get("favorite_count", 0),
|
||||
"comments": raw.get("comment_count", raw.get("comments_count", 0)),
|
||||
"shares": raw.get("share_count", 0),
|
||||
"last_fetched": datetime.now(),
|
||||
"publish_url": zhihu_url,
|
||||
"data_snapshot": raw,
|
||||
}
|
||||
if existing:
|
||||
for k, v in metric_data.items():
|
||||
setattr(existing, k, v)
|
||||
else:
|
||||
db.add(ContentMetrics(topic_id=topic.id, platform="zhihu", **metric_data))
|
||||
count += 1
|
||||
except Exception:
|
||||
continue
|
||||
logger.info("平台 %s 暂无指标同步支持,跳过", platform)
|
||||
continue
|
||||
if count:
|
||||
db.commit()
|
||||
logger.info("[Scheduled] Metrics sync completed: synced %d zhihu articles", count)
|
||||
@@ -661,6 +671,46 @@ class TaskScheduler:
|
||||
started_at=started, finished_at=datetime.now(timezone.utc))
|
||||
logger.exception("[GeoTracker] AI 搜索引用追踪失败: %s", e)
|
||||
|
||||
def _run_shortvideo(self):
|
||||
"""每日将前一日「待发布」选题的长文拆条为短视频脚本"""
|
||||
started = datetime.now(timezone.utc)
|
||||
log_id = _log_task("scheduled_shortvideo", "running", started_at=started)
|
||||
try:
|
||||
from ..database import SessionLocal
|
||||
from ..models import Topic
|
||||
db = SessionLocal()
|
||||
try:
|
||||
topics = db.query(Topic).filter(
|
||||
Topic.status.in_(["ready", "待发布", "pending_publish"])
|
||||
).order_by(Topic.ready_at.desc().nullslast()).limit(3).all()
|
||||
finally:
|
||||
db.close()
|
||||
if not topics:
|
||||
_log_task("scheduled_shortvideo", "success", log_id=log_id,
|
||||
message="无待拆条选题", started_at=started, finished_at=datetime.now(timezone.utc))
|
||||
return
|
||||
import subprocess
|
||||
total = 0
|
||||
for t in topics:
|
||||
res = subprocess.run(
|
||||
[sys.executable, str(PROJECT_ROOT / "scripts" / "shortvideo.py"), "--topic-id", t.id, "--count", "3"],
|
||||
capture_output=True, text=True, timeout=600
|
||||
)
|
||||
if res.returncode == 0:
|
||||
total += 1
|
||||
_log_task("scheduled_shortvideo", "success", log_id=log_id,
|
||||
message=f"拆条完成: {total}/{len(topics)} 选题",
|
||||
result_data={"topics": len(topics), "done": total},
|
||||
started_at=started, finished_at=datetime.now(timezone.utc))
|
||||
logger.info("[ShortVideo] 拆条完成: %d/%d", total, len(topics))
|
||||
except Exception as e:
|
||||
import traceback
|
||||
_log_task("scheduled_shortvideo", "failed", log_id=log_id,
|
||||
message=str(e),
|
||||
error_trace=traceback.format_exc(),
|
||||
started_at=started, finished_at=datetime.now(timezone.utc))
|
||||
logger.exception("[ShortVideo] 拆条失败: %s", e)
|
||||
|
||||
def get_jobs(self):
|
||||
"""返回当前所有定时任务的状态"""
|
||||
jobs = []
|
||||
|
||||
@@ -76,6 +76,17 @@ def import_initial_data():
|
||||
for cfg in default_system_configs:
|
||||
if db.query(SystemConfig).filter(SystemConfig.key == cfg["key"]).first() is None:
|
||||
db.add(SystemConfig(**cfg))
|
||||
|
||||
# 白标默认值(私有化部署/卖给他人时可改)
|
||||
default_branding = [
|
||||
{"key": "brand_name", "value": "宇之然内容创作平台", "description": "白标:平台名称"},
|
||||
{"key": "brand_logo", "value": "", "description": "白标:Logo URL(留空用文字)"},
|
||||
{"key": "brand_primary_color", "value": "#2563eb", "description": "白标:主色(导航/按钮)"},
|
||||
{"key": "brand_support_email", "value": "", "description": "白标:支持邮箱"},
|
||||
]
|
||||
for b in default_branding:
|
||||
if db.query(SystemConfig).filter(SystemConfig.key == b["key"]).first() is None:
|
||||
db.add(SystemConfig(**b))
|
||||
if db.query(SystemConfig).filter(SystemConfig.key == "review_llm_id").first() is None:
|
||||
first_llm = db.query(LLMConfig).filter(LLMConfig.is_active == True).first()
|
||||
if first_llm:
|
||||
@@ -294,21 +305,47 @@ def import_initial_data():
|
||||
db.commit()
|
||||
print("✅ 插入默认角色")
|
||||
|
||||
# 初始化默认菜单(与 uni-nav.js 对齐)
|
||||
if db.query(Menu).count() == 0:
|
||||
default_menus = [
|
||||
{"name": "仪表盘", "path": "/", "icon": "IconHome", "sort_order": 0, "roles": ["admin", "editor"]},
|
||||
{"name": "选题", "path": "topics.html", "icon": "IconTopic", "sort_order": 1, "roles": ["admin", "editor"]},
|
||||
{"name": "数据", "path": "metrics.html", "icon": "IconData", "sort_order": 2, "roles": ["admin", "editor"]},
|
||||
{"name": "日历", "path": "calendar.html", "icon": "IconCalendar", "sort_order": 3, "roles": ["admin", "editor"]},
|
||||
{"name": "素材", "path": "assets.html", "icon": "IconFolder", "sort_order": 4, "roles": ["admin", "editor"]},
|
||||
{"name": "任务", "path": "tasks.html", "icon": "IconMenu", "sort_order": 5, "roles": ["admin", "editor"]},
|
||||
{"name": "系统", "path": "admin.html", "icon": "IconSetting", "sort_order": 6, "roles": ["admin"]},
|
||||
]
|
||||
for m in default_menus:
|
||||
db.add(Menu(**m))
|
||||
# 归一化首页菜单路径,避免 index.html 与 /index.html 产生重复入口
|
||||
idx_plain = db.query(Menu).filter(Menu.path == "index.html").first()
|
||||
idx_slash = db.query(Menu).filter(Menu.path == "/index.html").first()
|
||||
if idx_plain and not idx_slash:
|
||||
idx_plain.path = "/index.html"
|
||||
db.commit()
|
||||
print("✅ 插入默认菜单")
|
||||
elif idx_plain and idx_slash:
|
||||
db.delete(idx_plain)
|
||||
db.commit()
|
||||
|
||||
# 初始化默认菜单:幂等按 path 对齐(已有时更新排序/角色,缺失时插入)。
|
||||
# 运行时会用 DB 菜单覆盖 uni-nav.js 的 fallback,因此这里必须保证文章管理/内容工厂/白标设置等入口存在。
|
||||
default_menus = [
|
||||
{"name": "工作台", "path": "/index.html", "icon": "IconHome", "sort_order": 0, "roles": ["admin", "editor"]},
|
||||
{"name": "创作工作台", "path": "studio.html", "icon": "IconEdit", "sort_order": 1, "roles": ["admin", "editor"]},
|
||||
{"name": "数据", "path": "metrics.html", "icon": "IconData", "sort_order": 2, "roles": ["admin", "editor"]},
|
||||
{"name": "日历", "path": "calendar.html", "icon": "IconCalendar", "sort_order": 3, "roles": ["admin", "editor"]},
|
||||
{"name": "素材", "path": "assets.html", "icon": "IconFolder", "sort_order": 4, "roles": ["admin", "editor"]},
|
||||
{"name": "任务", "path": "tasks.html", "icon": "IconMenu", "sort_order": 5, "roles": ["admin", "editor"]},
|
||||
{"name": "外推营销", "path": "campaigns.html", "icon": "IconStar", "sort_order": 6, "roles": ["admin", "editor"]},
|
||||
{"name": "AI味检测", "path": "ai-slop.html", "icon": "IconSearch", "sort_order": 7, "roles": ["admin", "editor"]},
|
||||
{"name": "白标设置", "path": "branding.html", "icon": "IconSetting", "sort_order": 8, "roles": ["admin"]},
|
||||
{"name": "系统", "path": "admin.html", "icon": "IconSetting", "sort_order": 9, "roles": ["admin"]},
|
||||
]
|
||||
for m in default_menus:
|
||||
found = db.query(Menu).filter(Menu.path == m["path"]).first()
|
||||
if found:
|
||||
found.sort_order = m["sort_order"]
|
||||
found.roles = m["roles"]
|
||||
found.icon = m["icon"]
|
||||
found.is_active = True
|
||||
# 保留原名称,避免意外重命名
|
||||
else:
|
||||
db.add(Menu(**m))
|
||||
# 原独立的选题/内容工厂/文章管理已合并进「创作工作台」,从主导航隐藏(页面仍可被 studio 内嵌与直接访问)
|
||||
for legacy in ["topics.html", "factory.html", "articles.html"]:
|
||||
legacy_menu = db.query(Menu).filter(Menu.path == legacy).first()
|
||||
if legacy_menu:
|
||||
legacy_menu.is_active = False
|
||||
db.commit()
|
||||
print("✅ 菜单已对齐(创作工作台合并选题/内容工厂/文章管理)")
|
||||
|
||||
# 同步 PostgreSQL 自增序列
|
||||
if os.getenv('USE_POSTGRES', 'true').lower() == 'true':
|
||||
|
||||
@@ -9,7 +9,7 @@ from pathlib import Path
|
||||
|
||||
from .database import engine, get_db, init_db
|
||||
from .models import Base
|
||||
from .api import topics, system, articles, publishing, auth, admin, audit, optimizer_logs, cases, task_logs, task_configs, prompt_configs, llm_configs, system_configs, topic_config, calendar, metrics, assets, tasks, platform_config, collector_mgmt, assistant, config_items, role_configs, menu_configs, search_providers, search_rankings, external_promotion
|
||||
from .api import topics, system, articles, publishing, auth, admin, audit, optimizer_logs, cases, task_logs, task_configs, prompt_configs, llm_configs, system_configs, topic_config, calendar, metrics, assets, tasks, platform_config, collector_mgmt, assistant, config_items, role_configs, menu_configs, search_providers, search_rankings, external_promotion, ai_slop, branding
|
||||
from .initial_data import import_initial_data
|
||||
from .core.scheduler import scheduler
|
||||
|
||||
@@ -106,6 +106,8 @@ app.include_router(menu_configs.public_router)
|
||||
app.include_router(search_providers.router)
|
||||
app.include_router(search_rankings.router)
|
||||
app.include_router(external_promotion.router)
|
||||
app.include_router(ai_slop.router)
|
||||
app.include_router(branding.router)
|
||||
|
||||
# 挂载自动生成的图片(必须先于前端根挂载)
|
||||
PROJECT_ROOT_DIR = Path(__file__).parent.parent.parent.parent
|
||||
|
||||
@@ -199,7 +199,8 @@
|
||||
<div class="empty-text">暂无平台配置</div>
|
||||
</div>
|
||||
</template>
|
||||
<el-table v-else :data="platformConfigs" border stripe style="width:100%">
|
||||
<template v-else>
|
||||
<el-table class="data-table" :data="platformConfigs" border stripe style="width:100%">
|
||||
<el-table-column prop="platform" label="标识" width="120"></el-table-column>
|
||||
<el-table-column prop="name" label="名称" width="120"></el-table-column>
|
||||
<el-table-column prop="icon" label="图标" width="100">
|
||||
@@ -230,6 +231,22 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="card-list-mobile">
|
||||
<div v-for="pc in platformConfigs" :key="pc.platform" class="card-item">
|
||||
<div class="card-row"><span class="card-label">标识</span><span class="card-value">{{ pc.platform }}</span></div>
|
||||
<div class="card-row"><span class="card-label">名称</span><span class="card-value">{{ pc.name }}</span></div>
|
||||
<div class="card-row"><span class="card-label">图标</span><span class="card-value">{{ pc.icon || '—' }}</span></div>
|
||||
<div class="card-row"><span class="card-label">网址</span><span class="card-value" style="word-break:break-all;">{{ pc.website_url || '—' }}</span></div>
|
||||
<div class="card-row"><span class="card-label">字数</span><span class="card-value">{{ pc.min_words }} - {{ pc.max_words }}</span></div>
|
||||
<div class="card-row"><span class="card-label">配图</span><span class="card-value">{{ pc.requires_image ? pc.image_count_min + '-' + pc.image_count_max + '张' : '不需要' }}</span></div>
|
||||
<div class="card-row"><span class="card-label">激活</span><span class="card-value">{{ pc.is_active ? '是' : '否' }}</span></div>
|
||||
<div class="card-actions">
|
||||
<el-button size="small" @click="showPcDialogFn(pc)">编辑</el-button>
|
||||
<el-button size="small" type="danger" @click="deletePlatformConfig(pc.platform)">删除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<el-dialog v-model="showPcDialog" :title="pcDialogTitle" width="750px" :close-on-click-modal="false">
|
||||
<el-form :model="pcForm" label-width="100px">
|
||||
<el-row :gutter="16">
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>宇之然内容创作平台 - AI味检测</title>
|
||||
<link rel="stylesheet" href="element-plus.css">
|
||||
<link rel="stylesheet" href="theme-modern.css">
|
||||
<script src="uni-nav.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" v-cloak>
|
||||
<uni-nav title="AI味检测" :username="currentUser.username" :is-admin="isAdmin" current-page="ai-slop" @navigate="redirectToPage" @logout="handleLogout">
|
||||
</uni-nav>
|
||||
<div class="main-content">
|
||||
<main class="content-area">
|
||||
<div class="card page-fade">
|
||||
<div class="page-header">
|
||||
<h2 class="page-title"><el-icon style="vertical-align:-2px;"><IconSearch /></el-icon> AI味检测 + 净化</h2>
|
||||
</div>
|
||||
<div class="filter-bar">
|
||||
<el-input v-model="topicId" placeholder="输入选题 ID,如 B02" clearable size="default" style="width:280px;" @keyup.enter="runReport">
|
||||
<template #prepend>选题</template>
|
||||
</el-input>
|
||||
<el-button type="primary" :loading="loadingReport" @click="runReport">检测</el-button>
|
||||
</div>
|
||||
<el-alert v-if="errorMsg" :title="errorMsg" type="error" show-icon :closable="false" style="margin-bottom:12px;"></el-alert>
|
||||
<div v-if="!loadingReport && report && report.platforms.length === 0" style="text-align:center;padding:40px 0;color:#909399;font-size:14px;">
|
||||
该选题暂无文章,请先创作内容。
|
||||
</div>
|
||||
<div v-for="p in (report ? report.platforms : [])" :key="p.platform" style="margin-bottom:20px;">
|
||||
<el-card shadow="hover">
|
||||
<template #header>
|
||||
<div style="display:flex;align-items:center;gap:12px;flex-wrap:wrap;">
|
||||
<strong style="font-size:16px;">{{ platformLabel(p.platform) }}</strong>
|
||||
<el-tag :type="p.passed ? 'success' : 'danger'" size="small">{{ p.passed ? '通过' : '未通过' }}</el-tag>
|
||||
<span style="font-size:13px;color:#909399;">合规分:<b :style="{color: p.score >= 80 ? '#67c23a' : (p.score >= 60 ? '#e6a23c' : '#f56c6c')}">{{ p.score }}</b></span>
|
||||
<el-button size="small" type="warning" :loading="p.purifying" @click="purify(p)" style="margin-left:auto;">一键净化</el-button>
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="p.message" style="margin-bottom:10px;color:#67c23a;font-size:13px;">{{ p.message }}</div>
|
||||
<div v-if="p.score_before !== null" style="margin-bottom:10px;font-size:13px;color:#606266;">
|
||||
净化前分:<b>{{ p.score_before }}</b> → 净化后分:<b :style="{color:'#67c23a'}">{{ p.score_after }}</b>
|
||||
<span style="margin-left:12px;">问题数:{{ p.issues_before.length }} → {{ p.issues_after.length }}</span>
|
||||
</div>
|
||||
<div v-if="p.issues.length === 0" style="color:#67c23a;font-size:14px;">✅ 未检测到明显问题</div>
|
||||
<template v-else>
|
||||
<el-table class="card-table" :data="p.issues" size="small" stripe>
|
||||
<el-table-column prop="type" label="类型" width="110">
|
||||
<template #default="s"><el-tag :type="s.row.severity === 'high' ? 'danger' : 'warning'" size="small">{{ s.row.type }}</el-tag></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="category" label="类别" width="130" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="detail" label="详情" min-width="200" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="suggestion" label="建议" min-width="180" show-overflow-tooltip></el-table-column>
|
||||
</el-table>
|
||||
<div class="card-list-mobile">
|
||||
<div v-for="iss in p.issues" :key="iss.type + iss.detail" class="card-item">
|
||||
<div class="card-row"><span class="card-label">类型</span><span class="card-value"><el-tag :type="iss.severity === 'high' ? 'danger' : 'warning'" size="small">{{ iss.type }}</el-tag></span></div>
|
||||
<div class="card-row"><span class="card-label">类别</span><span class="card-value">{{ iss.category }}</span></div>
|
||||
<div class="card-row"><span class="card-label">详情</span><span class="card-value">{{ iss.detail }}</span></div>
|
||||
<div class="card-row"><span class="card-label">建议</span><span class="card-value">{{ iss.suggestion }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-card>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<script src="vue.global.prod.js"></script>
|
||||
<script src="icon-components.js"></script>
|
||||
<script src="element-plus.full.js"></script>
|
||||
<script>
|
||||
const AiSlopApp = {
|
||||
data() {
|
||||
return {
|
||||
isLoggedIn: false, isAdmin: false, currentUser: { username: '' },
|
||||
topicId: '', loadingReport: false, report: null, errorMsg: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getToken() { return localStorage.getItem('authToken'); },
|
||||
async api(url, opts = {}) {
|
||||
const token = this.getToken();
|
||||
if (!token) { this.$message.error('请先登录'); setTimeout(() => window.location.href = '/login.html', 1500); return null; }
|
||||
const res = await fetch(url, { headers: { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json', ...(opts.headers || {}) }, ...opts });
|
||||
if (!res.ok) { const data = await res.json().catch(() => ({})); throw new Error(data.detail || `请求失败: ${res.status}`); }
|
||||
return res.json();
|
||||
},
|
||||
async runReport() {
|
||||
this.errorMsg = '';
|
||||
if (!this.topicId.trim()) { this.$message.warning('请输入选题 ID'); return; }
|
||||
this.loadingReport = true;
|
||||
this.report = null;
|
||||
try {
|
||||
const data = await this.api('/api/ai-slop/report?topic_id=' + encodeURIComponent(this.topicId.trim()));
|
||||
this.report = { topic_id: data.topic_id, platforms: (data.platforms || []).map(p => ({ ...p, purifying: false, message: '', score_before: null, score_after: null, issues_before: [], issues_after: [] })) };
|
||||
} catch (error) {
|
||||
this.errorMsg = error.message;
|
||||
} finally { this.loadingReport = false; }
|
||||
},
|
||||
async purify(p) {
|
||||
p.purifying = true; p.message = '';
|
||||
try {
|
||||
const data = await this.api('/api/ai-slop/purify', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ topic_id: this.topicId.trim(), platform: p.platform })
|
||||
});
|
||||
p.score_before = data.score_before;
|
||||
p.score_after = data.score_after;
|
||||
p.issues_before = data.issues_before || [];
|
||||
p.issues_after = data.issues_after || [];
|
||||
p.issues = data.issues_after || [];
|
||||
p.score = data.score_after;
|
||||
p.passed = (data.score_after !== null && data.issues_after.length === 0) || (data.issues_after && data.issues_after.every(i => i.severity !== 'high')) || (p.score >= 80);
|
||||
p.passed = data.score_after !== null ? (data.issues_after || []).every(i => i.severity !== 'high') : p.passed;
|
||||
p.message = data.message || '净化完成';
|
||||
this.$message.success('净化完成,合规分 ' + data.score_before + ' → ' + data.score_after);
|
||||
} catch (error) {
|
||||
this.$message.error('净化失败: ' + error.message);
|
||||
} finally { p.purifying = false; }
|
||||
},
|
||||
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
||||
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
||||
platformLabel(p) { return { zhihu: '知乎', wechat: '微信公众号', xiaohongshu: '小红书' }[p] || p; },
|
||||
},
|
||||
mounted() {
|
||||
const token = localStorage.getItem('authToken');
|
||||
if (!token) { window.location.href = '/login.html'; return; }
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const tid = params.get('topic_id');
|
||||
if (tid) this.topicId = tid;
|
||||
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
||||
.then(r => r.ok ? r.json() : Promise.reject())
|
||||
.then(data => {
|
||||
this.currentUser = data.user; this.isAdmin = data.user.role === 'admin'; this.isLoggedIn = true;
|
||||
if (tid) this.runReport();
|
||||
})
|
||||
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
||||
}
|
||||
};
|
||||
const app = Vue.createApp(AiSlopApp);
|
||||
app.use(ElementPlus);
|
||||
if (window.installIcons) { window.installIcons(app); }
|
||||
if (window.installUniNav) { window.installUniNav(app); }
|
||||
app.mount('#app');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+305
-193
@@ -24,86 +24,130 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" v-cloak>
|
||||
<uni-nav title="文章管理" :username="currentUser.username" :is-admin="isAdmin" current-page="articles" @navigate="redirectToPage" @logout="handleLogout">
|
||||
<uni-nav v-if="!isEmbed" title="文章管理" :username="currentUser.username" :is-admin="isAdmin" current-page="articles" @navigate="redirectToPage" @logout="handleLogout">
|
||||
</uni-nav>
|
||||
<div class="main-content">
|
||||
<main class="content-area">
|
||||
<div class="card page-fade">
|
||||
<div class="page-header">
|
||||
<h2 class="page-title"><el-icon style="vertical-align:-2px;"><IconDocument /></el-icon> 文章管理</h2>
|
||||
</div>
|
||||
<div class="filter-bar">
|
||||
<el-select v-model="filterPlatform" placeholder="全部平台" clearable size="default" style="width:140px;" @change="fetchArticles">
|
||||
<el-option label="全部平台" value=""></el-option>
|
||||
<el-option label="知乎" value="zhihu"></el-option>
|
||||
<el-option label="微信公众号" value="wechat"></el-option>
|
||||
<el-option label="小红书" value="xiaohongshu"></el-option>
|
||||
</el-select>
|
||||
<el-select v-model="filterStatus" placeholder="全部状态" clearable size="default" style="width:140px;" @change="fetchArticles">
|
||||
<el-option label="全部状态" value=""></el-option>
|
||||
<el-option label="草稿" value="draft"></el-option>
|
||||
<el-option label="已审查" value="reviewed"></el-option>
|
||||
<el-option label="已发布" value="published"></el-option>
|
||||
</el-select>
|
||||
<el-input v-model="searchQuery" placeholder="搜索文章 ID / 选题标题" clearable size="default" class="search-bar" @input="debouncedSearch" @clear="fetchArticles">
|
||||
<template #prefix><el-icon style="vertical-align:-2px;"><IconSearch /></el-icon></template>
|
||||
</el-input>
|
||||
</div>
|
||||
<el-table :data="filteredArticles" stripe v-loading="loadingTable">
|
||||
<el-table-column prop="id" label="文章 ID" width="160"></el-table-column>
|
||||
<el-table-column prop="topic_id" label="选题 ID" width="80"></el-table-column>
|
||||
<el-table-column prop="topic_title" label="选题标题" min-width="200" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="platform" label="平台" width="100">
|
||||
<template #default="scope">{{ platformLabel(scope.row.platform) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="90">
|
||||
<template #default="scope"><span class="status-dot" :class="scope.row.status"></span> {{ statusLabel(scope.row.status) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="compliance_score" label="合规分" width="80">
|
||||
<template #default="scope">{{ scope.row.compliance_score ?? '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="word_count" label="字数" width="70">
|
||||
<template #default="scope">{{ scope.row.word_count ?? '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="配图" width="60">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.images && scope.row.images.cover" style="cursor:pointer;font-size:16px;" title="有封面图"><el-icon style="vertical-align:-2px;"><IconPicture /></el-icon></span>
|
||||
<span v-else style="color:#dcdfe6;">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="140"><template #default="scope">{{ formatDate(scope.row.created_at) }}</template></el-table-column>
|
||||
<el-table-column label="操作" width="130" fixed="right">
|
||||
<template #default="scope">
|
||||
<div style="display: flex; gap: 4px;">
|
||||
<el-button size="small" type="primary" @click="previewArticle(scope.row)" style="padding:5px 8px;">预览</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteArticle(scope.row)" style="padding:5px 8px;">删除</el-button>
|
||||
<el-tabs v-model="activeTab">
|
||||
<el-tab-pane label="文章管理" name="articles">
|
||||
<div class="card page-fade">
|
||||
<div class="page-header">
|
||||
<h2 class="page-title"><el-icon style="vertical-align:-2px;"><IconDocument /></el-icon> 文章管理</h2>
|
||||
</div>
|
||||
<div class="filter-bar">
|
||||
<el-select v-model="filterPlatform" placeholder="全部平台" clearable size="default" style="width:140px;" @change="fetchArticles">
|
||||
<el-option label="全部平台" value=""></el-option>
|
||||
<el-option label="知乎" value="zhihu"></el-option>
|
||||
<el-option label="微信公众号" value="wechat"></el-option>
|
||||
<el-option label="小红书" value="xiaohongshu"></el-option>
|
||||
</el-select>
|
||||
<el-select v-model="filterStatus" placeholder="全部状态" clearable size="default" style="width:140px;" @change="fetchArticles">
|
||||
<el-option label="全部状态" value=""></el-option>
|
||||
<el-option label="草稿" value="draft"></el-option>
|
||||
<el-option label="已审查" value="reviewed"></el-option>
|
||||
<el-option label="已发布" value="published"></el-option>
|
||||
</el-select>
|
||||
<el-input v-model="searchQuery" placeholder="搜索文章 ID / 选题标题" clearable size="default" class="search-bar" @input="debouncedSearch" @clear="fetchArticles">
|
||||
<template #prefix><el-icon style="vertical-align:-2px;"><IconSearch /></el-icon></template>
|
||||
</el-input>
|
||||
</div>
|
||||
<el-table :data="filteredArticles" stripe v-loading="loadingTable">
|
||||
<el-table-column prop="id" label="文章 ID" width="160"></el-table-column>
|
||||
<el-table-column prop="topic_id" label="选题 ID" width="80"></el-table-column>
|
||||
<el-table-column prop="topic_title" label="选题标题" min-width="200" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="platform" label="平台" width="100">
|
||||
<template #default="scope">{{ platformLabel(scope.row.platform) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="90">
|
||||
<template #default="scope"><span class="status-dot" :class="scope.row.status"></span> {{ statusLabel(scope.row.status) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="compliance_score" label="合规分" width="80">
|
||||
<template #default="scope">{{ scope.row.compliance_score ?? '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="word_count" label="字数" width="70">
|
||||
<template #default="scope">{{ scope.row.word_count ?? '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="140"><template #default="scope">{{ formatDate(scope.row.created_at) }}</template></el-table-column>
|
||||
<el-table-column label="操作" width="210" fixed="right">
|
||||
<template #default="scope">
|
||||
<div style="display: flex; gap: 4px; flex-wrap: wrap;">
|
||||
<el-button size="small" type="primary" @click="previewArticle(scope.row)" style="padding:5px 8px;">预览</el-button>
|
||||
<el-button size="small" @click="editArticle(scope.row)" style="padding:5px 8px;">编辑</el-button>
|
||||
<el-button size="small" type="warning" @click="openSlop(scope.row)" style="padding:5px 8px;">检测</el-button>
|
||||
<el-button size="small" type="success" @click="goPublish()" style="padding:5px 8px;">发布</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteArticle(scope.row)" style="padding:5px 8px;">删除</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="article-card-list" v-if="filteredArticles && filteredArticles.length > 0">
|
||||
<div v-for="article in filteredArticles" :key="article.id" class="article-card">
|
||||
<div class="article-card-header">
|
||||
<div class="article-card-title">{{ article.topic_title || article.topic_id }}</div>
|
||||
<el-tag :type="statusTagType(article.status)" size="small">{{ statusLabel(article.status) }}</el-tag>
|
||||
</div>
|
||||
<div class="article-card-meta">
|
||||
<div>ID: {{ article.id }}</div>
|
||||
<div>平台: {{ platformLabel(article.platform) }}</div>
|
||||
<div>合规: {{ article.compliance_score ?? '-' }}</div>
|
||||
<div>字数: {{ article.word_count ?? '-' }}</div>
|
||||
<div>创建: {{ formatDate(article.created_at) }}</div>
|
||||
</div>
|
||||
<div class="article-card-actions">
|
||||
<el-button size="small" type="primary" @click="previewArticle(article)">预览</el-button>
|
||||
<el-button size="small" @click="editArticle(article)">编辑</el-button>
|
||||
<el-button size="small" type="warning" @click="openSlop(article)">检测</el-button>
|
||||
<el-button size="small" type="success" @click="goPublish()">发布</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteArticle(article)">删除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="article-card-list" v-if="filteredArticles && filteredArticles.length > 0">
|
||||
<div v-for="article in filteredArticles" :key="article.id" class="article-card">
|
||||
<div class="article-card-header">
|
||||
<div class="article-card-title">{{ article.topic_title || article.topic_id }}</div>
|
||||
<el-tag :type="statusTagType(article.status)" size="small">{{ statusLabel(article.status) }}</el-tag>
|
||||
</div>
|
||||
<div class="article-card-meta">
|
||||
<div>ID: {{ article.id }}</div>
|
||||
<div>平台: {{ platformLabel(article.platform) }}</div>
|
||||
<div>合规: {{ article.compliance_score ?? '-' }}</div>
|
||||
<div>字数: {{ article.word_count ?? '-' }}</div>
|
||||
<div>创建: {{ formatDate(article.created_at) }}</div>
|
||||
</div>
|
||||
<div class="article-card-actions">
|
||||
<el-button size="small" type="primary" @click="previewArticle(article)">预览</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteArticle(article)">删除</el-button>
|
||||
<div v-if="!loadingTable && filteredArticles.length === 0" style="text-align:center;padding:40px 0;color:#909399;font-size:14px;">
|
||||
<el-icon><IconDocument /></el-icon> 暂无文章
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!loadingTable && filteredArticles.length === 0" style="text-align:center;padding:40px 0;color:#909399;font-size:14px;">
|
||||
<el-icon><IconDocument /></el-icon> 暂无文章
|
||||
</div>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="发布记录" name="publish">
|
||||
<div class="card page-fade">
|
||||
<div class="page-header">
|
||||
<h2 class="page-title"><el-icon style="vertical-align:-2px;"><IconUpload /></el-icon> 发布记录</h2>
|
||||
<el-tag type="info" size="small">AI 内容需真人校验后发布,系统不代发</el-tag>
|
||||
</div>
|
||||
<el-table :data="publishRecords" stripe v-loading="loadingRecords">
|
||||
<el-table-column prop="topic_id" label="选题 ID" width="90"></el-table-column>
|
||||
<el-table-column prop="topic_title" label="选题标题" min-width="200" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="platform" label="平台" width="100">
|
||||
<template #default="scope">{{ platformLabel(scope.row.platform) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="110">
|
||||
<template #default="scope"><el-tag :type="scope.row.status === 'published' ? 'success' : 'warning'" size="small">{{ scope.row.status === 'published' ? '已发布' : '待人工发布' }}</el-tag></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="operator" label="操作人" width="100"></el-table-column>
|
||||
<el-table-column prop="created_at" label="生成时间" width="140"><template #default="scope">{{ formatDate(scope.row.created_at) }}</template></el-table-column>
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button v-if="scope.row.status === 'pending_manual'" size="small" type="success" @click="markRecord(scope.row)" style="padding:5px 8px;">标记已发布</el-button>
|
||||
<span v-else style="color:#909399;font-size:12px;">—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="card-list-mobile" v-if="publishRecords && publishRecords.length > 0">
|
||||
<div v-for="rec in publishRecords" :key="rec.id" class="card-item">
|
||||
<div class="card-row"><span class="card-label">选题</span><span class="card-value">{{ rec.topic_title || rec.topic_id }}</span></div>
|
||||
<div class="card-row"><span class="card-label">平台</span><span class="card-value">{{ platformLabel(rec.platform) }}</span></div>
|
||||
<div class="card-row"><span class="card-label">状态</span><span class="card-value"><el-tag :type="rec.status === 'published' ? 'success' : 'warning'" size="small">{{ rec.status === 'published' ? '已发布' : '待人工发布' }}</el-tag></span></div>
|
||||
<div class="card-row"><span class="card-label">操作人</span><span class="card-value">{{ rec.operator || '-' }}</span></div>
|
||||
<div class="card-actions" v-if="rec.status === 'pending_manual'">
|
||||
<el-button size="small" type="success" @click="markRecord(rec)">标记已发布</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!loadingRecords && publishRecords.length === 0" style="text-align:center;padding:40px 0;color:#909399;font-size:14px;">
|
||||
<el-icon><IconUpload /></el-icon> 暂无发布记录
|
||||
</div>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</main>
|
||||
</div>
|
||||
<el-dialog v-model="previewVisible" title="文章预览" width="85%" :modal-props="{ closeOnClickModal: false }" :before-close="() => previewVisible = false" class="preview-dialog-custom" :fullscreen="previewFullscreen" close-on-press-escape :lock-scroll="false">
|
||||
@@ -136,137 +180,205 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
<el-dialog v-model="editVisible" title="编辑正文" width="85%" :close-on-click-modal="false">
|
||||
<el-alert type="warning" :closable="false" show-icon style="margin-bottom:12px;">修改后保存即覆盖该平台文章,发布前请先完成 AI 味检测与人工校验。</el-alert>
|
||||
<el-input type="textarea" :rows="20" v-model="editForm.html_content" style="font-family:monospace;"></el-input>
|
||||
<template #footer>
|
||||
<el-button @click="editVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="savingEdit" @click="saveArticle">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
<script src="vue.global.prod.js"></script>
|
||||
<script src="icon-components.js"></script>
|
||||
<script src="element-plus.full.js"></script>
|
||||
<script>
|
||||
const ArticlesApp = {
|
||||
data() {
|
||||
return {
|
||||
isLoggedIn: false, isAdmin: false, currentUser: { username: '' },
|
||||
loadingTable: false,
|
||||
articles: [],
|
||||
filterPlatform: '', filterStatus: '', searchQuery: '',
|
||||
previewVisible: false, previewArticleData: null, previewFullscreen: false,
|
||||
debounceTimer: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
filteredArticles() {
|
||||
let list = this.articles;
|
||||
if (this.filterPlatform) list = list.filter(a => a.platform === this.filterPlatform);
|
||||
if (this.filterStatus) list = list.filter(a => a.status === this.filterStatus);
|
||||
if (this.searchQuery) {
|
||||
const q = this.searchQuery.toLowerCase();
|
||||
list = list.filter(a => (a.id && a.id.toLowerCase().includes(q)) || (a.topic_title && a.topic_title.toLowerCase().includes(q)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getToken() { return localStorage.getItem('authToken'); },
|
||||
async api(url, opts = {}) {
|
||||
const token = this.getToken();
|
||||
if (!token) { this.$message.error('请先登录'); setTimeout(() => window.location.href = '/login.html', 1500); return null; }
|
||||
const res = await fetch(url, { headers: { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json', ...opts.headers }, ...opts });
|
||||
if (!res.ok) { const data = await res.json().catch(() => ({})); throw new Error(data.detail || `请求失败: ${res.status}`); }
|
||||
return res.json();
|
||||
},
|
||||
async fetchArticles() {
|
||||
this.loadingTable = true;
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
if (this.filterPlatform) params.set('platform', this.filterPlatform);
|
||||
if (this.filterStatus) params.set('status', this.filterStatus);
|
||||
const qs = params.toString();
|
||||
const data = await this.api('/api/articles/list' + (qs ? '?' + qs : ''));
|
||||
this.articles = data.articles || [];
|
||||
} catch (error) {
|
||||
console.error('获取文章列表失败:', error);
|
||||
this.$message.error('获取文章列表失败: ' + error.message);
|
||||
this.articles = [];
|
||||
} finally { this.loadingTable = false; }
|
||||
},
|
||||
debouncedSearch() {
|
||||
clearTimeout(this.debounceTimer);
|
||||
this.debounceTimer = setTimeout(() => { this.fetchArticles(); }, 400);
|
||||
},
|
||||
async previewArticle(article) {
|
||||
this.previewArticleData = null;
|
||||
this.previewVisible = true;
|
||||
this.previewFullscreen = false;
|
||||
try {
|
||||
const data = await this.api('/api/articles/detail/' + article.id);
|
||||
this.previewArticleData = data;
|
||||
} catch (error) {
|
||||
this.$message.error('加载文章详情失败: ' + error.message);
|
||||
this.previewVisible = false;
|
||||
const ArticlesApp = {
|
||||
data() {
|
||||
return {
|
||||
isEmbed: false,
|
||||
isLoggedIn: false, isAdmin: false, currentUser: { username: '' },
|
||||
activeTab: 'articles',
|
||||
loadingTable: false,
|
||||
articles: [],
|
||||
filterPlatform: '', filterStatus: '', searchQuery: '',
|
||||
previewVisible: false, previewArticleData: null, previewFullscreen: false,
|
||||
editVisible: false, savingEdit: false, editForm: { topic_id: '', platform: '', html_content: '' },
|
||||
publishRecords: [], loadingRecords: false,
|
||||
debounceTimer: null
|
||||
}
|
||||
},
|
||||
togglePreviewFullscreen() {
|
||||
this.previewFullscreen = !this.previewFullscreen;
|
||||
this.$nextTick(() => {
|
||||
const overlays = document.querySelectorAll('.el-overlay');
|
||||
const overlay = overlays[overlays.length - 1];
|
||||
if (overlay) overlay.style.zIndex = this.previewFullscreen ? '100000' : '';
|
||||
const dialog = document.querySelector('.preview-dialog-custom');
|
||||
if (dialog) { dialog.style.zIndex = this.previewFullscreen ? '100001' : ''; }
|
||||
});
|
||||
computed: {
|
||||
filteredArticles() {
|
||||
let list = this.articles;
|
||||
if (this.filterPlatform) list = list.filter(a => a.platform === this.filterPlatform);
|
||||
if (this.filterStatus) list = list.filter(a => a.status === this.filterStatus);
|
||||
if (this.searchQuery) {
|
||||
const q = this.searchQuery.toLowerCase();
|
||||
list = list.filter(a => (a.id && a.id.toLowerCase().includes(q)) || (a.topic_title && a.topic_title.toLowerCase().includes(q)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
},
|
||||
copyPreviewHtml() {
|
||||
const html = this.previewArticleData?.html_content;
|
||||
if (!html) { this.$message.warning('暂无内容可复制'); return; }
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, 'text/html');
|
||||
const titleEl = doc.querySelector('h1');
|
||||
const title = titleEl ? titleEl.textContent.trim() : (this.previewArticleData.topic_title || '');
|
||||
const body = doc.body;
|
||||
if (body) body.querySelectorAll('script, style, nav, footer, .interaction, .ad, aside, .comment').forEach(el => el.remove());
|
||||
const container = doc.createElement('div');
|
||||
if (titleEl) { const h1 = doc.createElement('h1'); h1.textContent = title; container.appendChild(h1); }
|
||||
body.querySelectorAll('h2,h3,h4,p,li,blockquote,img,pre,code,table,hr').forEach(el => container.appendChild(el.cloneNode(true)));
|
||||
const cleanHtml = container.innerHTML;
|
||||
const blob = new Blob([cleanHtml], { type: 'text/html' });
|
||||
const plainText = container.textContent;
|
||||
const item = new ClipboardItem({ 'text/html': blob, 'text/plain': new Blob([plainText], { type: 'text/plain' }) });
|
||||
navigator.clipboard.write([item]).then(() => this.$message.success('✅ 已复制(含格式和配图),Ctrl+V 粘贴')).catch(() => {
|
||||
navigator.clipboard.writeText(cleanHtml).then(() => this.$message.success('✅ 已复制 HTML')).catch(() => this.$message.error('❌ 复制失败'));
|
||||
});
|
||||
watch: {
|
||||
activeTab(v) { if (v === 'publish') this.fetchRecords(); }
|
||||
},
|
||||
async deleteArticle(article) {
|
||||
try {
|
||||
await this.$confirm(`确定删除文章 [${article.id}]?`, '提示', { type: 'warning' });
|
||||
await this.api('/api/articles/' + article.id, { method: 'DELETE' });
|
||||
this.$message.success('删除成功');
|
||||
await this.fetchArticles();
|
||||
} catch (e) { if (e !== 'cancel') this.$message.error('删除失败: ' + (e.message || '未知错误')); }
|
||||
methods: {
|
||||
getToken() { return localStorage.getItem('authToken'); },
|
||||
async api(url, opts = {}) {
|
||||
const token = this.getToken();
|
||||
if (!token) { this.$message.error('请先登录'); setTimeout(() => window.location.href = '/login.html', 1500); return null; }
|
||||
const res = await fetch(url, { headers: { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json', ...opts.headers }, ...opts });
|
||||
if (!res.ok) { const data = await res.json().catch(() => ({})); throw new Error(data.detail || `请求失败: ${res.status}`); }
|
||||
return res.json();
|
||||
},
|
||||
async fetchArticles() {
|
||||
this.loadingTable = true;
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
if (this.filterPlatform) params.set('platform', this.filterPlatform);
|
||||
if (this.filterStatus) params.set('status', this.filterStatus);
|
||||
const qs = params.toString();
|
||||
const data = await this.api('/api/articles/list' + (qs ? '?' + qs : ''));
|
||||
this.articles = data.articles || [];
|
||||
} catch (error) {
|
||||
console.error('获取文章列表失败:', error);
|
||||
this.$message.error('获取文章列表失败: ' + error.message);
|
||||
this.articles = [];
|
||||
} finally { this.loadingTable = false; }
|
||||
},
|
||||
async fetchRecords() {
|
||||
this.loadingRecords = true;
|
||||
try {
|
||||
const data = await this.api('/api/publishing/records');
|
||||
this.publishRecords = data.records || [];
|
||||
} catch (error) {
|
||||
this.$message.error('加载发布记录失败: ' + error.message);
|
||||
this.publishRecords = [];
|
||||
} finally { this.loadingRecords = false; }
|
||||
},
|
||||
debouncedSearch() {
|
||||
clearTimeout(this.debounceTimer);
|
||||
this.debounceTimer = setTimeout(() => { this.fetchArticles(); }, 400);
|
||||
},
|
||||
async previewArticle(article) {
|
||||
this.previewArticleData = null;
|
||||
this.previewVisible = true;
|
||||
this.previewFullscreen = false;
|
||||
try {
|
||||
const data = await this.api('/api/articles/detail/' + article.id);
|
||||
this.previewArticleData = data;
|
||||
} catch (error) {
|
||||
this.$message.error('加载文章详情失败: ' + error.message);
|
||||
this.previewVisible = false;
|
||||
}
|
||||
},
|
||||
async editArticle(article) {
|
||||
this.editForm = { topic_id: article.topic_id, platform: article.platform, html_content: '' };
|
||||
this.editVisible = true;
|
||||
this.savingEdit = false;
|
||||
try {
|
||||
const data = await this.api('/api/articles/detail/' + article.id);
|
||||
this.editForm.html_content = data.html_content || '';
|
||||
} catch (error) {
|
||||
this.$message.error('加载正文失败: ' + error.message);
|
||||
this.editVisible = false;
|
||||
}
|
||||
},
|
||||
async saveArticle() {
|
||||
this.savingEdit = true;
|
||||
try {
|
||||
await this.api('/api/articles/' + encodeURIComponent(this.editForm.topic_id) + '/content', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ platform: this.editForm.platform, html_content: this.editForm.html_content })
|
||||
});
|
||||
this.$message.success('正文已保存');
|
||||
this.editVisible = false;
|
||||
await this.fetchArticles();
|
||||
} catch (error) {
|
||||
this.$message.error('保存失败: ' + error.message);
|
||||
} finally { this.savingEdit = false; }
|
||||
},
|
||||
openSlop(article) {
|
||||
window.open('ai-slop.html?topic_id=' + encodeURIComponent(article.topic_id), '_blank');
|
||||
},
|
||||
goPublish() { this.redirectToPage('topics.html'); },
|
||||
async markRecord(rec) {
|
||||
try {
|
||||
await this.$confirm('确认已在各平台完成发布?', '标记发布', { type: 'warning' });
|
||||
await this.api('/api/publishing/' + encodeURIComponent(rec.topic_id) + '/mark-published', { method: 'POST' });
|
||||
this.$message.success('已标记为已发布');
|
||||
await this.fetchRecords();
|
||||
} catch (e) {
|
||||
if (e === 'cancel') return;
|
||||
const msg = e?.response?.data?.detail || e?.message || '未知错误';
|
||||
this.$message.error('操作失败: ' + msg);
|
||||
}
|
||||
},
|
||||
togglePreviewFullscreen() {
|
||||
this.previewFullscreen = !this.previewFullscreen;
|
||||
this.$nextTick(() => {
|
||||
const overlays = document.querySelectorAll('.el-overlay');
|
||||
const overlay = overlays[overlays.length - 1];
|
||||
if (overlay) overlay.style.zIndex = this.previewFullscreen ? '100000' : '';
|
||||
const dialog = document.querySelector('.preview-dialog-custom');
|
||||
if (dialog) { dialog.style.zIndex = this.previewFullscreen ? '100001' : ''; }
|
||||
});
|
||||
},
|
||||
copyPreviewHtml() {
|
||||
const html = this.previewArticleData?.html_content;
|
||||
if (!html) { this.$message.warning('暂无内容可复制'); return; }
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, 'text/html');
|
||||
const titleEl = doc.querySelector('h1');
|
||||
const title = titleEl ? titleEl.textContent.trim() : (this.previewArticleData.topic_title || '');
|
||||
const body = doc.body;
|
||||
if (body) body.querySelectorAll('script, style, nav, footer, .interaction, .ad, aside, .comment').forEach(el => el.remove());
|
||||
const container = doc.createElement('div');
|
||||
if (titleEl) { const h1 = doc.createElement('h1'); h1.textContent = title; container.appendChild(h1); }
|
||||
body.querySelectorAll('h2,h3,h4,p,li,blockquote,img,pre,code,table,hr').forEach(el => container.appendChild(el.cloneNode(true)));
|
||||
const cleanHtml = container.innerHTML;
|
||||
const blob = new Blob([cleanHtml], { type: 'text/html' });
|
||||
const plainText = container.textContent;
|
||||
const item = new ClipboardItem({ 'text/html': blob, 'text/plain': new Blob([plainText], { type: 'text/plain' }) });
|
||||
navigator.clipboard.write([item]).then(() => this.$message.success('✅ 已复制(含格式和配图),Ctrl+V 粘贴')).catch(() => {
|
||||
navigator.clipboard.writeText(cleanHtml).then(() => this.$message.success('✅ 已复制 HTML')).catch(() => this.$message.error('❌ 复制失败'));
|
||||
});
|
||||
},
|
||||
async deleteArticle(article) {
|
||||
try {
|
||||
await this.$confirm(`确定删除文章 [${article.id}]?`, '提示', { type: 'warning' });
|
||||
await this.api('/api/articles/' + article.id, { method: 'DELETE' });
|
||||
this.$message.success('删除成功');
|
||||
await this.fetchArticles();
|
||||
} catch (e) { if (e !== 'cancel') this.$message.error('删除失败: ' + (e.message || '未知错误')); }
|
||||
},
|
||||
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
||||
redirectToPage(page) { const url = page.startsWith('/') ? page : '/' + page; if (this.isEmbed) window.top.location.href = url; else window.location.href = url; },
|
||||
platformLabel(p) { return { zhihu: '知乎', wechat: '微信公众号', xiaohongshu: '小红书' }[p] || p; },
|
||||
statusLabel(s) { return { draft: '草稿', reviewed: '已审查', published: '已发布' }[s] || s; },
|
||||
statusTagType(s) { return { draft: 'warning', reviewed: 'success', published: 'info' }[s] || 'primary'; },
|
||||
formatDate(dateStr) {
|
||||
if (!dateStr) return '-';
|
||||
try { return new Date(dateStr.replace(' ', 'T')).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); }
|
||||
catch (e) { return dateStr; }
|
||||
}
|
||||
},
|
||||
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
||||
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
||||
platformLabel(p) { return { zhihu: '知乎', wechat: '微信公众号', xiaohongshu: '小红书' }[p] || p; },
|
||||
statusLabel(s) { return { draft: '草稿', reviewed: '已审查', published: '已发布' }[s] || s; },
|
||||
statusTagType(s) { return { draft: 'warning', reviewed: 'success', published: 'info' }[s] || 'primary'; },
|
||||
formatDate(dateStr) {
|
||||
if (!dateStr) return '-';
|
||||
try { return new Date(dateStr.replace(' ', 'T')).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); }
|
||||
catch (e) { return dateStr; }
|
||||
mounted() {
|
||||
const token = localStorage.getItem('authToken');
|
||||
if (!token) { window.location.href = '/login.html'; return; }
|
||||
if (new URLSearchParams(window.location.search).get('embed') === '1') { this.isEmbed = true; document.body.classList.add('embed'); }
|
||||
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
||||
.then(r => r.ok ? r.json() : Promise.reject())
|
||||
.then(data => { this.currentUser = data.user; this.isAdmin = data.user.role === 'admin'; this.isLoggedIn = true; this.fetchArticles(); })
|
||||
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
const token = localStorage.getItem('authToken');
|
||||
if (!token) { window.location.href = '/login.html'; return; }
|
||||
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
||||
.then(r => r.ok ? r.json() : Promise.reject())
|
||||
.then(data => { this.currentUser = data.user; this.isAdmin = data.user.role === 'admin'; this.isLoggedIn = true; this.fetchArticles(); })
|
||||
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
||||
}
|
||||
};
|
||||
const app = Vue.createApp(ArticlesApp);
|
||||
app.use(ElementPlus);
|
||||
if (window.installIcons) { window.installIcons(app); }
|
||||
if (window.installUniNav) { window.installUniNav(app); }
|
||||
app.mount('#app');
|
||||
};
|
||||
const app = Vue.createApp(ArticlesApp);
|
||||
app.use(ElementPlus);
|
||||
if (window.installIcons) { window.installIcons(app); }
|
||||
if (window.installUniNav) { window.installUniNav(app); }
|
||||
app.mount('#app');
|
||||
</script>
|
||||
<script src="ai-assistant.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>宇之然内容创作平台 - 白标设置</title>
|
||||
<link rel="stylesheet" href="element-plus.css">
|
||||
<link rel="stylesheet" href="theme-modern.css">
|
||||
<script src="uni-nav.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" v-cloak>
|
||||
<uni-nav title="白标设置" :username="currentUser.username" :is-admin="isAdmin" current-page="branding" @navigate="redirectToPage" @logout="handleLogout">
|
||||
</uni-nav>
|
||||
<div class="main-content">
|
||||
<main class="content-area">
|
||||
<div class="card page-fade">
|
||||
<div class="page-header">
|
||||
<h2 class="page-title"><el-icon style="vertical-align:-2px;"><IconSetting /></el-icon> 白标 / 私有化品牌设置</h2>
|
||||
<el-tag type="info" size="small">仅管理员可见</el-tag>
|
||||
</div>
|
||||
<el-alert type="success" :closable="false" show-icon style="margin-bottom:16px;">
|
||||
<template #title>私有化交付说明</template>
|
||||
修改以下配置即可将本平台改名为贵司品牌(名称 / Logo / 主色 / 支持邮箱),保存后前台导航与品牌色即时生效。适合部署到客户内网或作为白标产品交付。
|
||||
</el-alert>
|
||||
|
||||
<el-form label-width="110px" style="max-width:640px;">
|
||||
<el-form-item label="平台名称">
|
||||
<el-input v-model="form.brand_name" placeholder="如:星辰内容中台" maxlength="20" show-word-limit></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="Logo 地址">
|
||||
<el-input v-model="form.brand_logo" placeholder="https 图片 URL,留空则显示文字名称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="主色">
|
||||
<el-color-picker v-model="form.brand_primary_color"></el-color-picker>
|
||||
<el-input v-model="form.brand_primary_color" style="width:120px;margin-left:12px;" placeholder="#2563eb"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="支持邮箱">
|
||||
<el-input v-model="form.brand_support_email" placeholder="support@yourcompany.com"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="saving" @click="save">保存并应用</el-button>
|
||||
<el-button @click="reset">重置为当前</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-divider>实时预览</el-divider>
|
||||
<div :style="{ background: 'linear-gradient(135deg,' + (form.brand_primary_color || '#2563eb') + ',' + (form.brand_primary_color || '#2563eb') + 'cc)', color:'#fff', padding:'10px 16px', borderRadius:'8px', display:'flex', alignItems:'center', gap:'8px', maxWidth:'480px' }">
|
||||
<img v-if="form.brand_logo" :src="form.brand_logo" style="height:22px;border-radius:4px;" />
|
||||
<strong>{{ form.brand_name || '平台名称预览' }}</strong>
|
||||
<span style="margin-left:auto;font-size:12px;opacity:.85;">v{{ version }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<script src="vue.global.prod.js"></script>
|
||||
<script src="icon-components.js"></script>
|
||||
<script src="element-plus.full.js"></script>
|
||||
<script>
|
||||
const BrandingApp = {
|
||||
data() {
|
||||
return {
|
||||
isLoggedIn: false, isAdmin: false, currentUser: { username: '' },
|
||||
form: { brand_name: '', brand_logo: '', brand_primary_color: '#2563eb', brand_support_email: '' },
|
||||
version: '0.1.0', saving: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getToken() { return localStorage.getItem('authToken'); },
|
||||
async load() {
|
||||
try {
|
||||
const data = await fetch('/api/branding').then(r => r.json());
|
||||
this.form = {
|
||||
brand_name: data.brand_name || '',
|
||||
brand_logo: data.brand_logo || '',
|
||||
brand_primary_color: data.brand_primary_color || '#2563eb',
|
||||
brand_support_email: data.brand_support_email || '',
|
||||
};
|
||||
this.version = data.version || '0.1.0';
|
||||
} catch (e) { this.$message.error('加载品牌配置失败'); }
|
||||
},
|
||||
async save() {
|
||||
this.saving = true;
|
||||
try {
|
||||
const token = this.getToken();
|
||||
const res = await fetch('/api/branding', {
|
||||
method: 'PUT',
|
||||
headers: { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(this.form)
|
||||
});
|
||||
if (!res.ok) throw new Error((await res.json()).detail || '保存失败');
|
||||
this.$message.success('已保存,刷新其他页面即可看到新品牌');
|
||||
setTimeout(() => this.load(), 300);
|
||||
} catch (e) {
|
||||
this.$message.error('保存失败:' + e.message);
|
||||
} finally { this.saving = false; }
|
||||
},
|
||||
reset() { this.load(); },
|
||||
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
||||
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
||||
},
|
||||
mounted() {
|
||||
const token = localStorage.getItem('authToken');
|
||||
if (!token) { window.location.href = '/login.html'; return; }
|
||||
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
||||
.then(r => r.ok ? r.json() : Promise.reject())
|
||||
.then(data => {
|
||||
this.currentUser = data.user; this.isAdmin = data.user.role === 'admin';
|
||||
if (!this.isAdmin) { this.$message.warning('需要管理员权限'); window.location.href = '/index.html'; return; }
|
||||
this.load();
|
||||
})
|
||||
.catch(() => { window.location.href = '/login.html'; });
|
||||
}
|
||||
};
|
||||
const app = Vue.createApp(BrandingApp);
|
||||
app.use(ElementPlus);
|
||||
if (window.installIcons) { window.installIcons(app); }
|
||||
if (window.installUniNav) { window.installUniNav(app); }
|
||||
app.mount('#app');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -186,7 +186,8 @@
|
||||
<div class="empty-text">该日暂无日程</div>
|
||||
<p style="font-size:13px;color:#909399;margin:4px 0 0 0;">点击上方"添加日程"创建发布计划</p>
|
||||
</div>
|
||||
<el-table v-else :data="selectedDayEntries" stripe>
|
||||
<template v-else>
|
||||
<el-table class="card-table" :data="selectedDayEntries" stripe>
|
||||
<el-table-column prop="title" label="标题" min-width="120"></el-table-column>
|
||||
<el-table-column prop="platform" label="平台" width="100">
|
||||
<template #default="scope">{{ scope.row._source === 'topic' ? (scope.row.status === 'published' ? '已发布' : '选题') : platformName(scope.row.platform) }}</template>
|
||||
@@ -201,6 +202,18 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="card-list-mobile">
|
||||
<div v-for="entry in selectedDayEntries" :key="entry.id || entry.topic_id || entry.title" class="card-item">
|
||||
<div class="card-row"><span class="card-label">标题</span><span class="card-value">{{ entry.title }}</span></div>
|
||||
<div class="card-row"><span class="card-label">平台</span><span class="card-value">{{ entry._source === 'topic' ? (entry.status === 'published' ? '已发布' : '选题') : platformName(entry.platform) }}</span></div>
|
||||
<div class="card-row"><span class="card-label">状态</span><span class="card-value"><el-tag :type="statusType(entry.status)" size="small">{{ statusLabel(entry.status) }}</el-tag></span></div>
|
||||
<div class="card-actions">
|
||||
<el-button v-if="entry._source === 'topic'" size="small" type="primary" @click="openEntryDialog(entry)">查看</el-button>
|
||||
<el-button v-else size="small" @click="openEntryDialog(entry)">编辑</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@
|
||||
/* ========== Topic Cards (待创作) ========== */
|
||||
.topic-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
|
||||
grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr));
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
.topic-card {
|
||||
@@ -565,7 +565,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" v-cloak>
|
||||
<uni-nav title="内容工厂" :username="currentUser.username" :is-admin="isAdmin" current-page="factory" @navigate="redirectToPage" @logout="handleLogout">
|
||||
<uni-nav v-if="!isEmbed" title="内容工厂" :username="currentUser.username" :is-admin="isAdmin" current-page="factory" @navigate="redirectToPage" @logout="handleLogout">
|
||||
</uni-nav>
|
||||
|
||||
<div class="main-content">
|
||||
@@ -838,6 +838,7 @@
|
||||
const FactoryApp = {
|
||||
data() {
|
||||
return {
|
||||
isEmbed: false,
|
||||
isLoggedIn: false,
|
||||
isAdmin: false,
|
||||
currentUser: { username: '' },
|
||||
@@ -1037,7 +1038,7 @@ const FactoryApp = {
|
||||
});
|
||||
},
|
||||
goToArticles() {
|
||||
window.location.href = '/articles.html';
|
||||
this.redirectToPage('/articles.html');
|
||||
},
|
||||
handleLogout() {
|
||||
localStorage.removeItem('authToken');
|
||||
@@ -1046,7 +1047,9 @@ const FactoryApp = {
|
||||
window.location.href = '/login.html';
|
||||
},
|
||||
redirectToPage(page) {
|
||||
window.location.href = page.startsWith('/') ? page : '/' + page;
|
||||
const url = page.startsWith('/') ? page : '/' + page;
|
||||
if (this.isEmbed) window.top.location.href = url;
|
||||
else window.location.href = url;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
@@ -1055,6 +1058,7 @@ const FactoryApp = {
|
||||
window.location.href = '/login.html';
|
||||
return;
|
||||
}
|
||||
if (new URLSearchParams(window.location.search).get('embed') === '1') { this.isEmbed = true; document.body.classList.add('embed'); }
|
||||
fetch('/api/auth/me', {
|
||||
headers: { 'Authorization': 'Bearer ' + token }
|
||||
})
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
.stat-card.danger { background: linear-gradient(135deg, #f56c6c 0%, #f78989 100%); }
|
||||
.stat-value { font-size: 32px; font-weight: 700; }
|
||||
.stat-label { font-size: 14px; opacity: 0.9; margin-top: 4px; }
|
||||
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 24px; }
|
||||
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 20px; margin-bottom: 24px; }
|
||||
.chart-container { background: white; border-radius: 12px; padding: 16px; margin-bottom: 24px; height: 320px; position: relative; }
|
||||
.platform-chart { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
|
||||
@media (max-width: 768px) {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>宇之然内容创作平台 - 创作工作台</title>
|
||||
<link rel="stylesheet" href="element-plus.css">
|
||||
<link rel="stylesheet" href="theme-modern.css">
|
||||
<style>
|
||||
html, body { margin: 0; height: 100%; }
|
||||
[v-cloak] { display: none; }
|
||||
#app { display: flex; flex-direction: column; height: 100vh; }
|
||||
.studio-body { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-top: var(--nav-height); }
|
||||
.studio-tabs { flex: 0 0 auto; padding: 0 16px; background: var(--color-bg-raised); border-bottom: 1px solid var(--color-border); }
|
||||
.studio-tabs .el-tabs__header { margin-bottom: 0; }
|
||||
.studio-iframe-wrap { flex: 1; position: relative; min-height: 0; background: var(--color-bg); }
|
||||
.studio-iframe-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: none; }
|
||||
@media (max-width: 768px) { .studio-tabs { padding: 0 8px; } }
|
||||
</style>
|
||||
<script src="uni-nav.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" v-cloak>
|
||||
<uni-nav title="创作工作台" :username="currentUser.username" :is-admin="isAdmin" current-page="studio" @navigate="redirectToPage" @logout="handleLogout">
|
||||
</uni-nav>
|
||||
<div class="studio-body">
|
||||
<div class="studio-tabs">
|
||||
<el-tabs v-model="activeTab" @tab-change="onTabChange">
|
||||
<el-tab-pane label="选题" name="topics"></el-tab-pane>
|
||||
<el-tab-pane label="内容生成" name="factory"></el-tab-pane>
|
||||
<el-tab-pane label="文章管理" name="articles"></el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
<div class="studio-iframe-wrap">
|
||||
<iframe v-if="tabs.topics" src="topics.html?embed=1" frameborder="0"></iframe>
|
||||
<iframe v-if="tabs.factory" src="factory.html?embed=1" frameborder="0"></iframe>
|
||||
<iframe v-if="tabs.articles" src="articles.html?embed=1" frameborder="0"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="vue.global.prod.js"></script>
|
||||
<script src="element-plus.js"></script>
|
||||
<script src="element-plus-icons.js"></script>
|
||||
<script>
|
||||
const { createApp } = Vue;
|
||||
const StudioApp = {
|
||||
data() {
|
||||
return {
|
||||
isLoggedIn: false, isAdmin: false, currentUser: { username: '' },
|
||||
activeTab: 'topics',
|
||||
tabs: { topics: true, factory: false, articles: false },
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onTabChange(name) { this.tabs[name] = true; },
|
||||
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
||||
handleLogout() {
|
||||
localStorage.removeItem('authToken');
|
||||
localStorage.removeItem('userRole');
|
||||
localStorage.removeItem('currentUser');
|
||||
window.location.href = '/login.html';
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
const token = localStorage.getItem('authToken');
|
||||
if (!token) { window.location.href = '/login.html'; return; }
|
||||
fetch('/api/auth/me', { headers: { 'Authorization': 'Bearer ' + token } })
|
||||
.then(r => r.ok ? r.json() : Promise.reject())
|
||||
.then(data => { this.currentUser = data.user; this.isAdmin = data.user.role === 'admin'; this.isLoggedIn = true; })
|
||||
.catch(() => { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; });
|
||||
}
|
||||
};
|
||||
const app = Vue.createApp(StudioApp);
|
||||
app.use(ElementPlus);
|
||||
if (window.installIcons) { window.installIcons(app); }
|
||||
if (window.installUniNav) { window.installUniNav(app); }
|
||||
app.mount('#app');
|
||||
</script>
|
||||
<script src="ai-assistant.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -68,7 +68,10 @@
|
||||
--content-max-width: 1400px;
|
||||
}
|
||||
|
||||
/* ========== Dark Mode ========== */
|
||||
/* ========== Dark Mode ==========
|
||||
注意:Element Plus 组件库为亮色主题,未同步切换会导致弹窗/卡片内
|
||||
自定义文字在深色变量下不可读。当前明确采用亮色主题以保证对比度,
|
||||
待引入 EP 暗色变量(dark theme vars)后再启用完整暗色模式。
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--color-bg: #1a1a2e;
|
||||
@@ -76,12 +79,10 @@
|
||||
--color-bg-subtle: #1a1a3e;
|
||||
--color-border: #2a2a4e;
|
||||
--color-border-hover: #4a4a6e;
|
||||
|
||||
--color-text-primary: #e0e6ed;
|
||||
--color-text-regular: #a0a6b0;
|
||||
--color-text-secondary: #6b7280;
|
||||
--color-text-placeholder: #4a4a5e;
|
||||
|
||||
--shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
|
||||
--shadow-md: 0 2px 12px rgba(0,0,0,0.3);
|
||||
--shadow-lg: 0 8px 28px rgba(0,0,0,0.4);
|
||||
@@ -90,6 +91,7 @@
|
||||
.card { background: var(--color-bg-raised); }
|
||||
.el-table { --el-table-tr-bg: var(--color-bg-raised); --el-table-header-bg: var(--color-bg-subtle); }
|
||||
}
|
||||
*/
|
||||
|
||||
/* ========== Reset & Base ========== */
|
||||
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
@@ -119,6 +121,12 @@ body {
|
||||
margin: 0 auto;
|
||||
min-height: calc(100vh - var(--nav-height));
|
||||
}
|
||||
|
||||
/* 嵌入模式(被创作工作台 iframe 加载时):去掉顶部导航留白 */
|
||||
body.embed .main-content {
|
||||
padding-top: 0 !important;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.content-area { flex: 1; padding: var(--spacing-md); overflow-y: auto; }
|
||||
|
||||
/* ========== Card ========== */
|
||||
@@ -128,7 +136,6 @@ body {
|
||||
padding: var(--spacing-lg);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
box-shadow: var(--shadow-md);
|
||||
overflow-x: auto;
|
||||
transition: all 0.3s var(--ease-out);
|
||||
}
|
||||
|
||||
@@ -405,7 +412,7 @@ body:has(.preview-dialog-custom.is-fullscreen) > [class*="el-overlay"] { z-index
|
||||
}
|
||||
@media (min-width: 769px) {
|
||||
.preview-iframe { min-height: 400px; }
|
||||
.preview-dialog-custom { position: relative; left: 90px; }
|
||||
.preview-dialog-custom { position: relative; }
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" v-cloak>
|
||||
<uni-nav title="选题管理" :username="currentUser.username" :is-admin="isAdmin" current-page="topics" @navigate="redirectToPage" @logout="handleLogout">
|
||||
<uni-nav v-if="!isEmbed" title="选题管理" :username="currentUser.username" :is-admin="isAdmin" current-page="topics" @navigate="redirectToPage" @logout="handleLogout">
|
||||
</uni-nav>
|
||||
<div class="main-content">
|
||||
<main class="content-area">
|
||||
@@ -56,6 +56,7 @@
|
||||
<el-button size="default" :type="filterStatus === 'review' ? 'primary' : ''" @click="filterStatus = 'review'; fetchTopics()">待审查 ({{ statusStats.review }})</el-button>
|
||||
<el-button size="default" :type="filterStatus === 'ready' ? 'primary' : ''" @click="filterStatus = 'ready'; fetchTopics()">待发布 ({{ statusStats.ready }})</el-button>
|
||||
<el-button size="default" :type="filterStatus === 'published' ? 'primary' : ''" @click="filterStatus = 'published'; fetchTopics()">已发布 ({{ statusStats.published }})</el-button>
|
||||
<el-button size="default" :type="filterStatus === 'pending_publish' ? 'primary' : ''" @click="filterStatus = 'pending_publish'; fetchTopics()">待人工发布 ({{ statusStats.pendingPublish }})</el-button>
|
||||
</div>
|
||||
<div style="margin-bottom:10px;">
|
||||
<span class="search-toggle" @click="showSearch = !showSearch">🔍 {{ showSearch ? '收起搜索' : '展开搜索' }}</span>
|
||||
@@ -64,30 +65,30 @@
|
||||
<div v-if="showSearch" class="search-area">
|
||||
<el-form :model="searchForm" size="small" label-width="70px" @submit.prevent>
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="6"><el-form-item label="选题ID"><el-input v-model="searchForm.id" placeholder="如 A07" clearable @input="doSearch"></el-input></el-form-item></el-col>
|
||||
<el-col :span="8"><el-form-item label="标题"><el-input v-model="searchForm.title" placeholder="关键词" clearable @input="doSearch"></el-input></el-form-item></el-col>
|
||||
<el-col :span="5"><el-form-item label="领域"><el-input v-model="searchForm.field" placeholder="如 科技前沿" clearable @input="doSearch"></el-input></el-form-item></el-col>
|
||||
<el-col :span="5"><el-form-item label="栏目"><el-select v-model="searchForm.series" clearable placeholder="全部" style="width:100%;" @change="doSearch"><el-option v-for="s in seriesOptions" :key="s" :label="s" :value="s"></el-option></el-select></el-form-item></el-col>
|
||||
<el-col :xs="24" :sm="12" :md="6"><el-form-item label="选题ID"><el-input v-model="searchForm.id" placeholder="如 A07" clearable @input="doSearch"></el-input></el-form-item></el-col>
|
||||
<el-col :xs="24" :sm="12" :md="8"><el-form-item label="标题"><el-input v-model="searchForm.title" placeholder="关键词" clearable @input="doSearch"></el-input></el-form-item></el-col>
|
||||
<el-col :xs="24" :sm="12" :md="5"><el-form-item label="领域"><el-input v-model="searchForm.field" placeholder="如 科技前沿" clearable @input="doSearch"></el-input></el-form-item></el-col>
|
||||
<el-col :xs="24" :sm="12" :md="5"><el-form-item label="栏目"><el-select v-model="searchForm.series" clearable placeholder="全部" style="width:100%;" @change="doSearch"><el-option v-for="s in seriesOptions" :key="s" :label="s" :value="s"></el-option></el-select></el-form-item></el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="12"><el-form-item label="创建时间">
|
||||
<el-col :xs="24" :sm="24" :md="12"><el-form-item label="创建时间">
|
||||
<el-date-picker v-model="searchForm.createdStart" type="date" placeholder="开始" style="width:130px;" value-format="YYYY-MM-DD" @change="doSearch"></el-date-picker>
|
||||
<span style="margin:0 4px;color:#909399;">~</span>
|
||||
<el-date-picker v-model="searchForm.createdEnd" type="date" placeholder="结束" style="width:130px;" value-format="YYYY-MM-DD" @change="doSearch"></el-date-picker>
|
||||
</el-form-item></el-col>
|
||||
<el-col :span="12"><el-form-item label="创作时间">
|
||||
<el-col :xs="24" :sm="24" :md="12"><el-form-item label="创作时间">
|
||||
<el-date-picker v-model="searchForm.generatedStart" type="date" placeholder="开始" style="width:130px;" value-format="YYYY-MM-DD" @change="doSearch"></el-date-picker>
|
||||
<span style="margin:0 4px;color:#909399;">~</span>
|
||||
<el-date-picker v-model="searchForm.generatedEnd" type="date" placeholder="结束" style="width:130px;" value-format="YYYY-MM-DD" @change="doSearch"></el-date-picker>
|
||||
</el-form-item></el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="12"><el-form-item label="审查时间">
|
||||
<el-col :xs="24" :sm="24" :md="12"><el-form-item label="审查时间">
|
||||
<el-date-picker v-model="searchForm.reviewedStart" type="date" placeholder="开始" style="width:130px;" value-format="YYYY-MM-DD" @change="doSearch"></el-date-picker>
|
||||
<span style="margin:0 4px;color:#909399;">~</span>
|
||||
<el-date-picker v-model="searchForm.reviewedEnd" type="date" placeholder="结束" style="width:130px;" value-format="YYYY-MM-DD" @change="doSearch"></el-date-picker>
|
||||
</el-form-item></el-col>
|
||||
<el-col :span="12"><el-form-item label="发布时间">
|
||||
<el-col :xs="24" :sm="24" :md="12"><el-form-item label="发布时间">
|
||||
<el-date-picker v-model="searchForm.publishedStart" type="date" placeholder="开始" style="width:130px;" value-format="YYYY-MM-DD" @change="doSearch"></el-date-picker>
|
||||
<span style="margin:0 4px;color:#909399;">~</span>
|
||||
<el-date-picker v-model="searchForm.publishedEnd" type="date" placeholder="结束" style="width:130px;" value-format="YYYY-MM-DD" @change="doSearch"></el-date-picker>
|
||||
@@ -134,6 +135,8 @@
|
||||
<el-button size="small" type="success" :disabled="isStatus(scope.row, 'published')" @click="createTopic(scope.row)" style="padding:5px 8px;">创作</el-button>
|
||||
<el-button size="small" type="warning" :disabled="!isStatus(scope.row, 'review')" @click="reviewTopic(scope.row)" style="padding:5px 8px;">审查</el-button>
|
||||
<el-button v-if="isStatus(scope.row, 'ready')" size="small" type="primary" @click="openPublishDialog(scope.row)" style="padding:5px 8px;">发布</el-button>
|
||||
<el-button v-if="isStatus(scope.row, 'pending_publish')" size="small" type="success" @click="markPublished(scope.row)" style="padding:5px 8px;">标记发布</el-button>
|
||||
<el-button size="small" :disabled="(scope.row.article_count || 0) === 0" @click="openSlop(scope.row)" style="padding:5px 8px;">检测</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteTopic(scope.row.id)" style="padding:5px 8px;">删除</el-button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -172,6 +175,8 @@
|
||||
<el-button size="small" type="success" :disabled="isStatus(topic, 'published')" @click="createTopic(topic)">创作</el-button>
|
||||
<el-button size="small" type="warning" :disabled="!isStatus(topic, 'review')" @click="reviewTopic(topic)">审查</el-button>
|
||||
<el-button v-show="isStatus(topic, 'ready')" size="small" type="primary" @click="openPublishDialog(topic)">发布</el-button>
|
||||
<el-button v-if="isStatus(topic, 'pending_publish')" size="small" type="success" @click="markPublished(topic)">标记发布</el-button>
|
||||
<el-button size="small" :disabled="(topic.article_count || 0) === 0" @click="openSlop(topic)">检测</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteTopic(topic.id)">删除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -256,6 +261,10 @@
|
||||
</template>
|
||||
</el-dialog>
|
||||
<el-dialog v-model="publishDialogVisible" title="发布确认" width="420px" :close-on-click-modal="false">
|
||||
<el-alert type="warning" :closable="false" show-icon style="margin-bottom:16px;">
|
||||
<template #title>AI 内容需真人校验后发布</template>
|
||||
系统仅生成各平台发布稿并置为「待人工发布」,<b>不代发</b>。请在对应平台粘贴、核对 AI 声明与合规后手动发布,再回来点「标记已发布」。
|
||||
</el-alert>
|
||||
<div v-if="publishTopic">
|
||||
<div style="margin-bottom:16px;">
|
||||
<div style="font-size:14px;color:#606266;margin-bottom:8px;">选题:</div>
|
||||
@@ -336,6 +345,7 @@
|
||||
const TopicsApp = {
|
||||
data() {
|
||||
return {
|
||||
isEmbed: false,
|
||||
isLoggedIn: false, isAdmin: false, currentUser: { username: '' },
|
||||
loadingTable: false, selectedTopicIds: [], filterStatus: '',
|
||||
stats: { total: 0, pending: 0, review: 0, ready: 0, published: 0, today: 0 },
|
||||
@@ -371,7 +381,7 @@ const TopicsApp = {
|
||||
if (this.filterStatus === 'today') list = this.todayTopics;
|
||||
else if (!this.filterStatus) list = this.topics;
|
||||
else {
|
||||
const map = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'] };
|
||||
const map = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'], 'pending_publish': ['pending_publish','待人工发布'] };
|
||||
const allowed = map[this.filterStatus] || [this.filterStatus];
|
||||
list = this.topics.filter(t => allowed.includes(t.status));
|
||||
}
|
||||
@@ -422,8 +432,8 @@ const TopicsApp = {
|
||||
return this.filteredTopics.slice(start, start + this.pageSize);
|
||||
},
|
||||
statusStats() {
|
||||
const s = { total: this.topics.length, pending: 0, review: 0, ready: 0, published: 0 };
|
||||
const aliases = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'] };
|
||||
const s = { total: this.topics.length, pending: 0, review: 0, ready: 0, published: 0, pendingPublish: 0 };
|
||||
const aliases = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'], 'pending_publish': ['pending_publish','待人工发布'] };
|
||||
this.topics.forEach(t => { for (const [k, v] of Object.entries(aliases)) { if (v.includes(t.status)) { s[k]++; break; } } });
|
||||
return s;
|
||||
},
|
||||
@@ -658,13 +668,28 @@ const TopicsApp = {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ topic_id: this.publishTopic.id, platforms: selected })
|
||||
});
|
||||
this.$message.success(`发布完成: ${this.publishTopic.title}`);
|
||||
this.$message.success(data.message || `已生成发布稿,请在各平台校验后手动发布`);
|
||||
this.publishDialogVisible = false;
|
||||
await this.fetchTopics();
|
||||
await this.fetchTodayCount();
|
||||
} catch (error) { this.$message.error(`发布失败: ${error.message}`); }
|
||||
finally { this.publishing = false; }
|
||||
},
|
||||
openSlop(topic) {
|
||||
window.open('ai-slop.html?topic_id=' + encodeURIComponent(topic.id), '_blank');
|
||||
},
|
||||
async markPublished(topic) {
|
||||
try {
|
||||
await this.$confirm('确认已在各平台完成发布?此操作将把选题标记为「已发布」并关闭发布记录。', '标记发布', { type: 'warning' });
|
||||
await this.api('/api/publishing/' + encodeURIComponent(topic.id) + '/mark-published', { method: 'POST' });
|
||||
this.$message.success('已标记为已发布');
|
||||
await this.fetchTopics();
|
||||
} catch (e) {
|
||||
if (e === 'cancel') return;
|
||||
const msg = e?.response?.data?.detail || e?.message || '未知错误';
|
||||
this.$message.error('操作失败: ' + msg);
|
||||
}
|
||||
},
|
||||
async deleteTopic(id) {
|
||||
try {
|
||||
await this.$confirm('确定删除选题 ' + id + '?将同时删除相关文章、发布记录等关联数据。', '提示', { type: 'warning' });
|
||||
@@ -806,8 +831,8 @@ const TopicsApp = {
|
||||
this.currentPage = 1;
|
||||
},
|
||||
handleLogout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); localStorage.removeItem('currentUser'); window.location.href = '/login.html'; },
|
||||
redirectToPage(page) { window.location.href = page.startsWith('/') ? page : '/' + page; },
|
||||
getStatusLabel(status) { return { 'pending': '待处理', 'review': '待审查', 'ready': '待发布', 'published': '已发布' }[status] || status; },
|
||||
redirectToPage(page) { const url = page.startsWith('/') ? page : '/' + page; if (this.isEmbed) window.top.location.href = url; else window.location.href = url; },
|
||||
getStatusLabel(status) { return { 'pending': '待处理', 'review': '待审查', 'ready': '待发布', 'published': '已发布', 'pending_publish': '待人工发布' }[status] || status; },
|
||||
toggleCheck(id) {
|
||||
const idx = this.selectedTopicIds.indexOf(id);
|
||||
if (idx >= 0) {
|
||||
@@ -835,12 +860,13 @@ const TopicsApp = {
|
||||
try { return new Date(dateStr.replace(' ', 'T')).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); }
|
||||
catch (e) { return dateStr; }
|
||||
},
|
||||
getStatusType(status) { return { 'pending': 'warning', 'review': 'danger', 'ready': 'success', 'published': 'info' }[status] || 'primary'; },
|
||||
isStatus(row, status) { const map = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'] }; return map[status] ? map[status].includes(row.status) : row.status === status; }
|
||||
getStatusType(status) { return { 'pending': 'warning', 'review': 'danger', 'ready': 'success', 'published': 'info', 'pending_publish': 'warning' }[status] || 'primary'; },
|
||||
isStatus(row, status) { const map = { 'pending': ['pending','待处理'], 'review': ['review','待审查'], 'ready': ['ready','待发布'], 'published': ['published','已发布'], 'pending_publish': ['pending_publish','待人工发布'] }; return map[status] ? map[status].includes(row.status) : row.status === status; }
|
||||
},
|
||||
mounted() {
|
||||
const token = localStorage.getItem('authToken');
|
||||
if (!token) { window.location.href = '/login.html'; return; }
|
||||
if (new URLSearchParams(window.location.search).get('embed') === '1') { this.isEmbed = true; document.body.classList.add('embed'); }
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const urlFilter = params.get('filter');
|
||||
if (urlFilter) this.filterStatus = urlFilter;
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
.uni-nav-dropdown-divider {\
|
||||
height: 1px; background: #f0f0f0; margin: 4px 0;\
|
||||
}\
|
||||
@media (max-width: 768px) {\
|
||||
@media (max-width: 1000px) {\
|
||||
.uni-nav-items { display: none; }\
|
||||
.uni-nav-username { display: none; }\
|
||||
.uni-nav-hamburger { display: inline-flex; }\
|
||||
@@ -121,20 +121,24 @@
|
||||
|
||||
function getCurrentPage() {
|
||||
var path = window.location.pathname;
|
||||
if (path === '/index.html') return 'workspace';
|
||||
var m = path.match(/\/(\w+)\.html/);
|
||||
return m ? m[1] : 'workspace';
|
||||
if (path === '/' || path === '/index.html') return 'index.html';
|
||||
var m = path.match(/\/([\w-]+)\.html$/);
|
||||
return m ? m[1] + '.html' : 'index.html';
|
||||
}
|
||||
|
||||
function navItems(isAdmin) {
|
||||
var items = [
|
||||
{ key: 'workspace', label: '工作台', page: 'index.html' },
|
||||
{ key: 'factory', label: '内容工厂', page: 'factory.html' },
|
||||
{ key: 'insights', label: '数据洞察', page: 'insights.html' },
|
||||
{ key: 'assets', label: '资产库', page: 'assets.html' },
|
||||
{ key: 'dashboard', label: '仪表盘', page: 'index.html' },
|
||||
{ key: 'studio', label: '创作工作台', page: 'studio.html' },
|
||||
{ key: 'insights', label: '数据', page: 'metrics.html' },
|
||||
{ key: 'calendar', label: '日历', page: 'calendar.html' },
|
||||
{ key: 'assets', label: '素材', page: 'assets.html' },
|
||||
{ key: 'tasks', label: '任务', page: 'tasks.html' },
|
||||
{ key: 'campaigns', label: '外推营销', page: 'campaigns.html' },
|
||||
{ key: 'ai-slop', label: 'AI味检测', page: 'ai-slop.html' },
|
||||
];
|
||||
if (isAdmin) {
|
||||
items.push({ key: 'branding', label: '白标设置', page: 'branding.html', admin: true });
|
||||
items.push({ key: 'admin', label: '系统管理', page: 'admin.html', admin: true });
|
||||
}
|
||||
return items;
|
||||
@@ -160,6 +164,9 @@
|
||||
pwdForm: { old_password: '', new_password: '', confirm: '' },
|
||||
pwdSubmitting: false,
|
||||
serverMenus: null,
|
||||
brandName: '',
|
||||
brandLogo: '',
|
||||
primaryColor: '',
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -167,15 +174,19 @@
|
||||
if (this.serverMenus) {
|
||||
return this.serverMenus
|
||||
.filter(function (m) { return m.is_active !== false; })
|
||||
.map(function (m) { return { key: m.name, label: m.name, page: m.path }; });
|
||||
.map(function (m) { return { key: m.name, label: m.name, page: (m.path || '').replace(/^\//, '') }; });
|
||||
}
|
||||
return navItems(this.isAdmin);
|
||||
},
|
||||
page: function () {
|
||||
return this.currentPage || getCurrentPage();
|
||||
return getCurrentPage();
|
||||
},
|
||||
showTitle: function () {
|
||||
return this.title || '宇之然';
|
||||
return this.brandName || this.title || '宇之然';
|
||||
},
|
||||
navStyle: function () {
|
||||
if (!this.primaryColor) return {};
|
||||
return { background: 'linear-gradient(135deg, ' + this.primaryColor + ', ' + this.primaryColor + 'cc)' };
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
@@ -189,6 +200,24 @@
|
||||
}.bind(this))
|
||||
.catch(function () {});
|
||||
},
|
||||
fetchBranding: function () {
|
||||
fetch('/api/branding')
|
||||
.then(function (r) { return r.ok ? r.json() : Promise.reject(); })
|
||||
.then(function (d) {
|
||||
if (d.brand_name) this.brandName = d.brand_name;
|
||||
if (d.brand_logo) this.brandLogo = d.brand_logo;
|
||||
if (d.brand_primary_color) {
|
||||
this.primaryColor = d.brand_primary_color;
|
||||
document.documentElement.style.setProperty('--color-primary', d.brand_primary_color);
|
||||
var s = document.getElementById('uni-nav-brand-style');
|
||||
if (!s) { s = document.createElement('style'); s.id = 'uni-nav-brand-style'; document.head.appendChild(s); }
|
||||
s.textContent = '.uni-nav-dropdown-item:hover,.uni-nav-dropdown-item.active{color:' + d.brand_primary_color + ';}' +
|
||||
'.uni-nav-dropdown-item.active{background:' + d.brand_primary_color + '14;}' +
|
||||
'.uni-nav-item.active{background:rgba(255,255,255,0.18);}';
|
||||
}
|
||||
}.bind(this))
|
||||
.catch(function () {});
|
||||
},
|
||||
navigate: function (page) {
|
||||
this.dropdownOpen = false; this.profileOpen = false;
|
||||
if (this.onNavigate) { this.onNavigate(page); return; }
|
||||
@@ -246,18 +275,22 @@
|
||||
mounted: function () {
|
||||
document.addEventListener('click', this.closeAll);
|
||||
this.fetchMenus();
|
||||
this.fetchBranding();
|
||||
},
|
||||
beforeUnmount: function () {
|
||||
document.removeEventListener('click', this.closeAll);
|
||||
},
|
||||
template: '\
|
||||
<nav class="uni-nav" style="position:relative;">\
|
||||
<nav class="uni-nav" :style="navStyle">\
|
||||
<div class="uni-nav-inner">\
|
||||
<div class="uni-nav-brand">{{ showTitle }}</div>\
|
||||
<div class="uni-nav-brand">\
|
||||
<img v-if="brandLogo" :src="brandLogo" style="height:24px;width:auto;margin-right:6px;vertical-align:middle;border-radius:4px;" />\
|
||||
<span>{{ showTitle }}</span>\
|
||||
</div>\
|
||||
<div class="uni-nav-items">\
|
||||
<button v-for="item in items" :key="item.key"\
|
||||
:class="[\'uni-nav-item\', { active: page === item.key }]"\
|
||||
@click="navigate(item.page)">{{ item.label }}</button>\
|
||||
<button v-for="item in items" :key="item.key"\
|
||||
:class="['uni-nav-item', { active: page === item.page }]"\
|
||||
@click="navigate(item.page)">{{ item.label }}</button>\
|
||||
</div>\
|
||||
<div class="uni-nav-right">\
|
||||
<button class="uni-nav-hamburger" @click.stop="toggleDropdown">\
|
||||
@@ -281,7 +314,7 @@
|
||||
</div>\
|
||||
<div :class="[\'uni-nav-dropdown\', { open: dropdownOpen }]" @click.stop>\
|
||||
<button v-for="item in items" :key="item.key"\
|
||||
:class="[\'uni-nav-dropdown-item\', { active: page === item.key }]"\
|
||||
:class="[\'uni-nav-dropdown-item\', { active: page === item.page }]"\
|
||||
@click="navigate(item.page)">\
|
||||
{{ item.label }}\
|
||||
</button>\
|
||||
|
||||
Reference in New Issue
Block a user