feat: 同步精简接口并统一表单校验

This commit is contained in:
GJ committed 2026-09-10 22:34:47 +08:00
1 parent 82d7bde631
commit 2eea0ea72e
66 files changed
+1611 -1100

No files matched your search

+76 -62
View File
@@ -1,4 +1,7 @@
<script setup lang="ts">
import AppForm from '../../components/ui/AppForm.vue'
import { NFormItem } from 'naive-ui'
import { integerRule, fieldRule } from '../../lib/form-rules'
import WorkspacePage from '../../components/ui/WorkspacePage.vue'
import ActionMenu from '../../components/ui/ActionMenu.vue'
import { NScrollbar, NAlert, NButton, NCheckbox, NInputNumber, NProgress, NTab, NTable, NTabs, NTag } from 'naive-ui'
@@ -132,6 +135,11 @@ function exportResult() {
'application/json'
)
}
const formModel = computed(() => ({ groupSize: groupSize.value, modules: modules.value }))
const rules = {
groupSize: integerRule('每组集数'),
modules: fieldRule(value => Array.isArray(value) && value.length > 0, '请至少选择一个抽取模块', true)
}
</script>
<template>
@@ -170,64 +178,73 @@ function exportResult() {
</div>
<NTag size="small" :bordered="false">来源:正式剧集</NTag>
</div>
<div class="breakdown-config">
<div class="breakdown-group-field">
<label class="field-label" for="group-size">每组集数</label>
<div class="breakdown-group-input">
<NInputNumber
:disabled="operation.pending"
:input-props="{ id: 'group-size' }"
class="breakdown-group-number"
:value="typeof groupSize === 'number' ? groupSize : null"
@update:value="groupSize = $event ?? 0"
:min="1"
:step="1"
></NInputNumber
><span class="breakdown-group-unit">集 / 组</span>
</div>
</div>
<fieldset class="breakdown-modules-field">
<legend class="field-label">抽取模块</legend>
<div class="breakdown-module-options">
<div
v-for="option in moduleOptions"
:key="option.value"
class="breakdown-module-option"
>
<NCheckbox
:checked="modules.includes(option.value)"
<AppForm
:model="formModel"
:rules="rules"
:disabled="operation.pending"
validate-on-change
@submit="loadPreview"
>
<div class="breakdown-config">
<NFormItem
class="breakdown-group-field"
path="groupSize"
label="每组集数"
:label-props="{ for: 'group-size' }"
>
<div class="breakdown-group-input">
<NInputNumber
:disabled="operation.pending"
:aria-label="option.label"
:aria-describedby="`breakdown-module-${option.value}-help`"
@update:checked="toggleModule(option.value, $event)"
class="control-row-checkbox"
><span class="text-sm font-medium">{{ option.label }}</span></NCheckbox
>
<p
:id="`breakdown-module-${option.value}-help`"
class="breakdown-module-description"
>
{{ option.description }}
</p>
:input-props="{ id: 'group-size' }"
class="breakdown-group-number"
:value="typeof groupSize === 'number' ? groupSize : null"
@update:value="groupSize = $event ?? 0"
:min="1"
:step="1"
></NInputNumber
><span class="breakdown-group-unit">集 / 组</span>
</div>
</div>
</fieldset>
<NButton
:disabled="
project?.status !== 'completed' ||
!configValid ||
previewBusy ||
operation.pending ||
!!error
"
@click="loadPreview"
class="breakdown-preview-button"
><LoaderCircle v-if="previewBusy" :size="14" class="animate-spin" />预览分组
</NButton>
</div>
<p v-if="!configValid" class="mt-4 text-xs text-danger">
每组集数必须是正整数,并至少选择一个抽取模块。
</p>
</NFormItem>
<NFormItem path="modules" label="抽取模块" class="breakdown-modules-field">
<div class="breakdown-module-options">
<div
v-for="option in moduleOptions"
:key="option.value"
class="breakdown-module-option"
>
<NCheckbox
:checked="modules.includes(option.value)"
:disabled="operation.pending"
:aria-label="option.label"
:aria-describedby="`breakdown-module-${option.value}-help`"
@update:checked="toggleModule(option.value, $event)"
class="control-row-checkbox"
><span class="text-sm font-medium">{{
option.label
}}</span></NCheckbox
>
<p
:id="`breakdown-module-${option.value}-help`"
class="breakdown-module-description"
>
{{ option.description }}
</p>
</div>
</div>
</NFormItem>
<NButton
:disabled="
project?.status !== 'completed' ||
previewBusy ||
operation.pending ||
!!error
"
attr-type="submit"
class="breakdown-preview-button"
><LoaderCircle v-if="previewBusy" :size="14" class="animate-spin" />预览分组
</NButton>
</div>
</AppForm>
<NAlert v-if="previewError" role="alert" type="error" :show-icon="false" class="mt-4">{{
previewError
}}</NAlert>
@@ -517,10 +534,7 @@ function exportResult() {
}
.breakdown-config {
@apply grid grid-cols-[180px_minmax(0,_1fr)_auto] items-start gap-y-4 gap-x-6;
--breakdown-label-offset: 28px;
}
.breakdown-config .field-label {
@apply mt-0 mx-0 mb-2 p-0 leading-[20px];
--breakdown-label-offset: 29px;
}
.breakdown-group-field,
.breakdown-modules-field,
@@ -528,7 +542,7 @@ function exportResult() {
@apply min-w-0;
}
.breakdown-group-input {
@apply flex items-center gap-3;
@apply w-full flex items-center gap-3;
}
.breakdown-group-number.n-input-number {
@apply flex-[0_0_120px] w-[120px];
@@ -540,7 +554,7 @@ function exportResult() {
@apply m-0 p-0 border-0;
}
.breakdown-module-options {
@apply grid grid-cols-[repeat(3,_minmax(0,_1fr))] gap-y-3 gap-x-4;
@apply w-full grid grid-cols-[repeat(3,_minmax(0,_1fr))] gap-y-3 gap-x-4;
}
.breakdown-module-description {
@apply mt-1 mx-0 mb-0 pl-6 text-muted text-[11px] leading-[18px] wrap-anywhere;