PRINTFILM: AI short-video marketing and AI short-drama creation platform
feat(drama): 优化项目创建并恢复多集规划
yi1c7a12535086
diff --git a/backend/app/api/team_content.py b/backend/app/api/team_content.pyindex 5a970cf..6e46360 100644--- a/backend/app/api/team_content.py+++ b/backend/app/api/team_content.py@@ -21,7 +21,7 @@ class TeamProjectCreate(BaseModel):title: str = Field(min_length=1, max_length=200)description: str = Field(default="", max_length=512)source: str = Field(min_length=20, max_length=100000)- episode_count: int = Field(default=12, strict=True, ge=1, le=120)+ episode_count: int = Field(default=1, strict=True, ge=1, le=120, description="初始集数,支持 1 至 120 集,后续可在项目中增加分集")workflow: Literal["script", "canvas"] = "script"diff --git a/backend/app/schemas_drama.py b/backend/app/schemas_drama.pyindex b53ac38..7c72898 100644--- a/backend/app/schemas_drama.py+++ b/backend/app/schemas_drama.py@@ -16,7 +16,7 @@ class DramaProjectCreate(BaseModel):title: str = Field(default="未命名漫剧", max_length=200)description: str | None = Nonesource: str = Field(default="", description="原始创意文案")- episode_count: int = Field(default=12, ge=1, le=120)+ episode_count: int = Field(default=1, strict=True, ge=1, le=120, description="初始集数,支持 1 至 120 集,后续可在项目中增加分集")image_style_id: str = Field(default="")# script=大纲分集流程;canvas=自由画布workflow: str = Field(default="script", description="script | canvas")diff --git a/backend/tests/test_drama_workflow_listing.py b/backend/tests/test_drama_workflow_listing.pyindex 585caf0..3e7905b 100644--- a/backend/tests/test_drama_workflow_listing.py+++ b/backend/tests/test_drama_workflow_listing.py@@ -2,11 +2,43 @@import pytest+from sqlalchemy import select+from app.models_drama import DramaProject, DramaScript+from app.models_tasks import TaskRunfrom tests.test_team_drama_integration import drama_api # noqa: F401from tests.test_teams_api import teams_api # noqa: F401+async def test_new_drama_preserves_selected_episode_count_without_changing_legacy_projects(drama_api):+ """初始集数支持 1 至 120 集,严格拒绝非法值并保持项目与剧本一致。"""+ a = drama_api+ payload = {"title": "雨夜来信", "source": "一个年轻的邮差在雨夜收到一封写给未来自己的信,决定寻找写信的人。"}+ for episode_count in [0, 121, 1.5, "1", True]:+ response = await a.client.post("/api/drama/projects", json={**payload, "episode_count": episode_count})+ assert response.status_code == 422, response.text+ for episode_count in [1, 12, 120]:+ created = await a.client.post("/api/drama/projects", json={**payload, "episode_count": episode_count, "params": {"episode_count": 5}})+ assert created.status_code == 200, created.text+ body = created.json()+ assert body["params"]["episode_count"] == episode_count+ assert body["script"]["params"]["episode_count"] == episode_count+ assert await a.db.scalar(select(TaskRun.id).where(TaskRun.drama_project_id == body["id"])) is None+ # 通用 params 不能覆盖受控的初始集数。+ created = await a.client.post("/api/drama/projects", json={**payload, "params": {"episode_count": 12}})+ assert created.status_code == 200, created.text+ body = created.json()+ assert body["params"]["episode_count"] == 1+ assert body["script"]["params"]["episode_count"] == 1+ legacy = DramaProject(user_id=a.owner.id, title="旧多集作品", params={"workflow": "script", "episode_count": 12})+ a.db.add(legacy)+ await a.db.commit()+ loaded = await a.client.get(f"/api/drama/projects/{legacy.id}")+ assert loaded.status_code == 200, loaded.text+ assert loaded.json()["params"]["episode_count"] == 12++@pytest.mark.asyncioasync def test_workflow_list_keeps_legacy_projects_and_unfiltered_contract(drama_api):a = drama_apidiff --git a/backend/tests/test_team_content.py b/backend/tests/test_team_content.pyindex 4b00275..430d454 100644--- a/backend/tests/test_team_content.py+++ b/backend/tests/test_team_content.py@@ -67,14 +67,23 @@ async def test_team_content_create_requires_real_source(content_api):"""创建沿用真实漫剧数据结构;短创意被拒绝,不伪造创意或启动生成。"""a = content_apipath = f"/api/teams/{a.team_id}/projects"- assert (await a.client.post(path, json={"title": "测试", "source": "太短", "episode_count": 2})).status_code == 422+ assert (await a.client.post(path, json={"title": "测试", "source": "太短", "episode_count": 1})).status_code == 422source = "这是由用户亲自提供的一段足够长的原始创意,用于创建真实团队项目。"- created = await a.client.post(path, json={"title": "新作品", "source": source, "episode_count": 3})- assert created.status_code == 201, created.text- body = created.json()- assert body["team_id"] == a.team_id- assert body["script"]["source"] == source- assert await a.db.scalar(select(TaskRun.id).where(TaskRun.drama_project_id == body["id"])) is None+ for episode_count in [0, 121, 1.5, "1", True]:+ invalid = await a.client.post(path, json={"title": "新作品", "source": source, "episode_count": episode_count})+ assert invalid.status_code == 422, invalid.text+ for requested_count in [None, 3, 120]:+ payload = {"title": "新作品", "source": source}+ if requested_count is not None:+ payload["episode_count"] = requested_count+ created = await a.client.post(path, json=payload)+ assert created.status_code == 201, created.text+ body = created.json()+ assert body["team_id"] == a.team_id+ assert body["script"]["source"] == source+ assert body["params"]["episode_count"] == (requested_count or 1)+ assert body["script"]["params"]["episode_count"] == (requested_count or 1)+ assert await a.db.scalar(select(TaskRun.id).where(TaskRun.drama_project_id == body["id"])) is None@pytest.mark.asynciodiff --git a/frontend/src/components/projects/ProjectCreateDialog.tsx b/frontend/src/components/projects/ProjectCreateDialog.tsxindex ff3e528..a47f468 100644--- a/frontend/src/components/projects/ProjectCreateDialog.tsx+++ b/frontend/src/components/projects/ProjectCreateDialog.tsx@@ -3,8 +3,7 @@ import { ArrowUpRight, Check, Clapperboard, LayoutGrid, LoaderCircle, Sparkles }import Modal from '../ui/Modal'import Button from '../ui/Button'import { DramaImageStyleModal } from '../../pages/drama/DramaImageStyleModal'-import { EPISODE_COUNT_PRESETS } from '../../lib/dramaImageStyles'-import { validateProjectCreate, type ProjectCreateConstraints, type ProjectCreateDraft, type ProjectCreateErrors, type ProjectCreateValues } from '../../lib/projectCreateForm'+import { PROJECT_EPISODE_MAX, validateProjectCreate, type ProjectCreateConstraints, type ProjectCreateDraft, type ProjectCreateErrors, type ProjectCreateValues } from '../../lib/projectCreateForm'import './project-create.css'export type { ProjectCreateValues } from '../../lib/projectCreateForm'@@ -19,12 +18,13 @@ export type ProjectCreateDialogProps = ProjectCreateConstraints & {footerNote?: string}-/** One creation flow for personal projects, team projects, and free canvases. */+/** 个人、团队和自由画布共用创建流程,关闭后清空草稿。 */export default function ProjectCreateDialog({ open, ...props }: ProjectCreateDialogProps) {// Unmount the form on close so a new opening always starts with clean inputs.return open ? <ProjectCreateDialogForm key={`${props.kind}:${props.contextLabel || ''}`} {...props} /> : null}+/** 故事与项目名称为主栏,集数和画风在旁栏统一配置。 */function ProjectCreateDialogForm({onClose,onSubmit,@@ -39,21 +39,24 @@ function ProjectCreateDialogForm({}: Omit<ProjectCreateDialogProps, 'open'>) {const formId = useId()const canvas = kind === 'canvas'- const [draft, setDraft] = useState<ProjectCreateDraft>({ title: canvas ? '未命名画布' : '', source: '', description: '', episodeCount: '12', imageStyleId: '' })+ /* 保留集数输入原文,允许用户清空后重新输入;提交时统一校验。 */+ const [draft, setDraft] = useState<ProjectCreateDraft>({ title: canvas ? '未命名画布' : '', source: '', description: '', imageStyleId: '', episodeCount: '1' })const [errors, setErrors] = useState<ProjectCreateErrors>({})const [error, setError] = useState('')const [busy, setBusy] = useState(false)const submitting = useRef(false)const Icon = canvas ? LayoutGrid : Clapperboard- const title = canvas ? '新建自由画布' : '新建漫剧项目'+ const title = canvas ? '新建自由画布' : '新建项目'const sourceLength = draft.source.trim().length+ /** 修改字段后清理对应错误,保留其他输入。 */function update<K extends keyof ProjectCreateDraft>(key: K, value: ProjectCreateDraft[K]) {setDraft((current) => ({ ...current, [key]: value }))if (key in errors) setErrors((current) => ({ ...current, [key]: undefined }))setError('')}+ /** 先校验并定位错误,再防重提交,失败时保留草稿。 */async function submit(event: FormEvent) {event.preventDefault()if (submitting.current) return@@ -78,19 +81,46 @@ function ProjectCreateDialogForm({const fieldError = (name: keyof ProjectCreateErrors) => errors[name] ? <span className="pf-project-create-field-error" id={`${formId}-${name}-error`} role="alert">{errors[name]}</span> : nullreturn <Modal open onClose={onClose} dismissible={!busy} title={title} size="lg" className="pf-project-create-modal" footer={<>- <p className="pf-project-create-footer-note">{footerNote || (canvas ? '先创建画布,再自由添加图片、视频与灵感。' : '创建后进入项目,可继续完善故事与分集。')}</p>+ <p className="pf-project-create-footer-note">{footerNote || (canvas ? '先创建画布,再自由添加图片、视频与灵感。' : '按故事与集数创建项目,进入后继续完善分集。')}</p><div className="pf-project-create-actions"><Button onClick={onClose} disabled={busy}>取消</Button><Button variant="lime" type="submit" form={formId} disabled={busy}>{busy ? <><LoaderCircle size={16} className="pf-project-create-spinner" />正在创建…</> : <>{submitLabel || (canvas ? '创建画布' : '创建项目')}<ArrowUpRight size={16} /></>}</Button></div></>}><form id={formId} className="pf-project-create-form" onSubmit={submit} noValidate aria-busy={busy}>- <div className="pf-project-create-intro"><span className="pf-project-create-icon"><Icon size={24} strokeWidth={1.6} /></span><div><span className="pf-project-create-context">{contextLabel}</span><h4>{canvas ? '给灵感一张自由的画布' : '从一个好故事开始'}</h4><p>{canvas ? '把图片、视频和想法放在一起,自由连接与创作。' : '写下人物、冲突和故事走向,让创作有一个清晰的起点。'}</p></div></div>+ <div className="pf-project-create-intro">+ <span className="pf-project-create-icon"><Icon size={23} strokeWidth={1.6} aria-hidden /></span>+ <div><span className="pf-project-create-context">{contextLabel}{!canvas && <span className="pf-project-create-mode">漫剧自建算力模式</span>}</span><h4>{canvas ? '给灵感一张自由的画布' : '从一个好故事开始'}</h4><p>{canvas ? '把图片、视频和想法放在一起,自由连接与创作。' : '写下故事,设定集数与画风,开始构建你的作品。'}</p></div>+ </div>- <label className="pf-project-create-field" htmlFor={`${formId}-title`}><span className="pf-project-create-label">{canvas ? '画布名称' : '项目名称'}{!canvas && !titleRequired && <small>选填,留空将根据故事命名</small>}</span><input id={`${formId}-title`} autoFocus value={draft.title} disabled={busy} onChange={(event) => update('title', event.target.value)} placeholder={canvas ? '为这张画布取个名字' : '例如:雨夜来信'} maxLength={titleMaxLength} aria-invalid={!!errors.title} aria-describedby={errors.title ? `${formId}-title-error` : undefined} required={canvas || titleRequired} />{fieldError('title')}</label>+ <div className={`pf-project-create-layout${canvas ? ' pf-project-create-layout--canvas' : ''}`}>+ <div className="pf-project-create-main">+ <label className="pf-project-create-field" htmlFor={`${formId}-title`}>+ <span className="pf-project-create-label">{canvas ? '画布名称' : '项目名称'}{!canvas && !titleRequired && <small>选填,留空自动命名</small>}</span>+ <input id={`${formId}-title`} autoFocus value={draft.title} disabled={busy} onChange={(event) => update('title', event.target.value)} placeholder={canvas ? '为这张画布取个名字' : '例如:雨夜来信'} maxLength={titleMaxLength} aria-invalid={!!errors.title} aria-describedby={errors.title ? `${formId}-title-error` : undefined} required={canvas || titleRequired} />{fieldError('title')}+ </label>- {!canvas && <label className="pf-project-create-field pf-project-create-story" htmlFor={`${formId}-source`}><span className="pf-project-create-label">故事内容<span className="pf-project-create-required">必填</span></span><textarea id={`${formId}-source`} value={draft.source} disabled={busy} onChange={(event) => update('source', event.target.value)} rows={6} placeholder={'主角是谁?他遇到了什么麻烦,又想得到什么?\n\n写下故事创意,或粘贴已有的故事与剧本。'} maxLength={sourceMaxLength} aria-invalid={!!errors.source} aria-describedby={`${formId}-source-hint${errors.source ? ` ${formId}-source-error` : ''}`} required /><span className={`pf-project-create-input-meta${sourceLength >= 20 ? ' is-ready' : ''}`} id={`${formId}-source-hint`}><span>{sourceLength >= 20 ? <><Check size={13} />故事已就绪</> : '至少 20 字,建议包含人物与核心冲突'}</span><span>{sourceLength.toLocaleString()} / {sourceMaxLength.toLocaleString()}</span></span>{fieldError('source')}</label>}+ {!canvas && <label className="pf-project-create-field pf-project-create-story" htmlFor={`${formId}-source`}>+ <span className="pf-project-create-label">故事内容<span className="pf-project-create-required">必填</span></span>+ <textarea id={`${formId}-source`} value={draft.source} disabled={busy} onChange={(event) => update('source', event.target.value)} rows={8} placeholder={'故事从谁开始?发生了什么冲突?\n\n写下创意,或粘贴已有故事与剧本。'} maxLength={sourceMaxLength} aria-invalid={!!errors.source} aria-describedby={`${formId}-source-hint${errors.source ? ` ${formId}-source-error` : ''}`} required />+ <span className={`pf-project-create-input-meta${sourceLength >= 20 ? ' is-ready' : ''}`} id={`${formId}-source-hint`}><span>{sourceLength >= 20 ? <><Check size={13} />故事已就绪</> : '至少 20 字,包含人物与核心冲突'}</span><span>{sourceLength.toLocaleString()} / {sourceMaxLength.toLocaleString()}</span></span>{fieldError('source')}+ </label>}- {!canvas && <div className={`pf-project-create-settings${!allowImageStyle ? ' pf-project-create-settings--single' : ''}`}><fieldset className="pf-project-create-episodes" disabled={busy}><legend>计划集数 <small>后续可调整</small></legend><div className="pf-project-create-episode-presets">{EPISODE_COUNT_PRESETS.map((count) => <button key={count} type="button" aria-pressed={Number(draft.episodeCount) === count} onClick={() => update('episodeCount', String(count))}>{count} 集</button>)}</div><label className="pf-project-create-episode-custom" htmlFor={`${formId}-episodeCount`}><span>自定义</span><input id={`${formId}-episodeCount`} type="number" value={draft.episodeCount} onChange={(event) => update('episodeCount', event.target.value)} min={1} max={120} step={1} inputMode="numeric" aria-invalid={!!errors.episodeCount} aria-describedby={`${formId}-episodeCount-hint${errors.episodeCount ? ` ${formId}-episodeCount-error` : ''}`} required /><span>集</span><small id={`${formId}-episodeCount-hint`}>1–120 集</small></label>{fieldError('episodeCount')}</fieldset>{allowImageStyle && <div className="pf-project-create-style"><span className="pf-project-create-label"><Sparkles size={14} />画面风格<small>选填</small></span><DramaImageStyleModal value={draft.imageStyleId} onChange={(value) => update('imageStyleId', value)} disabled={busy} variant="field" fieldLabel="" emptyLabel="选择画面风格" /><p>为角色和场景设置统一的视觉方向。</p></div>}</div>}+ <details className="pf-project-create-description" open={canvas || undefined}>+ <summary>{canvas ? '画布说明' : '补充项目简介'}<span>选填</span></summary>+ <label className="pf-project-create-field" htmlFor={`${formId}-description`}><span className="pf-project-create-sr-only">{canvas ? '画布说明' : '项目简介'}</span><textarea id={`${formId}-description`} value={draft.description} onChange={(event) => update('description', event.target.value)} rows={3} maxLength={500} disabled={busy} placeholder={canvas ? '这张画布想探索什么?' : '用一两句话概括作品,方便在项目列表中识别。'} aria-invalid={!!errors.description} aria-describedby={errors.description ? `${formId}-description-error` : undefined} /><span className="pf-project-create-input-meta"><span>会显示在项目卡片中</span><span>{draft.description.trim().length} / 500</span></span>{fieldError('description')}</label>+ </details>+ </div>- <details className="pf-project-create-description" open={canvas || undefined}><summary>{canvas ? '画布说明' : '补充项目简介'}<span>选填</span></summary><label className="pf-project-create-field" htmlFor={`${formId}-description`}><span className="pf-project-create-sr-only">{canvas ? '画布说明' : '项目简介'}</span><textarea id={`${formId}-description`} value={draft.description} onChange={(event) => update('description', event.target.value)} rows={3} maxLength={500} disabled={busy} placeholder={canvas ? '这张画布想探索什么?' : '用一两句话概括作品,方便在项目列表中识别。'} aria-invalid={!!errors.description} aria-describedby={errors.description ? `${formId}-description-error` : undefined} /><span className="pf-project-create-input-meta"><span>会显示在项目卡片中</span><span>{draft.description.trim().length} / 500</span></span>{fieldError('description')}</label></details>+ {!canvas && <aside className="pf-project-create-settings" aria-label="创作设置">+ <div className="pf-project-create-episodes">+ <label className="pf-project-create-label" htmlFor={`${formId}-episodeCount`}>初始集数<small>1–{PROJECT_EPISODE_MAX} 集</small></label>+ <div className="pf-project-create-episode-presets" role="group" aria-label="常用集数">+ {[1, 3, 6, 12].map((count) => <button key={count} type="button" aria-pressed={Number(draft.episodeCount) === count} disabled={busy} onClick={() => update('episodeCount', String(count))}>{count}<span>集</span></button>)}+ </div>+ <div className="pf-project-create-episode-input"><input id={`${formId}-episodeCount`} type="number" inputMode="numeric" min={1} max={PROJECT_EPISODE_MAX} step={1} value={draft.episodeCount} disabled={busy} onChange={(event) => update('episodeCount', event.target.value)} aria-invalid={!!errors.episodeCount} aria-describedby={`${formId}-episodeCount-hint${errors.episodeCount ? ` ${formId}-episodeCount-error` : ''}`} required /><span>集</span></div>+ <p id={`${formId}-episodeCount-hint`}>支持自定义集数,后续可在项目中继续增加分集。</p>{fieldError('episodeCount')}+ </div>+ {allowImageStyle && <div className="pf-project-create-style"><span className="pf-project-create-label"><Sparkles size={14} aria-hidden />画面风格<small>选填</small></span><DramaImageStyleModal value={draft.imageStyleId} onChange={(value) => update('imageStyleId', value)} disabled={busy} variant="field" fieldLabel="" emptyLabel="选择画面风格" /><p>为角色和场景设置统一的视觉方向。</p></div>}+ </aside>}+ </div>{error && <div className="pf-project-create-error" role="alert">{error}</div>}</form></Modal>diff --git a/frontend/src/components/projects/project-create.css b/frontend/src/components/projects/project-create.cssindex a910f6e..188d483 100644--- a/frontend/src/components/projects/project-create.css+++ b/frontend/src/components/projects/project-create.css@@ -1,52 +1,58 @@-.pf-project-create-modal.pf-modal-panel { width: min(760px, calc(100vw - 32px)); max-height: min(92dvh, 940px); border-radius: 22px; background: #fff; }-.pf-project-create-modal .pf-modal-head { padding: 21px 28px 18px; flex-shrink: 0; }-.pf-project-create-modal .pf-modal-head h3 { color: #161c16; font-family: inherit; font-size: 18px; font-weight: 750; }-.pf-project-create-modal .pf-modal-body { padding: 25px 28px 26px; min-height: 0; overscroll-behavior: contain; }-.pf-project-create-form { display: flex; flex-direction: column; gap: 24px; }-.pf-project-create-intro { display: flex; align-items: flex-start; gap: 15px; padding: 1px 0 4px; }-.pf-project-create-icon { display: grid; place-items: center; flex-shrink: 0; width: 52px; height: 52px; border: 1px solid #e0e8d2; border-radius: 15px; background: #f0f7df; color: #3c4b26; }-.pf-project-create-context { display: block; margin-bottom: 6px; font-size: 10px; font-weight: 700; letter-spacing: .13em; color: #7e886f; }-.pf-project-create-intro h4 { margin: 0; color: #192016; font-size: 21px; line-height: 1.35; letter-spacing: -.03em; }-.pf-project-create-intro p { margin: 7px 0 0; color: #858e7e; font-size: 12px; line-height: 1.7; }-.pf-project-create-field { display: flex; flex-direction: column; gap: 10px; min-width: 0; }-.pf-project-create-label { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; color: #303b29; font-size: 13px; font-weight: 650; }-.pf-project-create-label small, .pf-project-create-episodes legend small { color: #949d8c; font-size: 11px; font-weight: 400; }+.pf-project-create-modal.pf-modal-panel { width: min(920px, 100%); max-height: min(90dvh, calc(100dvh - 40px)); border: 1px solid #e8ebe5; border-radius: 20px; background: #fff; }+.pf-project-create-modal .pf-modal-head { padding: 19px 28px; flex-shrink: 0; }+.pf-project-create-modal .pf-modal-head h3 { color: #20261d; font-family: inherit; font-size: 17px; font-weight: 700; }+.pf-project-create-modal .pf-modal-body { padding: 22px 28px 24px; min-height: 0; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #d4dacb transparent; }+.pf-project-create-form { display: flex; flex-direction: column; gap: 22px; }+.pf-project-create-intro { display: flex; align-items: center; gap: 14px; padding-bottom: 20px; border-bottom: 1px solid #edf0e9; }+.pf-project-create-icon { display: grid; place-items: center; flex-shrink: 0; width: 48px; height: 48px; border: 1px solid #e0e8d2; border-radius: 14px; background: #f1f8e5; color: #4d622e; }+.pf-project-create-context { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin-bottom: 7px; font-size: 10px; font-weight: 500; color: #8a9380; }+.pf-project-create-mode { padding: 3px 7px; border-radius: 5px; background: #f2f6e9; color: #687d45; font-size: 10px; }+.pf-project-create-intro h4 { margin: 0; color: #20261d; font-size: 21px; font-weight: 650; line-height: 1.4; letter-spacing: -.02em; }+.pf-project-create-intro p { margin: 5px 0 0; color: #8a9283; font-size: 12px; line-height: 1.7; }+.pf-project-create-layout { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(240px, 1fr); align-items: start; gap: 24px; }+.pf-project-create-layout--canvas { grid-template-columns: minmax(0, 1fr); }+.pf-project-create-main { display: flex; flex-direction: column; gap: 22px; min-width: 0; }+.pf-project-create-field { display: flex; flex-direction: column; gap: 9px; min-width: 0; }+.pf-project-create-label { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; color: #343e2c; font-size: 12px; font-weight: 650; }+.pf-project-create-label small { margin-left: auto; color: #929b87; font-size: 10px; font-weight: 400; }.pf-project-create-required { color: #7d886e; background: #f0f3e9; font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 400; }-.pf-project-create-field > input, .pf-project-create-field > textarea { box-sizing: border-box; width: 100%; min-width: 0; border: 1px solid #dfe4d8; border-radius: 12px; padding: 13px 15px; background: #fbfcf9; font: inherit; font-size: 14px; line-height: 1.75; color: #283222; transition: border-color .16s, box-shadow .16s, background .16s; }+.pf-project-create-field > input, .pf-project-create-field > textarea { box-sizing: border-box; width: 100%; min-width: 0; border: 1px solid #dfe4d8; border-radius: 10px; padding: 11px 13px; background: #fff; font: inherit; font-size: 13px; line-height: 1.7; color: #283222; transition: border-color .16s, box-shadow .16s, background .16s; }.pf-project-create-field > textarea { resize: vertical; min-height: 104px; max-height: 360px; }-.pf-project-create-story > textarea { min-height: 180px; background: #f9fbf5; font-size: 14px; line-height: 1.95; }+.pf-project-create-story > textarea { min-height: 230px; background: #fafbf8; font-size: 13px; line-height: 1.9; }.pf-project-create-field > input::placeholder, .pf-project-create-field > textarea::placeholder { color: #a1a996; }-.pf-project-create-field > input:focus, .pf-project-create-field > textarea:focus, .pf-project-create-episode-custom input:focus { outline: 0; border-color: #8da958; background: #fff; box-shadow: 0 0 0 3px #b6ff0022; }-.pf-project-create-field [aria-invalid="true"], .pf-project-create-episode-custom input[aria-invalid="true"] { border-color: #c9634a; }-.pf-project-create-input-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: #949c8b; font-size: 11px; line-height: 1.6; }+.pf-project-create-field > input:focus, .pf-project-create-field > textarea:focus { outline: 0; border-color: #9ab56b; background: #fff; box-shadow: 0 0 0 2px #b6ff001a; }+.pf-project-create-field [aria-invalid="true"] { border-color: #c9634a; }+.pf-project-create-input-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: #949c8b; font-size: 10px; line-height: 1.6; }.pf-project-create-input-meta > span:first-child { display: flex; align-items: center; gap: 4px; }.pf-project-create-input-meta > span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }.pf-project-create-input-meta.is-ready > span:first-child { color: #688237; }-.pf-project-create-settings { display: grid; grid-template-columns: 1.15fr 1fr; gap: 25px; padding: 20px; border: 1px solid #e8ebdf; border-radius: 14px; background: #fcfdfb; }-.pf-project-create-settings--single { grid-template-columns: 1fr; }-.pf-project-create-episodes { padding: 0; margin: 0; min-width: 0; border: 0; }-.pf-project-create-episodes legend { padding: 0; margin-bottom: 12px; color: #303b29; font-size: 13px; font-weight: 650; }-.pf-project-create-episodes legend small { margin-left: 6px; }-.pf-project-create-episode-presets { display: flex; flex-wrap: wrap; gap: 5px; }-.pf-project-create-episode-presets button { border: 1px solid #e0e5d6; border-radius: 7px; background: #fff; padding: 7px 10px; color: #76816a; font: inherit; font-size: 11px; cursor: pointer; }-.pf-project-create-episode-presets button[aria-pressed="true"] { border-color: #b9d676; background: #eafaC9; color: #3b4b21; font-weight: 700; }-.pf-project-create-episode-presets button:focus-visible, .pf-project-create-description summary:focus-visible, .pf-project-create-style button:focus-visible { outline: 2px solid #8da958; outline-offset: 3px; }-.pf-project-create-episode-custom { display: flex; align-items: center; gap: 7px; margin-top: 12px; color: #8d9782; font-size: 11px; }-.pf-project-create-episode-custom input { width: 57px; padding: 6px; border: 1px solid #dde3d3; border-radius: 7px; background: #fff; font: inherit; color: #303b29; text-align: center; }-.pf-project-create-episode-custom small { margin-left: auto; color: #a1aa97; white-space: nowrap; font-size: 10px; }-.pf-project-create-style { min-width: 0; padding-left: 24px; border-left: 1px solid #e6eadd; }+.pf-project-create-settings { display: flex; flex-direction: column; gap: 14px; min-width: 0; }+.pf-project-create-episodes, .pf-project-create-style { min-width: 0; padding: 17px; border: 1px solid #e7ebdf; border-radius: 12px; background: #f9fbf6; }+.pf-project-create-episode-presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 14px; }+.pf-project-create-episode-presets button { display: inline-flex; align-items: baseline; justify-content: center; gap: 3px; min-height: 35px; padding: 5px; border: 1px solid #e0e5d7; border-radius: 7px; background: #fff; color: #707e5d; font-size: 13px; font-weight: 600; cursor: pointer; }+.pf-project-create-episode-presets button span { font-size: 10px; font-weight: 400; }+.pf-project-create-episode-presets button:hover { border-color: #b4cc89; }+.pf-project-create-episode-presets button[aria-pressed="true"] { border-color: #b6d57f; background: #edf8d9; color: #3c5620; box-shadow: inset 0 0 0 1px #b6d57f33; }+.pf-project-create-episode-input { position: relative; display: flex; align-items: center; margin-top: 10px; }+.pf-project-create-episode-input input { width: 100%; min-width: 0; height: 42px; padding: 8px 38px 8px 12px; border: 1px solid #dfe4d6; border-radius: 8px; background: #fff; color: #2d3824; font: inherit; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }+.pf-project-create-episode-input > span { position: absolute; right: 28px; color: #939c87; font-size: 11px; pointer-events: none; }+.pf-project-create-episode-input input:focus { outline: 0; border-color: #9ab56b; box-shadow: 0 0 0 2px #b6ff001a; }+.pf-project-create-episode-input input[aria-invalid="true"] { border-color: #c9634a; }+.pf-project-create-episodes > p { margin: 10px 0 0; color: #919b84; font-size: 10px; line-height: 1.8; }+.pf-project-create-description summary:focus-visible, .pf-project-create-style button:focus-visible, .pf-project-create-episode-presets button:focus-visible { outline: 2px solid #8da958; outline-offset: 3px; }.pf-project-create-style > .pf-project-create-label { margin-bottom: 12px; }.pf-project-create-style .drama-style-picker-field { width: 100%; display: flex; }.pf-project-create-style .drama-style-picker-field-label:empty { display: none; }-.pf-project-create-style .drama-style-picker-trigger { width: 100%; max-width: 100%; min-height: 44px; border-color: #dde3d3; box-shadow: none; }+.pf-project-create-style .drama-style-picker-trigger { width: 100%; max-width: 100%; min-height: 52px; border: 1px solid #e3e8da; border-radius: 9px; background: #fff; box-shadow: none; }+.pf-project-create-style .drama-style-picker-thumb { width: 36px; height: 36px; flex: none; }.pf-project-create-style .drama-style-picker-text { flex: 1; text-align: left; color: #56624b; font-size: 12px; }.pf-project-create-style > p { margin: 9px 0 0; color: #9aa28f; font-size: 10px; line-height: 1.7; }-.pf-project-create-description > summary { width: fit-content; padding: 2px 0; color: #626f55; font-size: 12px; cursor: pointer; }+.pf-project-create-description > summary { width: fit-content; padding: 2px 0; color: #77816c; font-size: 11px; cursor: pointer; }.pf-project-create-description > summary > span { margin-left: 8px; color: #a1a996; font-size: 11px; }.pf-project-create-description[open] > summary { margin-bottom: 12px; }.pf-project-create-field-error { color: #b94e36; font-size: 11px; line-height: 1.65; }.pf-project-create-error { padding: 12px 15px; border: 1px solid #f0cdbc; border-radius: 10px; background: #fff5ef; color: #b14d32; font-size: 12px; line-height: 1.7; }-.pf-project-create-modal .pf-modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 19px 28px; background: #fcfdf9; flex-shrink: 0; }+.pf-project-create-modal .pf-modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 17px 28px; background: #fcfdfb; flex-shrink: 0; }.pf-project-create-footer-note { max-width: 360px; margin: 0; color: #909a82; font-size: 10px; line-height: 1.75; }.pf-project-create-actions { display: flex; gap: 9px; flex-shrink: 0; }.pf-project-create-actions .pf-btn { min-height: 42px; border-radius: 10px; font-size: 13px; }@@ -55,21 +61,25 @@.pf-project-create-form :disabled { cursor: wait; opacity: .65; }.pf-project-create-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }@keyframes pf-project-create-spin { to { transform: rotate(360deg); } }-@media (max-width: 620px) {- .pf-project-create-modal.pf-modal-panel { max-height: 94dvh; border-radius: 18px; width: calc(100vw - 24px); }- .pf-project-create-modal .pf-modal-head { padding: 18px 20px 15px; }- .pf-project-create-modal .pf-modal-body { padding: 20px; }+@media (max-width: 759px) {+ .pf-project-create-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }+ .pf-project-create-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }+ .pf-project-create-story > textarea { height: 170px; min-height: 170px; }+}+@media (max-width: 540px) {+ .pf-project-create-modal.pf-modal-panel { max-height: calc(100dvh - 40px); border-radius: 18px; width: 100%; }+ .pf-project-create-modal .pf-modal-head { padding: 17px 20px; }+ .pf-project-create-modal .pf-modal-body { padding: 18px 20px; }.pf-project-create-intro h4 { font-size: 18px; }.pf-project-create-icon { width: 44px; height: 44px; border-radius: 12px; }.pf-project-create-intro { gap: 12px; }- .pf-project-create-settings { grid-template-columns: 1fr; padding: 16px; gap: 20px; }- .pf-project-create-style { padding-left: 0; padding-top: 18px; border-left: 0; border-top: 1px solid #e6eadd; }+ .pf-project-create-settings { grid-template-columns: minmax(0, 1fr); gap: 12px; }.pf-project-create-modal .pf-modal-foot { flex-direction: column; align-items: stretch; padding: 14px 20px 18px; gap: 10px; }.pf-project-create-footer-note { max-width: none; }.pf-project-create-actions { justify-content: flex-end; }.pf-project-create-actions .pf-btn-lime { flex: 1; }.pf-project-create-input-meta { align-items: flex-start; font-size: 10px; }.pf-project-create-label small { font-size: 10px; }- .pf-project-create-field > input, .pf-project-create-field > textarea, .pf-project-create-episode-custom input { font-size: 16px; }+ .pf-project-create-field > input, .pf-project-create-field > textarea { font-size: 16px; }}@media (prefers-reduced-motion: reduce) { .pf-project-create-spinner { animation: none; } }diff --git a/frontend/src/lib/projectCreateForm.ts b/frontend/src/lib/projectCreateForm.tsindex 106dfb3..30c0f0a 100644--- a/frontend/src/lib/projectCreateForm.ts+++ b/frontend/src/lib/projectCreateForm.ts@@ -13,6 +13,9 @@ export type ProjectCreateValues = {export type ProjectCreateDraft = Omit<ProjectCreateValues, 'episodeCount'> & { episodeCount: string }export type ProjectCreateErrors = Partial<Record<'title' | 'source' | 'description' | 'episodeCount', string>>+/** 与个人和团队创建接口的集数边界保持一致。 */+export const PROJECT_EPISODE_MAX = 120+export type ProjectCreateConstraints = {kind: ProjectCreateKindtitleRequired?: boolean@@ -20,7 +23,7 @@ export type ProjectCreateConstraints = {sourceMaxLength?: number}-/** Reject invalid input before creating a project; never clamp an entered episode count. */+/** 校验故事、名称与分集规划;自由画布不使用分集和画风参数。 */export function validateProjectCreate(draft: ProjectCreateDraft,{ kind, titleRequired = false, titleMaxLength = 80, sourceMaxLength = 2000 }: ProjectCreateConstraints,@@ -28,7 +31,7 @@ export function validateProjectCreate(const title = draft.title.trim()const source = draft.source.trim()const description = draft.description.trim()- const episodeCount = kind === 'canvas' ? 1 : Number(draft.episodeCount)+ const episodeCount = Number(draft.episodeCount)const errors: ProjectCreateErrors = {}if ((kind === 'canvas' || titleRequired) && !title) errors.title = kind === 'canvas' ? '请填写画布名称' : '请填写项目名称'@@ -37,13 +40,11 @@ export function validateProjectCreate(if (kind === 'drama') {if (source.length < 20) errors.source = '故事内容至少 20 字,请补充人物、情节或冲突'else if (source.length > sourceMaxLength) errors.source = `故事内容请控制在 ${sourceMaxLength} 字以内`- if (!/^\d+$/.test(draft.episodeCount) || !Number.isInteger(episodeCount) || episodeCount < 1 || episodeCount > 120) {- errors.episodeCount = '请输入 1–120 之间的整数集数'- }+ if (!Number.isInteger(episodeCount) || episodeCount < 1 || episodeCount > PROJECT_EPISODE_MAX) errors.episodeCount = `请输入 1–${PROJECT_EPISODE_MAX} 之间的整数集数`}return {- values: { title, source: kind === 'canvas' ? '' : source, description, episodeCount, imageStyleId: kind === 'canvas' ? '' : draft.imageStyleId },+ values: { title, source: kind === 'canvas' ? '' : source, description, episodeCount: kind === 'canvas' ? 1 : episodeCount, imageStyleId: kind === 'canvas' ? '' : draft.imageStyleId },errors,}}diff --git a/frontend/tests/project-create-form.test.mjs b/frontend/tests/project-create-form.test.mjsindex 11d9767..398f312 100644--- a/frontend/tests/project-create-form.test.mjs+++ b/frontend/tests/project-create-form.test.mjs@@ -2,20 +2,30 @@ import assert from 'node:assert/strict'import test from 'node:test'import { validateProjectCreate } from '../src/lib/projectCreateForm.ts'-const draft = (overrides = {}) => ({ title: '', source: '一个年轻的邮差在雨夜收到一封写给未来自己的信。', description: '', episodeCount: '12', imageStyleId: '', ...overrides })+const draft = (overrides = {}) => ({ title: '', source: '一个年轻的邮差在雨夜收到一封写给未来自己的信。', description: '', imageStyleId: '', episodeCount: '1', ...overrides })-test('personal drama accepts an optional name and trims fields without changing episode count', () => {- const { values, errors } = validateProjectCreate(draft({ source: ` ${draft().source} `, description: ' 一封来信 ', episodeCount: '120' }), { kind: 'drama' })+test('personal drama accepts an optional name, trims fields, and starts with one episode', () => {+ const { values, errors } = validateProjectCreate(draft({ source: ` ${draft().source} `, description: ' 一封来信 ' }), { kind: 'drama' })assert.deepEqual(errors, {})assert.equal(values.title, '')assert.equal(values.source, draft().source)assert.equal(values.description, '一封来信')- assert.equal(values.episodeCount, 120)+ assert.equal(values.episodeCount, 1)+})++test('personal and team creation preserve the selected episode count through 120 episodes', () => {+ for (const constraints of [{ kind: 'drama' }, { kind: 'drama', titleRequired: true }]) {+ for (const count of [1, 3, 6, 12, 25, 120]) {+ const { values, errors } = validateProjectCreate(draft({ title: '雨夜来信', episodeCount: String(count) }), constraints)+ assert.deepEqual(errors, {})+ assert.equal(values.episodeCount, count)+ }+ }})-test('invalid or fractional episode counts are rejected instead of silently clamped', () => {- for (const episodeCount of ['', '0', '121', '1.5', '-1', '1e2', 'Infinity']) {- assert.ok(validateProjectCreate(draft({ episodeCount }), { kind: 'drama' }).errors.episodeCount, episodeCount)+test('episode count rejects empty, fractional, and out of range values', () => {+ for (const count of ['', ' ', '0', '-1', '121', '1.5', 'abc', 'Infinity']) {+ assert.ok(validateProjectCreate(draft({ episodeCount: count }), { kind: 'drama' }).errors.episodeCount, count)}})