diff --git a/frontend/src/components/forms/SecretInput.tsx b/frontend/src/components/forms/SecretInput.tsx index b064e07..d0531b4 100644 --- a/frontend/src/components/forms/SecretInput.tsx +++ b/frontend/src/components/forms/SecretInput.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState, type InputHTMLAttributes } from 'react' +import { useEffect, useState, type InputHTMLAttributes, type Ref } from 'react' import { cn } from '../../lib/cn' import * as api from '../../api/client' import { EyeIcon } from './EyeIcon' @@ -27,6 +27,8 @@ export type SecretInputProps = { /** 取回明文的接口;不传就只做本地密文/明文切换 */ revealUrl?: string className?: string + /** React 19:ref 是普通 prop,跟着 rest 落到原生 input 上 */ + ref?: Ref } & Omit, 'value' | 'onChange' | 'id' | 'placeholder' | 'disabled' | 'className'> export function SecretInput({ diff --git a/frontend/src/components/ui/Page.tsx b/frontend/src/components/ui/Page.tsx new file mode 100644 index 0000000..b2b4c95 --- /dev/null +++ b/frontend/src/components/ui/Page.tsx @@ -0,0 +1,88 @@ +/** + * 页面级骨架(旧全局样式里的 header / .row / .between / .error / .sub)。 + * + * 这些不是"组件"那么重,但 13 个页面每一页都要用;写成一处的意义和 + * UI规范第二章一样:同一层级的东西在所有页面上量出来必须是同一个数。 + * 页面里再出现
就算抄回去了一遍。 + */ +import type { ReactNode } from 'react' +import { cn } from '../../lib/cn' + +/** 站内文字链配色(.link): 没有组件形态,用这个类名常量保持一致 */ +export const LINK_CLS = 'text-success text-caption no-underline hover:underline' + +/** + * 页头(旧
):左边「状态行 + 大标题」,右边整组动作。 + * 窄屏按旧站规则改成纵向堆叠,动作按钮拉满一行——两三个小按钮排在 + * 25px 标题右边,在 430px 屏上会挤成一团中文碎渣。 + */ +export function PageHead({ title, meta, eyebrow, actions, className }: { + title?: ReactNode; meta?: ReactNode; eyebrow?: ReactNode; actions?: ReactNode; className?: string +}) { + return ( +
+
+ {meta && {meta}} + {eyebrow &&
{eyebrow}
} + {title &&

{title}

} +
+ {actions && {actions}} +
+ ) +} + +/** 通用横排(.row):窄屏自动折行,同行控件等高由 --ctl-h 保证 */ +export function Row({ children, className, tight }: { children?: ReactNode; className?: string; tight?: boolean }) { + return ( +
+ {children} +
+ ) +} + +/** 两端对齐(.between):左说明右动作,窄屏折行后仍然左对齐 */ +export function Between({ children, className, tight }: { children?: ReactNode; className?: string; tight?: boolean }) { + return ( +
+ {children} +
+ ) +} + +/** 行内错误回显(.error):10px 红字,紧贴它说明的那个控件,不占提示条的位置 */ +export function ErrorText({ children, className }: { children?: ReactNode; className?: string }) { + if (!children) return null + return {children} +} + +/** 分节线(.sub):同一面板里两个话题之间用它,不要再塞一个 h3 */ +export function Sub({ children, className }: { children?: ReactNode; className?: string }) { + return
{children}
+} + +/** + * 两栏正文(.layout):主栏吃掉剩余宽度,侧栏最窄 300px。 + * ≤1100 收成单列——断点写在组件里,页面不许再为自己写 @media。 + */ +export function Layout({ children, className }: { children?: ReactNode; className?: string }) { + return ( +
*]:min-w-0 max-mid2:grid-cols-1', className)}> + {children} +
+ ) +} + +/** + * 一栏内的面板堆叠(.right)。 + * ≤1100 时 已经折成单列,这一层临时并排两列把宽度用掉; + * ≤900 再叠回来(max-* 变体按断点从宽到窄排进样式表,后者自然覆盖前者)。 + */ +export function Stack({ children, className }: { children?: ReactNode; className?: string }) { + return ( +
*]:min-w-0 ' + + 'max-mid2:grid max-mid2:grid-cols-2 max-mid2:gap-4 max-nav:flex max-nav:gap-[15px]', className)}> + {children} +
+ ) +} diff --git a/frontend/src/components/ui/Panel.tsx b/frontend/src/components/ui/Panel.tsx index bb5ac6d..83932c3 100644 --- a/frontend/src/components/ui/Panel.tsx +++ b/frontend/src/components/ui/Panel.tsx @@ -12,14 +12,22 @@ export function Panel({ children, className, style, pad = true }: { ) } -/** 面板头:标题 + 右侧动作。窄列必须允许换行,否则筛选控件会把面板内容顶出边界。 */ -export function PanelHead({ title, sub, right, className }: { - title?: ReactNode; sub?: ReactNode; right?: ReactNode; className?: string +/** + * 面板头:眉标 + 标题 + 右侧动作。 + * + * 旧站 25 处面板头全都是 +

,标题走的是全局 h2(17px); + * 第一版迁移手写成 14px 的 h3,整站面板标题比正文重不了多少,扫视时找不到锚点。 + * 窄列必须允许换行(旧站第二十章补的 .panel-head{flex-wrap:wrap}):两列栅格下 + * 每列只有 ~400px,筛选控件的最小宽度就超过整列,不换行会把内容压到相邻面板上。 + */ +export function PanelHead({ title, eyebrow, sub, right, className }: { + title?: ReactNode; eyebrow?: ReactNode; sub?: ReactNode; right?: ReactNode; className?: string }) { return (
*]:min-w-0', className)}>
- {title &&

{title}

} + {eyebrow && {eyebrow}} + {title &&

{title}

} {sub &&

{sub}

}
{right &&
{right}
} diff --git a/frontend/src/components/ui/index.ts b/frontend/src/components/ui/index.ts index db94a0c..7739667 100644 --- a/frontend/src/components/ui/index.ts +++ b/frontend/src/components/ui/index.ts @@ -1,6 +1,7 @@ export * from './Button' export * from './Status' export * from './Panel' +export * from './Page' export * from './Controls' export * from './Table' export * from './Overlay' diff --git a/frontend/src/hooks/index.ts b/frontend/src/hooks/index.ts index 5a05c42..9b0df1f 100644 --- a/frontend/src/hooks/index.ts +++ b/frontend/src/hooks/index.ts @@ -2,3 +2,4 @@ export * from './use-async' export * from './use-polling' export * from './use-outside-click' export * from './use-local-storage' +export * from './use-auto-refresh' diff --git a/frontend/src/pages/Account.tsx b/frontend/src/pages/Account.tsx index 730a9b8..adbe918 100644 --- a/frontend/src/pages/Account.tsx +++ b/frontend/src/pages/Account.tsx @@ -1,4 +1,182 @@ -/** 待迁移:我的账号(占位,见 .local/vue-ref/src/views/Account.vue) */ +/** + * 我的账号:基本资料、改密、登录设备。 + * + * 会话列表每 45 秒自己刷新(旧站是渲染不出界面的 ,现在是 useAutoRefresh)。 + * 只要资料改过没保存、或三个改密框里有字,就跳过刷新——把用户刚敲的内容冲掉, + * 是这种「顺手挂着轮询」的页面最容易犯的错。 + */ +import { useEffect, useState } from 'react' +import { useSearchParams } from 'react-router-dom' +import * as api from '../api/client' +import { fmtAgo, fmtTime } from '../lib/format' +import { useAutoRefresh } from '../hooks/use-auto-refresh' +import { SecretInput } from '../components/forms' +import { + Actions, Button, CardRow, Empty, ErrorText, Field, FormRow, Layout, Notice, PageHead, Panel, PanelHead, Stack, Tag +} from '../components/ui' +import { login, roleLabel, setUser, useAuthStore } from '../stores/auth' + +const RULES_HINT = '至少 8 位,且不能只有一类字符(字母 / 数字 / 符号至少两种)' + export default function Account() { - return
我的账号 迁移中…
+ const [params] = useSearchParams() + const auth = useAuthStore() + const [busy, setBusy] = useState('') + const [error, setError] = useState('') + const [notice, setNotice] = useState('') + const [sessions, setSessions] = useState([]) + const [profile, setProfile] = useState({ display_name: '', email: '' }) + const [savedSnapshot, setSavedSnapshot] = useState('') + const [pwd, setPwd] = useState({ current_password: '', new_password: '', confirm: '' }) + + const mustChange = params.get('must') === '1' || !!auth.user?.must_change_password + /** 资料改过没保存 / 改密框里有字 → 暂停轮询,别把用户刚敲的内容冲掉 */ + const formTouched = savedSnapshot !== JSON.stringify(profile) + || Boolean(pwd.current_password || pwd.new_password || pwd.confirm) + const role = roleLabel(auth.user?.role || '') + const isAdmin = auth.user?.role === 'admin' + + async function load(silent = true) { + if (!silent) setError('') + try { + const data = await api.get('/api/auth/me') + const user = data.user || auth.user + setUser(user) + const next = { display_name: user?.display_name || '', email: user?.email || '' } + setProfile(next) + setSessions(data.sessions || []) + setSavedSnapshot(JSON.stringify(next)) + } catch (exc: any) { + setError(exc?.message || String(exc)) + } + } + useEffect(() => { void load(false) }, []) + + async function saveProfile() { + setBusy('保存资料'); setError(''); setNotice('') + try { + setUser(await api.patch('/api/auth/me', { ...profile })) + setNotice('资料已更新。') + } catch (exc: any) { setError(exc?.message || String(exc)) } + finally { setBusy('') } + } + + async function changePassword() { + setError(''); setNotice('') + if (!pwd.current_password || !pwd.new_password) { setError('请填写当前密码与新密码'); return } + if (pwd.new_password !== pwd.confirm) { setError('两次输入的新密码不一致'); return } + setBusy('修改密码') + try { + const data = await api.post('/api/auth/password', { + current_password: pwd.current_password, new_password: pwd.new_password + }) + setUser(data.user || null) + setPwd({ current_password: '', new_password: '', confirm: '' }) + setNotice(`密码已更新,其它 ${data.revoked_sessions ?? 0} 个登录会话已注销。`) + await load() + } catch (exc: any) { setError(exc?.message || String(exc)) } + finally { setBusy('') } + } + + /** 首次登录的种子账号:改完密码就地重新签一次会话,确保 Cookie 属性是最新的 */ + async function relogin() { + if (!auth.user?.username || !pwd.new_password) return + try { await login(auth.user.username, pwd.new_password) } catch { /* 已经改完,重签失败不拦人 */ } + } + + async function revoke(row: any) { + setBusy('注销会话'); setError('') + try { + await api.del(`/api/auth/sessions/${row.id}`) + setSessions((list) => list.filter((item) => item.id !== row.id)) + setNotice(`已注销「${row.label}」的登录会话。`) + } catch (exc: any) { setError(exc?.message || String(exc)) } + finally { setBusy('') } + } + + useAutoRefresh(() => void load(), 45000, !!busy, !!busy || formTouched) + + return ( +
+ {role}} /> + + {mustChange && 这个账号还在使用初始密码,请先修改密码再开始制作。} + setNotice('')}>{notice} + {error} + + + + + + + + + setProfile((p) => ({ ...p, display_name: e.target.value }))} /> + + + setProfile((p) => ({ ...p, email: e.target.value }))} /> + + + + + + + + + + + + + setPwd((p) => ({ ...p, current_password: v }))} /> + + + setPwd((p) => ({ ...p, new_password: v }))} /> + + + setPwd((p) => ({ ...p, confirm: v }))} + onKeyUp={(e) => { if (e.key === 'Enter') void changePassword() }} /> + + + + + + + + + + + + + {!sessions.length + ? 只有一个当前会话,没有其它设备在线。 + : ( +
+ {sessions.map((row) => ( + 使用中 + : }> +

{row.ip || '未知 IP'} · 活跃于 {fmtAgo(row.last_seen_at)} · {fmtTime(row.expires_at)} 过期

+
+ ))} +
+ )} +
+
+
+
+ ) } diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index 3c73594..01b39e7 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -1,4 +1,107 @@ -/** 待迁移:登录(占位,见 .local/vue-ref/src/views/Login.vue) */ +/** + * 登录页(chromeless:不套顶栏/侧栏,也不拉需要鉴权的系统状态)。 + * + * 账号决定你能做什么:管理员管模型与账号,制作可以跑生产,观摩只读—— + * 这句话放在标题的 title 里,登录前不需要读一整段说明。 + */ +import { useEffect, useRef, useState, type FormEvent } from 'react' +import { useNavigate, useSearchParams } from 'react-router-dom' +import { SecretInput } from '../components/forms' +import { Button } from '../components/ui' +import { login, useAuthStore } from '../stores/auth' +import { setTheme, useAppliedTheme } from '../stores/theme' + export default function Login() { - return
登录 迁移中…
+ const navigate = useNavigate() + const [params] = useSearchParams() + const { offline, error: connError, hint, user } = useAuthStore() + const isLight = useAppliedTheme() === 'light' + const [form, setForm] = useState({ username: '', password: '' }) + const [busy, setBusy] = useState(false) + const [error, setError] = useState('') + const userRef = useRef(null) + const passRef = useRef(null) + + useEffect(() => { + /* 首次部署时库里只有一个种子账号,后端会把用户名带下来,省得用户猜 */ + setForm((f) => (f.username || !hint ? f : { ...f, username: hint })) + userRef.current?.focus() + }, [hint]) + + async function submit(event?: FormEvent) { + event?.preventDefault() + if (busy) return + if (!form.username.trim() || !form.password) { + setError('请输入用户名和密码') + return + } + setBusy(true) + setError('') + try { + const data = await login(form.username, form.password) + const next = String(params.get('next') || '').trim() + if (data?.user?.must_change_password) { + await navigate({ pathname: '/account', search: '?must=1' }, { replace: true }) + return + } + /* 只接受站内相对路径,//evil.com 这种会被当成外域跳走 */ + await navigate(next && next.startsWith('/') && !next.startsWith('//') ? next : '/', { replace: true }) + } catch (exc: any) { + setError(exc?.message || String(exc)) + setForm((f) => ({ ...f, password: '' })) + passRef.current?.focus() + } finally { + setBusy(false) + } + } + + return ( +
+ + +
+
+ + 长视频编导平台 + NEX ANIMATION STUDIO + +
+ +

登录以继续

+ + {params.get('loggedOut') === '1' && ( +

已退出登录。

+ )} + {offline && ( +

后端连接不上:{connError || '请确认服务已启动'}

+ )} + {error && ( +

{error}

+ )} + + + + + +

忘记密码请联系平台管理员在「用户管理」里重置。

+
+
+ ) } diff --git a/frontend/src/pages/ProjectDetail.tsx b/frontend/src/pages/ProjectDetail.tsx index 6ab2f04..95e4d6e 100644 --- a/frontend/src/pages/ProjectDetail.tsx +++ b/frontend/src/pages/ProjectDetail.tsx @@ -1,11 +1,144 @@ -/* 待迁移:项目工作台(占位,见 .local/vue-ref/src/views/ProjectDetail.vue) */ -import { Outlet } from 'react-router-dom' +/** + * 项目工作台外壳:标题行 + 可折叠「项目概况」+ 各业务页签()。 + * + * GL-1:项目概况(4 张指标卡 + 12 节点流程条)在桌面端同样要能收起。 + * 以前只有 ≤900px 才折叠,正文被顶出首屏 ≈470px,每个页签都要先滚一屏废话。 + * 折叠状态记在 project.ts(useBriefStore):分镜工作台也要能收起这块概况, + * 两处按钮共用同一份偏好,不会各说各话。 + */ +import { useEffect, useState } from 'react' +import { Link, Outlet, useNavigate, useParams } from 'react-router-dom' +import * as api from '../api/client' +import { allNodesDone, stageNote } from '../lib/pipeline' +import { fmtMoney, pct, statusLabel } from '../lib/format' +import { cn } from '../lib/cn' +import { + Button, Empty, ErrorText, Loading, Notice, Panel, PanelHead, Stat, StatGrid, Status, Tag, Value +} from '../components/ui' +import { WorkflowBar } from '../components/media/WorkflowBar' +import { loadProject, startPolling, stopPolling, useBriefStore, useProjectStore } from '../stores/project' export default function ProjectDetail() { + const { id: idParam } = useParams() + const id = Number(idParam) + const navigate = useNavigate() + const [error, setError] = useState('') + const [confirming, setConfirming] = useState(false) + const summaryOpen = useBriefStore((s) => s.open) + const setSummaryOpen = useBriefStore((s) => s.set) + const { project, workflow, stats, loading, error: storeError } = useProjectStore() + + const nextStep = workflow.find((s: any) => s.state === 'active' || s.state === 'failed') + /** 流程走完的项目不再报「当前节点:导出完整视频」,否则和旁边的「已交付」自相矛盾 */ + const flowDone = allNodesDone(workflow) + const flowNote = stageNote(project, workflow) + const taskHint = Object.entries(stats?.task_status || {}).map(([k, v]) => `${statusLabel(k)} ${v}`).join(' · ') + + /* 切项目:重新拉一次详情,并让轮询跟着新 id 走(卸载时一定停掉, + 否则离开工作台后每 6 秒还在请求上一个项目) */ + useEffect(() => { + if (!Number.isFinite(id)) return + setError('') + setConfirming(false) + void loadProject(id, false) + startPolling(id) + return stopPolling + }, [id]) + + async function removeProject() { + try { + await api.del(`/api/projects/${id}`, { purge_files: true }) + navigate('/') + } catch (exc: any) { + setError(exc?.message || String(exc)) + } + } + + if (loading && !project) return 正在载入项目… + + if (!project) { + return ( + + 未找到项目 #{id},可能已被删除。{' '} + 返回项目总览 + + ) + } + + const st = stats || {} return ( -
- 项目工作台迁移中… - +
+
+
+
+ ← 项目总览 + + {flowDone + ? {flowNote} + : 当前节点:{flowNote || project.stage_label}} +
+

{project.name}

+
+ {/* 项目状态由 project.ts 每 6 秒轮询,页面无需再单独刷新 */} +
+ +
+
+ + {error || storeError} + + {confirming && ( + setConfirming(false)}> +
+ 删除《{project.name}》会同时清除分镜、任务与已生成素材,确认? +
+ + +
+
+
+ )} + + {/* 折叠条在所有断点都可用:收起后这一行本身就是紧凑摘要,正文直接顶到首屏 */} + + +
+ + {st.shots_approved || 0} / {st.shots || 0}} + hint={`${statusLabel('failed')} ${st.shots_failed || 0} · ${st.shots_rejected || 0} 驳回`} /> + {(st.planned_duration || 0).toFixed(1)}s + / {(st.generated_duration || 0).toFixed(1)}s} + hint={`镜头合格进度 ${pct(st.progress_ratio)}`} /> + {st.tasks_active || 0} / {st.tasks || 0}} + hint={taskHint || '暂无任务'} /> + {fmtMoney(st.cost?.total_cost, st.cost?.currency)}} + hint={`${(st.exports || []).length} 个导出记录`} /> + + + + 下一步:{nextStep.label} — {nextStep.detail} : undefined} /> + + +
+ +
) }