feat(short-drama-agent-front): 完善质量规则确认与中文交互
This commit is contained in:
1 parent
190333d4f9
commit
c4b43b9725
85 files changed
+2059
-480
No files matched your search
@@ -6,7 +6,7 @@ import { useRoute, useRouter } from 'vue-router'
|
||||
import { NScrollbar, NButton, NPageHeader, NSpin, NEllipsis } from 'naive-ui'
|
||||
import { EmptyState, WorkspaceRefreshButton } from '../../components/ui'
|
||||
import { projectContextKey, useProjectData } from './context'
|
||||
import { getOperation } from '../workflows/operations'
|
||||
import { getOperation, operationErrorText } from '../workflows/operations'
|
||||
import { projectAccessKey, projectSectionFromPath, type ProjectAccess } from './access'
|
||||
import { useProjectStageAccess } from './useProjectStageAccess'
|
||||
import { useWorkflowExecution } from '../workflows/execution'
|
||||
@@ -116,7 +116,7 @@ type OperationGuide = {
|
||||
}
|
||||
/** 仅为明确缺失的前置条件提供恢复入口,不把同页生成失败变成无效跳转。 */
|
||||
const operationGuide = computed<OperationGuide | null>(() => {
|
||||
const error = operation.value.error?.trim()
|
||||
const error = operationErrorText(operation.value).trim()
|
||||
if (!error) return null
|
||||
const normalized = error.toLowerCase()
|
||||
if (normalized.includes('primary keyframe') || error.includes('主首帧'))
|
||||
|
||||
@@ -202,7 +202,7 @@ function clearFilters() {
|
||||
><div>
|
||||
{{
|
||||
query.error.value
|
||||
? '等待连接后端'
|
||||
? '正在尝试连接服务'
|
||||
: projects.length
|
||||
? '没有匹配的剧本'
|
||||
: '还没有剧本,点击右上角新建'
|
||||
|
||||
@@ -46,7 +46,7 @@ async function remove() {
|
||||
state.error = ''
|
||||
try {
|
||||
const result = await projectsApi.delete(id)
|
||||
if (!result.deleted || result.id !== id) throw new Error('后端未确认项目删除结果。')
|
||||
if (!result.deleted || result.id !== id) throw new Error('项目删除结果尚未确认,请刷新后核对。')
|
||||
emit('deleted', id)
|
||||
open.value = false
|
||||
} catch (cause) {
|
||||
@@ -64,8 +64,7 @@ async function remove() {
|
||||
<!-- 删除范围与后台任务状态属于同组,保持 8px 间距 -->
|
||||
<div class="space-y-2">
|
||||
<ContextNotice type="error" :show-icon="false">
|
||||
会永久删除剧本、主体、身份、形态、分镜、首帧、视频、工作流记录,以及本地 Storage
|
||||
中属于该项目的图片、视频和上传素材。
|
||||
会永久删除这个项目的剧本、人物、场景、道具、形态、分镜、首帧、视频和制作记录,以及上传或生成的素材文件。
|
||||
</ContextNotice>
|
||||
<ContextNotice v-if="readinessPending" type="info" :show-icon="false"
|
||||
>正在检查项目后台任务…</ContextNotice
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import { policyIssue } from './quality-policy'
|
||||
import type { ProjectQualityPolicy } from './types'
|
||||
|
||||
/** 同一页面中主动保存规则后,也撤销无法持久化的临时确认。 */
|
||||
const invalidations = new Map<string, number>()
|
||||
|
||||
/**
|
||||
* 只比较质量规则的规范化内容,不把模型参数或对象属性顺序作为变更。
|
||||
* @param policy 后端读取或用户编辑的完整规则
|
||||
* @returns 可精确比较的内容签名,不是后端授权令牌
|
||||
*/
|
||||
export function qualityPolicySignature(policy: ProjectQualityPolicy): string {
|
||||
if (!policy || !Array.isArray(policy.customRules) ||
|
||||
(policy.actionExceptions !== undefined && !Array.isArray(policy.actionExceptions)))
|
||||
throw new Error('质量规则响应不完整,请重新读取。')
|
||||
const issue = policyIssue(policy)
|
||||
if (issue) throw new Error(issue)
|
||||
return JSON.stringify({
|
||||
version: policy.version,
|
||||
physicsMode: policy.physicsMode,
|
||||
allowExaggeratedMotion: policy.allowExaggeratedMotion,
|
||||
allowNonPhysicalActions: policy.allowNonPhysicalActions,
|
||||
allowSupernaturalAbilities: policy.allowSupernaturalAbilities,
|
||||
customRules: policy.customRules.map(rule => rule.trim()),
|
||||
actionExceptions: (policy.actionExceptions ?? []).map(item => ({
|
||||
code: item.code,
|
||||
ownerRef: item.ownerRef.trim(),
|
||||
resource: item.resource,
|
||||
reason: item.reason.trim()
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 隔离项目及本地确认格式版本。
|
||||
* @param projectId 当前项目
|
||||
* @returns 本地 UX 记忆键
|
||||
*/
|
||||
function confirmationKey(projectId: string): string {
|
||||
return `short-drama:breakdown-quality-confirmation:v1:${projectId}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取当前浏览器明确确认过的规则,不将默认值当作确认。
|
||||
* @param projectId 当前项目
|
||||
* @returns 已确认内容或空值,损坏与不可用存储均不视为确认
|
||||
*/
|
||||
export function readQualityPolicyConfirmation(projectId: string): string | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(confirmationKey(projectId))
|
||||
if (!raw) return null
|
||||
const parsed: unknown = JSON.parse(raw)
|
||||
if (!parsed || typeof parsed !== 'object' || !('signature' in parsed) ||
|
||||
!('formatVersion' in parsed) || parsed.formatVersion !== 1 ||
|
||||
typeof parsed.signature !== 'string') return null
|
||||
return parsed.signature
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅在用户明确确认后记住当前浏览器的规则内容,不能代替后端门禁。
|
||||
* @param projectId 当前项目
|
||||
* @param signature 已核对的规则内容
|
||||
* @returns 是否成功持久化,失败时调用方只保留本次会话确认
|
||||
*/
|
||||
export function rememberQualityPolicyConfirmation(projectId: string, signature: string): boolean {
|
||||
try {
|
||||
localStorage.setItem(confirmationKey(projectId), JSON.stringify({ formatVersion: 1, signature }))
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则有实质变化时撤销本地确认,无变化保存不调用此方法。
|
||||
* @param projectId 规则所属项目
|
||||
*/
|
||||
export function invalidateQualityPolicyConfirmation(projectId: string) {
|
||||
invalidations.set(projectId, qualityPolicyConfirmationEpoch(projectId) + 1)
|
||||
try { localStorage.removeItem(confirmationKey(projectId)) } catch { /* 存储受限时仍撤销页面内确认。 */ }
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前页面内的确认失效代次,用于存储受限的降级场景。
|
||||
* @param projectId 当前项目
|
||||
* @returns 规则失效代次
|
||||
*/
|
||||
export function qualityPolicyConfirmationEpoch(projectId: string): number {
|
||||
return invalidations.get(projectId) ?? 0
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { userFacingText } from '../../lib/user-facing-text'
|
||||
import { computed, type Ref } from 'vue'
|
||||
import type { ProjectAccess, ProjectSection } from './access'
|
||||
import type { ProjectStageReadiness } from './types'
|
||||
@@ -6,11 +7,17 @@ function accessState(ready: boolean | undefined, reason: string | null | undefin
|
||||
return { enabled: Boolean(ready), reason: reason || fallback }
|
||||
}
|
||||
|
||||
/** 将服务端统一 readiness 转为侧栏、URL 门禁和下一步引导,前端不复制制作规则。 */
|
||||
/**
|
||||
* 使用真实准备情况控制侧栏与页面入口,仅转换原因文案。
|
||||
* @param projectId 当前项目编号
|
||||
* @param readiness 当前项目各步骤的准备情况
|
||||
* @returns 各步骤入口、原因与下一步引导
|
||||
*/
|
||||
export function useProjectStageAccess(projectId: Ref<string>, readiness: Ref<ProjectStageReadiness | null>) {
|
||||
/** 当前步骤能否进入及对应中文说明,不改变原始准备状态。 */
|
||||
const sections = computed<Record<ProjectSection, ProjectAccess['sections'][ProjectSection]>>(() => {
|
||||
const state = readiness.value
|
||||
return {
|
||||
const result: Record<ProjectSection, ProjectAccess['sections'][ProjectSection]> = {
|
||||
'create-drama': { enabled: true, reason: '' },
|
||||
breakdown: {
|
||||
...accessState(state?.script.ready, state?.script.reason, '请先完成剧本创作'),
|
||||
@@ -71,6 +78,8 @@ export function useProjectStageAccess(projectId: Ref<string>, readiness: Ref<Pro
|
||||
: '前往剧本拆解'
|
||||
}
|
||||
}
|
||||
for (const section of Object.values(result)) section.reason = userFacingText(section.reason)
|
||||
return result
|
||||
})
|
||||
const scriptReady = computed(() => readiness.value?.script.ready === true)
|
||||
return { projectId, scriptReady, sections }
|
||||
|
||||
Reference in new issue
Block a user