819 lines
42 KiB
Vue
819 lines
42 KiB
Vue
<script setup lang="ts">
|
||
import { userFacingText } from '../../lib/user-facing-text'
|
||
import { isOperationRunning } from '../workflows/operations'
|
||
|
||
import ContextNotice from '../../components/ui/ContextNotice.vue'
|
||
|
||
import AppForm from '../../components/ui/AppForm.vue'
|
||
import { NFormItem } from 'naive-ui'
|
||
import { integerRule } from '../../lib/form-rules'
|
||
import WorkspacePage from '../../components/ui/WorkspacePage.vue'
|
||
import ActionMenu from '../../components/ui/ActionMenu.vue'
|
||
import DetailDisclosure from '../../components/ui/DetailDisclosure.vue'
|
||
import WorkspaceTools from '../../components/ui/WorkspaceTools.vue'
|
||
import { NButton, NCheckbox, NInput, NInputNumber, NPopover, NScrollbar, NSelect, NTag } from 'naive-ui'
|
||
import { computed, onScopeDispose, ref, useTemplateRef, watch, type Directive } from 'vue'
|
||
import { useRoute, useRouter } from 'vue-router'
|
||
import {
|
||
Search,
|
||
Download,
|
||
ImagePlus,
|
||
ArrowLeft,
|
||
LayoutGrid,
|
||
Columns3,
|
||
LoaderCircle,
|
||
Settings2,
|
||
ClipboardCheck
|
||
} from '@lucide/vue'
|
||
import { AssetImage, EmptyState, StatusBadge } from '../../components/ui'
|
||
import { downloadText } from '../../lib/format'
|
||
import ConfirmAction from '../workflows/ConfirmAction.vue'
|
||
import { useSubjectImages } from './useSubjectImages'
|
||
import { hasRunningImages, primaryImage, isIdentityAnchorReuse } from './model'
|
||
import ProjectWorkspaceSkeleton from '../projects/components/ProjectWorkspaceSkeleton.vue'
|
||
import type { SubjectFormAsset } from './types'
|
||
import GenerateImageDialog from './components/GenerateImageDialog.vue'
|
||
import ImagePreparationDrawer from './components/ImagePreparationDrawer.vue'
|
||
import ImageGalleryDialog from './components/ImageGalleryDialog.vue'
|
||
import FormPromptDialog from './components/FormPromptDialog.vue'
|
||
import FormPromptBatch from './components/FormPromptBatch.vue'
|
||
import { useKeyframeImpact } from './useKeyframeImpact'
|
||
import { queryText, referenceLocation, referenceTargets } from '../production/asset-links'
|
||
import { masonryColumnCount, masonryRowSpan, type GalleryLayout } from './layout'
|
||
|
||
/** 形态图库以正式数据库为准;首次读取、手动刷新和自身操作完成后更新,不定时刷新。 */
|
||
const route = useRoute()
|
||
const router = useRouter()
|
||
const {
|
||
id,
|
||
forms,
|
||
query,
|
||
generationModelsQuery,
|
||
profileQuery,
|
||
refreshProject,
|
||
operation,
|
||
session,
|
||
concurrency,
|
||
force,
|
||
limit,
|
||
promptConcurrency,
|
||
promptForce,
|
||
batchModule,
|
||
generatePrompt,
|
||
generatePrompts,
|
||
blocked,
|
||
running,
|
||
batchValid,
|
||
generate,
|
||
generateProject
|
||
} = useSubjectImages()
|
||
const sourceShotId = computed(() => queryText(route.query.sourceShotId))
|
||
const targetFormId = computed(() => queryText(route.query.subjectFormId))
|
||
const targetForm = computed(() => forms.value.find(form => form.id === targetFormId.value))
|
||
const impact = useKeyframeImpact(id, sourceShotId)
|
||
const sourceShot = impact.source
|
||
const linkedReferences = computed(() => referenceTargets(impact.references.data.value, []))
|
||
/** 定位说明仅在有实际状态、引用或错误时出现,避免两项导航操作单独撑起空白横条。 */
|
||
const sourceMissing = computed(
|
||
() => sourceShotId.value && !sourceShot.value && !impact.query.loading.value && !impact.query.error.value
|
||
)
|
||
const targetUnlinked = computed(
|
||
() =>
|
||
targetForm.value &&
|
||
impact.references.data.value &&
|
||
!impact.references.error.value &&
|
||
!impact.relatedForms.value.has(targetForm.value.id)
|
||
)
|
||
const showImpactDetails = computed(
|
||
() =>
|
||
sourceShotId.value &&
|
||
(sourceMissing.value ||
|
||
impact.query.error.value ||
|
||
targetUnlinked.value ||
|
||
linkedReferences.value.length ||
|
||
impact.references.loading.value ||
|
||
impact.references.error.value)
|
||
)
|
||
const sourceLocation = computed(() =>
|
||
sourceShot.value
|
||
? {
|
||
path: `/projects/${encodeURIComponent(id.value)}/production`,
|
||
query: { episodeNo: String(sourceShot.value.episodeNo), shotId: sourceShot.value.shotId }
|
||
}
|
||
: null
|
||
)
|
||
const toolsOpen = ref(false)
|
||
/** 免费检查图片阶段规格和母版依赖。 */
|
||
const preparationOpen = ref(false)
|
||
/** 移动端禁用纯图标按钮的悬浮说明,避免触摸操作弹出多余浮层。 */
|
||
const isMobile = ref(false)
|
||
if (typeof window !== 'undefined') {
|
||
const mobileMedia = window.matchMedia('(max-width: 760px)')
|
||
const syncMobile = () => (isMobile.value = mobileMedia.matches)
|
||
syncMobile()
|
||
mobileMedia.addEventListener('change', syncMobile)
|
||
onScopeDispose(() => mobileMedia.removeEventListener('change', syncMobile))
|
||
}
|
||
/** 新批量回执到达时显示诊断,进入页面不自动遮挡图库。 */
|
||
watch(
|
||
() => session.value.receipt,
|
||
receipt => {
|
||
if (receipt) toolsOpen.value = true
|
||
}
|
||
)
|
||
watch(
|
||
() => session.value.promptReceipt,
|
||
receipt => {
|
||
if (receipt) toolsOpen.value = true
|
||
}
|
||
)
|
||
const search = ref('')
|
||
/** 切换排版复用同一份卡片和查询结果,不重新读取图库或清空筛选。 */
|
||
const layout = ref<GalleryLayout>('masonry')
|
||
const module = ref('all')
|
||
/** 形态图片状态筛选;单选下拉避免移动端复选项占据两行。 */
|
||
type ImageStatusFilter = 'all' | 'missing'
|
||
const statusFilter = ref<ImageStatusFilter>('all')
|
||
const statusFilterOptions: Array<{ label: string; value: ImageStatusFilter }> = [
|
||
{ label: '全部状态', value: 'all' },
|
||
{ label: '缺少主图', value: 'missing' }
|
||
]
|
||
/** 当前卡片容器,用于在筛选移除卡片后重新计算位置。 */
|
||
const galleryGrid = useTemplateRef<HTMLElement>('galleryGrid')
|
||
/** 保存每张卡片的尺寸观察器,切换回网格时及时释放。 */
|
||
const masonryCardObservers = new WeakMap<HTMLElement, ResizeObserver>()
|
||
|
||
/**
|
||
* 按素材顺序重新计算整个瀑布流的位置。
|
||
* @param container 瀑布流容器元素
|
||
*/
|
||
function syncMasonryLayout(container: HTMLElement) {
|
||
if (!container.classList.contains('form-image-masonry')) return
|
||
const styles = getComputedStyle(container)
|
||
const rowHeight = Number.parseFloat(styles.gridAutoRows)
|
||
const rowGap = Number.parseFloat(styles.rowGap)
|
||
const cardGap = Number.parseFloat(styles.columnGap)
|
||
const minCardWidth = Number.parseFloat(styles.getPropertyValue('--gallery-card-min-width'))
|
||
const columnCount = masonryColumnCount(container.clientWidth, minCardWidth, cardGap)
|
||
const nextRows = Array<number>(columnCount).fill(1)
|
||
const cards = Array.from(container.children).filter(
|
||
(element): element is HTMLElement =>
|
||
element instanceof HTMLElement && element.classList.contains('form-image-card')
|
||
)
|
||
cards.forEach((card, index) => {
|
||
const column = index % columnCount
|
||
const span = masonryRowSpan(card.getBoundingClientRect().height, rowHeight, rowGap)
|
||
card.style.setProperty('--form-image-column', String(column + 1))
|
||
const rowStart = nextRows[column] ?? 1
|
||
card.style.setProperty('--form-image-row-start', String(rowStart))
|
||
card.style.setProperty('--form-image-row-span', String(span))
|
||
// 隐式网格行不加 gap,仅在两张卡片之间预留与横向一致的间距。
|
||
nextRows[column] = rowStart + span + Math.ceil(cardGap / rowHeight)
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 开始监听瀑布流卡片尺寸变化。
|
||
* @param element 形态图片卡片元素
|
||
*/
|
||
function observeMasonryCard(element: HTMLElement) {
|
||
if (masonryCardObservers.has(element) || typeof ResizeObserver === 'undefined') return
|
||
const observer = new ResizeObserver(() => {
|
||
if (element.parentElement) syncMasonryLayout(element.parentElement)
|
||
})
|
||
observer.observe(element)
|
||
masonryCardObservers.set(element, observer)
|
||
if (element.parentElement) syncMasonryLayout(element.parentElement)
|
||
}
|
||
|
||
/**
|
||
* 停止监听瀑布流卡片并清理网格跨度。
|
||
* @param element 形态图片卡片元素
|
||
*/
|
||
function unobserveMasonryCard(element: HTMLElement) {
|
||
masonryCardObservers.get(element)?.disconnect()
|
||
masonryCardObservers.delete(element)
|
||
element.style.removeProperty('--form-image-column')
|
||
element.style.removeProperty('--form-image-row-start')
|
||
element.style.removeProperty('--form-image-row-span')
|
||
}
|
||
|
||
/** 让卡片按实际高度占据网格行,保持从左到右的 DOM 排列顺序。 */
|
||
const vMasonryCard: Directive<HTMLElement, boolean> = {
|
||
mounted(element, binding) {
|
||
if (binding.value) observeMasonryCard(element)
|
||
},
|
||
updated(element, binding) {
|
||
if (binding.value === binding.oldValue) return
|
||
if (binding.value) observeMasonryCard(element)
|
||
else unobserveMasonryCard(element)
|
||
},
|
||
beforeUnmount(element) {
|
||
unobserveMasonryCard(element)
|
||
}
|
||
}
|
||
const generateOpen = ref(false)
|
||
const galleryOpen = ref(false)
|
||
const generateId = ref('')
|
||
const galleryId = ref('')
|
||
const promptOpen = ref(false)
|
||
const promptId = ref('')
|
||
const promptForm = computed(() => forms.value.find(form => form.id === promptId.value) ?? null)
|
||
const generateForm = computed(() => forms.value.find(form => form.id === generateId.value) ?? null)
|
||
const galleryForm = computed(() => forms.value.find(form => form.id === galleryId.value) ?? null)
|
||
|
||
/**
|
||
* 用已记录的图片尺寸预留瀑布流卡片高度,缺少尺寸时保持方形。
|
||
* @param form 当前形态
|
||
* @returns 图片容器宽高比
|
||
*/
|
||
function formCoverRatio(form: SubjectFormAsset) {
|
||
const image = primaryImage(form.images)
|
||
const width = image?.width
|
||
const height = image?.height
|
||
return width && height && width > 0 && height > 0 ? `${width} / ${height}` : '1 / 1'
|
||
}
|
||
const completeCount = computed(() => forms.value.filter(form => primaryImage(form.images)).length)
|
||
const filtered = computed(() =>
|
||
forms.value.filter(
|
||
form =>
|
||
(!targetFormId.value || form.id === targetFormId.value) &&
|
||
(module.value === 'all' || form.subject.module === module.value) &&
|
||
(statusFilter.value !== 'missing' || !primaryImage(form.images)) &&
|
||
`${form.subject.name} ${form.subject.ref} ${form.name}`
|
||
.toLowerCase()
|
||
.includes(search.value.trim().toLowerCase())
|
||
)
|
||
)
|
||
/** 筛选或数据更新可能只移除卡片,保留的卡片尺寸不变也需要重新排位。 */
|
||
watch(
|
||
[filtered, layout],
|
||
() => {
|
||
if (galleryGrid.value) syncMasonryLayout(galleryGrid.value)
|
||
},
|
||
{ flush: 'post' }
|
||
)
|
||
watch(
|
||
() => [route.query.subjectRef, route.query.subjectFormId, route.query.sourceShotId],
|
||
() => {
|
||
search.value = targetFormId.value ? '' : queryText(route.query.subjectRef)
|
||
module.value = 'all'
|
||
statusFilter.value = 'all'
|
||
galleryOpen.value = false
|
||
generateOpen.value = false
|
||
promptOpen.value = false
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
|
||
/** 打开指定正式形态的提示词管理。 */
|
||
function openPrompt(form: SubjectFormAsset) {
|
||
promptId.value = form.id
|
||
promptOpen.value = true
|
||
}
|
||
|
||
/** 打开指定正式形态的生图表单。 */
|
||
function openGenerate(form: SubjectFormAsset) {
|
||
generateId.value = form.id
|
||
generateOpen.value = true
|
||
}
|
||
/** 查看形态全部候选图和失败记录。 */
|
||
function openGallery(form: SubjectFormAsset) {
|
||
galleryId.value = form.id
|
||
galleryOpen.value = true
|
||
}
|
||
/** 导出真实批量回执供排障,不构造成功图片地址。 */
|
||
function exportReceipt() {
|
||
downloadText('subject-images-receipt.json', JSON.stringify(session.value.receipt, null, 2), 'application/json')
|
||
}
|
||
/** 搜索为空时可一次恢复完整图库。 */
|
||
function resetFilters() {
|
||
search.value = ''
|
||
module.value = 'all'
|
||
statusFilter.value = 'all'
|
||
void router.replace({
|
||
query: { ...route.query, subjectFormId: undefined, subjectRef: undefined, sourceShotId: undefined }
|
||
})
|
||
}
|
||
|
||
/** 同时刷新素材和镜头影响状态,查询仍不启动生成。 */
|
||
async function refreshAssets() {
|
||
await Promise.all([refreshProject(), query.refresh(), impact.query.refresh(), impact.references.refresh()])
|
||
}
|
||
const formModel = computed(() => ({ concurrency: concurrency.value, limit: limit.value }))
|
||
const rules = { concurrency: integerRule('批量并发'), limit: integerRule('本批上限', 1, true) }
|
||
</script>
|
||
|
||
<template>
|
||
<!-- 以下是图库首次加载的完整工作区骨架 -->
|
||
<ProjectWorkspaceSkeleton v-if="!query.data.value && query.loading.value" variant="subject-images" />
|
||
<WorkspacePage v-else compact mobile-scroll class="gallery-workspace-page">
|
||
<template #default>
|
||
<!-- 以下是全屏形态生图配置与回执,入口跟随图库筛选区。 -->
|
||
<WorkspaceTools
|
||
triggerless
|
||
fullscreen
|
||
:pending="operation.pending"
|
||
:pending-label="operation.label"
|
||
v-model:open="toolsOpen"
|
||
title="形态生图配置与回执"
|
||
label="批量生图"
|
||
:has-receipt="!!session.receipt || !!session.promptReceipt"
|
||
><div class="flex flex-wrap items-end justify-between gap-4">
|
||
<div>
|
||
<h2 class="text-lg font-semibold">形态图片</h2>
|
||
<p class="mt-2 text-sm text-muted">准备人物、场景和道具参考图。</p>
|
||
</div>
|
||
</div>
|
||
<DetailDisclosure title="母版继承与过期处理" class="mt-4">
|
||
基础形态可复用已锁定母版。母版变化后,请复核已有图片。
|
||
</DetailDisclosure>
|
||
<FormPromptBatch
|
||
:generating="isOperationRunning(operation, '批量生成形态正式提示词')"
|
||
:forms="forms"
|
||
:disabled="blocked"
|
||
:pending="operation.pending"
|
||
:receipt="session.promptReceipt"
|
||
v-model:concurrency="promptConcurrency"
|
||
v-model:force="promptForce"
|
||
@generate="generatePrompts"
|
||
/>
|
||
<div class="mt-5 flex flex-wrap items-center gap-3">
|
||
<span class="text-xs text-muted">批处理范围</span>
|
||
<NSelect
|
||
v-model:value="batchModule"
|
||
class="w-40"
|
||
aria-label="形态批处理范围"
|
||
:options="[
|
||
{ label: String('全部类型'), value: 'all' },
|
||
{ label: String('仅人物'), value: 'character' },
|
||
{ label: String('仅场景'), value: 'scene' },
|
||
{ label: String('仅道具'), value: 'prop' }
|
||
]"
|
||
/>
|
||
<span class="text-xs text-muted">同时应用于批量提示词与批量生图。</span>
|
||
</div>
|
||
<div class="panel workspace-panel">
|
||
<div class="flex flex-wrap items-center justify-between gap-4">
|
||
<p class="text-sm">
|
||
<strong>{{ completeCount }}</strong> / {{ forms.length }} 个形态已有主图
|
||
<span class="ml-3 text-xs text-muted">使用项目图片模型</span>
|
||
</p>
|
||
</div>
|
||
<p class="mt-2 text-[11px] leading-6 text-muted">主图通过来源和质量检查后可用于分镜。</p>
|
||
<section class="mt-4 pt-4">
|
||
<h3 class="text-sm font-semibold">项目批量生图</h3>
|
||
<AppForm :model="formModel" :rules="rules" :disabled="operation.pending" validate-on-change>
|
||
<div class="form-controls mt-4 flex flex-wrap gap-4">
|
||
<NFormItem
|
||
class="w-28"
|
||
path="concurrency"
|
||
label="批量并发"
|
||
:label-props="{ for: 'image-concurrency' }"
|
||
>
|
||
<NInputNumber
|
||
:disabled="operation.pending"
|
||
:input-props="{ id: 'image-concurrency' }"
|
||
:value="typeof concurrency === 'number' ? concurrency : null"
|
||
@update:value="concurrency = $event ?? 0"
|
||
:min="1"
|
||
:step="1"
|
||
></NInputNumber>
|
||
</NFormItem>
|
||
<NFormItem class="w-36" path="limit" label="本批上限(可选)"
|
||
><NInputNumber
|
||
:disabled="operation.pending"
|
||
:value="typeof limit === 'number' ? limit : null"
|
||
@update:value="limit = $event ?? ''"
|
||
:min="1"
|
||
:step="1"
|
||
placeholder="不限制"
|
||
:input-props="{ 'aria-label': '生图本批上限' }"
|
||
/></NFormItem>
|
||
<NCheckbox
|
||
v-model:checked="force"
|
||
:disabled="operation.pending"
|
||
class="control-row-checkbox text-xs"
|
||
>已有主图也新增候选图
|
||
</NCheckbox>
|
||
<ConfirmAction
|
||
:loading="isOperationRunning(operation, '批量生成项目形态图片')"
|
||
:label="force ? '为全项目新增候选图' : '补齐项目主参考图'"
|
||
:disabled="blocked || running || !batchValid || !forms.length"
|
||
acknowledgement
|
||
:description="
|
||
force
|
||
? '对项目全部形态调用图片模型新增一张图片。已有主图不会被替换,生成后可在图片记录中手动选择主图。'
|
||
: '对缺少主图或主图已过期的形态调用图片模型,仍有效的主图跳过。已有过期主图不会被自动替换,生成后请在图片记录中确认新主图。操作面向整个项目,不受列表筛选影响。'
|
||
"
|
||
@confirm="generateProject"
|
||
/>
|
||
</div>
|
||
</AppForm>
|
||
<p class="mt-3 text-xs leading-6 text-muted">
|
||
批量生图覆盖全项目,使用项目尺寸和已保存的提示词。超过上限的形态留待下次处理。
|
||
</p>
|
||
</section>
|
||
</div>
|
||
<section v-if="session.receipt" class="panel workspace-panel" aria-label="生图批量回执">
|
||
<div class="flex items-center justify-between gap-3">
|
||
<h3 class="text-sm font-medium">{{ session.receipt.title }} · 本次回执</h3>
|
||
<NButton @click="exportReceipt" text size="small"><Download :size="13" />导出诊断</NButton>
|
||
</div>
|
||
<p class="mt-3 text-xs text-muted">
|
||
共 {{ session.receipt.result.total }} 个形态 · 本次目标
|
||
{{ session.receipt.result.targetCount }} · 生成 {{ session.receipt.result.generated }} · 跳过
|
||
{{ session.receipt.result.skipped }} · 失败
|
||
{{ session.receipt.result.failed }}
|
||
<span v-if="session.receipt.result.remaining !== undefined">
|
||
· 待后续处理 {{ session.receipt.result.remaining }}</span
|
||
>
|
||
</p>
|
||
<ContextNotice
|
||
v-if="session.receipt.result.failed"
|
||
role="alert"
|
||
type="error"
|
||
:show-icon="false"
|
||
class="mt-3"
|
||
>
|
||
部分形态生图失败。成功图片已保留,请核对原因后重试。
|
||
</ContextNotice>
|
||
<ul class="mt-3 space-y-2 text-xs text-danger">
|
||
<li v-for="failure in session.receipt.result.failures" :key="failure.subjectFormId">
|
||
<code>{{ failure.subjectFormId }}</code
|
||
>:{{ userFacingText(failure.error) }}
|
||
</li>
|
||
</ul>
|
||
<p class="mt-3 text-[11px] text-muted">刷新可查看最新图片。</p>
|
||
</section>
|
||
</WorkspaceTools>
|
||
<!-- 以下是图库筛选与来自镜头的定位操作 -->
|
||
<div class="gallery-sticky-controls">
|
||
<div class="form-image-filter-region">
|
||
<div class="form-image-toolbar" :class="{ 'has-impact-picker': sourceShotId }">
|
||
<div v-if="sourceShotId" class="asset-impact-picker" role="group" aria-label="镜头定位与导航">
|
||
<RouterLink v-if="sourceLocation" :to="sourceLocation" custom v-slot="{ href, navigate }">
|
||
<NButton
|
||
tag="a"
|
||
:href="href"
|
||
@click="navigate"
|
||
class="icon-button"
|
||
:aria-label="`返回第 ${sourceShot?.episodeNo} 集 · 镜头 ${sourceShot?.shotNo}`"
|
||
:title="`返回第 ${sourceShot?.episodeNo} 集 · 镜头 ${sourceShot?.shotNo}`"
|
||
>
|
||
<template #icon><ArrowLeft :size="16" /></template>
|
||
<span class="sr-only"
|
||
>返回第 {{ sourceShot?.episodeNo }} 集 · 镜头 {{ sourceShot?.shotNo }}</span
|
||
>
|
||
</NButton>
|
||
</RouterLink>
|
||
<NButton
|
||
v-if="sourceShotId || targetFormId"
|
||
class="icon-button"
|
||
aria-label="查看全部素材"
|
||
title="查看全部素材"
|
||
@click="resetFilters"
|
||
>
|
||
<template #icon><LayoutGrid :size="16" /></template>
|
||
</NButton>
|
||
</div>
|
||
<div class="form-image-filters" role="group" aria-label="形态图片筛选">
|
||
<NInput
|
||
class="search-filter"
|
||
placeholder="搜索主体、引用或形态"
|
||
:input-props="{ 'aria-label': '搜索形态图片' }"
|
||
v-model:value="search"
|
||
clearable
|
||
><template #prefix><Search :size="14" /></template
|
||
></NInput>
|
||
<NSelect
|
||
class="module-filter"
|
||
aria-label="筛选主体类型"
|
||
v-model:value="module"
|
||
:options="[
|
||
{ label: String('全部类型'), value: 'all' },
|
||
{ label: String('人物'), value: 'character' },
|
||
{ label: String('场景'), value: 'scene' },
|
||
{ label: String('道具'), value: 'prop' }
|
||
]"
|
||
></NSelect>
|
||
<NSelect
|
||
v-model:value="statusFilter"
|
||
:options="statusFilterOptions"
|
||
aria-label="筛选图片状态"
|
||
class="status-filter"
|
||
/>
|
||
<div class="form-image-display-controls">
|
||
<span class="filter-result-count">{{ filtered.length }} 个形态</span>
|
||
<!-- 四个纯图标按钮使用统一间距;桌面端通过 Popover 解释用途。 -->
|
||
<div class="gallery-layout-switch" role="group" aria-label="图库视图与操作">
|
||
<!-- 以下是图片阶段免费准备检查入口 -->
|
||
<NPopover trigger="hover" placement="top" :disabled="preparationOpen">
|
||
<template #trigger
|
||
><NButton
|
||
class="icon-button"
|
||
size="small"
|
||
aria-label="图片准备检查"
|
||
@click="preparationOpen = true"
|
||
><template #icon><ClipboardCheck :size="16" /></template></NButton
|
||
></template>
|
||
图片准备检查
|
||
</NPopover>
|
||
<NPopover trigger="hover" placement="top" :disabled="isMobile">
|
||
<template #trigger>
|
||
<NButton
|
||
class="icon-button layout-option-button"
|
||
:class="{ 'layout-option-active': layout === 'grid' }"
|
||
size="small"
|
||
:type="layout === 'grid' ? 'primary' : 'default'"
|
||
:aria-pressed="layout === 'grid'"
|
||
aria-label="网格布局"
|
||
@click="layout = 'grid'"
|
||
>
|
||
<template #icon><LayoutGrid :size="16" /></template>
|
||
</NButton>
|
||
</template>
|
||
网格布局
|
||
</NPopover>
|
||
<NPopover trigger="hover" placement="top" :disabled="isMobile">
|
||
<template #trigger>
|
||
<NButton
|
||
class="icon-button layout-option-button"
|
||
:class="{ 'layout-option-active': layout === 'masonry' }"
|
||
size="small"
|
||
:type="layout === 'masonry' ? 'primary' : 'default'"
|
||
:aria-pressed="layout === 'masonry'"
|
||
aria-label="瀑布流布局"
|
||
@click="layout = 'masonry'"
|
||
>
|
||
<template #icon><Columns3 :size="16" /></template>
|
||
</NButton>
|
||
</template>
|
||
瀑布流布局
|
||
</NPopover>
|
||
|
||
<NPopover trigger="hover" placement="top" :disabled="isMobile">
|
||
<template #trigger>
|
||
<NButton
|
||
class="icon-button gallery-action-button"
|
||
size="small"
|
||
data-workspace-tools
|
||
aria-label="批量生图"
|
||
aria-haspopup="dialog"
|
||
:aria-expanded="toolsOpen"
|
||
@click="toolsOpen = true"
|
||
>
|
||
<template #icon
|
||
><LoaderCircle
|
||
v-if="operation.pending"
|
||
:size="16"
|
||
class="animate-spin" /><Settings2 v-else :size="16"
|
||
/></template>
|
||
</NButton>
|
||
</template>
|
||
{{
|
||
session.receipt || session.promptReceipt ? '批量生图(有回执)' : '批量生图'
|
||
}}
|
||
</NPopover>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div v-if="showImpactDetails" class="asset-impact-context" aria-label="镜头与素材定位">
|
||
<p v-if="sourceMissing" class="text-danger">来源镜头不存在或不属于当前项目,未读取其素材。</p>
|
||
<p v-if="impact.query.error.value" class="text-xs text-danger">
|
||
无法读取镜头。
|
||
<NButton text size="small" @click="impact.query.refresh">重试</NButton>
|
||
</p>
|
||
<p v-if="targetUnlinked" class="text-xs text-danger">此形态已不在镜头的关联素材中。</p>
|
||
<NScrollbar
|
||
v-if="linkedReferences.length && !impact.references.error.value"
|
||
:key="sourceShotId"
|
||
class="asset-impact-links-scroll"
|
||
content-class="asset-impact-links"
|
||
x-scrollable
|
||
trigger="none"
|
||
role="region"
|
||
aria-label="本镜头关联素材,可横向滚动"
|
||
>
|
||
<span class="text-xs text-muted">本镜头当前关联素材:</span
|
||
><RouterLink
|
||
v-for="target in linkedReferences"
|
||
:key="target.formId || target.subjectRef"
|
||
:to="referenceLocation(id, sourceShotId, target)"
|
||
class="text-button"
|
||
>{{ target.label }} →</RouterLink
|
||
>
|
||
</NScrollbar>
|
||
<p v-if="impact.references.loading.value" class="text-xs text-muted">正在读取镜头关联素材…</p>
|
||
<p v-if="impact.references.error.value" class="text-xs text-danger">
|
||
{{ impact.references.error.value }}
|
||
<NButton text size="small" @click="impact.references.refresh">重试读取素材</NButton>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<ContextNotice
|
||
v-if="targetFormId"
|
||
:type="targetForm ? 'info' : 'warning'"
|
||
:show-icon="false"
|
||
class="mt-3"
|
||
data-focused-material
|
||
>
|
||
<template v-if="targetForm"
|
||
>已定位:{{ targetForm.subject.name }} · {{ targetForm.name }}({{
|
||
targetForm.subject.ref
|
||
}})。可直接查看下方图片与记录、主体身份与母版。</template
|
||
>
|
||
<template v-else>{{
|
||
query.loading.value ? '正在定位素材…' : '指定形态不存在或已被移除,请从本镜头当前关联素材重新选择。'
|
||
}}</template>
|
||
<NButton text size="small" @click="resetFilters">清除定位</NButton>
|
||
</ContextNotice>
|
||
|
||
<ContextNotice v-if="query.error.value" role="alert" type="error" :show-icon="false" class="mt-4"
|
||
>{{ query.error.value }}<span v-if="forms.length"> 当前展示上次读取的数据。</span></ContextNotice
|
||
><ContextNotice v-if="running" role="status" type="info" :show-icon="false" class="mt-4">
|
||
部分形态正在生成。任务完成后可再次批量生图。
|
||
</ContextNotice>
|
||
<!-- 以下是筛选结果,网格与瀑布流共用同一组卡片。 -->
|
||
<div
|
||
v-if="filtered.length"
|
||
ref="galleryGrid"
|
||
class="form-image-grid"
|
||
:class="{ 'form-image-masonry': layout === 'masonry' }"
|
||
>
|
||
<article
|
||
v-for="form in filtered"
|
||
v-masonry-card="layout === 'masonry'"
|
||
:key="form.id"
|
||
class="panel form-image-card"
|
||
:class="{
|
||
'form-image-card-focused': targetFormId === form.id
|
||
}"
|
||
:data-form-id="form.id"
|
||
>
|
||
<AssetImage
|
||
:src="primaryImage(form.images)?.imageUrl"
|
||
:alt="`${form.subject.name} · ${form.name}`"
|
||
:style="{ '--form-cover-ratio': formCoverRatio(form) }"
|
||
:object-fit="layout === 'masonry' ? 'contain' : 'cover'"
|
||
preview
|
||
:empty-text="
|
||
hasRunningImages(form.images)
|
||
? '后台正在生成图片'
|
||
: form.images.some(image => image.status === 'completed' && image.imageUrl)
|
||
? '已有候选图,请确认主参考图'
|
||
: form.isDefault
|
||
? '请先确认并锁定身份母版'
|
||
: '尚未生成主参考图'
|
||
"
|
||
/>
|
||
<div class="p-4">
|
||
<div class="flex flex-wrap items-center gap-2">
|
||
<h3 class="text-sm font-semibold">{{ form.subject.name }}</h3>
|
||
<code class="subject-ref">{{ form.subject.ref }}</code>
|
||
</div>
|
||
<p class="mt-2 flex items-center gap-2 text-xs">
|
||
<span>{{ form.name }}</span>
|
||
<NTag v-if="form.isDefault" size="small" :bordered="false">默认形态</NTag>
|
||
</p>
|
||
<p v-if="form.description" class="mt-3 line-clamp-2 text-xs leading-6 text-muted">
|
||
{{ form.description }}
|
||
</p>
|
||
<div class="mt-3 flex flex-wrap items-center gap-2">
|
||
<StatusBadge v-if="hasRunningImages(form.images)" status="generating" />
|
||
<NTag v-else-if="primaryImage(form.images)" size="small" :bordered="false">{{
|
||
isIdentityAnchorReuse(primaryImage(form.images)) ? '复用身份母版' : '主参考图'
|
||
}}</NTag>
|
||
<NTag
|
||
v-else-if="form.images.some(image => image.status === 'completed' && image.imageUrl)"
|
||
size="small"
|
||
:bordered="false"
|
||
>候选图 · 尚未设主图</NTag
|
||
>
|
||
<span v-else-if="form.images[0]?.status === 'failed'" class="text-xs text-danger"
|
||
>最近一次生成失败</span
|
||
>
|
||
<span class="text-[10px] text-muted">{{ form.images.length }} 条记录</span>
|
||
</div>
|
||
<p v-if="form.images[0]?.status === 'failed'" class="mt-2 line-clamp-2 text-xs text-danger">
|
||
{{ userFacingText(form.images[0].error) }}
|
||
</p>
|
||
<div class="mt-4 flex flex-wrap items-center justify-between gap-2">
|
||
<NButton @click="openGallery(form)" text size="small">查看图片与记录</NButton>
|
||
<ActionMenu
|
||
:label="`${form.subject.name} · ${form.name} 更多操作`"
|
||
:items="[
|
||
{ key: 'prompt', label: '提示词与生成' },
|
||
{ key: 'identity', label: '主体身份与母版' }
|
||
]"
|
||
@select="
|
||
$event === 'prompt'
|
||
? openPrompt(form)
|
||
: router.push({
|
||
path: `/projects/${id}/subject-identity`,
|
||
query: { subjectId: form.subjectId }
|
||
})
|
||
"
|
||
/>
|
||
<NButton :disabled="blocked || hasRunningImages(form.images)" @click="openGenerate(form)"
|
||
><ImagePlus :size="14" />
|
||
{{
|
||
isIdentityAnchorReuse(primaryImage(form.images))
|
||
? '重新生成'
|
||
: form.images.some(image => image.status === 'completed' && image.imageUrl)
|
||
? '再生成一张'
|
||
: '生成图片'
|
||
}}</NButton
|
||
>
|
||
</div>
|
||
</div>
|
||
</article>
|
||
</div>
|
||
<EmptyState
|
||
v-else-if="query.data.value"
|
||
:title="forms.length ? '没有匹配的形态' : '还没有正式形态'"
|
||
:description="
|
||
forms.length ? '调整筛选条件后再查看。批量生图不受筛选影响。' : '请先拆解剧本并保存主体形态。'
|
||
"
|
||
>
|
||
<NButton v-if="forms.length" @click="resetFilters">清除筛选</NButton> </EmptyState
|
||
><FormPromptDialog
|
||
v-model:open="promptOpen"
|
||
:form="promptForm"
|
||
:disabled="blocked || !promptForm"
|
||
@generate="generatePrompt" /><GenerateImageDialog
|
||
v-if="generationModelsQuery.data.value && profileQuery.data.value?.profile"
|
||
v-model:open="generateOpen"
|
||
:form="generateForm"
|
||
:catalog="generationModelsQuery.data.value"
|
||
:profile="profileQuery.data.value.profile"
|
||
:disabled="blocked || !generateForm || hasRunningImages(generateForm.images)"
|
||
:submit-generation="generate" /><ImageGalleryDialog
|
||
v-model:open="galleryOpen"
|
||
:project-id="id"
|
||
:form="galleryForm"
|
||
:disabled="blocked || !galleryForm"
|
||
@changed="refreshAssets" /></template
|
||
></WorkspacePage>
|
||
<!-- 以下是免费图片准备计划全屏模块 -->
|
||
<ImagePreparationDrawer v-model:open="preparationOpen" :project-id="id" />
|
||
</template>
|
||
|
||
<style>
|
||
/* 本组件专属布局与 Naive 内部结构覆盖。 */
|
||
@reference "../../styles/styles.css";
|
||
.form-image-card {
|
||
@apply overflow-hidden;
|
||
}
|
||
/* 普通网格的有图与空状态统一使用正方形图片区;瀑布流仍按原图比例展示。 */
|
||
.form-image-grid:not(.form-image-masonry) .asset-image {
|
||
aspect-ratio: 1 / 1;
|
||
}
|
||
/* 浅色卡片使用轻灰底,与白色画布区分;网格和瀑布流共用,深色保持原有层次。 */
|
||
:root:not([data-theme='dark']) .form-image-card {
|
||
background: var(--app-subtle);
|
||
}
|
||
.gallery-workspace-page .gallery-sticky-controls {
|
||
@apply sticky top-0 z-10 bg-(--app-body) m-0;
|
||
}
|
||
.gallery-workspace-page .form-image-grid {
|
||
padding-top: var(--app-content-gap);
|
||
}
|
||
.gallery-workspace-page .form-image-masonry {
|
||
@apply items-start;
|
||
/* 避免每个 1px 网格行都叠加间距,造成卡片下方出现额外空白。 */
|
||
column-gap: var(--gallery-gap);
|
||
row-gap: 0;
|
||
grid-auto-flow: row dense;
|
||
grid-auto-rows: 1px;
|
||
}
|
||
.form-image-masonry > .form-image-card {
|
||
grid-column-start: var(--form-image-column, auto);
|
||
grid-row-start: var(--form-image-row-start, auto);
|
||
grid-row-end: span var(--form-image-row-span, 1);
|
||
}
|
||
.form-image-masonry .asset-image {
|
||
aspect-ratio: var(--form-cover-ratio, 1 / 1);
|
||
}
|
||
.gallery-workspace-page .workspace-scroll > .n-scrollbar-container {
|
||
@apply [overflow-anchor:none];
|
||
}
|
||
.asset-impact-context {
|
||
@apply flex flex-col gap-2.5 py-[5px] px-4 bg-(--app-subtle) m-0 min-w-0;
|
||
}
|
||
.asset-impact-links-scroll.n-scrollbar {
|
||
@apply h-auto min-w-0 max-w-full;
|
||
}
|
||
.asset-impact-links {
|
||
@apply flex items-center gap-3 w-max whitespace-nowrap min-h-8 py-1.5;
|
||
}
|
||
.asset-impact-links > * {
|
||
@apply shrink-0;
|
||
}
|
||
.form-image-card-focused {
|
||
@apply shadow-[inset_3px_0_0_var(--app-accent-text)];
|
||
}
|
||
</style>
|