feat(shipping-notice): 完善发货通知自动推进与多库存源复核闭环
This commit is contained in:
1 parent
cfa19a0b7b
commit
8e0bbf7a81
180 files changed
+31210
-1864
No files matched your search
+420
@@ -0,0 +1,420 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-legacy-stp-jobs/ShippingLegacyStpJobsPage.vue
|
||||
用途:Phase 5-1 —— 管理员「历史 STP Job(928/929 回放)」运维面板。
|
||||
依赖:shipping-legacy-stp-jobs.api、Vue Router、Vue I18n、workspace.shippingNotice.actions 键。
|
||||
逻辑:
|
||||
[STEP 1] 左侧 ~38%:分页列表(筛选 q/case_no/error_code/blocking_reason/status/created_from/to)
|
||||
按创建时间倒序;
|
||||
[STEP 2] 右侧 sticky:详情 —— Job 摘要、回链 Review Case(case 非空时跳转工作台 Case 详情)、
|
||||
replay_plan(推荐 user_action)、
|
||||
「一键回放 Reconcile And Progress」按钮直接走
|
||||
POST /api/workspace/shipping-notice/order-review-cases/<case_no>/reconcile-and-progress
|
||||
带 legacy_job_id + replay_mode。
|
||||
全部只读 + 一个写操作(回放按钮),写操作必须管理员;非管理员会被后端 422。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
DEFAULT_LEGACY_STP_JOB_FILTERS,
|
||||
LEGACY_STP_JOB_STATUS_OPTIONS,
|
||||
getAdminLegacyStpJob,
|
||||
listAdminLegacyStpJobs,
|
||||
type LegacyStpJobDetailPayload,
|
||||
type LegacyStpJobListFilters,
|
||||
type LegacyStpJobRow,
|
||||
} from '@/features/admin/api/shipping-legacy-stp-jobs.api';
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const router = useRouter();
|
||||
const message = useMessage();
|
||||
|
||||
const loading = ref(false);
|
||||
const detailLoading = ref(false);
|
||||
const replaying = ref(false);
|
||||
const error = ref('');
|
||||
const page = ref(1);
|
||||
const pageSize = ref(25);
|
||||
const total = ref(0);
|
||||
const filters = ref<LegacyStpJobListFilters>({ ...DEFAULT_LEGACY_STP_JOB_FILTERS });
|
||||
const rows = ref<LegacyStpJobRow[]>([]);
|
||||
const selectedJobId = ref<number | null>(null);
|
||||
const detail = ref<LegacyStpJobDetailPayload | null>(null);
|
||||
const replayUserAction = ref<'auto' | 'reuse_existing' | 'create_revision' | 'force_create' | 'adjudicate'>('create_revision');
|
||||
const replayLastResult = ref<{ ok: boolean; outcome?: string | null; message?: string | null } | null>(null);
|
||||
|
||||
const formatTime = (value?: string | null) => (value ? new Date(value).toLocaleString() : '—');
|
||||
function jsonFormat(value: unknown): string {
|
||||
if (value == null) return '—';
|
||||
try { return JSON.stringify(value, null, 2); } catch { return String(value); }
|
||||
}
|
||||
type CodeLabelNs = 'admin.legacyStpJobs.statusLabels' | 'admin.legacyStpJobs.reasonCodes' | 'workspace.shippingNotice.processGate.actionCodes';
|
||||
|
||||
function codeLabel(code?: string | null, ns: CodeLabelNs = 'admin.legacyStpJobs.statusLabels'): string {
|
||||
const key = String(code || '').trim();
|
||||
if (!key) return '—';
|
||||
const i18nKey = `${ns}.${key}`;
|
||||
return te(i18nKey) ? t(i18nKey) : key;
|
||||
}
|
||||
function actionLabel(code?: string | null): string { return codeLabel(code, 'workspace.shippingNotice.processGate.actionCodes'); }
|
||||
|
||||
function resetFilters() {
|
||||
filters.value = { ...DEFAULT_LEGACY_STP_JOB_FILTERS };
|
||||
page.value = 1;
|
||||
selectedJobId.value = null;
|
||||
detail.value = null;
|
||||
}
|
||||
|
||||
async function loadList() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const payload = await listAdminLegacyStpJobs(page.value, pageSize.value, filters.value);
|
||||
const items = (payload as any).items ?? [];
|
||||
rows.value = Array.isArray(items) ? items : [];
|
||||
total.value = Number((payload as any).pagination?.total ?? 0);
|
||||
} catch (exc: any) {
|
||||
error.value = exc?.message || String(exc);
|
||||
rows.value = [];
|
||||
total.value = 0;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDetail(jobId: number) {
|
||||
detailLoading.value = true;
|
||||
detail.value = null;
|
||||
replayLastResult.value = null;
|
||||
replayUserAction.value = 'create_revision';
|
||||
try {
|
||||
detail.value = await getAdminLegacyStpJob(jobId);
|
||||
const plan = detail.value.replay_plan;
|
||||
if (plan?.recommended_user_action === 'force_create') {
|
||||
replayUserAction.value = 'force_create';
|
||||
} else if (plan?.recommended_user_action === 'create_revision') {
|
||||
replayUserAction.value = 'create_revision';
|
||||
}
|
||||
} catch (exc: any) {
|
||||
message.error(exc?.message || String(exc));
|
||||
} finally {
|
||||
detailLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onRowClick(row: LegacyStpJobRow) {
|
||||
selectedJobId.value = Number(row.job_id);
|
||||
loadDetail(Number(row.job_id)).catch(() => {});
|
||||
}
|
||||
|
||||
function openCaseInWorkspace(caseNo: string) {
|
||||
router.push({
|
||||
name: 'WorkspaceShippingNotice',
|
||||
query: { case_no: caseNo, focus: 'review_case' },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 【回放按钮】严格只走 /workspace/shipping-notice/order-review-cases/<case_no>/reconcile-and-progress,
|
||||
* 携带 operation_id / legacy_job_id / replay_mode / user_action 四参数。
|
||||
* 禁止任何绕过该 API 的直接 SQL/Job.status 修改。
|
||||
*/
|
||||
async function replaySelected() {
|
||||
if (!detail.value || !detail.value.job.case_no) {
|
||||
message.error(t('admin.legacyStpJobs.replayError_noCaseNo'));
|
||||
return;
|
||||
}
|
||||
const caseNo = String(detail.value.job.case_no).trim();
|
||||
const legacyJobId = Number(detail.value.job.job_id);
|
||||
const replayMode = Boolean(detail.value.replay_plan?.needs_replay_mode);
|
||||
const action = replayUserAction.value;
|
||||
const operationId = crypto.randomUUID
|
||||
? crypto.randomUUID()
|
||||
: String(Date.now()) + '-' + Math.random().toString(36).slice(2);
|
||||
const url = `/api/workspace/shipping-notice/order-review-cases/${encodeURIComponent(caseNo)}/reconcile-and-progress`;
|
||||
const headers = { 'Content-Type': 'application/json', ...getAuthHeaders() };
|
||||
const body = JSON.stringify({
|
||||
operation_id: operationId,
|
||||
user_action: action,
|
||||
legacy_job_id: legacyJobId,
|
||||
replay_mode: replayMode || action === 'force_create',
|
||||
});
|
||||
replaying.value = true;
|
||||
replayLastResult.value = null;
|
||||
try {
|
||||
const resp = await requestJson<any>(url, { method: 'POST', headers, body });
|
||||
const outcome = (resp as any)?.data?.outcome ?? null;
|
||||
const ok = !!(resp as any)?.success && String(outcome || '') !== 'ERROR';
|
||||
replayLastResult.value = {
|
||||
ok,
|
||||
outcome: outcome,
|
||||
message: (resp as any)?.data?.message ?? null,
|
||||
};
|
||||
if (ok) {
|
||||
message.success(t('admin.legacyStpJobs.replaySuccess', { outcome: String(outcome || '') }));
|
||||
} else {
|
||||
message.error(t('admin.legacyStpJobs.replayRejected', { outcome: String(outcome || '') }));
|
||||
}
|
||||
} catch (exc: any) {
|
||||
const err = exc?.message || String(exc);
|
||||
replayLastResult.value = { ok: false, outcome: 'ERROR', message: err };
|
||||
message.error(err);
|
||||
} finally {
|
||||
replaying.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadList);
|
||||
watch([page, pageSize], loadList);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col h-full gap-4 lg:gap-6 p-4 lg:p-6">
|
||||
<div class="flex items-center justify-between flex-wrap gap-3">
|
||||
<div>
|
||||
<h2 class="text-xl font-semibold">{{ t('admin.legacyStpJobs.pageTitle') }}</h2>
|
||||
<p class="text-sm text-gray-600">{{ t('admin.legacyStpJobs.pageSubtitle') }}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
class="px-3 py-1.5 text-sm rounded border border-gray-300 hover:bg-gray-50"
|
||||
type="button"
|
||||
@click="resetFilters"
|
||||
>
|
||||
{{ t('common.reset') }}
|
||||
</button>
|
||||
<button
|
||||
class="px-3 py-1.5 text-sm rounded bg-indigo-600 text-white hover:bg-indigo-700"
|
||||
type="button"
|
||||
@click="loadList"
|
||||
:disabled="loading"
|
||||
>
|
||||
{{ t('common.refresh') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-5 gap-3">
|
||||
<input
|
||||
v-model="filters.q"
|
||||
class="px-3 py-2 border rounded text-sm"
|
||||
:placeholder="t('admin.legacyStpJobs.filterQ')"
|
||||
@keyup.enter="page = 1, loadList()"
|
||||
/>
|
||||
<input
|
||||
v-model="filters.case_no"
|
||||
class="px-3 py-2 border rounded text-sm"
|
||||
:placeholder="t('admin.legacyStpJobs.filterCaseNo')"
|
||||
@keyup.enter="page = 1, loadList()"
|
||||
/>
|
||||
<input
|
||||
v-model="filters.error_code"
|
||||
class="px-3 py-2 border rounded text-sm"
|
||||
:placeholder="t('admin.legacyStpJobs.filterErrorCode')"
|
||||
@keyup.enter="page = 1, loadList()"
|
||||
/>
|
||||
<select
|
||||
v-model="filters.status"
|
||||
class="px-3 py-2 border rounded text-sm"
|
||||
@change="page = 1, loadList()"
|
||||
>
|
||||
<option value="">{{ t('admin.legacyStpJobs.statusAll') }}</option>
|
||||
<option v-for="s in LEGACY_STP_JOB_STATUS_OPTIONS" :key="s" :value="s">{{ codeLabel(s) }}</option>
|
||||
</select>
|
||||
<input
|
||||
v-model="filters.created_from"
|
||||
type="datetime-local"
|
||||
class="px-3 py-2 border rounded text-sm"
|
||||
@change="page = 1, loadList()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-[minmax(0,38%)_1fr] gap-4 lg:gap-6 min-h-0 flex-1">
|
||||
<!-- 左侧列表 -->
|
||||
<section class="flex flex-col min-h-0 border rounded bg-white/60">
|
||||
<div class="flex items-center justify-between px-4 py-2 border-b">
|
||||
<span class="text-sm font-medium">{{ t('admin.legacyStpJobs.listTitle', { count: total }) }}</span>
|
||||
<span v-if="loading" class="text-xs text-gray-500">{{ t('common.loading') }}</span>
|
||||
</div>
|
||||
<div v-if="error" class="p-3 text-sm text-red-700 bg-red-50 border-b">{{ error }}</div>
|
||||
<div class="overflow-auto min-h-0 max-h-[72vh] divide-y">
|
||||
<div
|
||||
v-for="row in rows"
|
||||
:key="row.job_id"
|
||||
class="px-4 py-3 cursor-pointer hover:bg-indigo-50/60"
|
||||
:class="selectedJobId === row.job_id ? 'bg-indigo-50 ring-2 ring-inset ring-indigo-300' : ''"
|
||||
@click="onRowClick(row)"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-center gap-2 text-sm">
|
||||
<span class="font-mono text-xs bg-gray-100 px-2 py-0.5 rounded">#{{ row.job_id }}</span>
|
||||
<span
|
||||
class="text-xs px-2 py-0.5 rounded"
|
||||
:class="row.status === 'failed' ? 'bg-red-100 text-red-700' : 'bg-gray-200 text-gray-700'"
|
||||
>{{ codeLabel(row.status) }}</span>
|
||||
<span class="truncate text-xs text-gray-500">{{ row.case_no || row.business_ref || '—' }}</span>
|
||||
</div>
|
||||
<div class="mt-1.5 text-sm">
|
||||
<span class="text-gray-700">{{ codeLabel(row.blocking_reason || row.error_code || '', 'admin.legacyStpJobs.reasonCodes') }}</span>
|
||||
<span class="mx-2 text-gray-300">·</span>
|
||||
<span class="text-xs text-gray-500">{{ row.attempts }}/{{ row.max_attempts }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right text-xs text-gray-500 leading-5 shrink-0">
|
||||
<div>{{ formatTime(row.created_at) }}</div>
|
||||
<div v-if="row.finished_at">→ {{ formatTime(row.finished_at) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!rows.length && !loading" class="p-8 text-center text-sm text-gray-500">
|
||||
{{ t('admin.legacyStpJobs.empty') }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between px-4 py-2 border-t text-sm">
|
||||
<span class="text-gray-500">{{ t('common.pageOf', { page, total: Math.max(1, Math.ceil(total / pageSize)) }) }}</span>
|
||||
<div class="flex items-center gap-1">
|
||||
<button
|
||||
class="px-2 py-1 rounded border disabled:opacity-50"
|
||||
:disabled="page <= 1"
|
||||
type="button"
|
||||
@click="page -= 1"
|
||||
>{{ t('common.prev') }}</button>
|
||||
<button
|
||||
class="px-2 py-1 rounded border disabled:opacity-50"
|
||||
:disabled="page * pageSize >= total"
|
||||
type="button"
|
||||
@click="page += 1"
|
||||
>{{ t('common.next') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 右侧详情 -->
|
||||
<section class="flex flex-col min-h-0 border rounded bg-white/60">
|
||||
<div class="flex items-center justify-between px-4 py-2 border-b">
|
||||
<span class="text-sm font-medium">{{ t('admin.legacyStpJobs.detailTitle') }}</span>
|
||||
<span v-if="detailLoading" class="text-xs text-gray-500">{{ t('common.loading') }}</span>
|
||||
</div>
|
||||
<div v-if="!detail && !detailLoading" class="p-8 text-center text-sm text-gray-500">
|
||||
{{ t('admin.legacyStpJobs.detailEmpty') }}
|
||||
</div>
|
||||
<div v-else-if="detail" class="overflow-auto min-h-0 max-h-[72vh] px-5 py-4 space-y-5">
|
||||
<!-- 摘要行 -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-3 text-sm">
|
||||
<div class="border rounded p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">{{ t('admin.legacyStpJobs.job') }}</div>
|
||||
<div class="font-mono">#{{ detail.job.job_id }} · {{ codeLabel(detail.job.status) }}</div>
|
||||
<div class="mt-1 text-xs text-gray-500">attempts: {{ detail.job.attempts }}/{{ detail.job.max_attempts }}</div>
|
||||
</div>
|
||||
<div class="border rounded p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">{{ t('admin.legacyStpJobs.reviewCase') }}</div>
|
||||
<button
|
||||
v-if="detail.job.case_no"
|
||||
class="text-indigo-600 hover:underline font-mono"
|
||||
type="button"
|
||||
@click="openCaseInWorkspace(detail.job.case_no!)"
|
||||
>{{ detail.job.case_no }}</button>
|
||||
<span v-else class="text-gray-400">—</span>
|
||||
<div class="mt-1 text-xs text-gray-500 truncate">{{ detail.job.business_ref || '—' }}</div>
|
||||
</div>
|
||||
<div class="border rounded p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">{{ t('admin.legacyStpJobs.blocking') }}</div>
|
||||
<div class="font-medium">{{ codeLabel(detail.job.blocking_reason || detail.job.error_code || '', 'admin.legacyStpJobs.reasonCodes') }}</div>
|
||||
<div class="mt-1 text-xs text-gray-500 truncate">{{ detail.job.message || detail.job.error_message || '—' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 回链 Case:若存在则展示 8 字段 -->
|
||||
<div v-if="detail.case" class="border rounded p-4">
|
||||
<div class="text-sm font-medium mb-2">{{ t('admin.legacyStpJobs.linkedCase') }}</div>
|
||||
<dl class="grid grid-cols-2 md:grid-cols-4 gap-3 text-sm">
|
||||
<div><dt class="text-xs text-gray-500">case_id</dt><dd class="font-mono">{{ detail.case.case_id }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">{{ t('admin.legacyStpJobs.caseStatus') }}</dt><dd>{{ detail.case.status }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">candidate_id</dt><dd class="font-mono">{{ detail.case.candidate_id ?? '—' }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">confirmed_task_id</dt><dd class="font-mono">{{ detail.case.confirmed_task_id ?? '—' }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">document_id</dt><dd class="font-mono">{{ detail.case.document_id ?? '—' }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">owner_user_id</dt><dd class="font-mono">{{ detail.case.owner_user_id ?? '—' }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">{{ t('common.createdAt') }}</dt><dd>{{ formatTime(detail.case.created_at) }}</dd></div>
|
||||
<div><dt class="text-xs text-gray-500">{{ t('common.updatedAt') }}</dt><dd>{{ formatTime(detail.case.updated_at) }}</dd></div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<!-- 回放计划:推荐动作 + 回放按钮 -->
|
||||
<div class="border rounded p-4 bg-amber-50/60">
|
||||
<div class="text-sm font-medium mb-2">{{ t('admin.legacyStpJobs.replayPlan') }}</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 items-center">
|
||||
<div class="text-sm space-y-1">
|
||||
<div>
|
||||
<span class="text-gray-500 mr-2">{{ t('admin.legacyStpJobs.recommendedAction') }}:</span>
|
||||
<span class="px-2 py-0.5 rounded bg-white border text-sm">
|
||||
{{ actionLabel(detail.replay_plan.recommended_user_action) }}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500 mr-2">{{ t('admin.legacyStpJobs.needsReplayMode') }}:</span>
|
||||
<span :class="detail.replay_plan.needs_replay_mode ? 'text-amber-700 font-medium' : 'text-gray-500'">
|
||||
{{ detail.replay_plan.needs_replay_mode ? t('common.yes') : t('common.no') }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="detail.replay_plan.reconcile_and_progress_endpoint" class="font-mono text-xs text-gray-500 break-all">
|
||||
POST {{ detail.replay_plan.reconcile_and_progress_endpoint }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 md:items-end">
|
||||
<label class="flex items-center gap-2 text-sm md:justify-end">
|
||||
<span class="text-gray-600 w-32">{{ t('admin.legacyStpJobs.userAction') }}</span>
|
||||
<select v-model="replayUserAction" class="px-3 py-1.5 border rounded text-sm">
|
||||
<option value="auto">{{ actionLabel('auto') }}</option>
|
||||
<option value="reuse_existing">{{ actionLabel('reuse_existing') }}</option>
|
||||
<option value="create_revision">{{ actionLabel('create_revision') }}</option>
|
||||
<option value="force_create">{{ actionLabel('force_create') }}</option>
|
||||
<option value="adjudicate">{{ actionLabel('adjudicate') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<button
|
||||
class="px-4 py-2 rounded bg-indigo-600 text-white hover:bg-indigo-700 disabled:opacity-60 max-w-xs"
|
||||
type="button"
|
||||
:disabled="replaying || !detail.job.case_no"
|
||||
@click="replaySelected"
|
||||
>
|
||||
{{ replaying ? t('common.loading') : t('admin.legacyStpJobs.replayButton') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="replayLastResult" class="mt-3 text-sm border-t pt-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
class="text-xs px-2 py-0.5 rounded"
|
||||
:class="replayLastResult.ok ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'"
|
||||
>
|
||||
{{ replayLastResult.ok ? t('common.ok') : t('common.error') }}
|
||||
</span>
|
||||
<span class="font-mono text-xs bg-white border rounded px-2 py-0.5">{{ replayLastResult.outcome ?? '—' }}</span>
|
||||
</div>
|
||||
<div v-if="replayLastResult.message" class="mt-1.5 text-xs text-gray-600 whitespace-pre-wrap break-all">
|
||||
{{ replayLastResult.message }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 原始 JSON:payload / result(masked) -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="border rounded p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">{{ t('admin.legacyStpJobs.payloadJson') }}</div>
|
||||
<pre class="text-xs whitespace-pre-wrap break-all bg-gray-50 p-2 rounded max-h-64 overflow-auto">{{ jsonFormat(detail.job.payload_json_masked) }}</pre>
|
||||
</div>
|
||||
<div class="border rounded p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">{{ t('admin.legacyStpJobs.resultJson') }}</div>
|
||||
<pre class="text-xs whitespace-pre-wrap break-all bg-gray-50 p-2 rounded max-h-64 overflow-auto">{{ jsonFormat(detail.job.result_json_masked) }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+4
-4
@@ -99,17 +99,17 @@ describe('OrderProfileXfaConfirmStep', () => {
|
||||
});
|
||||
|
||||
const wrapper = mountStep();
|
||||
await vi.waitFor(() => expect(wrapper.text()).toContain('datasets / data / ITEMS / DATA'));
|
||||
await vi.waitFor(() => expect(wrapper.text()).toContain('datasets / data / ITEMS / DATA'), { timeout: 10000 });
|
||||
expect(wrapper.find('input[type="radio"]').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain('创建前阻断项');
|
||||
});
|
||||
}, 15000);
|
||||
|
||||
it('没有任何候选集合时才显示空状态', async () => {
|
||||
getFieldTree.mockResolvedValue({ tree: {} });
|
||||
getCollections.mockResolvedValue({ collection_candidates: [], excluded_collection_candidates: [] });
|
||||
|
||||
const wrapper = mountStep();
|
||||
await vi.waitFor(() => expect(wrapper.text()).toContain('没有可用数据集'));
|
||||
await vi.waitFor(() => expect(wrapper.text()).toContain('没有可用数据集'), { timeout: 10000 });
|
||||
expect(wrapper.find('input[type="radio"]').exists()).toBe(false);
|
||||
});
|
||||
}, 15000);
|
||||
});
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/VcMergePreviewTable.vue
|
||||
用途:三来源候选合并预览表。严格后端决定 UI,只按后端返回的 resolution/decision_status 着色,
|
||||
绝不 if/else 推导合并结果。
|
||||
依赖:shipping-order-document-profile.vc.types.ts Section E(VCMergedObservationCandidate);
|
||||
所有着色规则由 resolutionClass 查表映射,禁止前端自行推导业务状态。
|
||||
逻辑:只读展示,无 emit。空态显示「暂无预览数据,请点击预览按钮」。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import type { VCMergedObservationCandidate } from '@/features/admin/types/shipping-order-document-profile.vc.types';
|
||||
|
||||
defineProps<{
|
||||
candidates: VCMergedObservationCandidate[];
|
||||
loading?: boolean;
|
||||
}>();
|
||||
|
||||
function sourceColorClass(source: string): string {
|
||||
if (source === 'header_region') return 'vc-map__src-header';
|
||||
if (source === 'table_column') return 'vc-map__src-table';
|
||||
if (source === 'vendor_comments') return 'vc-map__src-vc';
|
||||
return '';
|
||||
}
|
||||
|
||||
function resolutionClass(resolution: string, decisionStatus: string): string {
|
||||
const key = `${resolution}|${decisionStatus}`;
|
||||
const classMap: Record<string, string> = {
|
||||
'needs_review|pending': 'bg-red-50 text-red-700 border-red-200',
|
||||
'needs_review|needs_review': 'bg-red-50 text-red-700 border-red-200',
|
||||
'same_value_merged|accepted': 'bg-emerald-50 text-emerald-700 border-emerald-200',
|
||||
'single_source_direct|accepted': 'bg-green-50 text-green-700 border-green-200',
|
||||
'fill_missing|accepted': 'bg-sky-50 text-sky-700 border-sky-200',
|
||||
'annotation_only_dropped|accepted': 'bg-gray-50 text-gray-500 line-through',
|
||||
'annotation_only_dropped|missing': 'bg-gray-50 text-gray-500 line-through',
|
||||
'invalid_line_reference|blocked': 'bg-gray-50 text-gray-500 line-through',
|
||||
'no_value|missing': 'bg-gray-50 text-gray-500 line-through',
|
||||
};
|
||||
return classMap[key] ?? '';
|
||||
}
|
||||
|
||||
function resolutionBadge(resolution: string): string {
|
||||
const labelMap: Record<string, string> = {
|
||||
same_value_merged: '同值合并',
|
||||
fill_missing: '补空',
|
||||
needs_review: '需复核',
|
||||
no_value: '无值',
|
||||
single_source_direct: '单源直达',
|
||||
annotation_only_dropped: '仅备注(丢弃)',
|
||||
};
|
||||
return labelMap[resolution] ?? resolution;
|
||||
}
|
||||
|
||||
function conflictGroupKey(cand: VCMergedObservationCandidate): string {
|
||||
return `[${cand.target_scope}] ${cand.target_field_code} #${cand.effective_line_no ?? 'H'}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="vc-merge-preview">
|
||||
<div v-if="candidates.length === 0" class="vc-merge-preview__empty">
|
||||
<p v-if="loading">预览加载中…</p>
|
||||
<p v-else>暂无预览数据,请点击预览按钮</p>
|
||||
</div>
|
||||
<div v-else class="vc-merge-preview__body">
|
||||
<div
|
||||
v-for="(cand, i) in candidates"
|
||||
:key="i"
|
||||
class="vc-merge-preview__row"
|
||||
:class="resolutionClass(cand.resolution, cand.decision_status)"
|
||||
>
|
||||
<div class="vc-merge-preview__row-main">
|
||||
<div class="vc-merge-preview__key">
|
||||
<strong>{{ conflictGroupKey(cand) }}</strong>
|
||||
</div>
|
||||
<div class="vc-merge-preview__badge">
|
||||
<span class="vc-merge-preview__resolution" :class="`vc-merge-preview__resolution--${cand.resolution}`">
|
||||
{{ resolutionBadge(cand.resolution) }}
|
||||
</span>
|
||||
<span class="vc-merge-preview__status">
|
||||
{{ cand.decision_status }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="vc-merge-preview__accepted">
|
||||
<template v-if="cand.decision_status === 'needs_review' || cand.resolution === 'needs_review'">
|
||||
<span class="vc-merge-preview__needs-review">
|
||||
⚠ 需人工复核
|
||||
</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span v-if="cand.accepted_value !== null && cand.accepted_value !== undefined">
|
||||
accepted_value:<code>{{ cand.accepted_value }}</code>
|
||||
</span>
|
||||
<span v-else class="vc-merge-preview__muted">
|
||||
accepted_value:—
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="vc-merge-preview__conflicts">
|
||||
<div class="vc-merge-preview__conflicts-title">
|
||||
来源快照 ({{ cand.source_observations.length }})
|
||||
</div>
|
||||
<ul class="vc-map__src-list">
|
||||
<li
|
||||
v-for="(obs, j) in cand.source_observations"
|
||||
:key="j"
|
||||
:class="sourceColorClass(obs.source)"
|
||||
>
|
||||
<span class="vc-map__src-tag">{{ obs.source }}</span>
|
||||
<code>{{ obs.normalized_value }}</code>
|
||||
<small v-if="obs.format_valid === false" class="vc-map__format-invalid">
|
||||
(format: {{ obs.format_reason_code }})
|
||||
</small>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div v-if="cand.conflicts && cand.conflicts.length > 0" class="vc-merge-preview__conflicts-detail">
|
||||
<details>
|
||||
<summary>冲突详情 ({{ cand.conflicts.length }})</summary>
|
||||
<pre>{{ JSON.stringify(cand.conflicts, null, 2) }}</pre>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vc-merge-preview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-merge-preview__empty {
|
||||
padding: 20px 10px;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.82rem;
|
||||
border: 1px dashed var(--border-default);
|
||||
border-radius: 6px;
|
||||
}
|
||||
.vc-merge-preview__body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-merge-preview__row {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.vc-merge-preview__row-main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.vc-merge-preview__key {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.vc-merge-preview__badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-merge-preview__resolution {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border-radius: 10px;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 600;
|
||||
border: 1px solid;
|
||||
}
|
||||
.vc-merge-preview__resolution--same_value_merged {
|
||||
background: rgba(16, 185, 129, 0.1);
|
||||
border-color: rgba(16, 185, 129, 0.3);
|
||||
color: #047857;
|
||||
}
|
||||
.vc-merge-preview__resolution--single_source_direct {
|
||||
background: rgba(34, 197, 94, 0.1);
|
||||
border-color: rgba(34, 197, 94, 0.3);
|
||||
color: #15803d;
|
||||
}
|
||||
.vc-merge-preview__resolution--fill_missing {
|
||||
background: rgba(14, 165, 233, 0.1);
|
||||
border-color: rgba(14, 165, 233, 0.3);
|
||||
color: #0369a1;
|
||||
}
|
||||
.vc-merge-preview__resolution--needs_review {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border-color: rgba(239, 68, 68, 0.3);
|
||||
color: #b91c1c;
|
||||
}
|
||||
.vc-merge-preview__resolution--annotation_only_dropped,
|
||||
.vc-merge-preview__resolution--no_value {
|
||||
background: rgba(107, 114, 128, 0.1);
|
||||
border-color: rgba(107, 114, 128, 0.3);
|
||||
color: #4b5563;
|
||||
}
|
||||
.vc-merge-preview__status {
|
||||
font-size: 0.72rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.vc-merge-preview__accepted {
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
.vc-merge-preview__needs-review {
|
||||
color: #b91c1c;
|
||||
font-weight: 600;
|
||||
}
|
||||
.vc-merge-preview__muted {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.vc-merge-preview__conflicts {
|
||||
padding-top: 6px;
|
||||
border-top: 1px dashed var(--border-default);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-merge-preview__conflicts-title {
|
||||
font-size: 0.78rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.vc-map__src-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
.vc-map__src-tag {
|
||||
display: inline-block;
|
||||
padding: 1px 6px;
|
||||
border-radius: 10px;
|
||||
font-size: 0.7rem;
|
||||
margin-right: 4px;
|
||||
color: white;
|
||||
}
|
||||
.vc-map__src-header .vc-map__src-tag { background: #3b82f6; }
|
||||
.vc-map__src-table .vc-map__src-tag { background: #10b981; }
|
||||
.vc-map__src-vc .vc-map__src-tag { background: #f59e0b; }
|
||||
.vc-map__format-invalid {
|
||||
color: var(--text-danger);
|
||||
margin-left: 4px;
|
||||
}
|
||||
code {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
background: var(--bg-elevated);
|
||||
padding: 1px 4px;
|
||||
border-radius: 3px;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-merge-preview__conflicts-detail {
|
||||
margin-top: 4px;
|
||||
}
|
||||
.vc-merge-preview__conflicts-detail summary {
|
||||
cursor: pointer;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.vc-merge-preview__conflicts-detail pre {
|
||||
margin: 6px 0 0 0;
|
||||
padding: 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-elevated);
|
||||
font-size: 0.72rem;
|
||||
max-height: 160px;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
+432
@@ -0,0 +1,432 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/VcNamedRegionBox.vue
|
||||
用途:Vendor Comments 命名区域圈选框——薄封装 OrderProfileDocumentCanvas,维护 dedicated regions。
|
||||
依赖:shipping-order-document-profile.vc.types.ts Section A/H、OrderProfileDocumentCanvas。
|
||||
逻辑:不做任何 save,所有写操作走 emit 父级;region/page_scope/selection_mode 四元组变更触发
|
||||
VCProfileDraftTrigger(reasons: named_region_*),仅负责前端门禁,真实判定在后端。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import OrderProfileDocumentCanvas from './OrderProfileDocumentCanvas.vue';
|
||||
import type {
|
||||
OrderProfileCanvasRegion,
|
||||
OrderProfilePreviewPageGrant,
|
||||
OrderProfileRelativeRegion,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.types';
|
||||
import type {
|
||||
VCNamedRegion,
|
||||
VCNamedRegionPageScope,
|
||||
VCNamedRegionSelectionMode,
|
||||
VCProfileDraftTrigger,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.vc.types';
|
||||
|
||||
type VCNamedRegionCreatePartial = {
|
||||
label: string;
|
||||
page_scope: VCNamedRegionPageScope;
|
||||
selection_mode: VCNamedRegionSelectionMode;
|
||||
region: OrderProfileRelativeRegion;
|
||||
};
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
profileId: number | null;
|
||||
grant?: OrderProfilePreviewPageGrant | null;
|
||||
pageNo: number;
|
||||
pageCount: number;
|
||||
previewPagePath?: string | null;
|
||||
namedRegions: Record<string, VCNamedRegion>;
|
||||
selectedRegionId: string | null;
|
||||
regionOptions?: {
|
||||
page_scope_options?: { value: string; label: string }[];
|
||||
};
|
||||
readonly?: boolean;
|
||||
}>(), {
|
||||
regionOptions: () => ({}),
|
||||
readonly: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:namedRegions': [regions: Record<string, VCNamedRegion>];
|
||||
select: [regionId: string];
|
||||
create: [partial: VCNamedRegionCreatePartial];
|
||||
change: [regionId: string, patch: Partial<VCNamedRegion>];
|
||||
delete: [regionId: string];
|
||||
draftRequired: [trigger: VCProfileDraftTrigger];
|
||||
}>();
|
||||
|
||||
const defaultPageScopeOptions = computed(() => {
|
||||
if (props.regionOptions?.page_scope_options?.length) {
|
||||
return props.regionOptions.page_scope_options;
|
||||
}
|
||||
return [
|
||||
{ value: 'first_page', label: '首页' },
|
||||
{ value: 'last_page', label: '末页' },
|
||||
{ value: 'exact_page', label: '指定页' },
|
||||
];
|
||||
});
|
||||
|
||||
const selectionModeOptions: { value: VCNamedRegionSelectionMode; label: string }[] = [
|
||||
{ value: 'fixed_region', label: '固定区域 (box)' },
|
||||
{ value: 'auto_take_last_qualified', label: '取末段合格 (paragraph)' },
|
||||
];
|
||||
|
||||
const selectedOrderRegionId = computed(() => {
|
||||
return props.selectedRegionId ? `vc:${props.selectedRegionId}` : null;
|
||||
});
|
||||
|
||||
const canvasRegions = computed<OrderProfileCanvasRegion[]>(() => {
|
||||
const regions: OrderProfileCanvasRegion[] = [];
|
||||
Object.values(props.namedRegions || {}).forEach((nr) => {
|
||||
let pageNo = props.pageNo;
|
||||
if (nr.page_scope === 'exact_page' && nr.page_no) {
|
||||
pageNo = nr.page_no;
|
||||
}
|
||||
regions.push({
|
||||
id: `vc:${nr.region_id}`,
|
||||
kind: 'xfa_visual',
|
||||
label: nr.label,
|
||||
region: { ...nr.region },
|
||||
pageNo,
|
||||
});
|
||||
});
|
||||
return regions;
|
||||
});
|
||||
|
||||
const priorSnapshot = ref<string>('');
|
||||
|
||||
function snapshotRegions(): string {
|
||||
const entries = Object.entries(props.namedRegions || {})
|
||||
.sort(([a], [b]) => a.localeCompare(b))
|
||||
.map(([id, r]) => `${id}|${r.label}|${r.page_scope}|${r.selection_mode}|${JSON.stringify(r.region)}`);
|
||||
return entries.join('||');
|
||||
}
|
||||
|
||||
watch(() => snapshotRegions(), (next, prev) => {
|
||||
if (!prev || !next || next === prev) return;
|
||||
const prevMap = props.namedRegions || {};
|
||||
const reasons: VCProfileDraftTrigger['reasons'] = [];
|
||||
const prevIds = new Set(Object.keys(prevMap));
|
||||
const nextIds = new Set(Object.keys(prevMap));
|
||||
prevIds.forEach((id) => {
|
||||
if (!nextIds.has(id)) {
|
||||
reasons.push({ kind: 'named_region_removed', region_id: id });
|
||||
}
|
||||
});
|
||||
nextIds.forEach((id) => {
|
||||
if (!prevIds.has(id)) {
|
||||
reasons.push({ kind: 'named_region_added', region_id: id });
|
||||
}
|
||||
});
|
||||
nextIds.forEach((id) => {
|
||||
if (!prevIds.has(id)) return;
|
||||
const prev = prevMap[id];
|
||||
const nextR = prevMap[id];
|
||||
if (!prev || !nextR) return;
|
||||
if (prev.page_scope !== nextR.page_scope) {
|
||||
reasons.push({ kind: 'named_region_scope', region_id: id });
|
||||
}
|
||||
const prevGeo = `${prev.region.x0},${prev.region.y0},${prev.region.x1},${prev.region.y1}`;
|
||||
const nextGeo = `${nextR.region.x0},${nextR.region.y0},${nextR.region.x1},${nextR.region.y1}`;
|
||||
if (prevGeo !== nextGeo) {
|
||||
reasons.push({ kind: 'named_region_geometry', region_id: id });
|
||||
}
|
||||
});
|
||||
if (reasons.length > 0) {
|
||||
emit('draftRequired', {
|
||||
named_regions_changed: true,
|
||||
field_source_mappings_changed: false,
|
||||
requires_draft_reset: true,
|
||||
reasons,
|
||||
});
|
||||
}
|
||||
}, { flush: 'post' });
|
||||
|
||||
priorSnapshot.value = snapshotRegions();
|
||||
|
||||
function onCanvasSelect(regionId: string): void {
|
||||
if (!regionId.startsWith('vc:')) return;
|
||||
emit('select', regionId.slice(3));
|
||||
}
|
||||
|
||||
function onCanvasCreate(region: OrderProfileCanvasRegion['region']): void {
|
||||
const count = Object.keys(props.namedRegions || {}).length;
|
||||
emit('create', {
|
||||
label: `Vendor Comments ${count + 1}`,
|
||||
page_scope: 'first_page',
|
||||
selection_mode: 'fixed_region',
|
||||
region,
|
||||
});
|
||||
}
|
||||
|
||||
function onCanvasChange(regionId: string, region: OrderProfileCanvasRegion['region']): void {
|
||||
if (!regionId.startsWith('vc:')) return;
|
||||
const id = regionId.slice(3);
|
||||
emit('change', id, { region });
|
||||
}
|
||||
|
||||
function updateLabel(regionId: string, label: string): void {
|
||||
emit('change', regionId, { label });
|
||||
}
|
||||
|
||||
function updatePageScope(regionId: string, pageScope: VCNamedRegionPageScope): void {
|
||||
emit('change', regionId, { page_scope: pageScope });
|
||||
}
|
||||
|
||||
function updateSelectionMode(regionId: string, mode: VCNamedRegionSelectionMode): void {
|
||||
emit('change', regionId, { selection_mode: mode });
|
||||
}
|
||||
|
||||
function updatePageNo(regionId: string, pageNo: number | null): void {
|
||||
emit('change', regionId, { page_no: pageNo });
|
||||
}
|
||||
|
||||
function addRegion(): void {
|
||||
const count = Object.keys(props.namedRegions || {}).length;
|
||||
emit('create', {
|
||||
label: `Vendor Comments ${count + 1}`,
|
||||
page_scope: 'first_page',
|
||||
selection_mode: 'fixed_region',
|
||||
region: { x0: 0.1, y0: 0.1, x1: 0.9, y1: 0.15 },
|
||||
});
|
||||
}
|
||||
|
||||
const orderedRegions = computed(() => {
|
||||
return Object.values(props.namedRegions || {}).sort((a, b) => (
|
||||
a.label.localeCompare(b.label)
|
||||
));
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="vc-named-region-box">
|
||||
<div class="vc-named-region-box__toolbar">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly"
|
||||
class="vc-named-region-box__add-btn"
|
||||
@click="addRegion"
|
||||
>
|
||||
新增 Vendor Comments 区域
|
||||
</button>
|
||||
</div>
|
||||
<div class="vc-named-region-box__body">
|
||||
<aside class="vc-named-region-box__sidebar">
|
||||
<ul v-if="orderedRegions.length" class="vc-named-region-box__list">
|
||||
<li
|
||||
v-for="nr in orderedRegions"
|
||||
:key="nr.region_id"
|
||||
class="vc-named-region-box__item"
|
||||
:class="{ 'is-selected': selectedRegionId === nr.region_id }"
|
||||
@click="emit('select', nr.region_id)"
|
||||
>
|
||||
<div class="vc-named-region-box__item-header">
|
||||
<input
|
||||
class="vc-named-region-box__label-input"
|
||||
:disabled="readonly"
|
||||
:value="nr.label"
|
||||
@input="updateLabel(nr.region_id, ($event.target as HTMLInputElement).value)"
|
||||
@click.stop
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="vc-named-region-box__delete-btn"
|
||||
:disabled="readonly"
|
||||
@click.stop="emit('delete', nr.region_id)"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
<div class="vc-named-region-box__item-fields">
|
||||
<label>
|
||||
页范围
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="nr.page_scope"
|
||||
@change.stop="updatePageScope(nr.region_id, ($event.target as HTMLSelectElement).value as VCNamedRegionPageScope)"
|
||||
>
|
||||
<option
|
||||
v-for="opt in defaultPageScopeOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label v-if="nr.page_scope === 'exact_page'">
|
||||
页码
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
:max="pageCount || undefined"
|
||||
:disabled="readonly"
|
||||
:value="nr.page_no ?? ''"
|
||||
@input.stop="updatePageNo(nr.region_id, ($event.target as HTMLInputElement).value === '' ? null : Number(($event.target as HTMLInputElement).value))"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
选择模式
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="nr.selection_mode"
|
||||
@change.stop="updateSelectionMode(nr.region_id, ($event.target as HTMLSelectElement).value as VCNamedRegionSelectionMode)"
|
||||
>
|
||||
<option
|
||||
v-for="opt in selectionModeOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="vc-named-region-box__empty">
|
||||
暂无命名区域,点击上方按钮新增或在画布上拖动圈选。
|
||||
</p>
|
||||
</aside>
|
||||
<div class="vc-named-region-box__canvas">
|
||||
<OrderProfileDocumentCanvas
|
||||
:profile-id="profileId"
|
||||
:grant="grant"
|
||||
:preview-page-path="previewPagePath"
|
||||
:mode="readonly ? 'readonly' : 'edit'"
|
||||
:regions="canvasRegions"
|
||||
:selected-region-id="selectedOrderRegionId"
|
||||
:creation-kind="readonly ? null : 'xfa_visual'"
|
||||
:page-no="pageNo"
|
||||
:page-count="pageCount"
|
||||
annotation-tool-set="xfa_visual"
|
||||
@select="onCanvasSelect"
|
||||
@create="onCanvasCreate"
|
||||
@change="onCanvasChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vc-named-region-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
}
|
||||
.vc-named-region-box__toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-named-region-box__add-btn {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.vc-named-region-box__add-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.vc-named-region-box__body {
|
||||
display: grid;
|
||||
grid-template-columns: 280px 1fr;
|
||||
gap: 8px;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
}
|
||||
.vc-named-region-box__sidebar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
padding: 8px;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-named-region-box__list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-named-region-box__item {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
padding: 8px;
|
||||
cursor: pointer;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.vc-named-region-box__item.is-selected {
|
||||
border-color: var(--accent-primary);
|
||||
box-shadow: 0 0 0 1px var(--accent-primary);
|
||||
}
|
||||
.vc-named-region-box__item-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.vc-named-region-box__label-input {
|
||||
flex: 1;
|
||||
padding: 4px 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
font-size: 0.85rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.vc-named-region-box__delete-btn {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
color: var(--text-danger);
|
||||
}
|
||||
.vc-named-region-box__delete-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.vc-named-region-box__item-fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-named-region-box__item-fields label {
|
||||
display: grid;
|
||||
grid-template-columns: 56px 1fr;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-named-region-box__item-fields select,
|
||||
.vc-named-region-box__item-fields input {
|
||||
padding: 3px 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
font-size: 0.78rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.vc-named-region-box__empty {
|
||||
margin: 0;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.8rem;
|
||||
text-align: center;
|
||||
padding: 16px 8px;
|
||||
}
|
||||
.vc-named-region-box__canvas {
|
||||
min-height: 0;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
</style>
|
||||
+544
@@ -0,0 +1,544 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/VcSourceMappingPanel.vue
|
||||
用途:薄编排主面板——只做顶层三开关 + 引入 VcSourceMappingSection * 3 + VcSplitRuleEditor
|
||||
(抽屉/modal)+ VcMergePreviewTable。
|
||||
依赖:shipping-order-document-profile.vc.types.ts Section B/C/D/E/H/I;
|
||||
子组件:VcSourceMappingSection、VcSplitRuleEditor、VcMergePreviewTable。
|
||||
逻辑:emit update:definition 写回完整 patch;field_source_mappings 任何改动 + split_rules
|
||||
改动触发 VCProfileDraftTrigger(聚合所有子 trigger)。
|
||||
Props / Emits 保留原来的契约,确保父级零修改可切换。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import type {
|
||||
VCMergedObservationCandidate,
|
||||
VCProfileDefinitionExtensions,
|
||||
VCProfileDraftTrigger,
|
||||
VCProfileFieldSourceMapping,
|
||||
VCSplitRuleSet,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.vc.types';
|
||||
import VcSourceMappingSection from './VcSourceMappingSection.vue';
|
||||
import VcSplitRuleEditor from './VcSplitRuleEditor.vue';
|
||||
import VcMergePreviewTable from './VcMergePreviewTable.vue';
|
||||
|
||||
type VCProfileFieldSourceMappingPatch = Partial<VCProfileFieldSourceMapping>;
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
definition: VCProfileDefinitionExtensions;
|
||||
selectedFieldCode: string;
|
||||
targetScopes?: Array<'header' | 'line'>;
|
||||
readonly?: boolean;
|
||||
documentId: number;
|
||||
profileId: number;
|
||||
dirtyUnsaved?: boolean;
|
||||
persistedConfirmed?: boolean;
|
||||
canPreview?: boolean;
|
||||
}>(), {
|
||||
selectedFieldCode: 'reservation_id',
|
||||
targetScopes: () => ['header', 'line'],
|
||||
readonly: false,
|
||||
dirtyUnsaved: false,
|
||||
persistedConfirmed: false,
|
||||
canPreview: true,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:definition': [patch: VCProfileDefinitionExtensions];
|
||||
draftRequired: [trigger: VCProfileDraftTrigger];
|
||||
'vc:split-panel-confirmed': [
|
||||
rules: VCSplitRuleSet[],
|
||||
confirmationTokens: Record<string, string>,
|
||||
fieldCode: string,
|
||||
];
|
||||
}>();
|
||||
|
||||
function newClientId(): string {
|
||||
return `map-${crypto.randomUUID().replace(/-/g, '')}`;
|
||||
}
|
||||
|
||||
const DEFAULT_FORMAT_POLICY = {
|
||||
mode: 'inherit_global' as const,
|
||||
pattern: null,
|
||||
max_capture_groups: 1,
|
||||
timeout_ms: 500,
|
||||
case_sensitive: false,
|
||||
};
|
||||
|
||||
const EMPTY_MAPPING_BASE = (fieldCode: string, targetScope: 'header' | 'line'): VCProfileFieldSourceMapping => ({
|
||||
mapping_id: newClientId(),
|
||||
target_scope: targetScope,
|
||||
target_field_code: fieldCode,
|
||||
target_field_id: '',
|
||||
header_source_enabled: false,
|
||||
header_source_ref: null,
|
||||
header_normalizer_key: null,
|
||||
table_source_enabled: false,
|
||||
table_column_code: null,
|
||||
vendor_comments_enabled: false,
|
||||
vendor_comments_region_ref: null,
|
||||
vendor_comments_split_rule_set: null,
|
||||
relation_policy: 'bind_target_line',
|
||||
missing_relation_policy: 'default_all_lines',
|
||||
line_reference_basis: 'classified_logical_line_no',
|
||||
fill_missing_from_other_sources: true,
|
||||
format_policy: { ...DEFAULT_FORMAT_POLICY },
|
||||
});
|
||||
|
||||
const activeMappings = computed(() => {
|
||||
const list = props.definition?.field_source_mappings || [];
|
||||
return list.filter((m) => m.target_field_code === props.selectedFieldCode);
|
||||
});
|
||||
|
||||
const headerMapping = computed(() => activeMappings.value.find((m) => m.target_scope === 'header') || null);
|
||||
const lineMapping = computed(() => activeMappings.value.find((m) => m.target_scope === 'line') || null);
|
||||
|
||||
const scopeOptions = computed(() => (
|
||||
props.targetScopes.map((s) => ({
|
||||
value: s,
|
||||
label: s === 'header' ? 'Header (订单头)' : 'Line (明细行)',
|
||||
}))
|
||||
));
|
||||
|
||||
const splitEditorVisible = ref(false);
|
||||
const splitEditorScope = ref<'header' | 'line'>('line');
|
||||
|
||||
const splitEditorRuleSet = computed<VCSplitRuleSet | null>(() => {
|
||||
const mapping = splitEditorScope.value === 'header' ? headerMapping.value : lineMapping.value;
|
||||
return mapping?.vendor_comments_split_rule_set ?? null;
|
||||
});
|
||||
|
||||
const mergeLoading = ref(false);
|
||||
const mergePreviewResults = ref<VCMergedObservationCandidate[]>([]);
|
||||
|
||||
function cloneDefinitionForWrite(): VCProfileDefinitionExtensions {
|
||||
return {
|
||||
named_regions: props.definition?.named_regions ? { ...props.definition.named_regions } : null,
|
||||
field_source_mappings: props.definition?.field_source_mappings
|
||||
? props.definition.field_source_mappings.map((m) => ({ ...m }))
|
||||
: [],
|
||||
};
|
||||
}
|
||||
|
||||
function ensureMapping(scope: 'header' | 'line'): VCProfileFieldSourceMapping {
|
||||
const existing = scope === 'header' ? headerMapping.value : lineMapping.value;
|
||||
if (existing) return existing;
|
||||
const fresh = EMPTY_MAPPING_BASE(props.selectedFieldCode, scope);
|
||||
const patch = cloneDefinitionForWrite();
|
||||
patch.field_source_mappings = [...(patch.field_source_mappings || []), fresh];
|
||||
emit('update:definition', patch);
|
||||
emitDraftTriggerAggregated({
|
||||
reasons: [{ kind: 'field_source_mapping_added', mapping_id: fresh.mapping_id }],
|
||||
changed: true,
|
||||
});
|
||||
return fresh;
|
||||
}
|
||||
|
||||
function updateMapping(mappingId: string, patchFields: VCProfileFieldSourceMappingPatch): void {
|
||||
const patch = cloneDefinitionForWrite();
|
||||
const list = patch.field_source_mappings || [];
|
||||
const idx = list.findIndex((m) => m.mapping_id === mappingId);
|
||||
if (idx < 0) return;
|
||||
const current = list[idx];
|
||||
if (!current) return;
|
||||
const before = JSON.stringify(current);
|
||||
list[idx] = { ...current, ...patchFields };
|
||||
patch.field_source_mappings = list;
|
||||
emit('update:definition', patch);
|
||||
const after = JSON.stringify(list[idx]);
|
||||
if (before === after) return;
|
||||
|
||||
const beforeObj = JSON.parse(before) as VCProfileFieldSourceMapping;
|
||||
const afterObj = JSON.parse(after) as VCProfileFieldSourceMapping;
|
||||
const reasons: VCProfileDraftTrigger['reasons'] = [];
|
||||
|
||||
if (
|
||||
beforeObj.format_policy?.mode !== afterObj.format_policy?.mode
|
||||
|| beforeObj.format_policy?.pattern !== afterObj.format_policy?.pattern
|
||||
|| beforeObj.format_policy?.max_capture_groups !== afterObj.format_policy?.max_capture_groups
|
||||
) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: mappingId,
|
||||
});
|
||||
}
|
||||
|
||||
const enabledKeys = [
|
||||
'header_source_enabled',
|
||||
'table_source_enabled',
|
||||
'vendor_comments_enabled',
|
||||
] as const;
|
||||
let hasEnabledChange = false;
|
||||
for (const k of enabledKeys) {
|
||||
if (beforeObj[k] !== afterObj[k]) {
|
||||
hasEnabledChange = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasEnabledChange) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: mappingId,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
beforeObj.vendor_comments_region_ref !== afterObj.vendor_comments_region_ref
|
||||
|| beforeObj.table_column_code !== afterObj.table_column_code
|
||||
) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: mappingId,
|
||||
});
|
||||
}
|
||||
|
||||
if (reasons.length === 0) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: mappingId,
|
||||
});
|
||||
}
|
||||
|
||||
emitDraftTriggerAggregated({ reasons, changed: true });
|
||||
}
|
||||
|
||||
function emitDraftTriggerAggregated(opts: {
|
||||
reasons: VCProfileDraftTrigger['reasons'];
|
||||
changed: boolean;
|
||||
}): void {
|
||||
emit('draftRequired', {
|
||||
named_regions_changed: false,
|
||||
field_source_mappings_changed: opts.changed,
|
||||
requires_draft_reset: true,
|
||||
reasons: opts.reasons,
|
||||
});
|
||||
}
|
||||
|
||||
function handleSectionMappingUpdate(
|
||||
scope: 'header' | 'line',
|
||||
updatedMapping: VCProfileFieldSourceMapping,
|
||||
): void {
|
||||
const patch = cloneDefinitionForWrite();
|
||||
const list = patch.field_source_mappings || [];
|
||||
const idx = list.findIndex((m) => m.mapping_id === updatedMapping.mapping_id);
|
||||
if (idx < 0) {
|
||||
ensureMapping(scope);
|
||||
return;
|
||||
}
|
||||
const before = JSON.stringify(list[idx]);
|
||||
list[idx] = { ...updatedMapping };
|
||||
patch.field_source_mappings = list;
|
||||
emit('update:definition', patch);
|
||||
const after = JSON.stringify(list[idx]);
|
||||
if (before === after) return;
|
||||
|
||||
const beforeObj = JSON.parse(before) as VCProfileFieldSourceMapping;
|
||||
const afterObj = JSON.parse(after) as VCProfileFieldSourceMapping;
|
||||
const reasons: VCProfileDraftTrigger['reasons'] = [];
|
||||
|
||||
if (
|
||||
beforeObj.format_policy?.mode !== afterObj.format_policy?.mode
|
||||
|| beforeObj.format_policy?.pattern !== afterObj.format_policy?.pattern
|
||||
|| beforeObj.format_policy?.max_capture_groups !== afterObj.format_policy?.max_capture_groups
|
||||
) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: updatedMapping.mapping_id,
|
||||
});
|
||||
}
|
||||
|
||||
const enabledKeys = [
|
||||
'header_source_enabled',
|
||||
'table_source_enabled',
|
||||
'vendor_comments_enabled',
|
||||
] as const;
|
||||
for (const k of enabledKeys) {
|
||||
if (beforeObj[k] !== afterObj[k]) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: updatedMapping.mapping_id,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
beforeObj.vendor_comments_region_ref !== afterObj.vendor_comments_region_ref
|
||||
|| beforeObj.table_column_code !== afterObj.table_column_code
|
||||
) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: updatedMapping.mapping_id,
|
||||
});
|
||||
}
|
||||
|
||||
if (reasons.length === 0) {
|
||||
reasons.push({
|
||||
kind: 'field_source_mapping_format_policy_changed',
|
||||
mapping_id: updatedMapping.mapping_id,
|
||||
});
|
||||
}
|
||||
|
||||
emitDraftTriggerAggregated({ reasons, changed: true });
|
||||
}
|
||||
|
||||
function openSplitEditor(scope: 'header' | 'line'): void {
|
||||
ensureMapping(scope);
|
||||
splitEditorScope.value = scope;
|
||||
splitEditorVisible.value = true;
|
||||
}
|
||||
|
||||
function handleSplitRuleSetUpdate(updated: VCSplitRuleSet): void {
|
||||
const scope = splitEditorScope.value;
|
||||
const mapping = scope === 'header' ? headerMapping.value : lineMapping.value;
|
||||
if (!mapping) return;
|
||||
updateMapping(mapping.mapping_id, { vendor_comments_split_rule_set: updated });
|
||||
}
|
||||
|
||||
function handleSplitEditorConfirmed(ruleSet: VCSplitRuleSet, previewToken: string): void {
|
||||
emit('vc:split-panel-confirmed',
|
||||
[ruleSet],
|
||||
{ [ruleSet.rule_set_id]: previewToken },
|
||||
props.selectedFieldCode,
|
||||
);
|
||||
splitEditorVisible.value = false;
|
||||
}
|
||||
|
||||
function handleSplitEditorDraftRequired(trigger: VCProfileDraftTrigger): void {
|
||||
emit('draftRequired', {
|
||||
...trigger,
|
||||
reasons: trigger.reasons.map((r) => ({ ...r })),
|
||||
});
|
||||
}
|
||||
|
||||
async function runMergePreview(): Promise<void> {
|
||||
if (props.canPreview === false) return;
|
||||
mergeLoading.value = true;
|
||||
try {
|
||||
// TODO: 后端 API stub,后续接入实际 endpoint
|
||||
// 预期:POST /admin/shipping/document-profiles/{profileId}/documents/{documentId}/preview-merge
|
||||
// 请求体:{ field_code: selectedFieldCode, definition }
|
||||
// 响应:VCMergedObservationCandidate[]
|
||||
mergePreviewResults.value = [];
|
||||
} finally {
|
||||
mergeLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(splitEditorVisible, (v) => {
|
||||
if (!v) {
|
||||
// 关闭编辑器时无需特殊处理,ruleSet 已通过 update:ruleSet 实时同步
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="vc-source-mapping">
|
||||
<header class="vc-map__header">
|
||||
<h3 class="vc-map__title">字段来源映射 · {{ selectedFieldCode }}</h3>
|
||||
<div class="vc-map__scope-tabs">
|
||||
<span
|
||||
v-for="s in scopeOptions"
|
||||
:key="s.value"
|
||||
class="vc-map__scope-tab"
|
||||
:class="{ active: (s.value === 'header' ? headerMapping : lineMapping) != null }"
|
||||
>
|
||||
{{ s.label }}
|
||||
</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="vc-map__scopes">
|
||||
<div
|
||||
v-for="scope in scopeOptions"
|
||||
:key="scope.value"
|
||||
class="vc-map__scope-panel"
|
||||
>
|
||||
<div class="vc-map__scope-header">
|
||||
<strong>{{ scope.label }}</strong>
|
||||
<small v-if="!(scope.value === 'header' ? headerMapping : lineMapping)">
|
||||
(未启用——开启任一来源将自动创建)
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div class="vc-map__source-groups">
|
||||
<VcSourceMappingSection
|
||||
kind="header_region"
|
||||
:mapping="scope.value === 'header' ? headerMapping : lineMapping"
|
||||
:definition="definition"
|
||||
:readonly="readonly"
|
||||
:mapping-id="(scope.value === 'header' ? headerMapping : lineMapping)?.mapping_id || 'pending'"
|
||||
@update:mapping="(m) => handleSectionMappingUpdate(scope.value, m)"
|
||||
/>
|
||||
|
||||
<VcSourceMappingSection
|
||||
kind="table_column"
|
||||
:mapping="scope.value === 'header' ? headerMapping : lineMapping"
|
||||
:definition="definition"
|
||||
:readonly="readonly"
|
||||
:mapping-id="(scope.value === 'header' ? headerMapping : lineMapping)?.mapping_id || 'pending'"
|
||||
@update:mapping="(m) => handleSectionMappingUpdate(scope.value, m)"
|
||||
/>
|
||||
|
||||
<VcSourceMappingSection
|
||||
kind="vendor_comments"
|
||||
:mapping="scope.value === 'header' ? headerMapping : lineMapping"
|
||||
:definition="definition"
|
||||
:readonly="readonly"
|
||||
:show-split-rules="true"
|
||||
:mapping-id="(scope.value === 'header' ? headerMapping : lineMapping)?.mapping_id || 'pending'"
|
||||
@update:mapping="(m) => handleSectionMappingUpdate(scope.value, m)"
|
||||
@split-editor-open="openSplitEditor(scope.value)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="splitEditorVisible" class="vc-map__split-editor-wrapper">
|
||||
<VcSplitRuleEditor
|
||||
:rule-set="splitEditorRuleSet"
|
||||
:selected-field-code="selectedFieldCode"
|
||||
:document-id="documentId"
|
||||
:profile-id="profileId"
|
||||
:readonly="readonly"
|
||||
:dirty-unsaved="dirtyUnsaved"
|
||||
:persisted-confirmed="persistedConfirmed"
|
||||
:visible="splitEditorVisible"
|
||||
@update:rule-set="handleSplitRuleSetUpdate"
|
||||
@confirmed="handleSplitEditorConfirmed"
|
||||
@draft-required="handleSplitEditorDraftRequired"
|
||||
/>
|
||||
<div class="vc-map__split-editor-close">
|
||||
<button type="button" @click="splitEditorVisible = false">
|
||||
关闭编辑器
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="vc-map__merge-preview">
|
||||
<div class="vc-map__merge-toolbar">
|
||||
<h4>合并预览(后端决定 UI,禁止前端 if/else 推导)</h4>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="!canPreview || mergeLoading"
|
||||
@click="runMergePreview"
|
||||
>
|
||||
{{ mergeLoading ? '预览中…' : '拉取合并裁决 (stub)' }}
|
||||
</button>
|
||||
</div>
|
||||
<VcMergePreviewTable
|
||||
:candidates="mergePreviewResults"
|
||||
:loading="mergeLoading"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vc-source-mapping {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
.vc-map__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-map__title {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.vc-map__scope-tabs {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-map__scope-tab {
|
||||
padding: 4px 10px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--border-default);
|
||||
font-size: 0.78rem;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-map__scope-tab.active {
|
||||
border-color: var(--accent-primary);
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
.vc-map__scopes {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(480px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
.vc-map__scope-panel {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
background: var(--bg-primary);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-map__scope-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-map__scope-header small {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.vc-map__source-groups {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-map__split-editor-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 10px;
|
||||
border: 2px solid var(--accent-primary);
|
||||
border-radius: 8px;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-map__split-editor-close {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.vc-map__split-editor-close button {
|
||||
padding: 4px 12px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.vc-map__merge-preview {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-map__merge-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
.vc-map__merge-toolbar h4 {
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.vc-map__merge-toolbar button {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
}
|
||||
.vc-map__merge-toolbar button:disabled { opacity: 0.6; cursor: not-allowed; }
|
||||
</style>
|
||||
+393
@@ -0,0 +1,393 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/VcSourceMappingSection.vue
|
||||
用途:三来源通用配置区(Header/Table/Vendor Comments 每来源的开关+target_scope+relation_policy+missing_relation+format_policy),
|
||||
不包含拆分规则编辑器(Vendor Comments 区的拆分规则编辑按钮仅触发 emit)。
|
||||
依赖:shipping-order-document-profile.vc.types.ts Section B/D/I;
|
||||
由 VcSourceMappingPanel.vue 薄编排主面板统一编排事件。
|
||||
逻辑:任何字段变化通过 update:mapping 发射完整 mapping 对象;
|
||||
Vendor Comments 点击「编辑拆分规则」时触发 split-editor-open。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import type {
|
||||
VCLineReferenceBasis,
|
||||
VCMissingRelationPolicy,
|
||||
VCProfileDefinitionExtensions,
|
||||
VCProfileFieldSourceMapping,
|
||||
VCRelationPolicy,
|
||||
VCReservationFormatPolicy,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.vc.types';
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
kind: 'header_region' | 'table_column' | 'vendor_comments';
|
||||
mapping: VCProfileFieldSourceMapping | null;
|
||||
definition: VCProfileDefinitionExtensions;
|
||||
readonly?: boolean;
|
||||
showSplitRules?: boolean;
|
||||
mappingId: string;
|
||||
}>(), {
|
||||
readonly: false,
|
||||
showSplitRules: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:mapping': [mapping: VCProfileFieldSourceMapping];
|
||||
'split-editor-open': [];
|
||||
}>();
|
||||
|
||||
const enabledKey = computed<'header_source_enabled' | 'table_source_enabled' | 'vendor_comments_enabled'>(() => {
|
||||
if (props.kind === 'header_region') return 'header_source_enabled';
|
||||
if (props.kind === 'table_column') return 'table_source_enabled';
|
||||
return 'vendor_comments_enabled';
|
||||
});
|
||||
|
||||
const isEnabled = computed(() => props.mapping?.[enabledKey.value] ?? false);
|
||||
|
||||
function emitPatch(patch: Partial<VCProfileFieldSourceMapping>): void {
|
||||
if (!props.mapping) return;
|
||||
emit('update:mapping', { ...props.mapping, ...patch });
|
||||
}
|
||||
|
||||
function toggleEnabled(enabled: boolean): void {
|
||||
emitPatch({ [enabledKey.value]: enabled } as Partial<VCProfileFieldSourceMapping>);
|
||||
}
|
||||
|
||||
const namedRegionOptions = computed(() => {
|
||||
const map = props.definition?.named_regions || {};
|
||||
return Object.values(map).map((nr) => ({
|
||||
value: nr.region_id,
|
||||
label: nr.label,
|
||||
}));
|
||||
});
|
||||
|
||||
const scopeOptions = [
|
||||
{ value: 'header' as const, label: 'Header (订单头)' },
|
||||
{ value: 'line' as const, label: 'Line (明细行)' },
|
||||
];
|
||||
|
||||
const relationPolicyOptions: { value: VCRelationPolicy; label: string }[] = [
|
||||
{ value: 'bind_target_line', label: '绑定目标行 (bind_target_line)' },
|
||||
{ value: 'annotation_only', label: '仅备注 (annotation_only)' },
|
||||
{ value: 'no_relation', label: '无关联 (no_relation)' },
|
||||
];
|
||||
|
||||
const missingRelationPolicyOptions: { value: VCMissingRelationPolicy; label: string }[] = [
|
||||
{ value: 'default_all_lines', label: '默认所有行 (default_all_lines)' },
|
||||
{ value: 'default_header_only', label: '默认仅 Header (default_header_only)' },
|
||||
{ value: 'fallback_single_line_when_no_reference', label: '无参考回退单行 (fallback_single_line_when_no_reference)' },
|
||||
];
|
||||
|
||||
const lineReferenceBasisOptions: { value: VCLineReferenceBasis; label: string }[] = [
|
||||
{ value: 'explicit_line_column', label: '显式行列号 (explicit)' },
|
||||
{ value: 'profile_business_line_no', label: '业务行号 (profile_business_line_no)' },
|
||||
{ value: 'classified_logical_line_no', label: '分类逻辑行号 (classified_logical_line_no)' },
|
||||
];
|
||||
|
||||
const kindLabel = computed(() => {
|
||||
if (props.kind === 'header_region') return 'Header 来源';
|
||||
if (props.kind === 'table_column') return 'Table 来源';
|
||||
return 'Vendor Comments 来源';
|
||||
});
|
||||
|
||||
const sourceClass = computed(() => {
|
||||
if (props.kind === 'header_region') return 'vc-map__source--header';
|
||||
if (props.kind === 'table_column') return 'vc-map__source--table';
|
||||
return 'vc-map__source--vc';
|
||||
});
|
||||
|
||||
function updateFormatPolicy(policy: Partial<VCReservationFormatPolicy>): void {
|
||||
if (!props.mapping) return;
|
||||
const next: VCReservationFormatPolicy = {
|
||||
...props.mapping.format_policy,
|
||||
...policy,
|
||||
};
|
||||
emitPatch({ format_policy: next });
|
||||
}
|
||||
|
||||
const targetScopeDisabled = computed(() => {
|
||||
if (props.kind === 'table_column' || props.kind === 'vendor_comments') return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
const showLineReferenceBasis = computed(() => {
|
||||
return props.kind === 'table_column' || props.kind === 'vendor_comments';
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<fieldset class="vc-map__source" :class="sourceClass">
|
||||
<legend>
|
||||
<label class="vc-map__toggle-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
:disabled="readonly"
|
||||
:checked="isEnabled"
|
||||
@change="toggleEnabled(($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
{{ kindLabel }}
|
||||
</label>
|
||||
</legend>
|
||||
<template v-if="isEnabled && mapping">
|
||||
<template v-if="kind === 'header_region'">
|
||||
<label>
|
||||
Header 引用键
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="mapping.header_source_ref ?? ''"
|
||||
placeholder="header_ref / 留空走自动检测"
|
||||
@input="emitPatch({ header_source_ref: ($event.target as HTMLInputElement).value || null })"
|
||||
/>
|
||||
</label>
|
||||
</template>
|
||||
<template v-else-if="kind === 'table_column'">
|
||||
<label>
|
||||
列 column_code
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="mapping.table_column_code ?? ''"
|
||||
placeholder="例如:reservation_id"
|
||||
@input="emitPatch({ table_column_code: ($event.target as HTMLInputElement).value || null })"
|
||||
/>
|
||||
</label>
|
||||
</template>
|
||||
<template v-else-if="kind === 'vendor_comments'">
|
||||
<label>
|
||||
命名区域
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="mapping.vendor_comments_region_ref ?? ''"
|
||||
@change="emitPatch({ vendor_comments_region_ref: ($event.target as HTMLSelectElement).value || null })"
|
||||
>
|
||||
<option value="">— 请选择命名区域 —</option>
|
||||
<option v-for="opt in namedRegionOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div v-if="showSplitRules" class="vc-map__split-open-row">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly"
|
||||
class="vc-map__split-open-btn"
|
||||
@click="emit('split-editor-open')"
|
||||
>
|
||||
编辑拆分规则…
|
||||
</button>
|
||||
<span v-if="mapping.vendor_comments_split_rule_set" class="vc-map__split-status-inline">
|
||||
规则集:v{{ mapping.vendor_comments_split_rule_set.rule_version }}
|
||||
· {{ mapping.vendor_comments_split_rule_set.status || 'draft' }}
|
||||
</span>
|
||||
<span v-else class="vc-map__split-status-inline vc-map__split-status--muted">
|
||||
尚未配置规则集
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<label>
|
||||
目标作用域
|
||||
<select
|
||||
:disabled="readonly || targetScopeDisabled"
|
||||
:value="targetScopeDisabled ? 'line' : mapping.target_scope"
|
||||
@change="emitPatch({ target_scope: ($event.target as HTMLSelectElement).value as 'header' | 'line' })"
|
||||
>
|
||||
<option v-for="opt in scopeOptions" :key="opt.value" :value="opt.value">
|
||||
{{ opt.label }}{{ targetScopeDisabled && opt.value === 'line' ? ' (默认)' : '' }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
关联策略
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="mapping.relation_policy"
|
||||
@change="emitPatch({ relation_policy: ($event.target as HTMLSelectElement).value as VCRelationPolicy })"
|
||||
>
|
||||
<option v-for="opt in relationPolicyOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<template v-if="showLineReferenceBasis">
|
||||
<label>
|
||||
行参考基准
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="mapping.line_reference_basis"
|
||||
@change="emitPatch({ line_reference_basis: ($event.target as HTMLSelectElement).value as VCLineReferenceBasis })"
|
||||
>
|
||||
<option v-for="opt in lineReferenceBasisOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
</template>
|
||||
<label>
|
||||
缺关联策略
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="mapping.missing_relation_policy"
|
||||
@change="emitPatch({ missing_relation_policy: ($event.target as HTMLSelectElement).value as VCMissingRelationPolicy })"
|
||||
>
|
||||
<option v-for="opt in missingRelationPolicyOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="vc-map__checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
:disabled="readonly"
|
||||
:checked="mapping.fill_missing_from_other_sources ?? true"
|
||||
@change="emitPatch({ fill_missing_from_other_sources: ($event.target as HTMLInputElement).checked })"
|
||||
/>
|
||||
fill_missing_from_other_sources(从其他来源补空)
|
||||
</label>
|
||||
|
||||
<div class="vc-map__format-block">
|
||||
<div class="vc-map__format-title">格式策略</div>
|
||||
<div class="vc-map__format-radios">
|
||||
<label class="vc-map__radio">
|
||||
<input
|
||||
type="radio"
|
||||
:disabled="readonly"
|
||||
:name="`format-mode-${kind}-${mappingId}`"
|
||||
value="inherit_global"
|
||||
:checked="mapping.format_policy.mode === 'inherit_global'"
|
||||
@change="updateFormatPolicy({ mode: 'inherit_global' })"
|
||||
/>
|
||||
inherit_global(使用 Profile 全局设置)
|
||||
</label>
|
||||
<label class="vc-map__radio">
|
||||
<input
|
||||
type="radio"
|
||||
:disabled="readonly"
|
||||
:name="`format-mode-${kind}-${mappingId}`"
|
||||
value="numeric_5_or_10"
|
||||
:checked="mapping.format_policy.mode === 'numeric_5_or_10'"
|
||||
@change="updateFormatPolicy({ mode: 'numeric_5_or_10' })"
|
||||
/>
|
||||
numeric_5_or_10(单号 5 或 10 位数字)
|
||||
</label>
|
||||
<label class="vc-map__radio">
|
||||
<input
|
||||
type="radio"
|
||||
:disabled="readonly"
|
||||
:name="`format-mode-${kind}-${mappingId}`"
|
||||
value="custom_safe_regex"
|
||||
:checked="mapping.format_policy.mode === 'custom_safe_regex'"
|
||||
@change="updateFormatPolicy({ mode: 'custom_safe_regex' })"
|
||||
/>
|
||||
custom_safe_regex(自定义安全正则)
|
||||
</label>
|
||||
</div>
|
||||
<template v-if="mapping.format_policy.mode === 'custom_safe_regex'">
|
||||
<label>
|
||||
pattern
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="mapping.format_policy.pattern ?? ''"
|
||||
placeholder="例如:^[A-Z]?\d{5,10}$"
|
||||
@input="updateFormatPolicy({ pattern: ($event.target as HTMLInputElement).value || null })"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
max_capture_groups
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
:disabled="readonly"
|
||||
:value="mapping.format_policy.max_capture_groups ?? 1"
|
||||
@input="updateFormatPolicy({ max_capture_groups: Number(($event.target as HTMLInputElement).value) || 0 })"
|
||||
/>
|
||||
</label>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</fieldset>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vc-map__source {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
padding: 8px 10px;
|
||||
margin: 0;
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-map__source--header { border-left: 4px solid #3b82f6; }
|
||||
.vc-map__source--table { border-left: 4px solid #10b981; }
|
||||
.vc-map__source--vc { border-left: 4px solid #f59e0b; }
|
||||
.vc-map__source legend {
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
padding: 0 4px;
|
||||
}
|
||||
.vc-map__toggle-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
}
|
||||
.vc-map__source label {
|
||||
display: grid;
|
||||
grid-template-columns: 110px 1fr;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.vc-map__checkbox {
|
||||
grid-template-columns: auto 1fr !important;
|
||||
align-items: center;
|
||||
}
|
||||
.vc-map__radio {
|
||||
grid-template-columns: auto 1fr !important;
|
||||
align-items: center;
|
||||
}
|
||||
.vc-map__format-block {
|
||||
grid-column: 1 / -1;
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
padding: 6px;
|
||||
border: 1px dashed var(--border-default);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-map__format-title {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.vc-map__format-radios {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
.vc-map__source select,
|
||||
.vc-map__source input {
|
||||
padding: 4px 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
font-size: 0.8rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.vc-map__split-open-row {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.vc-map__split-open-btn {
|
||||
padding: 4px 12px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.vc-map__split-open-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.vc-map__split-status-inline {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.vc-map__split-status--muted {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
</style>
|
||||
+921
@@ -0,0 +1,921 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/VcSplitRuleEditor.vue
|
||||
用途:VC 专用拆分规则编辑器(只处理 Section C VCSplit* 类型,不引入任何 XfaSplit*)。
|
||||
复用 XfaSplitRulePanel 的 addRule/matcherFromExtraction/preview/dirty banner 交互模式,
|
||||
但所有类型、常量、stages 全部本地化,类型只用 vc.types.ts Section C。
|
||||
依赖:shipping-order-document-profile.vc.types.ts Section C/J;
|
||||
preview API 为本地 stub,标注后续接入 endpoint。
|
||||
逻辑:split_rules 变化时 emit draftRequired,reason=split_rule_changed;
|
||||
确认前必须先预览(needs_preview → diagnostics → confirm dialog → emit confirmed)。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, computed } from 'vue';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import type {
|
||||
VCProfileDraftTrigger,
|
||||
VCSplitEnginePreviewResult,
|
||||
VCSplitMatcher,
|
||||
VCSplitNormalization,
|
||||
VCSplitRule,
|
||||
VCSplitRuleSet,
|
||||
VCSplitSegment,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.vc.types';
|
||||
|
||||
type ExtractionMode = 'select_line' | 'select_line_range' | 'extract_prefix' | 'regex_capture' | 'substring';
|
||||
|
||||
type VCSplitStageType =
|
||||
| 'split_lines'
|
||||
| 'select_line'
|
||||
| 'select_line_range'
|
||||
| 'extract_prefix'
|
||||
| 'regex_capture'
|
||||
| 'replace'
|
||||
| 'substring'
|
||||
| 'normalize';
|
||||
|
||||
interface VCSplitStage {
|
||||
stage_id: string;
|
||||
type: VCSplitStageType;
|
||||
trim?: boolean;
|
||||
remove_empty_lines?: boolean;
|
||||
line_breaks?: string[];
|
||||
line_index?: number;
|
||||
line_start?: number;
|
||||
line_end?: number;
|
||||
join_with?: 'newline' | 'space' | 'comma';
|
||||
value?: string;
|
||||
separators?: string[];
|
||||
case_sensitive?: boolean;
|
||||
pattern?: string;
|
||||
capture_group?: number;
|
||||
find?: string;
|
||||
replace_with?: string;
|
||||
start?: number;
|
||||
end?: number | null;
|
||||
}
|
||||
|
||||
interface VCSplitRulePatch {
|
||||
order?: number;
|
||||
matcher?: VCSplitMatcher | null;
|
||||
segment?: Partial<VCSplitSegment>;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
ruleSet: VCSplitRuleSet | null;
|
||||
selectedFieldCode: string;
|
||||
documentId: number;
|
||||
profileId: number;
|
||||
readonly?: boolean;
|
||||
dirtyUnsaved?: boolean;
|
||||
persistedConfirmed?: boolean;
|
||||
visible: boolean;
|
||||
}>(), {
|
||||
selectedFieldCode: 'reservation_id',
|
||||
readonly: false,
|
||||
dirtyUnsaved: false,
|
||||
persistedConfirmed: false,
|
||||
visible: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:ruleSet': [ruleSet: VCSplitRuleSet];
|
||||
confirmed: [ruleSet: VCSplitRuleSet, previewToken: string];
|
||||
draftRequired: [trigger: VCProfileDraftTrigger];
|
||||
}>();
|
||||
|
||||
const message = useMessage();
|
||||
|
||||
function newClientId(prefix: 'rs' | 'rule' | 'seg' | 'stage'): string {
|
||||
return `${prefix}-${crypto.randomUUID().replace(/-/g, '')}`;
|
||||
}
|
||||
|
||||
const splitLoading = ref(false);
|
||||
const splitPreview = ref<VCSplitEnginePreviewResult | null>(null);
|
||||
const splitPreviewRuleSetHash = ref<string | null>(null);
|
||||
const splitPreviewConfirmationToken = ref<string | null>(null);
|
||||
const splitCollapsedRules = ref(new Set<string>());
|
||||
const splitAdvancedRules = ref(new Set<string>());
|
||||
|
||||
const showUnsavedConfirmBanner = computed(() => props.dirtyUnsaved && props.persistedConfirmed === false);
|
||||
|
||||
function createDefaultStage(type: VCSplitStageType): VCSplitStage {
|
||||
const stageId = newClientId('stage');
|
||||
if (type === 'split_lines') {
|
||||
return {
|
||||
stage_id: stageId,
|
||||
type,
|
||||
trim: true,
|
||||
remove_empty_lines: true,
|
||||
line_breaks: ['\r\n', '\r', '\n'],
|
||||
};
|
||||
}
|
||||
if (type === 'select_line') return { stage_id: stageId, type, line_index: 1 };
|
||||
if (type === 'select_line_range') return { stage_id: stageId, type, line_start: 1, line_end: 2, join_with: 'newline' };
|
||||
if (type === 'extract_prefix') return {
|
||||
stage_id: stageId,
|
||||
type,
|
||||
value: '',
|
||||
separators: [':', ':'],
|
||||
case_sensitive: false,
|
||||
};
|
||||
if (type === 'regex_capture') return { stage_id: stageId, type, pattern: '', capture_group: 1 };
|
||||
if (type === 'replace') return { stage_id: stageId, type, find: '', replace_with: '' };
|
||||
if (type === 'substring') return { stage_id: stageId, type, start: 0, end: null };
|
||||
return { stage_id: stageId, type: 'normalize', trim: true, remove_empty_lines: true };
|
||||
}
|
||||
|
||||
function createDefaultPipelineStages(lineIndex = 1): VCSplitStage[] {
|
||||
return [
|
||||
createDefaultStage('split_lines'),
|
||||
{ ...createDefaultStage('select_line'), line_index: lineIndex },
|
||||
];
|
||||
}
|
||||
|
||||
function matcherFromExtraction(mode: ExtractionMode, stage: Partial<VCSplitStage>, order: number): VCSplitMatcher {
|
||||
if (mode === 'extract_prefix') {
|
||||
return {
|
||||
type: 'prefix',
|
||||
value: String(stage.value || ''),
|
||||
separators: (stage.separators && stage.separators.length) ? stage.separators : [':', ':'],
|
||||
case_sensitive: Boolean(stage.case_sensitive),
|
||||
};
|
||||
}
|
||||
if (mode === 'regex_capture') {
|
||||
return {
|
||||
type: 'regex',
|
||||
pattern: String(stage.pattern || ''),
|
||||
capture_group: stage.capture_group ?? 1,
|
||||
case_sensitive: Boolean(stage.case_sensitive),
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: 'position',
|
||||
line_index: Number(stage.line_index || stage.line_start || order || 1),
|
||||
};
|
||||
}
|
||||
|
||||
function hashRuleSet(ruleSet: VCSplitRuleSet | null | undefined): string {
|
||||
if (!ruleSet) return '';
|
||||
return JSON.stringify(ruleSet);
|
||||
}
|
||||
|
||||
function invalidatePreview(): void {
|
||||
splitPreview.value = null;
|
||||
splitPreviewRuleSetHash.value = null;
|
||||
splitPreviewConfirmationToken.value = null;
|
||||
}
|
||||
|
||||
function ensureRuleSet(): VCSplitRuleSet {
|
||||
if (props.ruleSet) return props.ruleSet;
|
||||
const ruleSet: VCSplitRuleSet = {
|
||||
rule_set_id: newClientId('rs'),
|
||||
rule_version: 1,
|
||||
normalization: { trim: true, remove_empty_lines: true, line_breaks: ['\r\n', '\r', '\n'] },
|
||||
rules: [],
|
||||
unmatched_line_policy: 'evidence_only',
|
||||
duplicate_match_policy: 'needs_review',
|
||||
same_field_multiple_segment_policy: 'needs_review',
|
||||
source: 'user',
|
||||
status: 'draft',
|
||||
requires_confirmation: true,
|
||||
};
|
||||
emit('update:ruleSet', ruleSet);
|
||||
invalidatePreview();
|
||||
emitDraftTriggerForSplitChanged();
|
||||
return ruleSet;
|
||||
}
|
||||
|
||||
function markRuleSetDirty(ruleSet: VCSplitRuleSet): VCSplitRuleSet {
|
||||
const wasConfirmed = ruleSet.status === 'confirmed' || ruleSet.status === 'published';
|
||||
return {
|
||||
...ruleSet,
|
||||
status: 'draft',
|
||||
requires_confirmation: true,
|
||||
rule_version: wasConfirmed ? ruleSet.rule_version + 1 : ruleSet.rule_version,
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeRuleOrders(rules: VCSplitRule[]): VCSplitRule[] {
|
||||
return [...rules]
|
||||
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||
.map((rule, index) => ({ ...rule, order: index + 1 }));
|
||||
}
|
||||
|
||||
function writeRuleSet(ruleSet: VCSplitRuleSet, emitDraft = true): void {
|
||||
emit('update:ruleSet', ruleSet);
|
||||
invalidatePreview();
|
||||
if (emitDraft) {
|
||||
emitDraftTriggerForSplitChanged();
|
||||
}
|
||||
}
|
||||
|
||||
function applyRuleSetChange(updater: (ruleSet: VCSplitRuleSet) => VCSplitRuleSet): void {
|
||||
const current = ensureRuleSet();
|
||||
writeRuleSet(markRuleSetDirty(updater(current)));
|
||||
}
|
||||
|
||||
function emitDraftTriggerForSplitChanged(): void {
|
||||
const trigger: VCProfileDraftTrigger = {
|
||||
named_regions_changed: false,
|
||||
field_source_mappings_changed: true,
|
||||
requires_draft_reset: true,
|
||||
reasons: [{ kind: 'field_source_mapping_split_rule_changed' }],
|
||||
};
|
||||
emit('draftRequired', trigger);
|
||||
}
|
||||
|
||||
function addRule(): void {
|
||||
if (props.readonly) return;
|
||||
const ruleSet = ensureRuleSet();
|
||||
const order = (ruleSet.rules?.length || 0) + 1;
|
||||
const stages = createDefaultPipelineStages(order);
|
||||
const nextRule: VCSplitRule = {
|
||||
rule_id: newClientId('rule'),
|
||||
order,
|
||||
matcher: matcherFromExtraction('select_line', stages[1] || {}, order),
|
||||
segment: {
|
||||
segment_id: newClientId('seg'),
|
||||
segment_code: '',
|
||||
display_name: '',
|
||||
handling: 'evidence_only',
|
||||
target_field_id: null,
|
||||
target_field_code: props.selectedFieldCode,
|
||||
note: null,
|
||||
},
|
||||
};
|
||||
writeRuleSet(markRuleSetDirty({
|
||||
...ruleSet,
|
||||
rules: normalizeRuleOrders([...(ruleSet.rules || []), nextRule]),
|
||||
}));
|
||||
const next = new Set(splitCollapsedRules.value);
|
||||
next.delete(nextRule.rule_id);
|
||||
splitCollapsedRules.value = next;
|
||||
}
|
||||
|
||||
function deleteRule(ruleId: string): void {
|
||||
applyRuleSetChange((current) => ({
|
||||
...current,
|
||||
rules: normalizeRuleOrders(current.rules.filter((r) => r.rule_id !== ruleId)),
|
||||
}));
|
||||
const next = new Set(splitCollapsedRules.value);
|
||||
next.delete(ruleId);
|
||||
splitCollapsedRules.value = next;
|
||||
}
|
||||
|
||||
function moveRule(ruleId: string, direction: 'up' | 'down'): void {
|
||||
const current = ensureRuleSet();
|
||||
const rules = [...current.rules];
|
||||
const idx = rules.findIndex((r) => r.rule_id === ruleId);
|
||||
if (idx < 0) return;
|
||||
const swapIdx = direction === 'up' ? idx - 1 : idx + 1;
|
||||
if (swapIdx < 0 || swapIdx >= rules.length) return;
|
||||
const currentRule = rules[idx];
|
||||
const swapRule = rules[swapIdx];
|
||||
if (!currentRule || !swapRule) return;
|
||||
[rules[idx], rules[swapIdx]] = [swapRule, currentRule];
|
||||
applyRuleSetChange((rs) => ({ ...rs, rules: normalizeRuleOrders(rules) }));
|
||||
}
|
||||
|
||||
function toggleRule(ruleId: string): void {
|
||||
const next = new Set(splitCollapsedRules.value);
|
||||
if (next.has(ruleId)) next.delete(ruleId);
|
||||
else next.add(ruleId);
|
||||
splitCollapsedRules.value = next;
|
||||
}
|
||||
|
||||
function toggleAdvanced(ruleId: string): void {
|
||||
const next = new Set(splitAdvancedRules.value);
|
||||
if (next.has(ruleId)) next.delete(ruleId);
|
||||
else next.add(ruleId);
|
||||
splitAdvancedRules.value = next;
|
||||
}
|
||||
|
||||
function extractionStage(rule: VCSplitRule): VCSplitStage {
|
||||
if (rule.matcher?.type === 'prefix') {
|
||||
return {
|
||||
...createDefaultStage('extract_prefix'),
|
||||
value: rule.matcher.value ?? undefined,
|
||||
separators: rule.matcher.separators,
|
||||
case_sensitive: rule.matcher.case_sensitive,
|
||||
};
|
||||
}
|
||||
if (rule.matcher?.type === 'regex') {
|
||||
return {
|
||||
...createDefaultStage('regex_capture'),
|
||||
pattern: rule.matcher.pattern ?? undefined,
|
||||
capture_group: rule.matcher.capture_group ?? undefined,
|
||||
case_sensitive: rule.matcher.case_sensitive,
|
||||
};
|
||||
}
|
||||
if (rule.matcher?.type === 'position') {
|
||||
return {
|
||||
...createDefaultStage('select_line'),
|
||||
line_index: rule.matcher.line_index ?? rule.order ?? 1,
|
||||
};
|
||||
}
|
||||
return { ...createDefaultStage('select_line'), line_index: rule.order ?? 1 };
|
||||
}
|
||||
|
||||
function extractionMode(rule: VCSplitRule): ExtractionMode {
|
||||
if (rule.matcher?.type === 'prefix') return 'extract_prefix';
|
||||
if (rule.matcher?.type === 'regex') return 'regex_capture';
|
||||
if (rule.matcher?.type === 'position') return 'select_line';
|
||||
return 'select_line';
|
||||
}
|
||||
|
||||
function updateRule(ruleId: string, patch: VCSplitRulePatch): void {
|
||||
applyRuleSetChange((current) => ({
|
||||
...current,
|
||||
rules: current.rules.map((rule) => {
|
||||
if (rule.rule_id !== ruleId) return rule;
|
||||
return {
|
||||
...rule,
|
||||
...patch,
|
||||
segment: patch.segment ? { ...rule.segment, ...patch.segment } : rule.segment,
|
||||
matcher: patch.matcher !== undefined ? patch.matcher : rule.matcher,
|
||||
};
|
||||
}),
|
||||
}));
|
||||
}
|
||||
|
||||
function changeExtractionMode(rule: VCSplitRule, mode: ExtractionMode): void {
|
||||
const extraction = createDefaultStage(mode);
|
||||
if (mode === 'select_line') extraction.line_index = rule.order ?? 1;
|
||||
if (mode === 'select_line_range') {
|
||||
extraction.line_start = rule.order ?? 1;
|
||||
extraction.line_end = (rule.order ?? 1) + 1;
|
||||
}
|
||||
updateRule(rule.rule_id, {
|
||||
matcher: matcherFromExtraction(mode, extraction, rule.order ?? 1),
|
||||
});
|
||||
}
|
||||
|
||||
function updateExtraction(rule: VCSplitRule, patch: Partial<VCSplitStage>): void {
|
||||
const current = extractionStage(rule);
|
||||
const nextStage = { ...current, ...patch };
|
||||
const mode = extractionMode(rule);
|
||||
updateRule(rule.rule_id, {
|
||||
matcher: matcherFromExtraction(mode, nextStage, rule.order ?? 1),
|
||||
});
|
||||
}
|
||||
|
||||
function updateUnmatchedPolicy(policy: 'evidence_only' | 'needs_review'): void {
|
||||
applyRuleSetChange((current) => ({ ...current, unmatched_line_policy: policy }));
|
||||
}
|
||||
|
||||
function updateNormalization(patch: Partial<VCSplitNormalization>): void {
|
||||
applyRuleSetChange((current) => ({
|
||||
...current,
|
||||
normalization: { ...(current.normalization || {}), ...patch },
|
||||
}));
|
||||
}
|
||||
|
||||
function previewValueFor(rule: VCSplitRule): string | null {
|
||||
const segment = splitPreview.value?.segments?.find((s) => s.rule_id === rule.rule_id);
|
||||
return segment ? (segment.normalized_text || segment.raw_text) : null;
|
||||
}
|
||||
|
||||
function previewLineLabel(lineStart?: number | null, lineEnd?: number | null): string {
|
||||
if (!lineStart) return '—';
|
||||
return lineEnd && lineEnd !== lineStart ? `${lineStart}–${lineEnd}` : String(lineStart);
|
||||
}
|
||||
|
||||
async function runPreview(): Promise<void> {
|
||||
const ruleSet = ensureRuleSet();
|
||||
splitLoading.value = true;
|
||||
try {
|
||||
// TODO: 后端 API stub,后续接入实际 endpoint
|
||||
// 预期:POST /admin/shipping/document-profiles/{profileId}/documents/{documentId}/preview-split
|
||||
// 请求体:{ rule_set: ruleSet, field_code: selectedFieldCode }
|
||||
splitPreview.value = {
|
||||
status: 'parsed',
|
||||
rule_set_id: ruleSet.rule_set_id,
|
||||
rule_version: ruleSet.rule_version,
|
||||
mapped_fields: {},
|
||||
segments: [],
|
||||
evidence_only_segments: [],
|
||||
diagnostics: [],
|
||||
};
|
||||
splitPreviewRuleSetHash.value = hashRuleSet(ruleSet);
|
||||
splitPreviewConfirmationToken.value = `stub-${Date.now()}`;
|
||||
} catch (error) {
|
||||
message.error(error instanceof BusinessError ? error.message : '预览失败');
|
||||
} finally {
|
||||
splitLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function confirmRules(): void {
|
||||
const ruleSet = ensureRuleSet();
|
||||
const currentHash = hashRuleSet(ruleSet);
|
||||
if (!splitPreview.value || splitPreviewRuleSetHash.value !== currentHash || !splitPreviewConfirmationToken.value) {
|
||||
message.error('确认前请先预览当前规则集');
|
||||
return;
|
||||
}
|
||||
if (splitPreview.value.status === 'needs_review' || (splitPreview.value.diagnostics || []).length > 0) {
|
||||
message.error('存在 needs_review 或诊断错误,无法确认');
|
||||
return;
|
||||
}
|
||||
const confirmedRuleSet: VCSplitRuleSet = {
|
||||
...ruleSet,
|
||||
source: 'user',
|
||||
status: 'confirmed',
|
||||
requires_confirmation: false,
|
||||
};
|
||||
emit('update:ruleSet', confirmedRuleSet);
|
||||
emit('confirmed', confirmedRuleSet, splitPreviewConfirmationToken.value);
|
||||
}
|
||||
|
||||
function lineBreaksToDisplay(breaks: string[] | undefined): string {
|
||||
return (breaks || []).map((item) => item
|
||||
.replace(/\\/g, '\\\\')
|
||||
.replace(/\r/g, '\\r')
|
||||
.replace(/\n/g, '\\n')
|
||||
.replace(/\t/g, '\\t')).join(', ');
|
||||
}
|
||||
|
||||
function parseLineBreaks(value: string): string[] {
|
||||
return value.split(',')
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean)
|
||||
.map((token) => token
|
||||
.replace(/\\r\\n/g, '\r\n')
|
||||
.replace(/\\n/g, '\n')
|
||||
.replace(/\\r/g, '\r')
|
||||
.replace(/\\t/g, '\t')
|
||||
.replace(/\\\\/g, '\\'));
|
||||
}
|
||||
|
||||
function separatorsToString(separators: string[] | undefined): string {
|
||||
return (separators || []).join(', ');
|
||||
}
|
||||
|
||||
function parseSeparators(value: string): string[] {
|
||||
return value.split(',').map((item) => item.trim()).filter(Boolean);
|
||||
}
|
||||
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
ensureRuleSet();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="vc-split-editor">
|
||||
<div v-if="showUnsavedConfirmBanner" class="vc-map__banner" role="status">
|
||||
已确认的规则集有未保存改动,保存后将重置为 Draft。
|
||||
</div>
|
||||
|
||||
<div class="vc-split-editor__header">
|
||||
<h4>拆分规则编辑器 · {{ selectedFieldCode }}</h4>
|
||||
<div class="vc-split-editor__toolbar">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly"
|
||||
@click="addRule()"
|
||||
>
|
||||
新增拆分规则
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="splitLoading"
|
||||
@click="runPreview()"
|
||||
>
|
||||
{{ splitLoading ? '预览中…' : '预览拆分' }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly || !splitPreview || !splitPreviewConfirmationToken"
|
||||
@click="confirmRules()"
|
||||
>
|
||||
确认规则
|
||||
</button>
|
||||
<span class="vc-map__split-status">
|
||||
状态:{{ ruleSet?.status || 'draft' }}
|
||||
· v{{ ruleSet?.rule_version || 1 }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<fieldset class="vc-map__split-ruleset">
|
||||
<legend>规则集设置</legend>
|
||||
<label>
|
||||
未匹配策略
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="ruleSet?.unmatched_line_policy || 'evidence_only'"
|
||||
@change="updateUnmatchedPolicy(($event.target as HTMLSelectElement).value as 'evidence_only' | 'needs_review')"
|
||||
>
|
||||
<option value="evidence_only">仅留证据 (evidence_only)</option>
|
||||
<option value="needs_review">需复核 (needs_review)</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="vc-map__split-normalization">
|
||||
<label class="vc-map__checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
:disabled="readonly"
|
||||
:checked="ruleSet?.normalization?.trim ?? true"
|
||||
@change="updateNormalization({ trim: ($event.target as HTMLInputElement).checked })"
|
||||
/>
|
||||
trim
|
||||
</label>
|
||||
<label class="vc-map__checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
:disabled="readonly"
|
||||
:checked="ruleSet?.normalization?.remove_empty_lines ?? true"
|
||||
@change="updateNormalization({ remove_empty_lines: ($event.target as HTMLInputElement).checked })"
|
||||
/>
|
||||
去空行
|
||||
</label>
|
||||
<label>
|
||||
换行
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="lineBreaksToDisplay(ruleSet?.normalization?.line_breaks)"
|
||||
:placeholder="'\r\n, \r, \n'"
|
||||
@change="updateNormalization({ line_breaks: parseLineBreaks(($event.target as HTMLInputElement).value) })"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div v-if="splitPreview" class="vc-map__split-preview">
|
||||
<h5>拆分预览(stub,后端 API 待接入)</h5>
|
||||
<p>status: {{ splitPreview.status }}</p>
|
||||
<table v-if="splitPreview.segments?.length" class="vc-map__table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>行</th><th>segment_code</th><th>提取方式</th><th>识别值</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="seg in splitPreview.segments" :key="seg.segment_id">
|
||||
<td>{{ previewLineLabel(seg.line_no, seg.line_end_no) }}</td>
|
||||
<td>{{ seg.segment_code }}</td>
|
||||
<td>{{ seg.matcher_type }}</td>
|
||||
<td>{{ seg.normalized_text || seg.raw_text }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<ul v-if="splitPreview.diagnostics?.length" class="vc-map__diagnostics">
|
||||
<li v-for="(d, i) in splitPreview.diagnostics" :key="i">
|
||||
<strong>{{ d.code }}</strong>: {{ d.message }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<ul class="vc-map__split-rules">
|
||||
<li
|
||||
v-for="(rule, idx) in (ruleSet?.rules || [])"
|
||||
:key="rule.rule_id"
|
||||
>
|
||||
<div class="vc-map__split-rule-header">
|
||||
<button type="button" class="vc-map__split-rule-title" @click="toggleRule(rule.rule_id)">
|
||||
<span>{{ splitCollapsedRules.has(rule.rule_id) ? '›' : '⌄' }}</span>
|
||||
<strong>规则 {{ idx + 1 }}</strong>
|
||||
<span>{{ rule.segment.display_name || rule.segment.segment_code || '未命名' }}</span>
|
||||
</button>
|
||||
<div class="vc-map__split-rule-actions">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly || idx === 0"
|
||||
@click="moveRule(rule.rule_id, 'up')"
|
||||
>
|
||||
↑
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly || idx === (ruleSet?.rules?.length || 0) - 1"
|
||||
@click="moveRule(rule.rule_id, 'down')"
|
||||
>
|
||||
↓
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="readonly"
|
||||
@click="toggleAdvanced(rule.rule_id)"
|
||||
>
|
||||
{{ splitAdvancedRules.has(rule.rule_id) ? '高级 ▾' : '高级 ▸' }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="danger"
|
||||
:disabled="readonly"
|
||||
@click="deleteRule(rule.rule_id)"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!splitCollapsedRules.has(rule.rule_id)" class="vc-map__split-rule-detail">
|
||||
<label>
|
||||
segment_code
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="rule.segment.segment_code"
|
||||
@input="updateRule(rule.rule_id, { segment: { segment_code: ($event.target as HTMLInputElement).value } })"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
display_name
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="rule.segment.display_name"
|
||||
@input="updateRule(rule.rule_id, { segment: { display_name: ($event.target as HTMLInputElement).value } })"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
提取方式
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="extractionMode(rule)"
|
||||
@change="changeExtractionMode(rule, ($event.target as HTMLSelectElement).value as ExtractionMode)"
|
||||
>
|
||||
<option value="select_line">按行号 (position)</option>
|
||||
<option value="extract_prefix">按前缀标签 (prefix)</option>
|
||||
<option value="regex_capture">按正则捕获 (regex)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label v-if="extractionMode(rule) === 'select_line'">
|
||||
行号
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
:disabled="readonly"
|
||||
:value="extractionStage(rule).line_index ?? (rule.order ?? 1)"
|
||||
@input="updateExtraction(rule, { line_index: Number(($event.target as HTMLInputElement).value) || 1 })"
|
||||
/>
|
||||
</label>
|
||||
<template v-if="extractionMode(rule) === 'extract_prefix'">
|
||||
<label>
|
||||
前缀
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="extractionStage(rule).value || ''"
|
||||
@input="updateExtraction(rule, { value: ($event.target as HTMLInputElement).value })"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
分隔符
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="separatorsToString(extractionStage(rule).separators)"
|
||||
@input="updateExtraction(rule, { separators: parseSeparators(($event.target as HTMLInputElement).value) })"
|
||||
/>
|
||||
</label>
|
||||
</template>
|
||||
<template v-if="extractionMode(rule) === 'regex_capture'">
|
||||
<label>
|
||||
正则
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="extractionStage(rule).pattern || ''"
|
||||
@input="updateExtraction(rule, { pattern: ($event.target as HTMLInputElement).value })"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
捕获组
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
:disabled="readonly"
|
||||
:value="extractionStage(rule).capture_group ?? 1"
|
||||
@input="updateExtraction(rule, { capture_group: Number(($event.target as HTMLInputElement).value) || 0 })"
|
||||
/>
|
||||
</label>
|
||||
</template>
|
||||
<div v-if="splitAdvancedRules.has(rule.rule_id)" class="vc-map__split-rule-advanced">
|
||||
<label>
|
||||
handling
|
||||
<select
|
||||
:disabled="readonly"
|
||||
:value="rule.segment.handling"
|
||||
@change="updateRule(rule.rule_id, { segment: { handling: ($event.target as HTMLSelectElement).value as 'mapped' | 'evidence_only' } })"
|
||||
>
|
||||
<option value="evidence_only">仅证据 (evidence_only)</option>
|
||||
<option value="mapped">映射字段 (mapped)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
note
|
||||
<input
|
||||
:disabled="readonly"
|
||||
:value="rule.segment.note || ''"
|
||||
@input="updateRule(rule.rule_id, { segment: { note: ($event.target as HTMLInputElement).value || null } })"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div class="vc-map__split-inline-preview">
|
||||
<span>识别值:</span>
|
||||
<strong v-if="previewValueFor(rule)">{{ previewValueFor(rule) }}</strong>
|
||||
<span v-else>需预览</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.vc-split-editor {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 8px;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.vc-split-editor__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.vc-split-editor__header h4 {
|
||||
margin: 0;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.vc-split-editor__toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.vc-split-editor__toolbar button {
|
||||
padding: 4px 10px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-split-editor__toolbar button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.vc-map__banner {
|
||||
padding: 8px 10px;
|
||||
border-radius: 6px;
|
||||
background: var(--status-warning-bg);
|
||||
color: var(--status-warning-fg);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.vc-map__split-status {
|
||||
margin-left: auto;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.vc-map__split-ruleset {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
}
|
||||
.vc-map__split-ruleset legend {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
padding: 0 4px;
|
||||
}
|
||||
.vc-map__split-normalization {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
.vc-map__checkbox {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.vc-map__split-preview {
|
||||
padding: 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
font-size: 0.78rem;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.vc-map__split-preview h5 {
|
||||
margin: 0 0 6px 0;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
.vc-map__table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-map__table th,
|
||||
.vc-map__table td {
|
||||
border: 1px solid var(--border-default);
|
||||
padding: 4px 6px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
.vc-map__table th {
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-map__diagnostics {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 6px 0 0 0;
|
||||
color: var(--text-danger);
|
||||
}
|
||||
.vc-map__split-rules {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.vc-map__split-rules > li {
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.vc-map__split-rule-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 6px;
|
||||
padding: 6px 8px;
|
||||
}
|
||||
.vc-map__split-rule-title {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: 2px 4px;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
.vc-map__split-rule-title span {
|
||||
font-family: monospace;
|
||||
}
|
||||
.vc-map__split-rule-actions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
.vc-map__split-rule-actions button {
|
||||
padding: 2px 8px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
.vc-map__split-rule-actions button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.vc-map__split-rule-actions .danger {
|
||||
color: var(--text-danger);
|
||||
}
|
||||
.vc-map__split-rule-detail {
|
||||
padding: 6px 8px;
|
||||
border-top: 1px dashed var(--border-default);
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.vc-map__split-rule-detail label {
|
||||
display: grid;
|
||||
grid-template-columns: 100px 1fr;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-map__split-rule-detail select,
|
||||
.vc-map__split-rule-detail input,
|
||||
.vc-map__split-ruleset select,
|
||||
.vc-map__split-ruleset input {
|
||||
padding: 4px 6px;
|
||||
border: 1px solid var(--border-default);
|
||||
border-radius: 4px;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.vc-map__split-rule-advanced {
|
||||
grid-column: 1 / -1;
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
padding: 6px;
|
||||
border: 1px dashed var(--border-default);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-elevated);
|
||||
}
|
||||
.vc-map__split-inline-preview {
|
||||
grid-column: 1 / -1;
|
||||
font-size: 0.78rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.danger { color: var(--text-danger); }
|
||||
</style>
|
||||
Reference in new issue
Block a user