Files

97 lines
3.9 KiB
TypeScript

import { createApp, defineComponent, h, ref } from 'vue'
import { NButton, NConfigProvider, NMessageProvider, zhCN, dateZhCN } from 'naive-ui'
import Drawer from '../../src/features/production/components/ContinuityReviewDrawer.vue'
import { createContinuityMock, continuityShots, diagnosisFixture } from '../fixtures/continuity'
import { jointPlan, jointTask, stateContexts } from '../fixtures/continuity-joint'
import '../../src/styles/styles.css'
import '../../src/styles/admin.css'
/** 全部服务隔离,不向真实 API 发写请求。 */
const mock = createContinuityMock('http://localhost:4312/tests/browser/candidate.svg')
/** 当前隔离计划状态。 */
const planStatus = ref<'ready' | 'blocked' | 'reusable'>('ready')
/** 当前隔离签收。 */
const review = {
reviewId: 'mock-review',
reviewer: '隔离审核人',
reviewedAt: '',
status: 'passed',
invalidation: null,
diagnosis: diagnosisFixture(
{ shotIds: ['s1', 's2'], sceneFormId: 'scene-form' },
'http://localhost:4312/tests/browser/candidate.svg'
)
}
/**
* 只允许免费诊断、布局输入预览和只读回读,批准、签收、执行及恢复全部拒绝。
* @param input 请求地址
* @param init 请求选项
* @returns 隔离响应
*/
window.fetch = async (input, init) => {
const path = new URL(String(input), window.location.origin).pathname
if (
init?.method &&
init.method !== 'GET' &&
!path.endsWith('/continuity/diagnosis') &&
!path.endsWith('/keyframe/preview')
)
return new Response(JSON.stringify({ message: '隔离页禁止写入与付费' }), { status: 403 })
let data: unknown
if (path.includes('/vision/preview'))
data = {
...jointPlan,
projectId: 'mock-project',
reviewId: 'mock-review',
status: planStatus.value,
executionAvailable: planStatus.value === 'ready',
reusableTaskId: planStatus.value === 'reusable' ? 't' : null
}
else if (path.includes('/vision-tasks/')) data = { ...jointTask, reviewId: 'mock-review' }
else if (path.endsWith('/reviews/mock-review')) data = review
else if (path.includes('/workflow-executions/')) data = null
else if (path.endsWith('/continuity/diagnosis')) {
const response = await mock.fetcher(input, init)
const body = await response.json()
if (JSON.parse(String(init?.body)).scope) body.data.stateContext = stateContexts
return new Response(JSON.stringify(body))
} else return mock.fetcher(input, init)
return new Response(JSON.stringify({ data }))
}
/** 可复用现有抽屉的隔离浏览器入口。 */
const Preview = defineComponent({
setup() {
/** 当前抽屉。 */ const open = ref(false)
return () =>
h('main', { style: 'padding:24px' }, [
h('h1', 'V02 连续性隔离验收:批准、执行、保存均禁止'),
...(['ready', 'blocked', 'reusable'] as const).map(value =>
h(
NButton,
{
onClick: () => {
planStatus.value = value
open.value = true
}
},
() => value
)
),
h(Drawer, {
open: open.value,
'onUpdate:open': (v: boolean) => (open.value = v),
projectId: 'mock-project',
shots: continuityShots,
disabled: false
})
])
}
})
createApp({
render: () =>
h(
NConfigProvider,
{ locale: zhCN, dateLocale: dateZhCN },
{ default: () => h(NMessageProvider, null, { default: () => h(Preview) }) }
)
}).mount('#app')