添加seedance2.5

This commit is contained in:
Azmat@qq.com
2026-08-28 16:03:23 +08:00
parent c0a0b9603b
commit a618f02315
16 changed files with 416 additions and 80 deletions
@@ -1,17 +1,19 @@
// 自由创作·输入条工具栏:模型/模式/比例/分辨率/时长/种子 下拉 + 预估消耗 + 清空 + 生成。
// 约束联动(与后端校验一致):1080P/4K 仅标准档;切非标准档时分辨率自动回落 720P
// 模型下拉列后端返回的全部视频模型(FC_MODELS 只提供好看的标签)
// 约束联动(与后端校验一致):分辨率与时长档位取自所选模型的 metadata.capabilities,
// 换档时把超出新模型能力的选择夹回去。
import { useEffect, useRef, useState } from "react";
import { ArrowRight, ChevronDown } from "lucide-react";
import type { ModelConfig } from "../../types";
import {
DEFAULT_BILLING_RATES,
FC_DURATIONS,
FC_MODELS,
FC_RATIOS,
FC_RESOLUTIONS,
FC_STANDARD_MODEL,
MODE_LABELS,
estimateCost,
modelDurations,
modelResolutions,
type BillingRates,
type FreeMode,
type LocalRef
@@ -28,6 +30,7 @@ function FcDropdown({ label, display, items, onSelect, disabled }: {
}) {
const [open, setOpen] = useState(false);
const wrapRef = useRef<HTMLDivElement>(null);
const menuRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!open) return;
const onDown = (event: MouseEvent) => {
@@ -38,6 +41,15 @@ function FcDropdown({ label, display, items, onSelect, disabled }: {
document.addEventListener("keydown", onKey);
return () => { document.removeEventListener("mousedown", onDown); document.removeEventListener("keydown", onKey); };
}, [open]);
// 菜单封了高会滚动(时长有 27 档),打开时默认停在顶部会看不到当前选中项。
// 直接改菜单的 scrollTop,不用 scrollIntoView —— 后者会连带把整个页面滚一下。
useEffect(() => {
if (!open) return;
const menu = menuRef.current;
const active = menu?.querySelector<HTMLElement>(".fc-dd-item.selected");
if (!menu || !active) return;
menu.scrollTop = active.offsetTop - menu.clientHeight / 2 + active.offsetHeight / 2;
}, [open]);
return (
<div className={`fc-dd${open ? " open" : ""}`} ref={wrapRef}>
<button type="button" className="fc-chip" disabled={disabled} onClick={() => setOpen((v) => !v)} title={label}>
@@ -45,7 +57,7 @@ function FcDropdown({ label, display, items, onSelect, disabled }: {
<ChevronDown />
</button>
{open && (
<div className="fc-dd-menu">
<div className="fc-dd-menu" ref={menuRef}>
{items.map((item) => (
<button
key={item.value}
@@ -86,8 +98,10 @@ export function FreeToolbar({ mode, model, ratio, resolution, duration, seed, re
onClear: () => void;
onSend: () => void;
}) {
const isStandard = model === FC_STANDARD_MODEL;
const config = videoConfigs.find((c) => c.name === model);
// 可选的分辨率/时长按所选模型的能力来,不再写死 —— Seedance 2.5 能出 30 秒,2.0 只有 15。
const allowedResolutions = modelResolutions(config);
const allowedDurations = modelDurations(config);
const { tokens, points } = estimateCost(config, { ratio, resolution, duration, refs }, billingRates || DEFAULT_BILLING_RATES);
const [seedOpen, setSeedOpen] = useState(false);
const seedRef = useRef<HTMLDivElement>(null);
@@ -106,11 +120,23 @@ export function FreeToolbar({ mode, model, ratio, resolution, duration, seed, re
<div className="fc-chips">
<FcDropdown
label="模型"
display={FC_MODELS.find((m) => m.name === model)?.label || model}
items={FC_MODELS.map((m) => ({ value: m.name, label: m.label, desc: m.desc }))}
display={FC_MODELS.find((m) => m.name === model)?.label || config?.display_name || model}
items={videoConfigs.map((c) => {
const known = FC_MODELS.find((m) => m.name === c.name);
return { value: c.name, label: known?.label || c.display_name || c.name, desc: known?.desc };
})}
onSelect={(value) => {
onModelChange(value);
if (value !== FC_STANDARD_MODEL && (resolution === "1080p" || resolution === "4k")) onResolutionChange("720p");
// 换档后把分辨率/时长夹回新模型支持的范围,否则会带着上一档的选择提交然后被后端拒
const next = videoConfigs.find((c) => c.name === value);
const resolutions = modelResolutions(next);
if (!resolutions.includes(resolution)) {
onResolutionChange(resolutions.includes("720p") ? "720p" : resolutions[0]);
}
const durations = modelDurations(next);
if (!durations.includes(duration)) {
onDurationChange(durations.includes(5) ? 5 : durations[0]);
}
}}
/>
<FcDropdown
@@ -129,15 +155,15 @@ export function FreeToolbar({ mode, model, ratio, resolution, duration, seed, re
items={FC_RESOLUTIONS.map((r) => ({
value: r,
label: r.toUpperCase(),
disabled: (r === "1080p" || r === "4k") && !isStandard,
hint: "仅 Seedance 2.0 标准档支持"
disabled: !allowedResolutions.includes(r),
hint: "当前模型不支持这一档"
}))}
onSelect={onResolutionChange}
/>
<FcDropdown
label="时长"
display={`${duration}s`}
items={FC_DURATIONS.map((d) => ({ value: String(d), label: `${d}s` }))}
items={allowedDurations.map((d) => ({ value: String(d), label: `${d}s` }))}
onSelect={(value) => onDurationChange(Number(value))}
/>
<div className={`fc-dd${seedOpen ? " open" : ""}`} ref={seedRef}>