feat(shipping-notice): 落地字段资产治理与唯一 Schema,自动建单随版本冻结
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b7307fc573
commit
3a1dbf7ce5
144 files changed
+15167
-4480
No files matched your search
+151
-17
@@ -1,13 +1,14 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/OrderProfileCreateWizardPage.vue
|
||||
用途:订单模板三步创建向导。
|
||||
依赖:Schema/样本/表格 API、三个步骤组件、Router。
|
||||
逻辑:身份、样本、主表格均在浏览器内暂存;仅第三步完成调用原子 wizard-complete 接口。
|
||||
用途:以三步向导创建订单文档模板草稿。
|
||||
依赖:Schema/样本/表格 API、步骤组件和 Vue Router。
|
||||
逻辑:首步仅收集业务名称和 Schema;最后一步由服务端生成系统编码并原子创建草稿、样本绑定、Revision 与 Lease。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ArrowLeft, ArrowRight, Check, FileText, Layers3, Sparkles } from 'lucide-vue-next';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { getShippingOrderSchemaState } from '@/features/admin/api/shipping-order-schema.api';
|
||||
@@ -17,23 +18,156 @@ import OrderProfileIdentityStep from './components/OrderProfileIdentityStep.vue'
|
||||
import OrderProfileSampleStep from './components/OrderProfileSampleStep.vue';
|
||||
import OrderProfileModelStartStep from './components/OrderProfileModelStartStep.vue';
|
||||
|
||||
const { t } = useI18n(); const router = useRouter(); const message = useMessage();
|
||||
const step = ref(1); const saving = ref(false); const schemas = ref<ShippingOrderSchemaVersion[]>([]);
|
||||
const samples = ref<Array<{ document_id:number; intake_no:string; filename?:string|null; table_count:number }>>([]);
|
||||
const tables = ref<Array<{ table_id:string; page_no:number; row_count:number; column_count:number; rows:string[][] }>>([]);
|
||||
const identity = reactive({ displayName:'', profileCode:'', schemaId:0 }); const documentId = ref(0); const tableId = ref('');
|
||||
type Identity = { displayName: string; schemaId: number };
|
||||
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
const message = useMessage();
|
||||
const step = ref(1);
|
||||
const saving = ref(false);
|
||||
const schemas = ref<ShippingOrderSchemaVersion[]>([]);
|
||||
const samples = ref<Array<{ document_id: number; intake_no: string; filename?: string | null; table_count: number }>>([]);
|
||||
const tables = ref<Array<{ table_id: string; page_no: number; row_count: number; column_count: number; rows: string[][] }>>([]);
|
||||
const identity = reactive<Identity>({ displayName: '', schemaId: 0 });
|
||||
const documentId = ref(0);
|
||||
const tableId = ref('');
|
||||
const browserSessionId = crypto.randomUUID();
|
||||
const canNext = computed(() => step.value === 1 ? Boolean(identity.displayName.trim() && identity.profileCode.trim() && identity.schemaId) : step.value === 2 ? Boolean(documentId.value) : Boolean(tableId.value));
|
||||
const publishedSchemas = computed(() => schemas.value.filter((item) => item.status === 'published'));
|
||||
const canNext = computed(() => step.value === 1
|
||||
? Boolean(identity.displayName.trim() && identity.schemaId)
|
||||
: step.value === 2 ? Boolean(documentId.value) : Boolean(tableId.value));
|
||||
const steps = computed(() => [
|
||||
{ number: 1, label: t('admin.shippingOrderProfiles.wizard.identityStep'), icon: FileText },
|
||||
{ number: 2, label: t('admin.shippingOrderProfiles.wizard.sampleStep'), icon: Layers3 },
|
||||
{ number: 3, label: t('admin.shippingOrderProfiles.wizard.tableStep'), icon: Sparkles },
|
||||
]);
|
||||
|
||||
/** 接收首步身份快照;父级单一状态驱动下一步校验,避免子组件对象替换造成状态不同步。 */
|
||||
function updateIdentity(next: Identity): void {
|
||||
identity.displayName = next.displayName;
|
||||
identity.schemaId = next.schemaId;
|
||||
}
|
||||
/** 加载可用 Schema 与已解析样本;失败不创建或缓存任何 Profile。 */
|
||||
async function loadContext(): Promise<void> { try { const [state, nextSamples] = await Promise.all([getShippingOrderSchemaState(), listOrderProfileSamples()]); schemas.value = state.versions || []; samples.value = nextSamples; } catch (error) { message.error(error instanceof BusinessError ? error.message : t('admin.shippingOrderProfiles.wizard.loadFailed')); } }
|
||||
async function loadContext(): Promise<void> {
|
||||
try {
|
||||
const [state, nextSamples] = await Promise.all([getShippingOrderSchemaState(), listOrderProfileSamples()]);
|
||||
schemas.value = state.versions || [];
|
||||
samples.value = nextSamples;
|
||||
} catch (error) {
|
||||
message.error(error instanceof BusinessError ? error.message : t('admin.shippingOrderProfiles.wizard.loadFailed'));
|
||||
}
|
||||
}
|
||||
/** 刷新上传后的样本库;样本解析未完成时只会留在样本库,不能产出半成品模板。 */
|
||||
async function refreshSamples(): Promise<void> { try { samples.value = await listOrderProfileSamples(); } catch { message.error(t('admin.shippingOrderProfiles.wizard.loadFailed')); } }
|
||||
watch(documentId, async (id) => { tableId.value=''; tables.value=[]; if (!id) return; try { const preview = await getOrderProfileSampleTables(id); tables.value = preview.tables; } catch (error) { message.error(error instanceof BusinessError ? error.message : t('admin.shippingOrderProfiles.wizard.tableLoadFailed')); } });
|
||||
/** 前进仅校验本地步骤状态;最后一步才拥有正式落库权限。 */
|
||||
function next(): void { if (!canNext.value) { message.error(t('admin.shippingOrderProfiles.wizard.incomplete')); return; } if (step.value < 3) step.value += 1; }
|
||||
async function refreshSamples(): Promise<void> {
|
||||
try { samples.value = await listOrderProfileSamples(); }
|
||||
catch { message.error(t('admin.shippingOrderProfiles.wizard.loadFailed')); }
|
||||
}
|
||||
/** 加载选定样本的可用表格;单表场景由下一步直接作为订单明细表。 */
|
||||
async function loadTables(id: number): Promise<void> {
|
||||
try { tables.value = (await getOrderProfileSampleTables(id)).tables; }
|
||||
catch (error) { message.error(error instanceof BusinessError ? error.message : t('admin.shippingOrderProfiles.wizard.tableLoadFailed')); }
|
||||
}
|
||||
watch(documentId, async (id) => {
|
||||
tableId.value = '';
|
||||
tables.value = [];
|
||||
if (!id) return;
|
||||
await loadTables(id);
|
||||
});
|
||||
/** 前进仅校验当前步骤;单表直接创建,多表才要求管理员确认订单明细表。 */
|
||||
async function next(): Promise<void> {
|
||||
if (!canNext.value) {
|
||||
message.error(step.value === 1 && !publishedSchemas.value.length
|
||||
? t('admin.shippingOrderProfiles.wizard.schemaRequired')
|
||||
: t('admin.shippingOrderProfiles.wizard.incomplete'));
|
||||
return;
|
||||
}
|
||||
if (step.value === 2) {
|
||||
if (!tables.value.length) await loadTables(documentId.value);
|
||||
const onlyTable = tables.value.length === 1 ? tables.value[0] : undefined;
|
||||
if (onlyTable) {
|
||||
tableId.value = onlyTable.table_id;
|
||||
await finish(true);
|
||||
return;
|
||||
}
|
||||
if (!tables.value.length) {
|
||||
message.error(t('admin.shippingOrderProfiles.wizard.noTable'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (step.value < 3) step.value += 1;
|
||||
}
|
||||
/** 单事务完成后进入草稿编辑路由;创建草稿和创建并进入标注共享同一审计动作。 */
|
||||
async function finish(enterEditor: boolean): Promise<void> { if (!canNext.value) return; saving.value=true; try { const profile = await completeOrderDocumentProfileWizard({ profile_code:identity.profileCode, display_name:identity.displayName, schema_version_id:identity.schemaId, document_id:documentId.value, main_table_id:tableId.value, browser_session_id:browserSessionId, operation_id:crypto.randomUUID() }); message.success(t('admin.shippingOrderProfiles.created')); if (enterEditor) router.push({ name:'AdminShippingOrderDocumentProfileEdit', params:{ profileCode:profile.profile_code, profileId:profile.id }, query:{ editorSessionId:browserSessionId } }); else router.push({ name:'AdminShippingOrderDocumentProfiles' }); } catch (error) { message.error(error instanceof BusinessError ? error.message : t('admin.shippingOrderProfiles.wizard.createFailed')); } finally { saving.value=false; } }
|
||||
async function finish(enterEditor: boolean): Promise<void> {
|
||||
if (!canNext.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
const profile = await completeOrderDocumentProfileWizard({
|
||||
display_name: identity.displayName,
|
||||
schema_version_id: identity.schemaId, document_id: documentId.value, main_table_id: tableId.value,
|
||||
browser_session_id: browserSessionId, operation_id: crypto.randomUUID(),
|
||||
});
|
||||
message.success(t('admin.shippingOrderProfiles.created'));
|
||||
await router.push(enterEditor
|
||||
? { name: 'AdminShippingOrderDocumentProfileEdit', params: { profileCode: profile.profile_code, profileId: profile.id }, query: { editorSessionId: browserSessionId } }
|
||||
: { name: 'AdminShippingOrderDocumentProfiles' });
|
||||
} catch (error) {
|
||||
message.error(error instanceof BusinessError ? error.message : t('admin.shippingOrderProfiles.wizard.createFailed'));
|
||||
} finally { saving.value = false; }
|
||||
}
|
||||
onMounted(loadContext);
|
||||
</script>
|
||||
<template><section class="wizard"><header><button type="button" @click="router.push({ name:'AdminShippingOrderDocumentProfiles' })">{{ t('admin.cancel') }}</button><h1>{{ t('admin.shippingOrderProfiles.wizard.title') }}</h1><p>{{ t('admin.shippingOrderProfiles.wizard.steps', { step }) }}</p></header><OrderProfileIdentityStep v-if="step===1" v-model="identity" :schemas="schemas"/><OrderProfileSampleStep v-else-if="step===2" v-model="documentId" :samples="samples" @uploaded="refreshSamples"/><OrderProfileModelStartStep v-else v-model="tableId" :tables="tables"/><footer><button v-if="step>1" type="button" @click="step-=1">{{ t('admin.shippingOrderProfiles.wizard.previous') }}</button><span/><button v-if="step<3" class="primary" type="button" :disabled="!canNext" @click="next">{{ t('admin.shippingOrderProfiles.wizard.next') }}</button><template v-else><button type="button" :disabled="saving||!canNext" @click="finish(false)">{{ t('admin.shippingOrderProfiles.wizard.createDraft') }}</button><button class="primary" type="button" :disabled="saving||!canNext" @click="finish(true)">{{ t('admin.shippingOrderProfiles.wizard.createAndEdit') }}</button></template></footer></section></template>
|
||||
<style scoped>.wizard{display:grid;gap:1.5rem;max-width:58rem;margin:0 auto;padding:1.5rem}.wizard header{display:grid;gap:.5rem}.wizard h1,.wizard p{margin:0}.wizard p{color:#64748b}.wizard footer{display:flex;gap:.75rem;align-items:center}.wizard footer span{flex:1}.wizard button{padding:.55rem .8rem;border:1px solid #cbd5e1;border-radius:.4rem;background:#fff}.wizard .primary{background:#2563eb;color:#fff;border-color:#2563eb}.wizard button:disabled{opacity:.5;cursor:not-allowed}</style>
|
||||
|
||||
<template>
|
||||
<section class="wizard-page">
|
||||
<div class="wizard-shell">
|
||||
<header class="wizard-heading">
|
||||
<div class="wizard-eyebrow"><Sparkles :size="16" /> {{ t('admin.shippingOrderProfiles.title') }}</div>
|
||||
<h1>{{ t('admin.shippingOrderProfiles.wizard.title') }}</h1>
|
||||
<p>{{ t('admin.shippingOrderProfiles.wizard.description') }}</p>
|
||||
</header>
|
||||
|
||||
<ol class="stepper" :aria-label="t('admin.shippingOrderProfiles.wizard.steps', { step })">
|
||||
<li v-for="item in steps" :key="item.number" :class="{ active: item.number === step, complete: item.number < step }">
|
||||
<span class="stepper-icon"><Check v-if="item.number < step" :size="16" /><component :is="item.icon" v-else :size="16" /></span>
|
||||
<span><small>{{ t('admin.shippingOrderProfiles.wizard.stepLabel', { step: item.number }) }}</small>{{ item.label }}</span>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<main class="wizard-card">
|
||||
<div class="wizard-card__heading">
|
||||
<span>{{ t('admin.shippingOrderProfiles.wizard.stepLabel', { step }) }}</span>
|
||||
<h2>{{ steps[step - 1]?.label || '' }}</h2>
|
||||
</div>
|
||||
<OrderProfileIdentityStep
|
||||
v-if="step === 1"
|
||||
:model-value="identity"
|
||||
:schemas="schemas"
|
||||
@update:model-value="updateIdentity"
|
||||
/>
|
||||
<OrderProfileSampleStep v-else-if="step === 2" v-model="documentId" :samples="samples" @uploaded="refreshSamples" />
|
||||
<OrderProfileModelStartStep v-else v-model="tableId" :tables="tables" />
|
||||
</main>
|
||||
|
||||
<footer class="wizard-actions">
|
||||
<button type="button" class="button button--secondary" @click="router.push({ name: 'AdminShippingOrderDocumentProfiles' })">{{ t('admin.cancel') }}</button>
|
||||
<span class="wizard-actions__spacer" />
|
||||
<button v-if="step > 1" type="button" class="button button--ghost" @click="step -= 1"><ArrowLeft :size="17" />{{ t('admin.shippingOrderProfiles.wizard.previous') }}</button>
|
||||
<button v-if="step < 3" type="button" class="button button--primary" :disabled="!canNext" @click="next">{{ t('admin.shippingOrderProfiles.wizard.next') }}<ArrowRight :size="17" /></button>
|
||||
<template v-else>
|
||||
<button type="button" class="button button--secondary" :disabled="saving || !canNext" @click="finish(false)">{{ t('admin.shippingOrderProfiles.wizard.createDraft') }}</button>
|
||||
<button type="button" class="button button--primary" :disabled="saving || !canNext" @click="finish(true)">{{ t('admin.shippingOrderProfiles.wizard.createAndEdit') }}<ArrowRight :size="17" /></button>
|
||||
</template>
|
||||
</footer>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.wizard-page { min-height: 100%; padding: 24px; background: #f6f8fc; }
|
||||
.wizard-shell { width: 100%; }
|
||||
.wizard-heading { margin-bottom: 28px; }.wizard-eyebrow { display: flex; align-items: center; gap: 7px; color: #1677d2; font-size: .82rem; font-weight: 750; letter-spacing: .04em; }.wizard-heading h1 { margin: 10px 0 7px; color: #15213b; font-size: clamp(1.75rem, 3vw, 2.35rem); letter-spacing: -.035em; }.wizard-heading p { margin: 0; color: #64748b; }
|
||||
.stepper { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin: 0 0 18px; padding: 0; list-style: none; }.stepper li { display: flex; align-items: center; gap: 10px; color: #94a3b8; font-size: .86rem; font-weight: 650; }.stepper li:not(:last-child)::after { width: 100%; height: 1px; margin-left: 10px; background: #dbe4f0; content: ''; }.stepper li.active { color: #1677d2; }.stepper li.complete { color: #0f8a65; }.stepper-icon { display: inline-grid; flex: 0 0 auto; width: 32px; height: 32px; place-items: center; border: 1px solid currentColor; border-radius: 50%; background: #fff; }.stepper .complete .stepper-icon { color: #fff; border-color: #0f8a65; background: #0f8a65; }.stepper small { display: block; margin-bottom: 1px; color: #94a3b8; font-size: .68rem; font-weight: 700; text-transform: uppercase; }
|
||||
.wizard-card { min-height: 360px; padding: clamp(24px, 4vw, 44px); border: 1px solid #e1e8f2; border-radius: 12px; background: #fff; box-shadow: 0 8px 24px rgb(15 23 42 / .06); }.wizard-card__heading { margin-bottom: 28px; padding-bottom: 18px; border-bottom: 1px solid #edf1f7; }.wizard-card__heading span { color: #1677d2; font-size: .76rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }.wizard-card__heading h2 { margin: 6px 0 0; color: #1e293b; font-size: 1.25rem; }
|
||||
.wizard-actions { display: flex; align-items: center; gap: 10px; margin-top: 18px; }.wizard-actions__spacer { flex: 1; }.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; padding: 0 15px; border: 1px solid transparent; border-radius: 9px; font-weight: 700; cursor: pointer; transition: transform .15s ease, box-shadow .15s ease, background .15s ease; }.button:hover:not(:disabled) { transform: translateY(-1px); }.button:focus-visible { outline: 3px solid rgb(22 119 210 / .25); outline-offset: 2px; }.button:disabled { opacity: .48; cursor: not-allowed; }.button--primary { color: #fff; border-color: #1668dc; background: #1677d2; box-shadow: 0 6px 16px rgb(22 119 210 / .2); }.button--secondary { color: #34445d; border-color: #d6e0ed; background: #fff; }.button--ghost { color: #47617e; background: transparent; }
|
||||
@media (max-width: 640px) { .wizard-page { padding: 24px 16px; }.stepper { grid-template-columns: 1fr; gap: 10px; }.stepper li:not(:last-child)::after { display: none; }.wizard-card { min-height: 300px; border-radius: 14px; }.wizard-actions { flex-wrap: wrap; }.wizard-actions__spacer { display: none; }.button--secondary:first-child { margin-right: auto; } }
|
||||
</style>
|
||||
+19
-8
@@ -1,19 +1,30 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/OrderProfileIdentityStep.vue
|
||||
用途:收集创建向导第一步的模板身份与 Schema。
|
||||
用途:收集模板名称与已发布 Schema。
|
||||
依赖:Schema DTO、Vue I18n。
|
||||
逻辑:仅双向绑定浏览器状态,不调用创建 API,profile_code 在完成后由服务端永久冻结。
|
||||
逻辑:系统编码由服务端在创建时生成;父级拥有唯一表单状态,避免 v-model 对象替换丢失首步校验状态。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingOrderSchemaVersion } from '@/features/admin/types/shipping-order-schema.types';
|
||||
const props = defineProps<{ modelValue: { displayName: string; profileCode: string; schemaId: number }; schemas: ShippingOrderSchemaVersion[] }>();
|
||||
const emit = defineEmits<{ 'update:modelValue': [value: { displayName: string; profileCode: string; schemaId: number }] }>();
|
||||
type Identity = { displayName: string; schemaId: number };
|
||||
const props = defineProps<{ modelValue: Identity; schemas: ShippingOrderSchemaVersion[] }>();
|
||||
const emit = defineEmits<{ 'update:modelValue': [value: Identity] }>();
|
||||
const { t } = useI18n();
|
||||
const publishedSchemas = computed(() => props.schemas.filter((item) => item.status === 'published'));
|
||||
/** 更新单个身份字段但不触发创建;向导刷新前没有正式 Profile。 */
|
||||
function update(key: 'displayName' | 'profileCode' | 'schemaId', value: string | number): void { emit('update:modelValue', { ...props.modelValue, [key]: value }); }
|
||||
/** 每次更新都提交完整快照,确保父级的下一步校验始终读取最新值。 */
|
||||
function update(key: keyof Identity, value: string | number): void { emit('update:modelValue', { ...props.modelValue, [key]: value }); }
|
||||
</script>
|
||||
<template><div class="wizard-step"><label>{{ t('admin.shippingOrderProfiles.name') }}<input :value="modelValue.displayName" @input="update('displayName', ($event.target as HTMLInputElement).value)"></label><label>{{ t('admin.shippingOrderProfiles.code') }}<input :value="modelValue.profileCode" @input="update('profileCode', ($event.target as HTMLInputElement).value.toUpperCase())"></label><small>{{ t('admin.shippingOrderProfiles.wizard.codeHint') }}</small><label>{{ t('admin.shippingOrderProfiles.schema') }}<select :value="modelValue.schemaId" @change="update('schemaId', Number(($event.target as HTMLSelectElement).value))"><option :value="0">{{ t('admin.shippingOrderProfiles.wizard.selectSchema') }}</option><option v-for="schema in publishedSchemas" :key="schema.id" :value="schema.id">v{{ schema.version }}</option></select></label></div></template>
|
||||
<style scoped>.wizard-step{display:grid;gap:1rem;max-width:36rem}.wizard-step label{display:grid;gap:.35rem;font-weight:600}.wizard-step input,.wizard-step select{padding:.6rem;border:1px solid #cbd5e1;border-radius:.4rem}small{color:#64748b}</style>
|
||||
|
||||
<template>
|
||||
<div class="identity-step">
|
||||
<label class="field"><span>{{ t('admin.shippingOrderProfiles.name') }}<b>*</b></span><input :value="modelValue.displayName" :placeholder="t('admin.shippingOrderProfiles.wizard.namePlaceholder')" @input="update('displayName', ($event.target as HTMLInputElement).value)" /></label>
|
||||
<div class="system-code"><strong>{{ t('admin.shippingOrderProfiles.code') }}</strong><span>{{ t('admin.shippingOrderProfiles.wizard.systemCodeHint') }}</span></div>
|
||||
<label class="field"><span>{{ t('admin.shippingOrderProfiles.schema') }}<b>*</b></span><select :value="modelValue.schemaId" @change="update('schemaId', Number(($event.target as HTMLSelectElement).value))"><option :value="0">{{ t('admin.shippingOrderProfiles.wizard.selectSchema') }}</option><option v-for="schema in publishedSchemas" :key="schema.id" :value="schema.id">v{{ schema.version }}</option></select><small v-if="!publishedSchemas.length" class="field-warning">{{ t('admin.shippingOrderProfiles.wizard.schemaRequired') }}</small></label>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.identity-step { display: grid; gap: 22px; max-width: 560px; }.field { display: grid; gap: 8px; color: #263650; font-weight: 700; }.field > span { display: flex; gap: 4px; }.field b { color: #d14343; }.field input,.field select { width: 100%; min-height: 44px; box-sizing: border-box; border: 1px solid #ccd8e6; border-radius: 9px; padding: 0 12px; color: #172033; background: #fff; font: inherit; outline: none; transition: border-color .15s ease, box-shadow .15s ease; }.field input:focus,.field select:focus { border-color: #1677d2; box-shadow: 0 0 0 3px rgb(22 119 210 / .13); }.field small { color: #71829a; font-size: .8rem; font-weight: 500; }.system-code { display: grid; gap: 4px; padding: 13px 14px; border: 1px solid #dbe7f5; border-radius: 9px; color: #52657d; background: #f7fbff; font-size: .86rem; }.system-code strong { color: #263650; }.field-warning { color: #b45309 !important; }
|
||||
</style>
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/OrderProfileModelStartStep.vue
|
||||
用途:确认样本文档中作为建模起点的主表格。
|
||||
用途:在多表样本中选择用于订单明细标注的表格。
|
||||
依赖:样本表格预览 DTO、Vue I18n。
|
||||
逻辑:只让用户选定服务端已发现的 table_id;缺少有效表格时禁止完成向导。
|
||||
逻辑:只让用户选定服务端已发现的 table_id;预览限制在容器内横向滚动,避免宽表撑破页面。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -10,5 +10,5 @@ const props = defineProps<{ tables: Array<{ table_id: string; page_no: number; r
|
||||
const emit = defineEmits<{ 'update:modelValue': [value: string] }>();
|
||||
const { t } = useI18n();
|
||||
</script>
|
||||
<template><div class="wizard-step"><label>{{ t('admin.shippingOrderProfiles.table') }}<select :value="modelValue" @change="emit('update:modelValue', ($event.target as HTMLSelectElement).value)"><option value="">{{ t('admin.shippingOrderProfiles.selectTable') }}</option><option v-for="table in tables" :key="table.table_id" :value="table.table_id">{{ t('admin.shippingOrderProfiles.wizard.tableOption', { page: table.page_no, rows: table.row_count, columns: table.column_count }) }}</option></select></label><p v-if="!tables.length">{{ t('admin.shippingOrderProfiles.wizard.noTable') }}</p><table v-else-if="modelValue"><tbody><tr v-for="row in tables.find((item) => item.table_id === modelValue)?.rows.slice(0, 4) || []" :key="row.join('|')"><td v-for="cell in row" :key="cell">{{ cell }}</td></tr></tbody></table></div></template>
|
||||
<style scoped>.wizard-step{display:grid;gap:1rem}.wizard-step label{display:grid;gap:.35rem;font-weight:600}.wizard-step select{padding:.6rem;border:1px solid #cbd5e1;border-radius:.4rem}table{border-collapse:collapse}td{padding:.35rem;border:1px solid #e2e8f0}p{color:#b45309}</style>
|
||||
<template><div class="wizard-step"><div><label>{{ t('admin.shippingOrderProfiles.wizard.orderLineTable') }}<select :value="modelValue" @change="emit('update:modelValue', ($event.target as HTMLSelectElement).value)"><option value="">{{ t('admin.shippingOrderProfiles.selectTable') }}</option><option v-for="table in tables" :key="table.table_id" :value="table.table_id">{{ t('admin.shippingOrderProfiles.wizard.tableOption', { page: table.page_no, rows: table.row_count, columns: table.column_count }) }}</option></select></label><p class="field-hint">{{ t('admin.shippingOrderProfiles.wizard.orderLineTableHint') }}</p></div><p v-if="!tables.length" class="warning">{{ t('admin.shippingOrderProfiles.wizard.noTable') }}</p><div v-else-if="modelValue" class="table-preview"><table><tbody><tr v-for="row in tables.find((item) => item.table_id === modelValue)?.rows.slice(0, 4) || []" :key="row.join('|')"><td v-for="cell in row" :key="cell">{{ cell }}</td></tr></tbody></table></div></div></template>
|
||||
<style scoped>.wizard-step{display:grid;min-width:0;gap:1rem}.wizard-step label{display:grid;gap:.35rem;font-weight:600}.wizard-step select{min-width:0;padding:.6rem;border:1px solid #cbd5e1;border-radius:.4rem}.field-hint{margin:.45rem 0 0;color:#64748b;font-size:.875rem}.warning{color:#b45309}.table-preview{max-width:100%;overflow-x:auto;border:1px solid #e2e8f0;border-radius:.5rem}.table-preview table{width:max-content;min-width:100%;border-collapse:collapse}.table-preview td{max-width:16rem;padding:.55rem;border:1px solid #e2e8f0;overflow-wrap:anywhere;vertical-align:top}</style>
|
||||
+93
-12
@@ -1,21 +1,102 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/components/OrderProfileSampleStep.vue
|
||||
用途:选择或上传模板样本,并显示其异步解析状态。
|
||||
依赖:模板样本 API、文件资产上传 API、Vue I18n。
|
||||
逻辑:上传只创建样本库 Intake;此步骤不创建 Profile,解析完成后才允许选择样本文档。
|
||||
用途:上传新模板样本或复用已解析样本,并自动选择上传后解析完成的文档。
|
||||
依赖:模板样本 Intake 状态 API、文件资产上传 API、Vue I18n。
|
||||
逻辑:上传后轮询同一 Intake;只有 ready 样本进入父级选择值,避免要求管理员重复选择刚上传的文件。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { computed, onBeforeUnmount, ref } from 'vue';
|
||||
import { CheckCircle2, Clock3, UploadCloud } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { uploadFileAsset } from '@/shared/api/file-assets.api';
|
||||
import { createOrderProfileSample } from '@/features/admin/api/shipping-order-document-profile.api';
|
||||
const props = defineProps<{ samples: Array<{ document_id: number; filename?: string | null; table_count: number; intake_no: string }>; modelValue: number }>();
|
||||
const emit = defineEmits<{ 'update:modelValue': [value: number]; uploaded: [] }>();
|
||||
const { t } = useI18n(); const message = useMessage(); const uploading = ref(false);
|
||||
/** 上传文件后仅投递样本解析;父级轮询并刷新可选样本列表。 */
|
||||
async function upload(event: Event): Promise<void> { const file = (event.target as HTMLInputElement).files?.[0]; if (!file) return; if (!/\.(pdf|eml)$/i.test(file.name)) { message.error(t('admin.shippingOrderProfiles.sampleFileTypeInvalid')); return; } uploading.value = true; try { const asset = await uploadFileAsset(file); await createOrderProfileSample(asset.asset_no); emit('uploaded'); } catch (error) { message.error(error instanceof BusinessError ? error.message : t('admin.shippingOrderProfiles.wizard.uploadFailed')); } finally { uploading.value = false; } }
|
||||
import { createOrderProfileSample, getOrderProfileSampleStatus } from '@/features/admin/api/shipping-order-document-profile.api';
|
||||
|
||||
type Sample = { document_id: number; filename?: string | null; table_count: number; intake_no: string };
|
||||
const props = defineProps<{ samples: Sample[]; modelValue: number }>();
|
||||
const emit = defineEmits<{ 'update:modelValue': [value: number]; uploaded: []; }>();
|
||||
const { t } = useI18n();
|
||||
const message = useMessage();
|
||||
const uploading = ref(false);
|
||||
const pendingIntake = ref<{ intakeNo: string; filename: string; state: 'parsing' | 'failed' } | null>(null);
|
||||
let pollingTimer: number | null = null;
|
||||
const selectedSample = computed(() => props.samples.find((item) => item.document_id === props.modelValue) || null);
|
||||
|
||||
/** 停止当前轮询;离开步骤或开始新上传时都不保留后台计时器。 */
|
||||
function stopPolling(): void { if (pollingTimer) window.clearTimeout(pollingTimer); pollingTimer = null; }
|
||||
/** 刷新样本列表后按 Intake 精确定位新文档,防止同名历史文件被误选。 */
|
||||
function selectUploadedSample(intakeNo: string): boolean {
|
||||
const sample = props.samples.find((item) => item.intake_no === intakeNo);
|
||||
if (!sample) return false;
|
||||
emit('update:modelValue', sample.document_id);
|
||||
pendingIntake.value = null;
|
||||
return true;
|
||||
}
|
||||
/** 查询异步解析状态,完成后请求父级刷新列表并自动选中当前上传的样本。 */
|
||||
async function pollIntake(intakeNo: string): Promise<void> {
|
||||
try {
|
||||
const result = await getOrderProfileSampleStatus(intakeNo);
|
||||
if (result.parse_status === 'parsed' && result.document_count > 0) {
|
||||
emit('uploaded');
|
||||
window.setTimeout(() => {
|
||||
if (selectUploadedSample(intakeNo)) message.success(t('admin.shippingOrderProfiles.wizard.sampleReady'));
|
||||
else pollingTimer = window.setTimeout(() => void pollIntake(intakeNo), 800);
|
||||
}, 350);
|
||||
return;
|
||||
}
|
||||
if (['failed', 'error'].includes(result.parse_status)) {
|
||||
pendingIntake.value = { intakeNo, filename: pendingIntake.value?.filename || '', state: 'failed' };
|
||||
return;
|
||||
}
|
||||
pollingTimer = window.setTimeout(() => void pollIntake(intakeNo), 1500);
|
||||
} catch {
|
||||
pollingTimer = window.setTimeout(() => void pollIntake(intakeNo), 2000);
|
||||
}
|
||||
}
|
||||
/** 上传后立即显示解析状态;此处不创建 Profile,解析成功才自动选择样本文档。 */
|
||||
async function upload(event: Event): Promise<void> {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
if (!file || uploading.value) return;
|
||||
if (!/\.(pdf|eml)$/i.test(file.name)) { message.error(t('admin.shippingOrderProfiles.sampleFileTypeInvalid')); return; }
|
||||
stopPolling();
|
||||
uploading.value = true;
|
||||
try {
|
||||
const asset = await uploadFileAsset(file);
|
||||
const intake = await createOrderProfileSample(asset.asset_no);
|
||||
pendingIntake.value = { intakeNo: intake.intake_no, filename: file.name, state: 'parsing' };
|
||||
void pollIntake(intake.intake_no);
|
||||
} catch (error) {
|
||||
message.error(error instanceof BusinessError ? error.message : t('admin.shippingOrderProfiles.wizard.uploadFailed'));
|
||||
} finally { uploading.value = false; }
|
||||
}
|
||||
onBeforeUnmount(stopPolling);
|
||||
</script>
|
||||
<template><div class="wizard-step"><label>{{ t('admin.shippingOrderProfiles.uploadSample') }}<input type="file" accept=".pdf,.eml,application/pdf,message/rfc822" :disabled="uploading" @change="upload"></label><p>{{ t('admin.shippingOrderProfiles.wizard.sampleHint') }}</p><label>{{ t('admin.shippingOrderProfiles.selectSample') }}<select :value="modelValue" @change="emit('update:modelValue', Number(($event.target as HTMLSelectElement).value))"><option :value="0">{{ t('admin.shippingOrderProfiles.selectSample') }}</option><option v-for="sample in samples" :key="sample.document_id" :value="sample.document_id">{{ sample.filename || sample.intake_no }} · {{ sample.table_count }} {{ t('admin.shippingOrderProfiles.tablesUnit') }}</option></select></label></div></template>
|
||||
<style scoped>.wizard-step{display:grid;gap:1rem;max-width:36rem}.wizard-step label{display:grid;gap:.35rem;font-weight:600}.wizard-step select{padding:.6rem;border:1px solid #cbd5e1;border-radius:.4rem}p{margin:0;color:#64748b}</style>
|
||||
|
||||
<template>
|
||||
<div class="sample-step">
|
||||
<section class="upload-panel">
|
||||
<div class="upload-panel__icon"><UploadCloud :size="22" /></div>
|
||||
<div><h3>{{ t('admin.shippingOrderProfiles.wizard.uploadNewSample') }}</h3><p>{{ t('admin.shippingOrderProfiles.wizard.uploadNewSampleHint') }}</p></div>
|
||||
<label class="upload-action"><input type="file" accept=".pdf,.eml,application/pdf,message/rfc822" :disabled="uploading" @change="upload"><span>{{ uploading ? t('admin.shippingOrderProfiles.wizard.uploading') : t('admin.shippingOrderProfiles.uploadSample') }}</span></label>
|
||||
</section>
|
||||
|
||||
<div v-if="pendingIntake" class="parse-status" :class="{ failed: pendingIntake.state === 'failed' }">
|
||||
<Clock3 v-if="pendingIntake.state === 'parsing'" :size="19" /><span v-else>!</span>
|
||||
<div><strong>{{ pendingIntake.filename }}</strong><p>{{ pendingIntake.state === 'parsing' ? t('admin.shippingOrderProfiles.wizard.sampleParsing') : t('admin.shippingOrderProfiles.wizard.sampleParseFailed') }}</p></div>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedSample" class="selected-sample"><CheckCircle2 :size="20" /><div><strong>{{ t('admin.shippingOrderProfiles.wizard.sampleSelected') }}</strong><span>{{ selectedSample.filename || selectedSample.intake_no }} · {{ selectedSample.table_count }} {{ t('admin.shippingOrderProfiles.tablesUnit') }}</span></div></div>
|
||||
|
||||
<section class="reuse-panel">
|
||||
<div class="reuse-panel__heading"><h3>{{ t('admin.shippingOrderProfiles.wizard.reuseSample') }}</h3><p>{{ t('admin.shippingOrderProfiles.wizard.reuseSampleHint') }}</p></div>
|
||||
<label class="field"><span>{{ t('admin.shippingOrderProfiles.selectSample') }}</span><select :value="modelValue" @change="emit('update:modelValue', Number(($event.target as HTMLSelectElement).value))"><option :value="0">{{ t('admin.shippingOrderProfiles.selectSample') }}</option><option v-for="sample in samples" :key="sample.document_id" :value="sample.document_id">{{ sample.filename || sample.intake_no }} · {{ sample.table_count }} {{ t('admin.shippingOrderProfiles.tablesUnit') }}</option></select></label>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.sample-step { display: grid; gap: 18px; max-width: 640px; }.upload-panel,.reuse-panel,.parse-status,.selected-sample { border: 1px solid #dce6f2; border-radius: 12px; background: #fff; }.upload-panel { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 18px; background: linear-gradient(110deg, #f6fbff, #fff); }.upload-panel__icon { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 10px; color: #1677d2; background: #e6f4ff; }.upload-panel h3,.reuse-panel h3,.parse-status p,.selected-sample span { margin: 0; }.upload-panel h3,.reuse-panel h3 { color: #263650; font-size: 1rem; }.upload-panel p,.reuse-panel p { margin: 5px 0 0; color: #71829a; font-size: .84rem; }.upload-action { display: inline-flex; min-height: 38px; align-items: center; border-radius: 8px; padding: 0 13px; color: #fff; background: #1677d2; font-weight: 700; cursor: pointer; }.upload-action input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }.parse-status,.selected-sample { display: flex; gap: 10px; align-items: center; padding: 13px 15px; color: #1677d2; background: #f7fbff; }.parse-status strong,.selected-sample strong { display: block; color: #263650; }.parse-status p,.selected-sample span { display: block; margin-top: 3px; color: #64748b; font-size: .83rem; }.parse-status.failed { color: #cf4b4b; border-color: #f0caca; background: #fff8f8; }.parse-status.failed > span { display: grid; width: 19px; height: 19px; place-items: center; border-radius: 50%; color: #fff; background: #cf4b4b; font-weight: 800; }.selected-sample { color: #0f8a65; border-color: #c6eadc; background: #f3fcf8; }.reuse-panel { padding: 18px; }.reuse-panel__heading { margin-bottom: 14px; }.field { display: grid; gap: 7px; color: #475c78; font-size: .88rem; font-weight: 700; }.field select { min-height: 44px; border: 1px solid #ccd8e6; border-radius: 9px; padding: 0 12px; color: #263650; background: #fff; font: inherit; }.field select:focus { outline: 3px solid rgb(22 119 210 / .13); border-color: #1677d2; } @media (max-width: 640px) { .upload-panel { grid-template-columns: auto 1fr; }.upload-action { grid-column: 1 / -1; justify-content: center; } }
|
||||
</style>
|
||||
Reference in new issue
Block a user