Files

139 lines
6.2 KiB
TypeScript

import { createApp, defineComponent, h, ref } from 'vue'
import { NButton, NMessageProvider, NConfigProvider } from 'naive-ui'
import KeyframeCard from '../../src/features/production/components/KeyframeCard.vue'
import KeyframeValidationHistory from '../../src/features/production/components/KeyframeValidationHistory.vue'
import QualityResult from '../../src/features/production/components/QualityResult.vue'
import { keyframeFixture } from '../../src/features/production/testing/fixtures'
import type { EffectiveKeyframeQualityStatus } from '../../src/features/production/quality-api'
import '../../src/styles/styles.css'
import '../../src/styles/admin.css'
import QualityDialog from '../../src/features/production/components/QualityDialog.vue'
import SourceReviewDrawer from '../../src/features/production/components/SourceReviewDrawer.vue'
/** 浏览器隔离场景,仅拦截本页所有请求,不连接真实 API 或 Provider。 */
const status = ref<EffectiveKeyframeQualityStatus>('stale')
/** 场景切换后重挂组件,模拟重新进入当前候选。 */
const revision = ref(0)
/** 仅在待人工复核时开放服务端模拟权限。 */
const available = ref(false)
/** 历史回执保留 Passed,用于确认当前 Stale 不被覆盖。 */
const result = {
shotId: 's',
keyframeId: 'k',
validationTaskId: 't',
imageUrl: '',
isPrimary: false,
passed: true,
summary: '历史机器通过,本页使用隔离数据。',
subjects: [],
issues: [],
subjectCountConsistent: true,
unauthorizedText: { detected: false, texts: [] }
}
/**
* 隔离所有请求;写请求直接拒绝,验收不会保存业务数据。
* @param input 请求路径
* @param init 请求选项
* @returns 隔离业务响应
*/
window.fetch = async (input, init) => {
if (init?.method && init.method !== 'GET') return new Response('{}', { status: 403 })
const path = String(input)
const data = path.includes('/quality-review')
? {
shotId: 's',
keyframeId: 'k',
qualityDecision: 'passed',
effectiveQualityStatus: status.value,
manualReviewAvailable: available.value,
validationTaskId: 't',
historicalGazePreview: [],
manualReview: null
}
: []
return new Response(JSON.stringify({ data }), { headers: { 'Content-Type': 'application/json' } })
}
/** 复用真实组件进行可重复的桌面和窄屏验收。 */
const Preview = defineComponent({
setup() {
/** 仅打开只读面板,不执行审核。 */
const qualityOpen = ref(false)
/** 独立来源抽屉仅查看当前质量。 */
const sourceOpen = ref(false)
return () =>
h('main', { style: 'padding:24px;max-width:1100px;margin:auto;height:100dvh;overflow:auto' }, [
h('h1', { style: 'font-size:24px;margin-bottom:16px' }, '首帧当前质量 · 隔离验收'),
h(
'div',
{ style: 'display:flex;flex-wrap:wrap;gap:12px;margin-bottom:24px' },
(['stale', 'blocked', 'passed', 'unknown', 'needs_review'] as const).map(value =>
h(
NButton,
{
onClick: () => {
status.value = value
available.value = value === 'needs_review'
revision.value++
}
},
() => value
)
)
),
h(NButton, { onClick: () => (qualityOpen.value = true) }, () => '查看质量弹窗'),
h(NButton, { onClick: () => (sourceOpen.value = true) }, () => '查看来源抽屉'),
h(QualityDialog, {
open: qualityOpen.value,
'onUpdate:open': (value: boolean) => (qualityOpen.value = value),
projectId: 'p',
target: { kind: 'keyframe', shotId: 's', assetId: 'k', title: '隔离候选' },
disabled: true
}),
h(SourceReviewDrawer, {
open: sourceOpen.value,
'onUpdate:open': (value: boolean) => (sourceOpen.value = value),
projectId: 'p',
shotId: 's',
keyframeId: 'k'
}),
h(
'div',
{
style: 'display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,320px),1fr));gap:24px'
},
[
h(KeyframeCard, {
key: 'card' + revision.value,
item: keyframeFixture({
id: 'k',
shotId: 's',
imageUrl: 'http://localhost:4312/tests/browser/candidate.svg',
isPrimary: false
}),
projectId: 'p',
shotId: 's',
shotNo: 1,
stale: false,
blocked: false,
validationPassed: true,
confirming: false
}),
h('div', [
h(KeyframeValidationHistory, {
key: 'history' + revision.value,
projectId: 'p',
shotId: 's',
keyframeId: 'k',
initialOpen: true
}),
h(QualityResult, { receipt: { kind: 'keyframe', result }, currentStatus: status.value })
])
]
)
])
}
})
createApp({
render: () => h(NConfigProvider, null, { default: () => h(NMessageProvider, null, { default: () => h(Preview) }) })
}).mount('#app')