feat(shipping-notice): 添加 MinerU 订单附件表格结构化功能,更新环境配置和数据模型以支持新布局解析和文档模板管理
This commit is contained in:
1 parent
c4095b08da
commit
c35223d49d
148 files changed
+15709
-1353
No files matched your search
@@ -513,10 +513,14 @@ export const listAdminAgentRuntimeBindings = (agentId: number) =>
|
||||
requestJson<import('@/features/admin/types/agent.types').AgentRuntimeBindingRow[]>(
|
||||
`/api/admin/agents/${agentId}/runtime-bindings`, auth(),
|
||||
);
|
||||
export const listApprovedOrderExtractionQualityBatches = (ownerAgentId: number) =>
|
||||
requestJson<import('@/features/admin/types/agent.types').OrderExtractionQualityBatchOption[]>(
|
||||
`/api/admin/shipping-notice/order-extraction-quality-batches?owner_agent_id=${ownerAgentId}`, auth(),
|
||||
);
|
||||
export const saveAdminAgentRuntimeBinding = (
|
||||
agentId: number,
|
||||
capabilityCode: string,
|
||||
payload: { provider_agent_id: number; enabled: boolean; config: Record<string, number> },
|
||||
payload: { provider_agent_id: number; enabled: boolean; config: Record<string, unknown> },
|
||||
) => requestJson<import('@/features/admin/types/agent.types').AgentRuntimeBindingRow>(
|
||||
`/api/admin/agents/${agentId}/runtime-bindings/${capabilityCode}`,
|
||||
{ method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload) },
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* features/admin/api/shipping-order-document-profile.api.ts
|
||||
* 用途:订单文档 Profile 管理、MinerU 样本选择和发布 API。
|
||||
* 依赖:shared/api/client、auth headers、Profile DTO。
|
||||
* 逻辑:页面只使用结构化接口;结构指纹和 HTML 始终由后端持有。
|
||||
*/
|
||||
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import type {
|
||||
CreateOrderProfileFromSampleInput,
|
||||
OrderProfileSampleDocument,
|
||||
OrderProfileSamplePreview,
|
||||
ShippingOrderDocumentProfile,
|
||||
} from '../types/shipping-order-document-profile.types';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
||||
|
||||
/** 列出全部 Profile 版本。 */
|
||||
export const listOrderDocumentProfiles = () =>
|
||||
requestJson<ShippingOrderDocumentProfile[]>('/api/admin/shipping-notice/order-document-profiles', auth());
|
||||
|
||||
/** 列出已具备 ready MinerU 表格的样本文档。 */
|
||||
export const listOrderProfileSamples = () =>
|
||||
requestJson<OrderProfileSampleDocument[]>('/api/admin/shipping-notice/order-document-profile-samples', auth());
|
||||
|
||||
/** 读取一个样本文档的网格预览,不返回 HTML 或 bbox。 */
|
||||
export const getOrderProfileSampleTables = (documentId: number) =>
|
||||
requestJson<OrderProfileSamplePreview>(
|
||||
`/api/admin/shipping-notice/order-document-profile-samples/${documentId}/tables`, auth(),
|
||||
);
|
||||
|
||||
/** 由真实样本和结构化列选择创建 Profile 草稿。 */
|
||||
export const createOrderProfileFromSample = (payload: CreateOrderProfileFromSampleInput) =>
|
||||
requestJson<ShippingOrderDocumentProfile>('/api/admin/shipping-notice/order-document-profiles/from-sample', {
|
||||
method: 'POST', body: JSON.stringify(payload), ...jsonAuth(),
|
||||
});
|
||||
|
||||
/** 用新样本和乐观锁更新已存在草稿。 */
|
||||
export const updateOrderProfileFromSample = (
|
||||
profileId: number, payload: CreateOrderProfileFromSampleInput & { expected_lock_version: number },
|
||||
) => requestJson<ShippingOrderDocumentProfile>(
|
||||
`/api/admin/shipping-notice/order-document-profiles/${profileId}/from-sample`, {
|
||||
method: 'PUT', body: JSON.stringify(payload), ...jsonAuth(),
|
||||
},
|
||||
);
|
||||
|
||||
/** 发布草稿并退役同编码旧版本。 */
|
||||
export const publishOrderDocumentProfile = (profileId: number, expectedLockVersion: number) =>
|
||||
requestJson<ShippingOrderDocumentProfile>(
|
||||
`/api/admin/shipping-notice/order-document-profiles/${profileId}/publish`,
|
||||
{ method: 'POST', body: JSON.stringify({ expected_lock_version: expectedLockVersion }), ...jsonAuth() },
|
||||
);
|
||||
|
||||
/** 从不可变版本复制下一草稿。 */
|
||||
export const cloneOrderDocumentProfile = (profileId: number) =>
|
||||
requestJson<ShippingOrderDocumentProfile>(
|
||||
`/api/admin/shipping-notice/order-document-profiles/${profileId}/clone`,
|
||||
{ method: 'POST', ...jsonAuth() },
|
||||
);
|
||||
|
||||
/** 退役当前发布版本。 */
|
||||
export const retireOrderDocumentProfile = (profileId: number) =>
|
||||
requestJson<ShippingOrderDocumentProfile>(
|
||||
`/api/admin/shipping-notice/order-document-profiles/${profileId}/retire`,
|
||||
{ method: 'POST', ...jsonAuth() },
|
||||
);
|
||||
|
||||
/** 删除错误草稿。 */
|
||||
export const deleteOrderDocumentProfile = (profileId: number) =>
|
||||
requestJson<void>(`/api/admin/shipping-notice/order-document-profiles/${profileId}`, {
|
||||
method: 'DELETE', ...auth(),
|
||||
});
|
||||
@@ -25,6 +25,12 @@ const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getA
|
||||
export const getShippingOrderSchemaState = () =>
|
||||
requestJson<ShippingOrderSchemaState>('/api/admin/shipping-order-schema', auth());
|
||||
|
||||
/** 保存订单字段模板中的自动建单总开关。 */
|
||||
export const saveShippingOrderAutoCreationPolicy = (enabled: boolean) =>
|
||||
requestJson<{ enabled: boolean }>('/api/admin/shipping-order-schema/auto-creation-policy', {
|
||||
method: 'PUT', body: JSON.stringify({ enabled }), ...jsonAuth(),
|
||||
});
|
||||
|
||||
/** 初始化全局唯一订单 Schema。 */
|
||||
export const initializeShippingOrderSchema = (payload: { display_name: string; description?: string }) =>
|
||||
requestJson<ShippingOrderSchemaState>('/api/admin/shipping-order-schema', {
|
||||
@@ -116,7 +122,11 @@ export const getShippingOrderExtractionAudit = (extractionId: number) =>
|
||||
/** 整体保存草稿字段配置及每个字段的版本纳入状态。 */
|
||||
export const saveShippingOrderSchemaDraft = (
|
||||
versionId: number,
|
||||
payload: { fields: ShippingOrderFieldConfig[]; change_note?: string; expected_lock_version: number },
|
||||
payload: {
|
||||
fields: ShippingOrderFieldConfig[];
|
||||
change_note?: string;
|
||||
expected_lock_version: number;
|
||||
},
|
||||
) => requestJson<ShippingOrderSchemaVersion>(`/api/admin/shipping-order-schema/versions/${versionId}`, {
|
||||
method: 'PUT', body: JSON.stringify(payload), ...jsonAuth(),
|
||||
});
|
||||
|
||||
@@ -15,8 +15,8 @@ export interface AdminModuleMeta {
|
||||
|
||||
export interface ShippingConfigSubModuleMeta {
|
||||
id: ShippingConfigSubModuleId;
|
||||
routeName: 'AdminShippingInventory' | 'AdminShippingIdentityRules' | 'AdminShippingOrderExtractionRuns';
|
||||
path: 'shipping-notice' | 'shipping-identity-rules' | 'shipping-order-extraction-runs';
|
||||
routeName: 'AdminShippingInventory' | 'AdminShippingIdentityRules' | 'AdminShippingOrderExtractionRuns' | 'AdminShippingOrderDocumentProfiles';
|
||||
path: 'shipping-notice' | 'shipping-identity-rules' | 'shipping-order-extraction-runs' | 'shipping-order-document-profiles';
|
||||
labelKey: string;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ export const SHIPPING_CONFIG_SUB_MODULE_METAS: ShippingConfigSubModuleMeta[] = [
|
||||
{ id: 'inventory', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.nav.shippingInventory' },
|
||||
{ id: 'identity_rules', routeName: 'AdminShippingIdentityRules', path: 'shipping-identity-rules', labelKey: 'admin.nav.shippingIdentityRules' },
|
||||
{ id: 'order_extraction_runs', routeName: 'AdminShippingOrderExtractionRuns', path: 'shipping-order-extraction-runs', labelKey: 'admin.nav.shippingOrderExtractionRuns' },
|
||||
{ id: 'order_document_profiles', routeName: 'AdminShippingOrderDocumentProfiles', path: 'shipping-order-document-profiles', labelKey: 'admin.nav.shippingOrderDocumentProfiles' },
|
||||
];
|
||||
|
||||
export const ADMIN_REPORT_TABLES: AdminReportTableId[] = [
|
||||
|
||||
@@ -371,61 +371,31 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
<h4 class="text-sm font-semibold text-primary">{{ t('admin.agent.runtimeBinding.title') }}</h4>
|
||||
<p class="mt-1 text-xs text-muted">{{ t('admin.agent.runtimeBinding.subtitle') }}</p>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.provider') }}</label>
|
||||
<select v-model="form.order_extraction_provider_agent_id" class="w-full input-field text-sm">
|
||||
<option :value="null">{{ t('admin.agent.runtimeBinding.selectProvider') }}</option>
|
||||
<option v-for="agent in orderExtractionProviderOptions" :key="agent.id" :value="agent.id">
|
||||
{{ agent.name }} (Workflow #{{ agent.id }})
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.timeout') }}</label>
|
||||
<input v-model.number="form.order_extraction_timeout_seconds" type="number" min="30" max="3600" class="w-full input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.maxAttempts') }}</label>
|
||||
<input v-model.number="form.order_extraction_max_attempts" type="number" min="1" max="10" class="w-full input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.unitConcurrency') }}</label>
|
||||
<input v-model.number="form.order_extraction_unit_concurrency" type="number" min="2" max="4" class="w-full input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.unitMaxAttempts') }}</label>
|
||||
<input v-model.number="form.order_extraction_unit_max_attempts" type="number" min="1" max="3" class="w-full input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.unitRetryBackoff') }}</label>
|
||||
<input v-model.number="form.order_extraction_unit_retry_backoff_ms" type="number" min="100" max="5000" step="100" class="w-full input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.maxModelUnits') }}</label>
|
||||
<input v-model.number="form.order_extraction_max_model_units" type="number" min="1" max="100" class="w-full input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.providerMaxConcurrency') }}</label>
|
||||
<input v-model.number="form.order_extraction_provider_max_concurrency" type="number" min="1" max="20" class="w-full input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.circuitFailureThreshold') }}</label>
|
||||
<input v-model.number="form.order_extraction_circuit_failure_threshold" type="number" min="2" max="20" class="w-full input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.circuitCooldown') }}</label>
|
||||
<input v-model.number="form.order_extraction_circuit_cooldown_seconds" type="number" min="10" max="600" class="w-full input-field text-sm" />
|
||||
</div>
|
||||
<label class="flex items-center gap-3 rounded-lg border border-default px-3 py-2 md:col-span-2">
|
||||
<input v-model="form.order_extraction_auto_create_enabled" type="checkbox" class="h-4 w-4" />
|
||||
<span class="text-sm">{{ t('admin.agent.runtimeBinding.autoCreateEnabled') }}</span>
|
||||
</label>
|
||||
<div class="overflow-x-auto rounded-lg border border-default">
|
||||
<table class="min-w-full text-sm">
|
||||
<thead class="bg-surface-soft text-left text-xs font-bold uppercase tracking-wider text-muted">
|
||||
<tr><th class="px-3 py-2">{{ t('admin.agent.runtimeBinding.capability') }}</th><th class="px-3 py-2">{{ t('admin.agent.runtimeBinding.provider') }}</th><th class="px-3 py-2">{{ t('admin.agent.runtimeBinding.timeout') }}</th><th class="px-3 py-2">{{ t('admin.agent.runtimeBinding.maxAttempts') }}</th></tr>
|
||||
</thead>
|
||||
<tbody><tr class="border-t border-default">
|
||||
<td class="px-3 py-3 font-medium text-primary">{{ t('admin.agent.runtimeBinding.orderExtraction') }}</td>
|
||||
<td class="px-3 py-3"><select v-model="form.order_extraction_provider_agent_id" class="w-full input-field text-sm"><option :value="null">{{ t('admin.agent.runtimeBinding.selectProvider') }}</option><option v-for="agent in orderExtractionProviderOptions" :key="agent.id" :value="agent.id">{{ agent.name }} (Workflow #{{ agent.id }})</option></select></td>
|
||||
<td class="px-3 py-3"><input v-model.number="form.order_extraction_timeout_seconds" type="number" min="30" max="3600" class="w-28 input-field text-sm" /></td>
|
||||
<td class="px-3 py-3"><input v-model.number="form.order_extraction_max_attempts" type="number" min="1" max="10" class="w-20 input-field text-sm" /></td>
|
||||
</tr></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p v-if="!orderExtractionProviderOptions.length" class="mt-3 text-xs text-amber-700">
|
||||
{{ t('admin.agent.runtimeBinding.noProvider') }}
|
||||
</p>
|
||||
</div>
|
||||
<div v-if="isInternalExecutor" class="col-span-1 md:col-span-2 rounded-xl border border-default bg-surface-soft p-4">
|
||||
<div class="mb-4"><h4 class="text-sm font-semibold text-primary">{{ t('admin.agent.runtimeBinding.executorGovernance') }}</h4></div>
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<div class="space-y-2"><label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.providerMaxConcurrency') }}</label><input v-model.number="form.executor_provider_max_concurrency" type="number" min="1" max="20" class="w-full input-field text-sm" /></div>
|
||||
<div class="space-y-2"><label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.circuitFailureThreshold') }}</label><input v-model.number="form.executor_circuit_failure_threshold" type="number" min="2" max="20" class="w-full input-field text-sm" /></div>
|
||||
<div class="space-y-2"><label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.runtimeBinding.circuitCooldown') }}</label><input v-model.number="form.executor_circuit_cooldown_seconds" type="number" min="10" max="600" class="w-full input-field text-sm" /></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-if="showIframeFields">
|
||||
<div class="col-span-1 md:col-span-2 space-y-2">
|
||||
|
||||
@@ -412,18 +412,14 @@ export function useAgentsAdmin() {
|
||||
form.value.order_extraction_provider_agent_id = binding?.provider_agent_id ?? null;
|
||||
form.value.order_extraction_timeout_seconds = Number(binding?.config?.timeout_seconds || 900);
|
||||
form.value.order_extraction_max_attempts = Number(binding?.config?.max_attempts || 3);
|
||||
form.value.order_extraction_unit_concurrency = Number(binding?.config?.unit_concurrency || 2);
|
||||
form.value.order_extraction_unit_max_attempts = Number(binding?.config?.unit_max_attempts || 2);
|
||||
form.value.order_extraction_unit_retry_backoff_ms = Number(binding?.config?.unit_retry_backoff_ms || 500);
|
||||
form.value.order_extraction_max_model_units = Number(binding?.config?.max_model_units || 20);
|
||||
form.value.order_extraction_provider_max_concurrency = Number(binding?.config?.provider_max_concurrency || 4);
|
||||
form.value.order_extraction_circuit_failure_threshold = Number(binding?.config?.circuit_failure_threshold || 5);
|
||||
form.value.order_extraction_circuit_cooldown_seconds = Number(binding?.config?.circuit_cooldown_seconds || 60);
|
||||
form.value.order_extraction_auto_create_enabled = binding?.config?.auto_create_enabled === true;
|
||||
}).catch((error) => {
|
||||
console.error('Error loading Agent runtime bindings:', error);
|
||||
});
|
||||
}
|
||||
const governance = asRecord(extra.order_extraction_governance);
|
||||
form.value.executor_provider_max_concurrency = Number(governance.provider_max_concurrency || 4);
|
||||
form.value.executor_circuit_failure_threshold = Number(governance.circuit_failure_threshold || 5);
|
||||
form.value.executor_circuit_cooldown_seconds = Number(governance.circuit_cooldown_seconds || 60);
|
||||
};
|
||||
|
||||
const openDeleteConfirm = (
|
||||
@@ -538,17 +534,17 @@ export function useAgentsAdmin() {
|
||||
config: {
|
||||
timeout_seconds: form.value.order_extraction_timeout_seconds,
|
||||
max_attempts: form.value.order_extraction_max_attempts,
|
||||
unit_concurrency: form.value.order_extraction_unit_concurrency,
|
||||
unit_max_attempts: form.value.order_extraction_unit_max_attempts,
|
||||
unit_retry_backoff_ms: form.value.order_extraction_unit_retry_backoff_ms,
|
||||
max_model_units: form.value.order_extraction_max_model_units,
|
||||
provider_max_concurrency: form.value.order_extraction_provider_max_concurrency,
|
||||
circuit_failure_threshold: form.value.order_extraction_circuit_failure_threshold,
|
||||
circuit_cooldown_seconds: form.value.order_extraction_circuit_cooldown_seconds,
|
||||
auto_create_enabled: form.value.order_extraction_auto_create_enabled,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (form.value.exposure_mode === 'internal') {
|
||||
extra_config.order_extraction_governance = {
|
||||
provider_max_concurrency: form.value.executor_provider_max_concurrency,
|
||||
circuit_failure_threshold: form.value.executor_circuit_failure_threshold,
|
||||
circuit_cooldown_seconds: form.value.executor_circuit_cooldown_seconds,
|
||||
};
|
||||
registryPayload.extra_config = extra_config;
|
||||
}
|
||||
|
||||
try {
|
||||
const editingId = isEditing.value ? Number(form.value.id) : null;
|
||||
|
||||
+365
@@ -0,0 +1,365 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/ShippingOrderDocumentProfilesPage.vue
|
||||
用途:通过 MinerU 样本表格可视化创建和发布订单文档 Profile。
|
||||
依赖:Profile/Schema API、BusinessError、useMessage、Vue I18n。
|
||||
逻辑:管理员选择真实样本、表格、表头行和列目标;浏览器不展示 HTML,也不编辑 JSON/结构指纹。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
cloneOrderDocumentProfile,
|
||||
createOrderProfileFromSample,
|
||||
deleteOrderDocumentProfile,
|
||||
getOrderProfileSampleTables,
|
||||
listOrderDocumentProfiles,
|
||||
listOrderProfileSamples,
|
||||
publishOrderDocumentProfile,
|
||||
retireOrderDocumentProfile,
|
||||
updateOrderProfileFromSample,
|
||||
} from '@/features/admin/api/shipping-order-document-profile.api';
|
||||
import { getShippingOrderSchemaState } from '@/features/admin/api/shipping-order-schema.api';
|
||||
import type {
|
||||
OrderProfileSampleDocument,
|
||||
OrderProfileSamplePreview,
|
||||
OrderProfileSampleTable,
|
||||
ShippingOrderDocumentProfile,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.types';
|
||||
import {
|
||||
buildOrderProfileColumnRules,
|
||||
findDuplicateOrderProfileTargets,
|
||||
} from './orderProfileForm.utils';
|
||||
import type {
|
||||
ShippingOrderFieldConfig,
|
||||
ShippingOrderSchemaVersion,
|
||||
} from '@/features/admin/types/shipping-order-schema.types';
|
||||
|
||||
const { t } = useI18n();
|
||||
const message = useMessage();
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const editingProfileId = ref<number | null>(null);
|
||||
const editingLockVersion = ref<number | null>(null);
|
||||
const profiles = ref<ShippingOrderDocumentProfile[]>([]);
|
||||
const samples = ref<OrderProfileSampleDocument[]>([]);
|
||||
const preview = ref<OrderProfileSamplePreview | null>(null);
|
||||
const publishedSchemas = ref<ShippingOrderSchemaVersion[]>([]);
|
||||
const form = reactive({
|
||||
profile_code: '', display_name: '', schema_version_id: 0,
|
||||
document_id: 0, table_id: '', header_row_index: 0, data_start_row_index: 1,
|
||||
row_structure: 'preserved' as 'preserved' | 'unsupported_row_structure',
|
||||
drop_zero_qty: true, change_note: '',
|
||||
});
|
||||
const columnRules = ref<Array<{ extractor_key: 'direct' | 'temp_internal_parts'; target: string }>>([]);
|
||||
|
||||
const selectedTable = computed<OrderProfileSampleTable | null>(() => (
|
||||
preview.value?.tables.find((item) => item.table_id === form.table_id) || null
|
||||
));
|
||||
const selectedSchema = computed(() => publishedSchemas.value.find((item) => item.id === form.schema_version_id) || null);
|
||||
const lineFields = computed<ShippingOrderFieldConfig[]>(() => (
|
||||
selectedSchema.value?.definition?.fields.filter((item) => item.enabled !== false && item.scope === 'line') || []
|
||||
));
|
||||
const compositeExtractorAvailable = computed(() => {
|
||||
const codes = new Set(lineFields.value.map((item) => item.field_code));
|
||||
return codes.has('customer_part_number') && codes.has('part_number');
|
||||
});
|
||||
const hasConfiguredColumn = computed(() => columnRules.value.some((item) => (
|
||||
item.extractor_key === 'temp_internal_parts' ? compositeExtractorAvailable.value : Boolean(item.target)
|
||||
)));
|
||||
const duplicateTargets = computed(() => {
|
||||
if (form.row_structure !== 'preserved') return [];
|
||||
return findDuplicateOrderProfileTargets(normalizedRules());
|
||||
});
|
||||
const canSave = computed(() => Boolean(
|
||||
form.profile_code.trim() && form.display_name.trim() && form.schema_version_id
|
||||
&& form.document_id && form.table_id && selectedTable.value
|
||||
&& form.data_start_row_index > form.header_row_index
|
||||
&& form.header_row_index >= 0
|
||||
&& form.data_start_row_index < (selectedTable.value?.row_count || 0)
|
||||
&& duplicateTargets.value.length === 0
|
||||
&& (form.row_structure === 'unsupported_row_structure' || hasConfiguredColumn.value),
|
||||
));
|
||||
|
||||
/** 将 API 错误映射到统一消息;页面不展示后端内部详情。 */
|
||||
const showError = (error: unknown) => {
|
||||
if (error instanceof BusinessError) message.error(t(`errors.codes.${error.code}`, error.message));
|
||||
else message.error(t('admin.shippingOrderProfiles.loadFailed'));
|
||||
};
|
||||
|
||||
/** 加载 Profile、样本和不可变 Schema 版本。 */
|
||||
const load = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const [profileRows, sampleRows, schemaState] = await Promise.all([
|
||||
listOrderDocumentProfiles(), listOrderProfileSamples(), getShippingOrderSchemaState(),
|
||||
]);
|
||||
profiles.value = profileRows;
|
||||
samples.value = sampleRows;
|
||||
publishedSchemas.value = schemaState.versions.filter((item) => item.status !== 'draft' && item.definition);
|
||||
if (!form.schema_version_id) form.schema_version_id = schemaState.versions.find((item) => item.status === 'published')?.id || 0;
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 选择样本文档后读取由后端展开的网格。 */
|
||||
const loadPreview = async () => {
|
||||
preview.value = null;
|
||||
form.table_id = '';
|
||||
if (!form.document_id) return;
|
||||
try {
|
||||
preview.value = await getOrderProfileSampleTables(form.document_id);
|
||||
form.table_id = preview.value.tables[0]?.table_id || '';
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
}
|
||||
};
|
||||
|
||||
/** 表格变化时按真实列数初始化受控列映射。 */
|
||||
const resetColumns = () => {
|
||||
const count = selectedTable.value?.column_count || 0;
|
||||
columnRules.value = Array.from({ length: count }, () => ({ extractor_key: 'direct', target: '' }));
|
||||
form.header_row_index = 0;
|
||||
form.data_start_row_index = Math.min(1, Math.max((selectedTable.value?.row_count || 1) - 1, 0));
|
||||
};
|
||||
|
||||
/** 转换结构化表单为后端白名单列规则,不提交结构指纹或 HTML。 */
|
||||
const normalizedRules = () => buildOrderProfileColumnRules(
|
||||
columnRules.value, compositeExtractorAvailable.value,
|
||||
);
|
||||
|
||||
/** 模板渲染前确保指定列存在规则对象。 */
|
||||
const columnRule = (columnIndex: number) => {
|
||||
if (!columnRules.value[columnIndex]) {
|
||||
columnRules.value[columnIndex] = { extractor_key: 'direct', target: '' };
|
||||
}
|
||||
return columnRules.value[columnIndex]!;
|
||||
};
|
||||
|
||||
/** 创建或更新草稿;指纹由后端按当前样本 HTML 计算。 */
|
||||
const saveDraft = async () => {
|
||||
if (!canSave.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
const payload = {
|
||||
...form,
|
||||
profile_code: form.profile_code.trim().toUpperCase(),
|
||||
display_name: form.display_name.trim(),
|
||||
column_rules: form.row_structure === 'preserved' ? normalizedRules() : [],
|
||||
};
|
||||
if (editingProfileId.value && editingLockVersion.value !== null) {
|
||||
await updateOrderProfileFromSample(editingProfileId.value, {
|
||||
...payload, expected_lock_version: editingLockVersion.value,
|
||||
});
|
||||
} else {
|
||||
await createOrderProfileFromSample(payload);
|
||||
}
|
||||
message.success(t(editingProfileId.value
|
||||
? 'admin.shippingOrderProfiles.updated'
|
||||
: 'admin.shippingOrderProfiles.created'));
|
||||
editingProfileId.value = null;
|
||||
editingLockVersion.value = null;
|
||||
await load();
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 进入草稿配置模式;结构仍必须从管理员随后选择的新样本生成。 */
|
||||
const editDraft = (profile: ShippingOrderDocumentProfile) => {
|
||||
editingProfileId.value = profile.id;
|
||||
editingLockVersion.value = profile.lock_version;
|
||||
form.profile_code = profile.profile_code;
|
||||
form.display_name = profile.display_name;
|
||||
form.schema_version_id = profile.schema_version_id;
|
||||
form.row_structure = profile.definition.row_structure;
|
||||
form.drop_zero_qty = profile.definition.drop_zero_qty;
|
||||
form.change_note = profile.change_note || '';
|
||||
form.document_id = 0;
|
||||
preview.value = null;
|
||||
form.table_id = '';
|
||||
};
|
||||
|
||||
/** 取消草稿编辑并恢复新建模式。 */
|
||||
const cancelEdit = () => {
|
||||
editingProfileId.value = null;
|
||||
editingLockVersion.value = null;
|
||||
form.profile_code = '';
|
||||
form.display_name = '';
|
||||
form.change_note = '';
|
||||
form.document_id = 0;
|
||||
};
|
||||
|
||||
/** 从不可变版本复制下一草稿,并立即进入样本重配模式。 */
|
||||
const createNextVersion = async (profile: ShippingOrderDocumentProfile) => {
|
||||
try {
|
||||
const draft = await cloneOrderDocumentProfile(profile.id);
|
||||
editDraft(draft);
|
||||
message.success(t('admin.shippingOrderProfiles.cloned'));
|
||||
await load();
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
}
|
||||
};
|
||||
|
||||
/** 发布草稿并刷新版本列表。 */
|
||||
const publishProfile = async (profile: ShippingOrderDocumentProfile) => {
|
||||
try {
|
||||
await publishOrderDocumentProfile(profile.id, profile.lock_version);
|
||||
message.success(t('admin.shippingOrderProfiles.published'));
|
||||
await load();
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
}
|
||||
};
|
||||
|
||||
/** 删除错误草稿;发布版本由服务端保护。 */
|
||||
const removeProfile = async (profile: ShippingOrderDocumentProfile) => {
|
||||
if (!window.confirm(t('admin.shippingOrderProfiles.deleteConfirm'))) return;
|
||||
try {
|
||||
await deleteOrderDocumentProfile(profile.id);
|
||||
message.success(t('admin.shippingOrderProfiles.deleted'));
|
||||
await load();
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
}
|
||||
};
|
||||
|
||||
/** 退役当前发布版本;历史运行继续使用冻结快照。 */
|
||||
const retireProfile = async (profile: ShippingOrderDocumentProfile) => {
|
||||
if (!window.confirm(t('admin.shippingOrderProfiles.retireConfirm'))) return;
|
||||
try {
|
||||
await retireOrderDocumentProfile(profile.id);
|
||||
message.success(t('admin.shippingOrderProfiles.retired'));
|
||||
await load();
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
}
|
||||
};
|
||||
|
||||
watch(() => form.document_id, loadPreview);
|
||||
watch(() => form.table_id, resetColumns);
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="min-h-full bg-slate-50 p-6 text-slate-900">
|
||||
<div class="mx-auto max-w-[1500px] space-y-6">
|
||||
<header>
|
||||
<h1 class="text-2xl font-semibold">{{ t('admin.shippingOrderProfiles.title') }}</h1>
|
||||
<p class="mt-1 text-sm text-slate-500">{{ t('admin.shippingOrderProfiles.subtitle') }}</p>
|
||||
</header>
|
||||
|
||||
<div class="grid gap-6 xl:grid-cols-[420px_minmax(0,1fr)]">
|
||||
<form class="space-y-4 rounded-xl border border-slate-200 bg-white p-5 shadow-sm" @submit.prevent="saveDraft">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<h2 class="font-semibold">{{ t(editingProfileId ? 'admin.shippingOrderProfiles.editTitle' : 'admin.shippingOrderProfiles.createTitle') }}</h2>
|
||||
<button v-if="editingProfileId" type="button" class="text-sm text-slate-500" @click="cancelEdit">{{ t('common.cancel') }}</button>
|
||||
</div>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.sample') }}</span>
|
||||
<select v-model.number="form.document_id" class="w-full rounded-lg border border-slate-300 px-3 py-2">
|
||||
<option :value="0">{{ t('admin.shippingOrderProfiles.selectSample') }}</option>
|
||||
<option v-for="sample in samples" :key="sample.document_id" :value="sample.document_id">
|
||||
{{ sample.filename || `Document ${sample.document_id}` }} ({{ sample.table_count }})
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.table') }}</span>
|
||||
<select v-model="form.table_id" class="w-full rounded-lg border border-slate-300 px-3 py-2" :disabled="!preview">
|
||||
<option value="">{{ t('admin.shippingOrderProfiles.selectTable') }}</option>
|
||||
<option v-for="table in preview?.tables || []" :key="table.table_id" :value="table.table_id">
|
||||
P{{ table.page_no }} · {{ table.row_count }}×{{ table.column_count }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<label class="text-sm"><span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.code') }}</span><input v-model="form.profile_code" :disabled="Boolean(editingProfileId)" class="w-full rounded-lg border border-slate-300 px-3 py-2 disabled:bg-slate-100" /></label>
|
||||
<label class="text-sm"><span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.name') }}</span><input v-model="form.display_name" class="w-full rounded-lg border border-slate-300 px-3 py-2" /></label>
|
||||
</div>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.schema') }}</span>
|
||||
<select v-model.number="form.schema_version_id" :disabled="Boolean(editingProfileId)" class="w-full rounded-lg border border-slate-300 px-3 py-2 disabled:bg-slate-100">
|
||||
<option v-for="schema in publishedSchemas" :key="schema.id" :value="schema.id">v{{ schema.version }} · {{ schema.status }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.rowStructure') }}</span>
|
||||
<select v-model="form.row_structure" class="w-full rounded-lg border border-slate-300 px-3 py-2">
|
||||
<option value="preserved">{{ t('admin.shippingOrderProfiles.rowPreserved') }}</option>
|
||||
<option value="unsupported_row_structure">{{ t('admin.shippingOrderProfiles.rowUnsupported') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<label class="text-sm"><span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.headerRow') }}</span><input v-model.number="form.header_row_index" type="number" min="0" class="w-full rounded-lg border border-slate-300 px-3 py-2" /></label>
|
||||
<label class="text-sm"><span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.dataRow') }}</span><input v-model.number="form.data_start_row_index" type="number" min="1" class="w-full rounded-lg border border-slate-300 px-3 py-2" /></label>
|
||||
</div>
|
||||
<label class="flex items-center gap-2 text-sm"><input v-model="form.drop_zero_qty" type="checkbox" />{{ t('admin.shippingOrderProfiles.dropZeroQty') }}</label>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.changeNote') }}</span>
|
||||
<textarea v-model="form.change_note" rows="2" class="w-full rounded-lg border border-slate-300 px-3 py-2" />
|
||||
</label>
|
||||
<p v-if="duplicateTargets.length" class="rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700">
|
||||
{{ t('admin.shippingOrderProfiles.duplicateTargets', { fields: duplicateTargets.join(', ') }) }}
|
||||
</p>
|
||||
<button type="submit" :disabled="!canSave || saving" class="w-full rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white disabled:opacity-50">
|
||||
{{ saving ? t('admin.shippingOrderProfiles.saving') : t(editingProfileId ? 'admin.shippingOrderProfiles.updateDraft' : 'admin.shippingOrderProfiles.createDraft') }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="min-w-0 space-y-4">
|
||||
<div class="overflow-auto rounded-xl border border-slate-200 bg-white shadow-sm">
|
||||
<table v-if="selectedTable" class="min-w-full border-collapse text-sm">
|
||||
<tbody>
|
||||
<tr v-for="(row, rowIndex) in selectedTable.rows" :key="rowIndex" :class="rowIndex === form.header_row_index ? 'bg-blue-50 font-semibold' : ''">
|
||||
<td class="sticky left-0 border border-slate-200 bg-slate-50 px-2 py-2 text-xs text-slate-500">{{ rowIndex }}</td>
|
||||
<td v-for="(cell, columnIndex) in row" :key="columnIndex" class="max-w-[260px] border border-slate-200 px-3 py-2 align-top">
|
||||
<div class="break-words">{{ cell }}</div>
|
||||
<div v-if="rowIndex === form.header_row_index && form.row_structure === 'preserved'" class="mt-2 space-y-1">
|
||||
<div v-if="columnRule(columnIndex).extractor_key === 'temp_internal_parts'" class="rounded bg-slate-100 px-2 py-1 text-xs text-slate-600">
|
||||
customer_part_number + part_number
|
||||
</div>
|
||||
<select v-else v-model="columnRule(columnIndex).target" class="w-full rounded border border-slate-300 px-2 py-1 text-xs">
|
||||
<option value="">{{ t('admin.shippingOrderProfiles.ignoreColumn') }}</option>
|
||||
<option v-for="field in lineFields" :key="field.field_id" :value="field.field_code">{{ field.display_name }} · {{ field.field_code }}</option>
|
||||
</select>
|
||||
<select v-model="columnRule(columnIndex).extractor_key" class="w-full rounded border border-slate-300 px-2 py-1 text-xs">
|
||||
<option value="direct">{{ t('admin.shippingOrderProfiles.direct') }}</option>
|
||||
<option value="temp_internal_parts" :disabled="!compositeExtractorAvailable">{{ t('admin.shippingOrderProfiles.compositePart') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div v-else class="p-10 text-center text-sm text-slate-500">{{ t('admin.shippingOrderProfiles.previewEmpty') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-xl border border-slate-200 bg-white shadow-sm">
|
||||
<div class="border-b border-slate-200 px-5 py-4 font-semibold">{{ t('admin.shippingOrderProfiles.versions') }}</div>
|
||||
<div v-if="loading" class="p-6 text-sm text-slate-500">{{ t('common.loading') }}</div>
|
||||
<div v-else class="divide-y divide-slate-100">
|
||||
<div v-for="profile in profiles" :key="profile.id" class="flex flex-wrap items-center justify-between gap-3 px-5 py-4">
|
||||
<div><div class="font-medium">{{ profile.display_name }} · v{{ profile.version }}</div><div class="text-xs text-slate-500">{{ profile.profile_code }} · Schema v{{ profile.schema_version }} · {{ profile.status }}<span v-if="profile.change_note"> · {{ profile.change_note }}</span></div></div>
|
||||
<div class="flex gap-2">
|
||||
<button v-if="profile.status === 'draft'" class="rounded border border-slate-300 px-3 py-1.5 text-sm text-slate-700" @click="editDraft(profile)">{{ t('common.edit') }}</button>
|
||||
<button v-if="profile.status === 'draft'" class="rounded border border-blue-300 px-3 py-1.5 text-sm text-blue-700" @click="publishProfile(profile)">{{ t('admin.shippingOrderProfiles.publish') }}</button>
|
||||
<button v-if="profile.status === 'draft'" class="rounded border border-red-300 px-3 py-1.5 text-sm text-red-700" @click="removeProfile(profile)">{{ t('common.delete') }}</button>
|
||||
<button v-if="profile.status === 'published' || profile.status === 'retired'" class="rounded border border-blue-300 px-3 py-1.5 text-sm text-blue-700" @click="createNextVersion(profile)">{{ t('admin.shippingOrderProfiles.newVersion') }}</button>
|
||||
<button v-if="profile.status === 'published'" class="rounded border border-amber-300 px-3 py-1.5 text-sm text-amber-700" @click="retireProfile(profile)">{{ t('admin.shippingOrderProfiles.retire') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.spec.ts
|
||||
* 用途:验证可视化订单模板表单只生成受控规则并阻止目标字段重复映射。
|
||||
* 依赖:Vitest、orderProfileForm.utils。
|
||||
* 逻辑:覆盖 direct、复合解析器开关及跨列冲突,避免无效配置进入后端。
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
buildOrderProfileColumnRules,
|
||||
findDuplicateOrderProfileTargets,
|
||||
} from './orderProfileForm.utils';
|
||||
|
||||
describe('order profile form rules', () => {
|
||||
it('builds only registered direct and composite rules', () => {
|
||||
const rules = buildOrderProfileColumnRules([
|
||||
{ extractor_key: 'direct', target: 'qty' },
|
||||
{ extractor_key: 'direct', target: '' },
|
||||
{ extractor_key: 'temp_internal_parts', target: '' },
|
||||
], true);
|
||||
|
||||
// 断言忽略空列,并保持复合解析器的固定双字段输出契约。
|
||||
expect(rules).toEqual([
|
||||
{ column_index: 0, extractor_key: 'direct', target_field_codes: ['qty'] },
|
||||
{
|
||||
column_index: 2,
|
||||
extractor_key: 'temp_internal_parts',
|
||||
target_field_codes: ['customer_part_number', 'part_number'],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('blocks targets repeated by direct or composite mappings', () => {
|
||||
const rules = buildOrderProfileColumnRules([
|
||||
{ extractor_key: 'temp_internal_parts', target: '' },
|
||||
{ extractor_key: 'direct', target: 'part_number' },
|
||||
], true);
|
||||
|
||||
// 断言复合解析器与普通列之间的隐式重复也能在提交前被发现。
|
||||
expect(findDuplicateOrderProfileTargets(rules)).toEqual(['part_number']);
|
||||
});
|
||||
|
||||
it('does not emit an unavailable composite extractor', () => {
|
||||
expect(buildOrderProfileColumnRules([
|
||||
{ extractor_key: 'temp_internal_parts', target: '' },
|
||||
], false)).toEqual([]);
|
||||
});
|
||||
});
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.ts
|
||||
* 用途:构造可视化订单模板的白名单列规则,并在提交前发现目标字段冲突。
|
||||
* 依赖:订单 Profile DTO。
|
||||
* 逻辑:页面状态只允许 direct 或已注册复合解析器;同一目标字段跨列只能出现一次。
|
||||
*/
|
||||
|
||||
import type { OrderProfileColumnRule } from '@/features/admin/types/shipping-order-document-profile.types';
|
||||
|
||||
export interface OrderProfileColumnSelection {
|
||||
extractor_key: 'direct' | 'temp_internal_parts';
|
||||
target: string;
|
||||
}
|
||||
|
||||
/** 将逐列选择转换为后端白名单规则;不可用的复合解析器不会进入请求。 */
|
||||
export const buildOrderProfileColumnRules = (
|
||||
selections: OrderProfileColumnSelection[], compositeExtractorAvailable: boolean,
|
||||
): OrderProfileColumnRule[] => {
|
||||
const rules: OrderProfileColumnRule[] = [];
|
||||
selections.forEach((item, columnIndex) => {
|
||||
if (item.extractor_key === 'temp_internal_parts') {
|
||||
if (compositeExtractorAvailable) rules.push({
|
||||
column_index: columnIndex,
|
||||
extractor_key: 'temp_internal_parts',
|
||||
target_field_codes: ['customer_part_number', 'part_number'],
|
||||
});
|
||||
} else if (item.target) {
|
||||
rules.push({
|
||||
column_index: columnIndex,
|
||||
extractor_key: 'direct',
|
||||
target_field_codes: [item.target],
|
||||
});
|
||||
}
|
||||
});
|
||||
return rules;
|
||||
};
|
||||
|
||||
/** 返回跨列重复映射的目标字段,供页面阻止提交并显示明确提示。 */
|
||||
export const findDuplicateOrderProfileTargets = (rules: OrderProfileColumnRule[]): string[] => {
|
||||
const targets = rules.flatMap((item) => item.target_field_codes);
|
||||
return [...new Set(targets.filter((target, index) => targets.indexOf(target) !== index))];
|
||||
};
|
||||
+34
-1
@@ -28,6 +28,7 @@ import {
|
||||
publishShippingOrderSchemaDraft,
|
||||
reorderShippingOrderFields,
|
||||
saveShippingOrderSchemaDraft,
|
||||
saveShippingOrderAutoCreationPolicy,
|
||||
updateShippingOrderField,
|
||||
} from '@/features/admin/api/shipping-order-schema.api';
|
||||
import SchemaVersionHistoryDrawer from '@/features/admin/modules/shipping-order-schema/components/SchemaVersionHistoryDrawer.vue';
|
||||
@@ -66,6 +67,7 @@ const fieldForm = reactive({
|
||||
});
|
||||
const schemaForm = reactive({ display_name: '发货订单字段', description: '' });
|
||||
const draftFields = ref<DraftFieldEditor[]>([]);
|
||||
const autoCreationEnabled = ref(false);
|
||||
const changeNote = ref('');
|
||||
const selectedDraftFieldId = ref<string | null>(null);
|
||||
const editingFieldCode = ref('');
|
||||
@@ -426,6 +428,7 @@ const syncContextExposurePolicy = (config: ShippingOrderFieldConfig): void => {
|
||||
|
||||
/** 将草稿字段配置同步到本地编辑状态,并保留未纳入版本的 active 字段供管理员选择。 */
|
||||
const syncDraftFields = (): void => {
|
||||
autoCreationEnabled.value = state.value?.schema?.auto_creation_policy?.enabled === true;
|
||||
const existing = draft.value?.definition?.fields || published.value?.definition?.fields || [];
|
||||
const byId = new Map(existing.map((item) => [item.field_id, item]));
|
||||
const globalSequence = new Map((state.value?.fields || []).map((field) => [field.id, field.display_sequence]));
|
||||
@@ -436,6 +439,8 @@ const syncDraftFields = (): void => {
|
||||
field_id: field.id,
|
||||
display_name: published.value?.definition?.fields.find((item) => item.field_id === field.id)?.display_name || field.field_code,
|
||||
business_purpose: 'general' as const,
|
||||
auto_create_key_field: false,
|
||||
minimum_confidence: null,
|
||||
required: false,
|
||||
aliases: [],
|
||||
...defaultRule(field),
|
||||
@@ -614,6 +619,23 @@ const saveDraft = async (): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 保存自动建单总开关;字段级置信度仍由当前草稿保存并发布。 */
|
||||
const saveAutoCreationEnabled = async (): Promise<void> => {
|
||||
const previous = !autoCreationEnabled.value;
|
||||
saving.value = true;
|
||||
try {
|
||||
const saved = await saveShippingOrderAutoCreationPolicy(autoCreationEnabled.value);
|
||||
autoCreationEnabled.value = saved.enabled;
|
||||
if (state.value?.schema) state.value.schema.auto_creation_policy = saved;
|
||||
message.success(t('admin.shippingOrderSchema.autoCreationSaved'));
|
||||
} catch (error) {
|
||||
autoCreationEnabled.value = previous;
|
||||
showError(error);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 发布当前草稿;发布后不可原地修改。 */
|
||||
const publishDraft = async (): Promise<void> => {
|
||||
if (!draft.value) return;
|
||||
@@ -766,6 +788,11 @@ onMounted(async () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="auto-creation-switch">
|
||||
<input v-model="autoCreationEnabled" :disabled="saving" type="checkbox" @change="saveAutoCreationEnabled">
|
||||
<span><strong>{{ t('admin.shippingOrderSchema.autoCreationEnabled') }}</strong><small>{{ t('admin.shippingOrderSchema.autoCreationHint') }}</small></span>
|
||||
</label>
|
||||
|
||||
<div class="schema-workbench">
|
||||
<aside class="field-panel">
|
||||
<div class="panel-heading">
|
||||
@@ -849,6 +876,7 @@ onMounted(async () => {
|
||||
</template>
|
||||
<template v-else>
|
||||
<label><span>{{ t('admin.shippingOrderSchema.businessPurpose') }}</span><select v-model="selectedRuleConfig.business_purpose" :disabled="isReadOnly || !selectedDraftField?.enabled || fieldFor(selectedRuleConfig)?.scope !== 'line'"><option v-for="item in ['general', 'part_number', 'quantity', 'reservation_id', 'inventory_source_hint']" :key="item" :value="item">{{ t(`admin.shippingOrderSchema.businessPurposeOption.${item}`) }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingOrderSchema.minimumKeyFieldConfidence') }}</span><input v-model.number="selectedRuleConfig.minimum_confidence" :disabled="isReadOnly || !selectedDraftField?.enabled || !selectedRuleConfig.auto_create_key_field" :required="selectedRuleConfig.auto_create_key_field" min="0" max="1" step="0.01" type="number"></label>
|
||||
<label class="span-two"><span>{{ t('admin.shippingOrderSchema.aliases') }}</span><input :value="selectedRuleConfig.aliases.join(', ')" :disabled="isReadOnly || !selectedDraftField?.enabled" @input="!isReadOnly && (selectedRuleConfig.aliases = splitValues(($event.target as HTMLInputElement).value))"></label>
|
||||
<label class="span-two"><span>{{ t('admin.shippingOrderSchema.extractionInstruction') }}</span><textarea v-model="selectedRuleConfig.extraction_instruction" :disabled="isReadOnly || !selectedDraftField?.enabled" :placeholder="t('admin.shippingOrderSchema.extractionInstructionPlaceholder')"></textarea></label>
|
||||
<template v-if="selectedIsOrderHeader">
|
||||
@@ -857,7 +885,7 @@ onMounted(async () => {
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
<template v-if="!selectedIsContext"><div class="rule-switches"><label><input v-model="selectedRuleConfig.required" :disabled="isReadOnly || !selectedDraftField?.enabled" type="checkbox"><span><strong>{{ t('admin.shippingOrderSchema.required') }}</strong></span></label><label><input v-model="selectedRuleConfig.evidence_policy.required" :disabled="isReadOnly || !selectedDraftField?.enabled" type="checkbox"><span><strong>{{ t('admin.shippingOrderSchema.evidenceRequired') }}</strong></span></label><label><input v-model="selectedRuleConfig.evidence_policy.allow_single_source" :disabled="isReadOnly || !selectedDraftField?.enabled" type="checkbox"><span><strong>{{ t('admin.shippingOrderSchema.allowSingleSource') }}</strong></span></label></div>
|
||||
<template v-if="!selectedIsContext"><div class="rule-switches"><label><input v-model="selectedRuleConfig.required" :disabled="isReadOnly || !selectedDraftField?.enabled" type="checkbox"><span><strong>{{ t('admin.shippingOrderSchema.required') }}</strong></span></label><label><input v-model="selectedRuleConfig.auto_create_key_field" :disabled="isReadOnly || !selectedDraftField?.enabled" type="checkbox"><span><strong>{{ t('admin.shippingOrderSchema.autoCreateKeyField') }}</strong></span></label><label><input v-model="selectedRuleConfig.evidence_policy.required" :disabled="isReadOnly || !selectedDraftField?.enabled" type="checkbox"><span><strong>{{ t('admin.shippingOrderSchema.evidenceRequired') }}</strong></span></label><label><input v-model="selectedRuleConfig.evidence_policy.allow_single_source" :disabled="isReadOnly || !selectedDraftField?.enabled" type="checkbox"><span><strong>{{ t('admin.shippingOrderSchema.allowSingleSource') }}</strong></span></label></div>
|
||||
<details class="advanced-rules"><summary>{{ t('admin.shippingOrderSchema.advancedRules') }}</summary><div class="advanced-content"><div class="rule-grid"><label><span>{{ t('admin.shippingOrderSchema.normalizer') }}</span><select v-model="selectedRuleConfig.normalizer_key" :disabled="isReadOnly || !selectedDraftField?.enabled"><option v-for="item in compatibleRules(selectedRuleConfig, 'type_normalizers')" :key="item" :value="item">{{ ruleLabel(item) }}</option></select></label><label><span>{{ t('admin.shippingOrderSchema.comparator') }}</span><select v-model="selectedRuleConfig.comparator_key" :disabled="isReadOnly || !selectedDraftField?.enabled"><option v-for="item in compatibleRules(selectedRuleConfig, 'type_comparators')" :key="item" :value="item">{{ ruleLabel(item) }}</option></select></label><label><span>{{ t('admin.shippingOrderSchema.relationRole') }}</span><select v-model="selectedRuleConfig.relation_role" :disabled="isReadOnly || !selectedDraftField?.enabled"><option :value="null">{{ t('admin.shippingOrderSchema.notSet') }}</option><option v-for="item in state.catalog.relation_roles" :key="item" :value="item">{{ ruleLabel(item) }}</option></select></label><label><span>{{ t('admin.shippingOrderSchema.conflictPolicy') }}</span><select v-model="selectedRuleConfig.evidence_policy.conflict_policy" :disabled="isReadOnly || !selectedDraftField?.enabled"><option v-for="item in state.catalog.conflict_policies" :key="item" :value="item">{{ ruleLabel(item) }}</option></select></label></div><fieldset><legend>{{ t('admin.shippingOrderSchema.validators') }}</legend><div class="check-row"><label v-for="item in compatibleRules(selectedRuleConfig, 'type_validators')" :key="item"><input :checked="selectedRuleConfig.validator_keys.includes(item)" :disabled="isReadOnly || !selectedDraftField?.enabled" type="checkbox" @change="!isReadOnly && (selectedRuleConfig.validator_keys = toggleValue(selectedRuleConfig.validator_keys, item))">{{ ruleLabel(item) }}</label></div></fieldset><fieldset><legend>{{ t('admin.shippingOrderSchema.sourcePrecedence') }}</legend><div class="check-row"><label v-for="item in state.catalog.source_types" :key="item"><input :checked="selectedRuleConfig.evidence_policy.source_precedence.includes(item)" :disabled="isReadOnly || !selectedDraftField?.enabled" type="checkbox" @change="!isReadOnly && (selectedRuleConfig.evidence_policy.source_precedence = toggleValue(selectedRuleConfig.evidence_policy.source_precedence, item))">{{ sourceLabel(item) }}</label></div></fieldset></div></details></template>
|
||||
</div>
|
||||
<footer v-if="!isReadOnly" class="rule-footer"><label><span>{{ t('admin.shippingOrderSchema.changeNote') }}</span><input v-model="changeNote" :placeholder="t('admin.shippingOrderSchema.changeNotePlaceholder')"></label><button :disabled="saving" class="text-danger" @click="deleteDraft">{{ t('admin.shippingOrderSchema.deleteDraft') }}</button></footer>
|
||||
@@ -931,6 +959,11 @@ onMounted(async () => {
|
||||
.schema-toolbar span { color: #94a3b8; font-size: 12px; }
|
||||
.toolbar-actions, .form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.schema-workbench { display: grid; height: min(700px, calc(100vh - 280px)); min-height: 540px; grid-template-columns: 300px minmax(0, 1fr); overflow: hidden; border: 1px solid #dfe7ef; border-radius: 10px; background: #fff; box-shadow: 0 1px 2px rgb(15 23 42 / 3%); }
|
||||
.auto-creation-switch { display: flex; align-items: center; gap: 9px; margin: 0 0 16px; border: 1px solid #dbe6ef; border-radius: 8px; background: #fbfdff; padding: 11px 14px; color: #475569; cursor: pointer; }
|
||||
.auto-creation-switch input { width: 16px; height: 16px; margin: 0; accent-color: #0ea5e9; }
|
||||
.auto-creation-switch span { display: grid; gap: 3px; }
|
||||
.auto-creation-switch strong { color: #334155; font-size: 13px; }
|
||||
.auto-creation-switch small { color: #64748b; font-size: 11px; }
|
||||
.field-panel { display: flex; min-width: 0; min-height: 0; flex-direction: column; border-right: 1px solid #e5ebf1; background: #fbfcfe; }
|
||||
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 16px 10px; }
|
||||
.panel-heading h2, .rule-heading h2 { margin: 0; color: #1e293b; font-size: 15px; font-weight: 600; }
|
||||
|
||||
@@ -10,7 +10,10 @@ import { adminRoutes } from '@/app/router/routes/admin.routes';
|
||||
import { SHIPPING_CONFIG_SUB_MODULE_METAS } from './constants/modules';
|
||||
|
||||
const shippingRoutes = adminRoutes[0].children?.filter((route) =>
|
||||
route.name === 'AdminShippingInventory' || route.name === 'AdminShippingIdentityRules' || route.name === 'AdminShippingOrderExtractionRuns',
|
||||
route.name === 'AdminShippingInventory'
|
||||
|| route.name === 'AdminShippingIdentityRules'
|
||||
|| route.name === 'AdminShippingOrderExtractionRuns'
|
||||
|| route.name === 'AdminShippingOrderDocumentProfiles',
|
||||
) ?? [];
|
||||
|
||||
describe('shipping configuration navigation contract', () => {
|
||||
@@ -20,8 +23,9 @@ describe('shipping configuration navigation contract', () => {
|
||||
{ id: 'inventory', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.nav.shippingInventory' },
|
||||
{ id: 'identity_rules', routeName: 'AdminShippingIdentityRules', path: 'shipping-identity-rules', labelKey: 'admin.nav.shippingIdentityRules' },
|
||||
{ id: 'order_extraction_runs', routeName: 'AdminShippingOrderExtractionRuns', path: 'shipping-order-extraction-runs', labelKey: 'admin.nav.shippingOrderExtractionRuns' },
|
||||
{ id: 'order_document_profiles', routeName: 'AdminShippingOrderDocumentProfiles', path: 'shipping-order-document-profiles', labelKey: 'admin.nav.shippingOrderDocumentProfiles' },
|
||||
]);
|
||||
expect(shippingRoutes).toHaveLength(3);
|
||||
expect(shippingRoutes).toHaveLength(4);
|
||||
});
|
||||
|
||||
it('keeps all deep links behind the shared shipping inventory admin boundary', () => {
|
||||
@@ -30,6 +34,7 @@ describe('shipping configuration navigation contract', () => {
|
||||
expect.objectContaining({ requiresAdmin: true, adminModule: 'shipping_inventory', adminSubModule: 'inventory' }),
|
||||
expect.objectContaining({ requiresAdmin: true, adminModule: 'shipping_inventory', adminSubModule: 'identity_rules' }),
|
||||
expect.objectContaining({ requiresAdmin: true, adminModule: 'shipping_inventory', adminSubModule: 'order_extraction_runs' }),
|
||||
expect.objectContaining({ requiresAdmin: true, adminModule: 'shipping_inventory', adminSubModule: 'order_document_profiles' }),
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -21,7 +21,7 @@ export type AdminModuleId =
|
||||
| 'reports';
|
||||
|
||||
/** 货代配置领域下可由侧栏展示和高亮的稳定子页面。 */
|
||||
export type ShippingConfigSubModuleId = 'inventory' | 'identity_rules' | 'order_extraction_runs';
|
||||
export type ShippingConfigSubModuleId = 'inventory' | 'identity_rules' | 'order_extraction_runs' | 'order_document_profiles';
|
||||
|
||||
export type AdminReportTableId =
|
||||
| 'usage_analysis'
|
||||
|
||||
@@ -136,14 +136,9 @@ export interface AgentFormState {
|
||||
order_extraction_provider_agent_id: number | null;
|
||||
order_extraction_timeout_seconds: number;
|
||||
order_extraction_max_attempts: number;
|
||||
order_extraction_unit_concurrency: number;
|
||||
order_extraction_unit_max_attempts: number;
|
||||
order_extraction_unit_retry_backoff_ms: number;
|
||||
order_extraction_max_model_units: number;
|
||||
order_extraction_provider_max_concurrency: number;
|
||||
order_extraction_circuit_failure_threshold: number;
|
||||
order_extraction_circuit_cooldown_seconds: number;
|
||||
order_extraction_auto_create_enabled: boolean;
|
||||
executor_provider_max_concurrency: number;
|
||||
executor_circuit_failure_threshold: number;
|
||||
executor_circuit_cooldown_seconds: number;
|
||||
}
|
||||
|
||||
export const createEmptyTrainingQuestionForm = (): AgentTrainingQuestionFormItem => ({
|
||||
@@ -207,16 +202,23 @@ export const createEmptyAgentForm = (
|
||||
order_extraction_provider_agent_id: null,
|
||||
order_extraction_timeout_seconds: 900,
|
||||
order_extraction_max_attempts: 3,
|
||||
order_extraction_unit_concurrency: 2,
|
||||
order_extraction_unit_max_attempts: 2,
|
||||
order_extraction_unit_retry_backoff_ms: 500,
|
||||
order_extraction_max_model_units: 20,
|
||||
order_extraction_provider_max_concurrency: 4,
|
||||
order_extraction_circuit_failure_threshold: 5,
|
||||
order_extraction_circuit_cooldown_seconds: 60,
|
||||
order_extraction_auto_create_enabled: false,
|
||||
executor_provider_max_concurrency: 4,
|
||||
executor_circuit_failure_threshold: 5,
|
||||
executor_circuit_cooldown_seconds: 60,
|
||||
});
|
||||
|
||||
export interface OrderExtractionQualityBatchOption {
|
||||
id: number;
|
||||
batch_no: string;
|
||||
approved_at: string | null;
|
||||
metrics: {
|
||||
agreed_sample_count: number;
|
||||
precision: number;
|
||||
recall: number;
|
||||
eligible: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export interface AgentRuntimeBindingRow {
|
||||
id: number;
|
||||
owner_agent_id: number;
|
||||
@@ -226,13 +228,5 @@ export interface AgentRuntimeBindingRow {
|
||||
config: {
|
||||
timeout_seconds?: number;
|
||||
max_attempts?: number;
|
||||
unit_concurrency?: number;
|
||||
unit_max_attempts?: number;
|
||||
unit_retry_backoff_ms?: number;
|
||||
max_model_units?: number;
|
||||
provider_max_concurrency?: number;
|
||||
circuit_failure_threshold?: number;
|
||||
circuit_cooldown_seconds?: number;
|
||||
auto_create_enabled?: boolean;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* features/admin/types/shipping-order-document-profile.types.ts
|
||||
* 用途:订单文档 Profile、MinerU 样本预览和结构化列规则 DTO。
|
||||
* 依赖:无。
|
||||
* 逻辑:管理页面只提交样本选择和白名单解析器,不持有或提交 HTML/结构指纹。
|
||||
*/
|
||||
|
||||
export type OrderProfileExtractorKey = 'direct' | 'temp_internal_parts';
|
||||
|
||||
export interface OrderProfileColumnRule {
|
||||
column_index: number;
|
||||
extractor_key: OrderProfileExtractorKey;
|
||||
target_field_codes: string[];
|
||||
target_fields?: Array<{ field_id: string; field_code: string }>;
|
||||
}
|
||||
|
||||
export interface ShippingOrderDocumentProfile {
|
||||
id: number;
|
||||
profile_code: string;
|
||||
display_name: string;
|
||||
version: number;
|
||||
status: 'draft' | 'published' | 'retired';
|
||||
schema_version_id: number;
|
||||
schema_version?: number | null;
|
||||
schema_checksum?: string | null;
|
||||
structure_fingerprint: string;
|
||||
definition: {
|
||||
contract_version: string;
|
||||
structure_fingerprint: string;
|
||||
header_row_index: number;
|
||||
data_start_row_index: number;
|
||||
row_structure: 'preserved' | 'unsupported_row_structure';
|
||||
column_rules: OrderProfileColumnRule[];
|
||||
drop_zero_qty: boolean;
|
||||
};
|
||||
checksum?: string | null;
|
||||
lock_version: number;
|
||||
change_note?: string | null;
|
||||
source_profile_id?: number | null;
|
||||
published_at?: string | null;
|
||||
retired_at?: string | null;
|
||||
}
|
||||
|
||||
export interface OrderProfileSampleDocument {
|
||||
document_id: number;
|
||||
intake_id: number;
|
||||
filename?: string | null;
|
||||
content_hash?: string | null;
|
||||
provider?: string | null;
|
||||
provider_version?: string | null;
|
||||
table_count: number;
|
||||
created_at?: string | null;
|
||||
}
|
||||
|
||||
export interface OrderProfileSampleTable {
|
||||
table_id: string;
|
||||
page_no: number;
|
||||
row_count: number;
|
||||
column_count: number;
|
||||
rows: string[][];
|
||||
}
|
||||
|
||||
export interface OrderProfileSamplePreview {
|
||||
document: Pick<OrderProfileSampleDocument, 'document_id' | 'intake_id' | 'filename' | 'content_hash'>;
|
||||
tables: OrderProfileSampleTable[];
|
||||
}
|
||||
|
||||
export interface CreateOrderProfileFromSampleInput {
|
||||
profile_code: string;
|
||||
display_name: string;
|
||||
schema_version_id: number;
|
||||
document_id: number;
|
||||
table_id: string;
|
||||
header_row_index: number;
|
||||
data_start_row_index: number;
|
||||
row_structure: 'preserved' | 'unsupported_row_structure';
|
||||
column_rules: OrderProfileColumnRule[];
|
||||
drop_zero_qty: boolean;
|
||||
change_note?: string;
|
||||
}
|
||||
@@ -27,6 +27,8 @@ export interface ShippingOrderFieldConfig {
|
||||
display_name: string;
|
||||
description?: string | null;
|
||||
business_purpose?: 'general' | 'part_number' | 'quantity' | 'reservation_id' | 'inventory_source_hint';
|
||||
auto_create_key_field?: boolean;
|
||||
minimum_confidence?: number | null;
|
||||
required: boolean;
|
||||
aliases: string[];
|
||||
normalizer_key: string;
|
||||
@@ -173,6 +175,7 @@ export interface ShippingOrderSchemaState {
|
||||
display_name: string;
|
||||
description?: string | null;
|
||||
status: string;
|
||||
auto_creation_policy: { enabled: boolean };
|
||||
};
|
||||
fields: ShippingOrderField[];
|
||||
versions: ShippingOrderSchemaVersion[];
|
||||
|
||||
Reference in new issue
Block a user