Files
short-drama-agent-front/src/features/projects/ProjectsPage.vue
T
GouJ 7a60db3ced feat: 同步动作与首帧编辑能力并统一工作区反馈
接入动作时间轴、密度审计、人工视线目标和后台首帧编辑;独立读取已保存提示词,并在首帧晋升前重新核对持久化质量状态。
统一 NMessage 结果反馈、局部 loading 和业务说明间距,保留真实长任务进度与部分失败语义。
验证:pnpm check(49 个文件、393 项测试)、pnpm build;当前环境无法完成 localhost 浏览器验收及真实后端联调。
2026-10-12 20:05:03 +08:00

322 lines
11 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import ContextNotice from '../../components/ui/ContextNotice.vue'
import { computed, h, nextTick, ref, watch } from 'vue'
import { RouterLink, useRouter } from 'vue-router'
import {
NButton,
NDataTable,
NInput,
NDropdown,
NRadioButton,
NRadioGroup,
type DataTableColumns,
type DataTableInst
} from 'naive-ui'
import { MoreHorizontal, Pencil, Search, Trash2 } from '@lucide/vue'
import WorkspacePage from '../../components/ui/WorkspacePage.vue'
import { useQuery } from '../../composables/useQuery'
import { StatusBadge } from '../../components/ui'
import { formatDate } from '../../lib/format'
import { projectsApi } from './api'
import type { Project } from './types'
import CreateProjectDialog from './components/CreateProjectDialog.vue'
import EditProjectDialog from './components/EditProjectDialog.vue'
import DeleteProjectDialog from './components/DeleteProjectDialog.vue'
/** 项目表格使用固定表头与独立滚动;搜索筛选仍作用于真实接口数据。 */
const router = useRouter()
/** 列表在进入或自身操作完成后读取;筛选在完整结果中进行。 */
const query = useQuery(ref('projects'), (_, signal) => projectsApi.list(signal))
const search = ref('')
const filter = ref('all')
/** 接口暂未分页:对完整查询结果分批展示,滚动时追加而非切换页码。 */
const PAGE_SIZE = 20
const visibleCount = ref(PAGE_SIZE)
const table = ref<DataTableInst | null>(null)
const projects = computed(() => query.data.value ?? [])
const editOpen = ref(false)
const deleteOpen = ref(false)
const managedProject = ref<Project | null>(null)
function editProject(project: Project) {
managedProject.value = project
editOpen.value = true
}
function deleteProject(project: Project) {
managedProject.value = project
deleteOpen.value = true
}
const filtered = computed(() =>
projects.value.filter(item => {
const matches = ((item.title ?? '') + ' ' + item.topic + ' ' + (item.style ?? ''))
.toLowerCase()
.includes(search.value.trim().toLowerCase())
return matches && (filter.value === 'all' || item.status === filter.value)
})
)
const filters = [
{ value: 'all', label: '全部' },
{ value: 'generating', label: '生成中' },
{ value: 'completed', label: '已完成' },
{ value: 'need_review', label: '待审核' },
{ value: 'failed', label: '失败' }
]
const visibleProjects = computed(() => filtered.value.slice(0, visibleCount.value))
/** 条件或接口数据更新后从首批重新展示,避免保留旧列表的滚动位置。 */
watch([search, filter, query.data], async () => {
visibleCount.value = PAGE_SIZE
await nextTick()
table.value?.scrollTo({ top: 0 })
})
/** 靠近表格底部时追加下一批,保留已有行与当前位置。 */
function loadMore(event: Event) {
const scroller = event.target as HTMLElement | null
if (!scroller || query.loading.value || visibleCount.value >= filtered.value.length) return
if (scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight > 120) return
visibleCount.value = Math.min(visibleCount.value + PAGE_SIZE, filtered.value.length)
}
/** 表格列通过正式项目 ID 跳转,不依赖列表索引。 */
const columns: DataTableColumns<Project> = [
{
title: '剧本名称',
key: 'title',
width: 300,
render: row =>
h(
RouterLink,
{ to: '/projects/' + encodeURIComponent(row.id) + '/create-drama', class: 'project-name-cell' },
() => [h('strong', row.title || row.topic), h('small', row.topic)]
)
},
{ title: '风格', key: 'style', width: 200, ellipsis: { tooltip: true }, render: row => row.style || '未设置' },
{ title: '状态', key: 'status', width: 120, render: row => h(StatusBadge, { status: row.status }) },
{ title: '最近更新', key: 'updatedAt', width: 165, render: row => formatDate(row.updatedAt) },
{
title: '',
key: 'actions',
width: 64,
render: row =>
h(
NDropdown,
{
trigger: 'click',
placement: 'bottom-end',
options: [
{ label: '编辑', key: 'edit', icon: () => h(Pencil, { size: 16 }) },
{ label: '删除', key: 'delete', icon: () => h(Trash2, { size: 16 }) }
],
onSelect: key => {
if (key === 'edit') editProject(row)
if (key === 'delete') deleteProject(row)
}
},
{
default: () =>
h(
NButton,
{
quaternary: true,
circle: true,
title: '更多操作',
'aria-label': `${row.title || row.topic} 更多操作`
},
{ icon: () => h(MoreHorizontal, { size: 18 }) }
)
}
)
}
]
/** 创建回执只用于跳转,生成进度以后端查询为准。 */
function openProject(id: string, executionId: string) {
if (typeof localStorage !== 'undefined' && executionId) {
localStorage.setItem(`short-drama:workflow-execution:${id}:create-drama`, executionId)
}
void router.push('/projects/' + encodeURIComponent(id) + '/create-drama')
}
/** 清空条件后返回首批,不改变后端数据。 */
function clearFilters() {
search.value = ''
filter.value = 'all'
}
</script>
<template>
<WorkspacePage split compact>
<template #header>
<div class="project-index-chrome">
<!-- 以下是标题与新建 -->
<div class="page-heading project-index-heading">
<div>
<h1>我的剧本</h1>
<p class="page-description">从故事到镜头,继续你的创作。</p>
</div>
<CreateProjectDialog @created="openProject" />
</div>
<!-- 以下是状态筛选与搜索模块 -->
<div class="project-index-toolbar">
<div class="project-status-filter-scroller">
<NRadioGroup
v-model:value="filter"
size="medium"
class="project-status-filters"
aria-label="项目状态筛选"
><NRadioButton v-for="item in filters" :key="item.value" :value="item.value">{{
item.label
}}</NRadioButton></NRadioGroup
>
</div>
<div class="project-index-search-row">
<NInput
v-model:value="search"
clearable
placeholder="搜索剧本"
class="project-search"
:input-props="{ 'aria-label': '搜索项目' }"
><template #prefix><Search :size="15" /></template
></NInput>
</div>
</div>
</div>
</template>
<ContextNotice v-if="query.error.value" type="error" :show-icon="false"
>{{ query.error.value }}<NButton text class="ml-3" @click="query.refresh">重新连接</NButton></ContextNotice
>
<EditProjectDialog v-model:open="editOpen" :project="managedProject" @changed="query.refresh" />
<DeleteProjectDialog v-model:open="deleteOpen" :project="managedProject" @deleted="query.refresh" />
<div class="project-table-area">
<NDataTable
ref="table"
class="project-data-table"
:bordered="false"
:bottom-bordered="false"
striped
:columns="columns"
:data="visibleProjects"
:row-key="row => row.id"
:loading="query.loading.value"
flex-height
table-layout="fixed"
:scroll-x="850"
@scroll="loadMore"
>
<template #empty
><div>
{{
query.error.value
? '等待连接后端'
: projects.length
? '没有匹配的剧本'
: '还没有剧本,点击右上角新建'
}}
</div>
<NButton v-if="search || filter !== 'all'" text class="mt-3" @click="clearFilters"
>清除筛选</NButton
></template
>
</NDataTable>
</div>
</WorkspacePage>
</template>
<style>
/* 本组件专属布局与 Naive 内部结构覆盖。 */
@reference "../../styles/styles.css";
.page-heading {
@apply flex items-center justify-between gap-6;
}
.page-heading h1 {
@apply mt-[9px] mx-0 mb-0 text-[27px] font-semibold tracking-[-0.035em] leading-[1.4];
}
.page-description {
@apply mt-[9px] text-muted text-xs leading-[1.7];
}
@media (max-width: 760px) {
.page-heading {
@apply items-start flex-col gap-4;
}
.page-heading h1 {
@apply text-[23px];
}
}
.project-table-area {
@apply flex-1 min-h-0;
}
.project-data-table {
@apply h-full;
}
.project-data-table .n-data-table-base-table {
@apply flex-1 min-h-0;
}
.project-index-chrome {
@apply flex flex-col gap-3;
}
.project-index-heading {
@apply m-0;
}
.project-index-heading h1 {
@apply text-[22px] font-semibold;
}
.project-index-toolbar {
@apply flex items-center justify-between flex-wrap gap-3;
}
.project-index-search-row {
@apply flex min-w-0 items-center gap-2;
}
.project-search {
@apply w-[240px];
}
.project-status-filters.n-radio-group {
@apply flex flex-wrap h-auto min-h-(--n-height) gap-y-1 gap-x-px;
}
.project-status-filters .n-radio-group__splitor {
@apply hidden;
}
.project-status-filters .n-radio-button {
@apply min-w-[76px] px-[18px] text-center;
}
.project-name-cell {
@apply block min-w-0;
}
.project-name-cell strong,
.project-name-cell small {
@apply block overflow-hidden text-ellipsis whitespace-nowrap;
}
.project-name-cell small {
@apply text-muted mt-1 text-[11px];
}
@media (max-width: 800px) {
.project-index-chrome {
@apply gap-2;
}
.project-index-heading {
@apply flex-row items-center gap-3;
}
.project-index-heading h1 {
@apply mt-0 text-lg;
}
.project-index-heading .page-description {
@apply hidden;
}
.project-index-heading .n-button {
@apply h-9 px-3 shrink-0;
}
.project-index-toolbar {
@apply flex-col items-stretch gap-2 mb-0;
}
.project-status-filter-scroller {
@apply w-full m-0;
}
.project-status-filters.n-radio-group {
@apply flex w-full flex-nowrap m-0 p-0;
}
.project-status-filters .n-radio-button {
@apply flex-1 min-w-0 px-2;
}
.project-index-search-row {
@apply w-full;
}
.project-search {
@apply w-auto min-w-0 flex-1;
}
}
</style>