66 lines
2.3 KiB
Svelte
66 lines
2.3 KiB
Svelte
<script lang="ts">
|
|
import { createQuery, useQueryClient } from "@tanstack/svelte-query";
|
|
import Modal from "$lib/components/ui/Modal.svelte";
|
|
import { agentApi, resultsApi, type WorkbenchStageKey } from "$lib/api";
|
|
import { toast } from "$lib/toast";
|
|
let { jobId, onclose }: { jobId: number | null; onclose: () => void } =
|
|
$props();
|
|
const client = useQueryClient();
|
|
const projects = createQuery({
|
|
queryKey: ["b4-projects"],
|
|
queryFn: agentApi.listLinkableProjects,
|
|
});
|
|
let projectId = $state<number | null>(null);
|
|
let stage = $state<WorkbenchStageKey>("assets");
|
|
let busy = $state(false),
|
|
error = $state("");
|
|
async function store() {
|
|
if (!jobId || !projectId || busy) return;
|
|
busy = true;
|
|
error = "";
|
|
try {
|
|
const res = await resultsApi.store({
|
|
job_id: jobId,
|
|
project_id: projectId,
|
|
stage_key: stage,
|
|
});
|
|
await client.invalidateQueries({ queryKey: ["workbench", projectId] });
|
|
toast.success(
|
|
res.already_attached
|
|
? "该结果已存入此阶段"
|
|
: "已存入项目草稿,等待确认",
|
|
);
|
|
onclose();
|
|
} catch (e) {
|
|
error = e instanceof Error ? e.message : String(e);
|
|
} finally {
|
|
busy = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<Modal open={jobId != null} title="存入项目草稿" {onclose} dismissible={!busy}>
|
|
<p>选择项目和阶段,结果将在该阶段等待确认。</p>
|
|
<label class="field"
|
|
>项目<select aria-label="存入项目" bind:value={projectId}
|
|
><option value={null}>选择项目</option
|
|
>{#each $projects.data ?? [] as p (p.id)}<option value={p.id}
|
|
>{p.title}</option
|
|
>{/each}</select
|
|
></label
|
|
>
|
|
<label class="field"
|
|
>阶段<select aria-label="存入阶段" bind:value={stage}
|
|
>{#each [["script", "剧本创作"], ["style", "视觉设计"], ["storyboard", "分镜设计"], ["assets", "素材资产"], ["shot", "镜头脚本"]] as [value, label] (value)}<option
|
|
{value}>{label}</option
|
|
>{/each}</select
|
|
></label
|
|
>
|
|
{#if error}<p role="alert">{error}</p>{/if}
|
|
{#snippet footer()}<button class="a-btn" disabled={busy} onclick={onclose}
|
|
>取消</button
|
|
><button class="a-btn primary" disabled={!projectId || busy} onclick={store}
|
|
>存入待确认草稿</button
|
|
>{/snippet}
|
|
</Modal>
|