nex_animation/scripts/ui/helpshots.py

127 lines
5.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""重拍《使用手册》的 12 张插图 → frontend/public/help/*.png。
为什么需要这支脚本:插图是 `Help.tsx` 里 `<img src="/help/x.png">` 直出的**静态截图**,
不参与构建。UI 每换一次皮肤,这 12 张就整批过期——上一轮换掉绿色配色后,手册里
仍然是 10-28 拍的旧绿色 UI,用户在正文里看到的和新配色对不上,
「浅绿色标签都要处理」这句话在插图上是字面成立的。改完 UI 必须跑一次这里。
口径(改之前先读,别随手换):
· 视口 1600×1000(16:10,和现有 12 张一致),`device_scale_factor=2` 拍到 3200×2000
再用 LANCZOS 缩回 1600 宽——比直接 1x 拍清晰,且产物尺寸与旧图逐项相等。
· 主题锁 **light**:12 张彼此要一致,且浅色才是这套「标准现代」皮肤的门面。
· 拍摄主角 = 项目 12《告诉你个小秘密第2期》:已交付、12 个节点全通、4 镜头 4 合格、
117 任务、5 条导出记录、有真实剧照。空草稿项目拍出来一片 0,半程项目缺内容。
· 项目子页**不再需要收起任何东西**(2026-11 第十一轮):项目身份 / 指标 / 流程条
从每一页顶部收进顶栏那颗项目胶囊点开的「项目概况」抽屉,`展开概况` 那颗按钮整颗删了,
子页进来就是看板本身。以前那段「先收起概况」的口径随按钮一起作废。
· 资产管理三张拍的是 **平台资产库**(/assets 的人物 / 场景 / 声线三页签),沿用历史选题。
用法:`.venv/bin/python scripts/ui/helpshots.py [输出目录]`
默认直写 `frontend/public/help/`;给一个目录就落在那儿,先人工过一眼再覆盖。
前置:dev `vite :5173` + 后端 `:8000` 在跑,账号 admin/admin1234。
"""
import io
import os
import sys
from PIL import Image
from playwright.sync_api import sync_playwright
BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173")
DEST = sys.argv[1] if len(sys.argv) > 1 else "frontend/public/help"
W, H = 1600, 1000
PROJECT = 12 # 拍摄主角,见模块 docstring
# name → (路由, 是否收起「项目概况」);顺序 = 手册正文里的出场顺序
SHOTS = [
("dashboard", "/"),
("overview", f"/projects/{PROJECT}/overview"),
("model-center", "/models"),
("asset-management", "/assets"), # 人物页签(默认)
("scene-assets", "/assets"), # 点「场景」页签
("voice-assets", "/assets"), # 点「声线」页签
("storyboard", f"/projects/{PROJECT}/storyboard"),
("storyboard-inspector", None), # 分镜 + ?shot= 打开检查器
("dispatch", f"/projects/{PROJECT}/dispatch"),
("review", f"/projects/{PROJECT}/review"),
("timeline", f"/projects/{PROJECT}/timeline"),
("delivery", f"/projects/{PROJECT}/delivery"),
]
ASSET_TABS = {"scene-assets": "场景", "voice-assets": "声线"}
def main() -> int:
os.makedirs(DEST, exist_ok=True)
with sync_playwright() as p:
b = p.chromium.launch()
pg = b.new_context(viewport={"width": W, "height": H}, device_scale_factor=2).new_page()
login(pg)
shot_id = first_shot(pg)
for name, route in SHOTS:
if route is None: # 检查器特写
pg.goto(f"{BASE}/projects/{PROJECT}/storyboard?shot={shot_id}", wait_until="networkidle")
pg.wait_for_timeout(1800)
else:
pg.goto(BASE + route, wait_until="networkidle")
pg.wait_for_timeout(1500)
tab = ASSET_TABS.get(name)
if tab:
click_tab(pg, tab)
save(pg, name)
b.close()
return 0
def login(pg) -> None:
"""主题必须在 goto 之后写:首帧脚本读 localStorage 定底色,先写会被登录页重定向冲掉。"""
pg.goto(BASE + "/login", wait_until="networkidle")
pg.evaluate("() => localStorage.setItem('nex-the','light')")
pg.goto(BASE + "/login", wait_until="networkidle")
pg.fill("#login-user", "admin")
pg.fill("#login-pass", "admin1234")
pg.click("button[type=submit]")
pg.wait_for_url(BASE + "/")
pg.wait_for_timeout(800)
def first_shot(pg):
"""检查器要停在一镜真实数据上:镜头 id 从看板接口取,别硬编码。"""
return pg.evaluate(
"""() => fetch(`/api/projects/%d/shots/board`)
.then(r => r.json())
.then(d => (d.shots || d.items || d)[0]?.id)""" % PROJECT
)
def click_tab(pg, label: str) -> None:
"""平台资产库的大分类是页签(`Tabs`),没有 URL 参数,只能点。"""
ok = pg.evaluate(
"""(label) => {
const hit = [...document.querySelectorAll('[role=tab], .ant-tabs-tab, button')]
.find((n) => (n.innerText || '').trim().startsWith(label));
if (hit) hit.click();
return !!hit;
}""",
label,
)
print(f" 页签 {label} -> {ok}")
pg.wait_for_timeout(1200)
def save(pg, name: str) -> None:
pg.wait_for_timeout(900)
pg.evaluate("() => window.scrollTo(0,0)")
pg.wait_for_timeout(250)
buf = pg.screenshot(type="png", clip={"x": 0, "y": 0, "width": W, "height": H})
im = Image.open(io.BytesIO(buf)).convert("RGB")
if im.width != W:
im = im.resize((W, int(im.height * W / im.width)), Image.LANCZOS)
path = f"{DEST}/{name}.png"
im.save(path, optimize=True)
print(f"shot {name:24s} {im.size} {os.path.getsize(path) // 1024} KB")
if __name__ == "__main__":
sys.exit(main())