feat(freight-rpa): 支持从来源站点复制为未保存草稿
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
31434f8424
commit
95e7db0831
8 files changed
+426
-16
No files matched your search
+1
-1
@@ -201,7 +201,7 @@
|
||||
| 人工复核与字段证据闭环(阶段 5) | 已实现 | 单头、订单行、冲突解决均要求乐观锁、原因和结构化 `document_cell`/`manual_input` 证据;跨订单或伪造证据在写值前拒绝,复核审计保存结构化证据且详情页展示页码、表格、单元格与原文 |
|
||||
| 原 PDF 双层重解析 | 已实现 | “重新识别此 PDF”仅为当前原始文件创建后继 Run;“重新解析本批次”逐 PDF 创建独立子 Run、局部成功替换,按完整 Run 谱系选择每个原文件的当前 Case;已确认/履约文件排除;不支持上传替代 PDF。 |
|
||||
| 多订单 Candidate 判重与自动建批 | 已实现 | Candidate 身份/内容双指纹;高置信 SKU+Qty 订单自动建 Task,低置信/冲突/修订保留待处理;部分消费 Intake 不丢剩余订单;缺 Reservation/Source Type/Hub Code 的 Task 停在自然对话补字段门禁 |
|
||||
| 库存 RPA 源配置 | 已实现 | 源、报表路径与查询参数维护在数据库 `freight_rpa_sources`(管理端货代 RPA 页);期初 YAML 已于 2026-10-20 删除,运行时只读数据库 |
|
||||
| 库存 RPA 源配置 | 已实现 | 源、报表路径与查询参数维护在数据库 `freight_rpa_sources`(管理端货代 RPA 页);期初 YAML 已于 2026-10-20 删除,运行时只读数据库。来源站点可复制为未保存草稿(连接、模板、仓库解析、库存/入站/出站报表),保存后保持停用;不复制快照、仓库映射、路由规则与测试结果。 |
|
||||
| 订单解析阶段库存源判定 | 已实现 | `parse_notice` 内 adjudicate 写线索;低置信度先 `parse_review`,解析通过后再 `inventory_source_review`;稳定态 `resolved`/`user_confirmed` |
|
||||
| 文件解析阶段问题清单 | 已实现 | 步骤 2 工作台/`ui_state.summary.issues` 一次列出解析复核、RSV、库存源门禁与 parse warnings |
|
||||
| 发货通知关键字段真值校验 | 已实现 | LLM 出候选、后端裁决;支持多模板 Reservation 别名,拒绝 32 位 hex/UUID;仅按 TSV 列关系与唯一 SKU/APN/MPN 证据纠错;`parse_validation` 留痕,blocking issue 在解析确认和库存匹配前双重阻断 |
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<!--
|
||||
features/admin/modules/freight-rpa/FreightRpaPage.vue
|
||||
用途:货代来源站点管理工作台,维护解析方案、连接、站点、入站/出站报表配置、模板与运行审计。
|
||||
依赖:element-plus(抽屉/弹窗/表单控件/标签/空态,沿用管理端 element-trial 主题)、
|
||||
依赖:element-plus(抽屉/弹窗/表单控件/标签/提示/空态,沿用管理端 element-trial 主题)、
|
||||
admin.api、inboundReportConfigForm、outboundReportConfigForm、parsingProfileListGroups、
|
||||
Vue Router、Vue Composition API、Vue I18n。
|
||||
逻辑:由 AdminLayout 统一业务目录选择工作区;section 深链与当前工作区双向同步。
|
||||
来源站点详情三块折叠——库存报表|入站报表|出站报表;入站/出站走独立 get/save API。
|
||||
复制新增只预填未保存草稿(sourceCloneDraft),保存后新站点保持停用。卡片入口是右上角复制图标,抽屉底栏保留文字按钮。
|
||||
报表规则列表按用途分段(库存→入站→出站),组内按 profile_code / version 排序。
|
||||
视觉层已迁移 Element Plus(element-trial 主题),间距由 AdminLayout 壳层持有。
|
||||
-->
|
||||
@@ -96,18 +97,28 @@
|
||||
</section>
|
||||
</div>
|
||||
<div v-else class="object-list">
|
||||
<button
|
||||
<article
|
||||
v-for="item in currentItems"
|
||||
:key="String(item.id)"
|
||||
type="button"
|
||||
class="object-row"
|
||||
class="object-row object-row-split"
|
||||
:class="{ selected: selectedId === Number(item.id) }"
|
||||
@click="selectItem(item)"
|
||||
>
|
||||
<span class="row-primary">{{ rowTitle(item) }}</span>
|
||||
<span class="row-secondary">{{ rowMeta(item) }}</span>
|
||||
<span class="status-dot" :class="item.enabled === false || item.status === 'retired' ? 'off' : 'on'"></span>
|
||||
</button>
|
||||
<button type="button" class="object-row-main" @click="selectItem(item)">
|
||||
<span class="row-primary">{{ rowTitle(item) }}</span>
|
||||
<span class="row-secondary">{{ rowMeta(item) }}</span>
|
||||
<span class="status-dot" :class="item.enabled === false || item.status === 'retired' ? 'off' : 'on'"></span>
|
||||
</button>
|
||||
<el-tooltip v-if="activeTab === 'sources'" :content="t('admin.freightRpa.cloneSource')" placement="top">
|
||||
<el-button
|
||||
class="object-row-copy"
|
||||
text
|
||||
:icon="CopyDocument"
|
||||
:aria-label="t('admin.freightRpa.cloneSourceAria', { name: rowTitle(item) })"
|
||||
:data-testid="`clone-source-${item.id}`"
|
||||
@click="duplicateSource(item)"
|
||||
/>
|
||||
</el-tooltip>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<el-drawer
|
||||
@@ -157,7 +168,15 @@
|
||||
</template>
|
||||
|
||||
<template v-else-if="activeTab === 'sources'">
|
||||
<label><span>{{ t('admin.freightRpa.sourceCode') }}</span><el-input v-model="source.source_code" required /></label>
|
||||
<el-alert
|
||||
v-if="sourceCloneFrom && !selectedId"
|
||||
class="full"
|
||||
type="info"
|
||||
:closable="false"
|
||||
:title="t('admin.freightRpa.cloneSourceBanner', { code: sourceCloneFrom.source_code, name: sourceCloneFrom.display_name })"
|
||||
data-testid="clone-source-banner"
|
||||
/>
|
||||
<label><span>{{ t('admin.freightRpa.sourceCode') }}</span><el-input ref="sourceCodeInputRef" v-model="source.source_code" required data-testid="source-code-input" /></label>
|
||||
<label><span>{{ t('admin.freightRpa.inventorySiteName') }}</span><el-input v-model="source.display_name" required /></label>
|
||||
<label><span>{{ t('admin.freightRpa.connectorType') }}</span><el-select v-model="source.connector_type"><el-option value="dbs" :label="t('admin.freightRpa.platform.dbs')" /><el-option value="crane" :label="t('admin.freightRpa.platform.crane')" /></el-select></label>
|
||||
<label><span>{{ t('admin.freightRpa.connection') }}</span><el-select v-model="source.rpa_profile_id"><el-option :value="0" :label="t('admin.freightRpa.chooseConnection')" /><el-option v-for="item in compatibleProfiles" :key="String(item.id)" :value="Number(item.id)" :label="item.display_name || item.profile_code" /></el-select></label>
|
||||
@@ -193,7 +212,7 @@
|
||||
<label class="full"><span>{{ t('admin.freightRpa.parsingProfiles') }}</span><el-select v-model="source.onhand_report_config.parsing_profile_id"><el-option :value="0" :label="t('admin.freightRpa.notConfigured')" /><el-option v-for="item in parsingProfiles.filter((row) => row.status === 'published' && row.purpose === 'onhand')" :key="String(item.id)" :value="Number(item.id)" :label="`${item.display_name || item.profile_code} V${item.version}`" /></el-select></label>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="selectedId" class="path-card inbound full" :class="{ configured: inboundConfigExists }">
|
||||
<section v-if="selectedId || inboundConfigExists" class="path-card inbound full" :class="{ configured: inboundConfigExists }">
|
||||
<button type="button" class="path-card-header" :aria-expanded="inboundSectionOpen" @click="toggleInboundSection">
|
||||
<span class="path-card-title"><b>{{ t('admin.freightRpa.inboundReportConfig') }}</b></span>
|
||||
<el-tag class="path-badge" :type="inboundConfigExists ? 'success' : 'info'" size="small">{{ inboundConfigExists ? t('admin.freightRpa.pathSectionConfigured') : t('admin.freightRpa.pathSectionNotConfigured') }}</el-tag>
|
||||
@@ -219,7 +238,7 @@
|
||||
<label class="full"><span>{{ t('admin.freightRpa.movementBindingLabel') }}</span><el-select v-model="inboundConfig.parsing_profile_id"><el-option :value="null as unknown as string" :label="t('admin.freightRpa.movementBindingNone')" /><el-option v-for="item in parsingProfiles.filter((row) => row.status === 'published' && row.purpose === 'inbound')" :key="`movement-bind-${item.id}`" :value="Number(item.id)" :label="`${item.display_name || item.profile_code} V${item.version}`" /></el-select></label>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="selectedId" class="path-card outbound full" :class="{ configured: outboundConfigExists }">
|
||||
<section v-if="selectedId || outboundConfigExists" class="path-card outbound full" :class="{ configured: outboundConfigExists }">
|
||||
<button type="button" class="path-card-header" :aria-expanded="outboundSectionOpen" @click="toggleOutboundSection">
|
||||
<span class="path-card-title"><b>{{ t('admin.freightRpa.outboundReportConfig') }}</b></span>
|
||||
<el-tag class="path-badge" :type="outboundConfigExists ? 'success' : 'info'" size="small">{{ outboundConfigExists ? t('admin.freightRpa.pathSectionConfigured') : t('admin.freightRpa.pathSectionNotConfigured') }}</el-tag>
|
||||
@@ -455,6 +474,7 @@
|
||||
<el-button v-if="activeTab === 'rules' && selectedId && selectedRuleStatus === 'published'" size="small" @click="retireCurrentRule">{{ t('admin.freightRpa.retire') }}</el-button>
|
||||
<el-button v-if="activeTab === 'templates' && selectedId && selectedTemplateStatus === 'draft'" size="small" @click="publishCurrentTemplate">{{ t('admin.freightRpa.publishTemplate') }}</el-button>
|
||||
<el-button v-if="activeTab === 'templates' && selectedId && selectedTemplateStatus !== 'draft'" size="small" @click="createTemplateVersion">{{ t('admin.freightRpa.createTemplateVersion') }}</el-button>
|
||||
<el-button v-if="activeTab === 'sources' && selectedId" size="small" data-testid="clone-source-drawer" @click="duplicateSourceFromDrawer">{{ t('admin.freightRpa.cloneSource') }}</el-button>
|
||||
<el-button v-if="activeTab === 'templates' && selectedId" size="small" @click="openTemplateCloneDialog">{{ t('admin.freightRpa.cloneTemplate') }}</el-button>
|
||||
<el-button v-if="activeTab === 'templates' && selectedId && selectedTemplateStatus === 'published'" type="danger" plain size="small" class="retire-template-action" @click="retireCurrentTemplate">{{ t('admin.freightRpa.retireTemplate') }}</el-button>
|
||||
<el-button v-if="activeTab === 'parsing' && selectedId && selectedParsingStatus === 'draft'" size="small" @click="publishCurrentParsingProfile">{{ t('admin.freightRpa.publishProfile') }}</el-button>
|
||||
@@ -581,8 +601,9 @@ import {
|
||||
ElSelect,
|
||||
ElSwitch,
|
||||
ElTag,
|
||||
ElTooltip,
|
||||
} from 'element-plus';
|
||||
import { Plus, Search } from '@element-plus/icons-vue';
|
||||
import { CopyDocument, Plus, Search } from '@element-plus/icons-vue';
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||
import '@/features/admin/styles/element-trial.css';
|
||||
@@ -642,6 +663,7 @@ import {
|
||||
} from '@/features/admin/api/admin.api';
|
||||
import type { ShippingOnhandReadinessCheck, ShippingOnhandValidationBatch } from '@/features/admin/api/admin.api';
|
||||
import { normaliseInventoryReportPath } from './shippingOnhandSourceForm';
|
||||
import { buildSourceCloneDraft, type SourceCloneDraft, type SourceCloneReportConfig } from './sourceCloneDraft';
|
||||
import { buildInboundReportConfigPayload } from './inboundReportConfigForm';
|
||||
import { buildOutboundReportConfigPayload } from './outboundReportConfigForm';
|
||||
import { buildMovementFieldMapping } from './movementParsingProfileForm';
|
||||
@@ -663,6 +685,8 @@ const router = useRouter();
|
||||
const message = useMessage();
|
||||
const activeTab = ref<TabKey>('parsing');
|
||||
const selectedId = ref<number | null>(null);
|
||||
const sourceCloneFrom = ref<{ source_code: string; display_name: string } | null>(null);
|
||||
const sourceCodeInputRef = ref<InstanceType<typeof ElInput> | null>(null);
|
||||
const drawerOpen = ref(false);
|
||||
const orderSchemaPublished = ref(false);
|
||||
const saving = ref(false);
|
||||
@@ -1123,6 +1147,7 @@ function selectInventoryMappingTab(tab: 'parsing' | 'inventoryFields'): void {
|
||||
/** 重置当前工作区的编辑表单,作为创建新对象的入口。 */
|
||||
function createNew(): void {
|
||||
selectedId.value = null;
|
||||
sourceCloneFrom.value = null;
|
||||
if (activeTab.value === 'profiles') Object.assign(profile, { profile_code: '', display_name: '', connector_type: 'dbs', login_url: '', username: '', password: '', login_config_json: { auth_mode: 'password' }, enabled: true, upload_config_json: defaultUploadConfig('dbs') });
|
||||
if (activeTab.value === 'parsing') { Object.assign(parsing, { profile_code: '', display_name: '', file_format: 'xlsx', sheet_name: '', header_row_index: 1, purpose: 'onhand', field_mappings: [], match_keys: [], movement_mappings: [] }); structureAnalysis.value = null; pendingSampleReplacement.value = null; sampleReplacementConfirmed.value = false; selectedTemporaryInventorySession.value = ''; }
|
||||
if (activeTab.value === 'inventoryFields') Object.assign(inventoryField, { display_name: '', description: '', value_type: 'text', usage_type: 'general', sort_order: 100, status: 'active' });
|
||||
@@ -1154,6 +1179,7 @@ function createNew(): void {
|
||||
/** 将列表对象复制到当前编辑表单,凭据字段永远不从列表回填。 */
|
||||
function selectItem(item: Item): void {
|
||||
selectedId.value = Number(item.id);
|
||||
sourceCloneFrom.value = null;
|
||||
if (activeTab.value === 'profiles') Object.assign(profile, { ...item, username: '', password: '', login_config_json: item.login_config_json || { auth_mode: 'password' }, upload_config_json: item.upload_config_json || defaultUploadConfig(item.connector_type) });
|
||||
if (activeTab.value === 'parsing') Object.assign(parsing, {
|
||||
profile_code: item.profile_code, display_name: item.display_name, file_format: item.file_format,
|
||||
@@ -1321,10 +1347,159 @@ function closeDrawer(): void {
|
||||
resetReceiptConfig(source.connector_type);
|
||||
resetOutboundConfig(source.connector_type);
|
||||
sourceBaseline.value = '';
|
||||
sourceCloneFrom.value = null;
|
||||
drawerOpen.value = false;
|
||||
selectedId.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把接口里的入站或出站配置整理成复制草稿能接受的形状。
|
||||
* 核心逻辑:Crane 固定报表名,与抽屉读取逻辑一致;没有配置时返回 null。
|
||||
* @param config - 入站或出站 GET 返回;不存在时为 null。
|
||||
* @param connectorType - 货代类型,决定路径默认值。
|
||||
* @param kind - inbound 或 outbound。
|
||||
* @returns 深拷贝前的报表配置,或 null。
|
||||
*/
|
||||
function movementConfigFromApi(config: Record<string, unknown> | null, connectorType: string, kind: 'inbound' | 'outbound'): SourceCloneReportConfig | null {
|
||||
if (!config) return null;
|
||||
const isCrane = connectorType.toLowerCase() === 'crane';
|
||||
const defaults: Record<string, string> = kind === 'inbound'
|
||||
? (isCrane ? { report_name: 'Inbound Details' } : { program_group: '', program_label: '', report_group: 'Inbound', report_name: '' })
|
||||
: (isCrane ? { report_name: 'Outbound Details' } : { program_group: '', program_label: '', report_group: 'Outbound', report_name: '' });
|
||||
const storedPath = (config.report_path_json || {}) as Record<string, string>;
|
||||
const parameters = Array.isArray(config.query_parameters_json) ? config.query_parameters_json as Parameter[] : [];
|
||||
return {
|
||||
report_path_json: isCrane ? defaults : { ...defaults, ...storedPath },
|
||||
query_parameters_json: parameters.map((parameter) => ({ ...parameter, values: [...(parameter.values || [])] })),
|
||||
parsing_profile_id: config.parsing_profile_id ? Number(config.parsing_profile_id) : null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 把复制草稿写入新建表单,并在有入站或出站时展开对应卡片。
|
||||
* 核心逻辑:selectedId 保持为空,保存前不落库;已有报表配置标记为待写入,避免空配置被创建。
|
||||
* @param draft - buildSourceCloneDraft 的返回值。
|
||||
*/
|
||||
function applySourceCloneDraft(draft: SourceCloneDraft): void {
|
||||
// [STEP 1] 站点头部与库存报表进入新建表单,启用检查不继承来源站点。
|
||||
selectedId.value = null;
|
||||
Object.assign(source, {
|
||||
source_code: draft.source_code,
|
||||
display_name: draft.display_name,
|
||||
connector_type: draft.connector_type,
|
||||
rpa_profile_id: draft.rpa_profile_id,
|
||||
excel_template_id: draft.excel_template_id,
|
||||
warehouse_resolution_mode: draft.warehouse_resolution_mode,
|
||||
fixed_warehouse_id: draft.fixed_warehouse_id,
|
||||
snapshot_ttl_seconds: draft.snapshot_ttl_seconds,
|
||||
onhand_report_config: draft.onhand_report_config,
|
||||
enabled: false,
|
||||
activation: { ready: false, checks: [], missing_requirements: ['parsing_profile', 'excel_template'] },
|
||||
});
|
||||
// [STEP 2] 仅当来源站点已有入站或出站时预填,并标记为保存时必须写入。
|
||||
if (draft.inbound_report_config) {
|
||||
Object.assign(inboundConfig, draft.inbound_report_config);
|
||||
inboundConfigExists.value = true;
|
||||
inboundSectionTouched.value = true;
|
||||
inboundSectionOpen.value = true;
|
||||
inboundBaseline.value = serialiseInboundInput();
|
||||
} else {
|
||||
resetReceiptConfig(draft.connector_type);
|
||||
inboundConfigExists.value = false;
|
||||
inboundSectionTouched.value = false;
|
||||
inboundSectionOpen.value = false;
|
||||
inboundBaseline.value = '';
|
||||
}
|
||||
if (draft.outbound_report_config) {
|
||||
Object.assign(outboundConfig, draft.outbound_report_config);
|
||||
outboundConfigExists.value = true;
|
||||
outboundSectionTouched.value = true;
|
||||
outboundSectionOpen.value = true;
|
||||
outboundBaseline.value = serialiseOutboundInput();
|
||||
} else {
|
||||
resetOutboundConfig(draft.connector_type);
|
||||
outboundConfigExists.value = false;
|
||||
outboundSectionTouched.value = false;
|
||||
outboundSectionOpen.value = false;
|
||||
outboundBaseline.value = '';
|
||||
}
|
||||
sourceCloneFrom.value = draft.clone_from;
|
||||
inventoryPathOpen.value = true;
|
||||
sourceBaseline.value = '';
|
||||
drawerOpen.value = true;
|
||||
void nextTick(() => sourceCodeInputRef.value?.focus());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从卡片复制来源站点。先读取独立的入站和出站配置,再打开未保存草稿。
|
||||
* @param item - 列表中的来源站点。
|
||||
*/
|
||||
async function duplicateSource(item: Item): Promise<void> {
|
||||
const sourceId = Number(item.id);
|
||||
const connectorType = String(item.connector_type || '');
|
||||
try {
|
||||
const [inbound, outbound] = await Promise.all([
|
||||
getInboundReportConfig(sourceId),
|
||||
getOutboundReportConfig(sourceId),
|
||||
]);
|
||||
const itemConfig = (item.onhand_report_config || {}) as { report_path_json?: Record<string, string>; query_parameters_json?: Parameter[]; parsing_profile_id?: number | string };
|
||||
const reportPath = connectorType === 'dbs'
|
||||
? { program_group: '', program_label: '', report_group: 'Inventory', report_name: '', ...(itemConfig.report_path_json || {}) }
|
||||
: (itemConfig.report_path_json || {});
|
||||
applySourceCloneDraft(buildSourceCloneDraft({
|
||||
source_code: String(item.source_code || ''),
|
||||
display_name: String(item.display_name || ''),
|
||||
connector_type: connectorType,
|
||||
rpa_profile_id: Number(item.rpa_profile_id) || 0,
|
||||
excel_template_id: Number(item.excel_template_id) || 0,
|
||||
warehouse_resolution_mode: String(item.warehouse_resolution_mode || 'fixed'),
|
||||
fixed_warehouse_id: String(item.fixed_warehouse_id || ''),
|
||||
snapshot_ttl_seconds: Number(item.snapshot_ttl_seconds) || 86400,
|
||||
onhand_report_config: {
|
||||
report_path_json: normaliseInventoryReportPath(connectorType, reportPath) as Record<string, string>,
|
||||
query_parameters_json: (itemConfig.query_parameters_json || []).map((parameter) => ({ ...parameter, values: [...(parameter.values || [])] })),
|
||||
parsing_profile_id: itemConfig.parsing_profile_id ? Number(itemConfig.parsing_profile_id) : 0,
|
||||
},
|
||||
inbound_report_config: movementConfigFromApi(inbound, connectorType, 'inbound'),
|
||||
outbound_report_config: movementConfigFromApi(outbound, connectorType, 'outbound'),
|
||||
}, t('admin.freightRpa.copySuffix')));
|
||||
} catch (cause) {
|
||||
showError(cause, 'loadFailed');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从已打开的站点抽屉复制当前表单,包含尚未保存的入站和出站修改。
|
||||
*/
|
||||
function duplicateSourceFromDrawer(): void {
|
||||
if (activeTab.value !== 'sources' || !selectedId.value) return;
|
||||
applySourceCloneDraft(buildSourceCloneDraft({
|
||||
source_code: source.source_code,
|
||||
display_name: source.display_name,
|
||||
connector_type: source.connector_type,
|
||||
rpa_profile_id: Number(source.rpa_profile_id) || 0,
|
||||
excel_template_id: Number(source.excel_template_id) || 0,
|
||||
warehouse_resolution_mode: source.warehouse_resolution_mode,
|
||||
fixed_warehouse_id: source.fixed_warehouse_id || '',
|
||||
snapshot_ttl_seconds: Number(source.snapshot_ttl_seconds) || 86400,
|
||||
onhand_report_config: {
|
||||
report_path_json: { ...source.onhand_report_config.report_path_json },
|
||||
query_parameters_json: source.onhand_report_config.query_parameters_json.map((parameter) => ({ ...parameter, values: [...parameter.values] })),
|
||||
parsing_profile_id: Number(source.onhand_report_config.parsing_profile_id) || 0,
|
||||
},
|
||||
inbound_report_config: inboundConfigExists.value ? {
|
||||
report_path_json: { ...inboundConfig.report_path_json },
|
||||
query_parameters_json: inboundConfig.query_parameters_json.map((parameter) => ({ ...parameter, values: [...parameter.values] })),
|
||||
parsing_profile_id: inboundConfig.parsing_profile_id ? Number(inboundConfig.parsing_profile_id) : null,
|
||||
} : null,
|
||||
outbound_report_config: outboundConfigExists.value ? {
|
||||
report_path_json: { ...outboundConfig.report_path_json },
|
||||
query_parameters_json: outboundConfig.query_parameters_json.map((parameter) => ({ ...parameter, values: [...parameter.values] })),
|
||||
parsing_profile_id: outboundConfig.parsing_profile_id ? Number(outboundConfig.parsing_profile_id) : null,
|
||||
} : null,
|
||||
}, t('admin.freightRpa.copySuffix')));
|
||||
}
|
||||
|
||||
/** 按当前对象类型调用对应 API,成功后重新加载服务端真相。 */
|
||||
async function saveCurrent(): Promise<void> {
|
||||
saving.value = true;
|
||||
@@ -1383,11 +1558,18 @@ async function saveCurrent(): Promise<void> {
|
||||
}
|
||||
if (activeTab.value === 'sources') {
|
||||
// s18 起在手报表配置随站点载荷内嵌 onhand_report_config 提交(服务端写配置行),站点头部只存基础字段。
|
||||
await saveShippingOnhandSource({ ...source, enabled: false, fixed_warehouse_id: source.warehouse_resolution_mode === 'fixed' ? source.fixed_warehouse_id : null, onhand_report_config: {
|
||||
const savedSource = await saveShippingOnhandSource({ ...source, enabled: false, fixed_warehouse_id: source.warehouse_resolution_mode === 'fixed' ? source.fixed_warehouse_id : null, onhand_report_config: {
|
||||
report_path_json: normaliseInventoryReportPath(source.connector_type, source.onhand_report_config.report_path_json),
|
||||
query_parameters_json: source.onhand_report_config.query_parameters_json,
|
||||
parsing_profile_id: source.onhand_report_config.parsing_profile_id,
|
||||
} }, selectedId.value || undefined);
|
||||
} }, selectedId.value || undefined) as Item;
|
||||
// 复制草稿首次保存后立刻记下新主键,入站或出站失败时重试走更新,避免再插入一条站点。
|
||||
if (!selectedId.value) {
|
||||
const createdId = Number(savedSource?.id);
|
||||
if (!createdId) throw new Error(t('admin.freightRpa.saveFailed'));
|
||||
selectedId.value = createdId;
|
||||
sourceCloneFrom.value = null;
|
||||
}
|
||||
// 入站与站点同批保存:仅当已有配置或管理员展开过入站卡时才提交,避免未配置站点被误建空入站配置。
|
||||
if (selectedId.value && (inboundSectionTouched.value || (inboundConfigExists.value && inboundBaseline.value !== serialiseInboundInput()))) {
|
||||
try {
|
||||
@@ -1916,6 +2098,14 @@ onMounted(load);
|
||||
.object-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
|
||||
.object-empty { grid-column: 1 / -1; }
|
||||
.object-row { position: relative; display: flex; width: 100%; min-height: 72px; flex-direction: column; justify-content: center; gap: 4px; border: 1px solid var(--el-border-color-light); border-radius: 8px; background: var(--el-bg-color); padding: 12px 30px 12px 13px; text-align: left; cursor: pointer; }
|
||||
.object-row-split { height: 100%; justify-content: flex-start; padding: 0; cursor: default; }
|
||||
.object-row-main { display: flex; width: 100%; flex: 1 1 auto; min-height: 72px; flex-direction: column; justify-content: center; gap: 4px; border: 0; background: transparent; padding: 12px 30px 12px 13px; text-align: left; cursor: pointer; color: inherit; font: inherit; }
|
||||
.object-row-split:has(.object-row-copy) .object-row-main { padding-right: 62px; }
|
||||
.object-row-main:focus-visible { outline: 2px solid var(--el-color-primary); outline-offset: -2px; }
|
||||
/* 复制图标贴在状态点左侧。平时保持可见但较淡,悬停或键盘聚焦时再加深,避免底栏把卡片垫高。 */
|
||||
.object-row-copy { position: absolute; top: 6px; right: 28px; width: 28px; min-width: 28px; height: 28px; margin: 0; padding: 0; opacity: 0.45; --el-button-text-color: var(--el-text-color-secondary); }
|
||||
.object-row:hover .object-row-copy,
|
||||
.object-row-copy:focus-visible { opacity: 1; --el-button-text-color: var(--el-color-primary); }
|
||||
.object-row:hover { border-color: var(--el-color-primary-light-5); background: var(--el-color-primary-light-9); }
|
||||
.object-row.selected { border-color: var(--el-color-primary-light-7); background: var(--el-color-primary-light-9); }
|
||||
.row-primary { color: var(--el-text-color-regular); font-size: 13px; font-weight: 600; }
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* features/admin/modules/freight-rpa/sourceCloneDraft.spec.ts
|
||||
* 用途:锁定来源站点复制草稿的字段边界。
|
||||
* 依赖:sourceCloneDraft、vitest。
|
||||
* 逻辑:复制必须清空唯一编号、强制停用,并深拷贝查询条件;没有的入站或出站不得变成空配置。
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildSourceCloneDraft, type SourceCloneInput } from './sourceCloneDraft';
|
||||
|
||||
function sourceInput(overrides: Partial<SourceCloneInput> = {}): SourceCloneInput {
|
||||
return {
|
||||
source_code: 'BYAWSATL01',
|
||||
display_name: 'DSV 360 / Bison / AWSBI',
|
||||
connector_type: 'dbs',
|
||||
rpa_profile_id: 7,
|
||||
excel_template_id: 3,
|
||||
warehouse_resolution_mode: 'fixed',
|
||||
fixed_warehouse_id: 'WH-ATL',
|
||||
snapshot_ttl_seconds: 86400,
|
||||
onhand_report_config: {
|
||||
report_path_json: { program_group: 'Bison', program_label: 'AWSBI', report_group: 'Inventory', report_name: 'On Hand' },
|
||||
query_parameters_json: [{ name: 'Site', mode: 'single', values: ['ATL'], required: true, select_all: false }],
|
||||
parsing_profile_id: 11,
|
||||
},
|
||||
inbound_report_config: {
|
||||
report_path_json: { program_group: 'Bison', program_label: 'AWSBI', report_group: 'Inbound', report_name: 'Receipt' },
|
||||
query_parameters_json: [{ name: 'Warehouse', mode: 'multi_text', values: ['ATL'], required: false, select_all: false }],
|
||||
parsing_profile_id: 21,
|
||||
},
|
||||
outbound_report_config: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe('buildSourceCloneDraft', () => {
|
||||
it('clears the unique code, suffixes the name, and forces the draft to stay disabled', () => {
|
||||
// 关键断言:编号必须由管理员重填,名称带副本后缀,且不能继承已启用状态。
|
||||
const draft = buildSourceCloneDraft(sourceInput(), '副本');
|
||||
|
||||
expect(draft.source_code).toBe('');
|
||||
expect(draft.display_name).toBe('DSV 360 / Bison / AWSBI 副本');
|
||||
expect(draft.enabled).toBe(false);
|
||||
expect(draft.clone_from).toEqual({ source_code: 'BYAWSATL01', display_name: 'DSV 360 / Bison / AWSBI' });
|
||||
expect(draft.rpa_profile_id).toBe(7);
|
||||
expect(draft.excel_template_id).toBe(3);
|
||||
expect(draft.fixed_warehouse_id).toBe('WH-ATL');
|
||||
expect(draft.onhand_report_config.parsing_profile_id).toBe(11);
|
||||
expect(draft.onhand_report_config.report_path_json.report_name).toBe('On Hand');
|
||||
});
|
||||
|
||||
it('deep-copies query values so editing the draft does not change the source', () => {
|
||||
const input = sourceInput();
|
||||
const draft = buildSourceCloneDraft(input, '副本');
|
||||
|
||||
draft.onhand_report_config.query_parameters_json[0].values.push('FRA');
|
||||
draft.inbound_report_config?.query_parameters_json[0].values.push('FRA');
|
||||
|
||||
// 关键断言:来源卡片上的条件数组保持原值,草稿修改不得回写。
|
||||
expect(input.onhand_report_config.query_parameters_json[0].values).toEqual(['ATL']);
|
||||
expect(input.inbound_report_config?.query_parameters_json[0].values).toEqual(['ATL']);
|
||||
});
|
||||
|
||||
it('omits inbound and outbound configs that the source does not have', () => {
|
||||
const draft = buildSourceCloneDraft(sourceInput({ inbound_report_config: null, outbound_report_config: null }), 'Copy');
|
||||
|
||||
// 关键断言:缺失的报表配置保持 null,保存时才不会建出空的入站或出站行。
|
||||
expect(draft.inbound_report_config).toBeNull();
|
||||
expect(draft.outbound_report_config).toBeNull();
|
||||
expect(draft.display_name).toBe('DSV 360 / Bison / AWSBI Copy');
|
||||
});
|
||||
|
||||
it('does not carry identity, activation, or unrelated records', () => {
|
||||
const draft = buildSourceCloneDraft({
|
||||
...sourceInput(),
|
||||
id: 99,
|
||||
enabled: true,
|
||||
activation: { ready: true, checks: [{ code: 'configuration_test' }] },
|
||||
external_mappings: [{ external_warehouse_code: 'SHOULD-NOT-COPY' }],
|
||||
} as SourceCloneInput & Record<string, unknown>, '副本');
|
||||
|
||||
// 关键断言:主键、启用检查、仓库映射不属于可复制配置。
|
||||
expect(draft).not.toHaveProperty('id');
|
||||
expect(draft).not.toHaveProperty('activation');
|
||||
expect(draft).not.toHaveProperty('external_mappings');
|
||||
expect(draft.enabled).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* features/admin/modules/freight-rpa/sourceCloneDraft.ts
|
||||
* 用途:把已有来源站点配置变成一份尚未落库的新建草稿。
|
||||
* 依赖:无。
|
||||
* 逻辑:FreightRpaPage 在卡片或抽屉点击「复制新增」时调用;保存仍走既有新建接口。
|
||||
*/
|
||||
|
||||
export type SourceCloneParameter = {
|
||||
name: string;
|
||||
mode: string;
|
||||
values: string[];
|
||||
required: boolean;
|
||||
select_all: boolean;
|
||||
joiner?: string;
|
||||
};
|
||||
|
||||
export type SourceCloneReportConfig = {
|
||||
report_path_json: Record<string, string>;
|
||||
query_parameters_json: SourceCloneParameter[];
|
||||
parsing_profile_id: number | null;
|
||||
};
|
||||
|
||||
export type SourceCloneInput = {
|
||||
source_code: string;
|
||||
display_name: string;
|
||||
connector_type: string;
|
||||
rpa_profile_id: number;
|
||||
excel_template_id: number;
|
||||
warehouse_resolution_mode: string;
|
||||
fixed_warehouse_id: string;
|
||||
snapshot_ttl_seconds: number;
|
||||
onhand_report_config: {
|
||||
report_path_json: Record<string, string>;
|
||||
query_parameters_json: SourceCloneParameter[];
|
||||
parsing_profile_id: number;
|
||||
};
|
||||
inbound_report_config: SourceCloneReportConfig | null;
|
||||
outbound_report_config: SourceCloneReportConfig | null;
|
||||
};
|
||||
|
||||
export type SourceCloneDraft = {
|
||||
source_code: '';
|
||||
display_name: string;
|
||||
connector_type: string;
|
||||
rpa_profile_id: number;
|
||||
excel_template_id: number;
|
||||
warehouse_resolution_mode: string;
|
||||
fixed_warehouse_id: string;
|
||||
snapshot_ttl_seconds: number;
|
||||
enabled: false;
|
||||
onhand_report_config: {
|
||||
report_path_json: Record<string, string>;
|
||||
query_parameters_json: SourceCloneParameter[];
|
||||
parsing_profile_id: number;
|
||||
};
|
||||
inbound_report_config: SourceCloneReportConfig | null;
|
||||
outbound_report_config: SourceCloneReportConfig | null;
|
||||
clone_from: { source_code: string; display_name: string };
|
||||
};
|
||||
|
||||
/**
|
||||
* 深拷贝查询条件,避免草稿里改值时回写到来源对象。
|
||||
* @param parameters - 来源站点上的查询条件。
|
||||
* @returns 条件与取值都是新数组的副本。
|
||||
*/
|
||||
function cloneParameters(parameters: SourceCloneParameter[] | undefined): SourceCloneParameter[] {
|
||||
return (parameters || []).map((parameter) => ({
|
||||
...parameter,
|
||||
values: [...(parameter.values || [])],
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制一份报表配置;没有配置时返回 null,避免保存时建出空的入站或出站行。
|
||||
* @param config - 已有报表配置;空表示该站点没有这块配置。
|
||||
* @returns 深拷贝后的配置,或 null。
|
||||
*/
|
||||
function cloneReport(config: SourceCloneReportConfig | null | undefined): SourceCloneReportConfig | null {
|
||||
if (!config) return null;
|
||||
return {
|
||||
report_path_json: { ...(config.report_path_json || {}) },
|
||||
query_parameters_json: cloneParameters(config.query_parameters_json),
|
||||
parsing_profile_id: config.parsing_profile_id ? Number(config.parsing_profile_id) : null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从来源站点生成未保存草稿。
|
||||
* 核心逻辑:配置字段逐项深拷贝;库存源编号清空;名称追加副本后缀;启用状态固定为停用。
|
||||
* 不复制主键、启用检查、快照、仓库映射和路由规则。
|
||||
* @param input - 来源站点当前可见配置,入站或出站没有配置时传 null。
|
||||
* @param copySuffix - 追加在名称后的本地化后缀,例如「副本」。
|
||||
* @returns 可直接填入新建表单的草稿,source_code 恒为空字符串。
|
||||
*/
|
||||
export function buildSourceCloneDraft(input: SourceCloneInput, copySuffix: string): SourceCloneDraft {
|
||||
const displayName = String(input.display_name || input.source_code || '').trim();
|
||||
const suffix = String(copySuffix || '').trim();
|
||||
return {
|
||||
source_code: '',
|
||||
display_name: suffix ? `${displayName} ${suffix}` : displayName,
|
||||
connector_type: input.connector_type,
|
||||
rpa_profile_id: Number(input.rpa_profile_id) || 0,
|
||||
excel_template_id: Number(input.excel_template_id) || 0,
|
||||
warehouse_resolution_mode: input.warehouse_resolution_mode,
|
||||
fixed_warehouse_id: input.fixed_warehouse_id || '',
|
||||
snapshot_ttl_seconds: Number(input.snapshot_ttl_seconds) || 86400,
|
||||
enabled: false,
|
||||
onhand_report_config: {
|
||||
report_path_json: { ...(input.onhand_report_config?.report_path_json || {}) },
|
||||
query_parameters_json: cloneParameters(input.onhand_report_config?.query_parameters_json),
|
||||
parsing_profile_id: Number(input.onhand_report_config?.parsing_profile_id) || 0,
|
||||
},
|
||||
inbound_report_config: cloneReport(input.inbound_report_config),
|
||||
outbound_report_config: cloneReport(input.outbound_report_config),
|
||||
clone_from: {
|
||||
source_code: String(input.source_code || ''),
|
||||
display_name: displayName,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -877,6 +877,9 @@
|
||||
"cloneTemplateCodeHint": "Enter a new unique template code. The new template starts as a v1 draft.",
|
||||
"cloneTemplateConfirm": "Create new template",
|
||||
"copySuffix": "Copy",
|
||||
"cloneSource": "Copy as new",
|
||||
"cloneSourceAria": "Copy {name} as a new site",
|
||||
"cloneSourceBanner": "Copied from \"{code} · {name}\". Nothing is created until you save. Enter a new source code.",
|
||||
"confirmRetireTemplate": "Retire this template? It can no longer be bound to a new inventory site.",
|
||||
"connectionsHelp": "Manage login URLs and credentials for separate accounts. A connection only handles login; it does not define browser actions.",
|
||||
"credentialsHint": "Usernames and passwords are write-only and are never returned by the UI or API.",
|
||||
|
||||
@@ -877,6 +877,9 @@
|
||||
"cloneTemplateCodeHint": "กรอกรหัสเทมเพลตใหม่ที่ไม่ซ้ำ เทมเพลตใหม่จะเริ่มเป็นฉบับร่าง v1",
|
||||
"cloneTemplateConfirm": "สร้างเทมเพลตใหม่",
|
||||
"copySuffix": "สำเนา",
|
||||
"cloneSource": "คัดลอกเป็นรายการใหม่",
|
||||
"cloneSourceAria": "คัดลอก {name} เป็นไซต์ใหม่",
|
||||
"cloneSourceBanner": "คัดลอกจาก \"{code} · {name}\" ระบบจะยังไม่สร้างไซต์จนกว่าจะบันทึก กรอกรหัสแหล่งสินค้าใหม่",
|
||||
"confirmRetireTemplate": "ต้องการเลิกใช้เทมเพลตนี้หรือไม่ หลังจากนั้นจะผูกกับไซต์สินค้าคงคลังใหม่ไม่ได้",
|
||||
"connectionsHelp": "จัดการ URL เข้าสู่ระบบและข้อมูลรับรองของแต่ละบัญชี การเชื่อมต่อมีหน้าที่เฉพาะการเข้าสู่ระบบ ไม่กำหนดการทำงานของหน้าเว็บ",
|
||||
"credentialsHint": "ชื่อผู้ใช้และรหัสผ่านเขียนได้เท่านั้น และจะไม่ส่งกลับจากหน้าเว็บหรือ API",
|
||||
|
||||
@@ -1007,6 +1007,9 @@
|
||||
"cloneTemplateCodeHint": "请输入新的唯一模板编码;新模板将从 v1 草稿开始。",
|
||||
"cloneTemplateConfirm": "创建新模板",
|
||||
"copySuffix": "副本",
|
||||
"cloneSource": "复制新增",
|
||||
"cloneSourceAria": "复制新增 {name}",
|
||||
"cloneSourceBanner": "基于「{code} · {name}」复制。保存前不会创建站点。请填写新的库存源编号。",
|
||||
"confirmRetireTemplate": "确定退役这个模板吗?退役后不能再绑定新的库存站点。",
|
||||
"templateLayoutReadFailed": "无法读取 Excel 模板的工作表和表头,请确认文件未损坏后重试。",
|
||||
"connectionsHelp": "维护不同账号的登录地址和凭据;每个连接配置只负责登录,不维护页面点击路径。",
|
||||
|
||||
@@ -877,6 +877,9 @@
|
||||
"cloneTemplateCodeHint": "請輸入新的唯一範本編碼;新範本將從 v1 草稿開始。",
|
||||
"cloneTemplateConfirm": "建立新範本",
|
||||
"copySuffix": "副本",
|
||||
"cloneSource": "複製新增",
|
||||
"cloneSourceAria": "複製新增 {name}",
|
||||
"cloneSourceBanner": "基於「{code} · {name}」複製。儲存前不會建立站點。請填寫新的庫存源編號。",
|
||||
"confirmRetireTemplate": "確定要退役這個範本嗎?退役後不能再綁定新的庫存站點。",
|
||||
"connectionsHelp": "維護不同帳號的登入網址和憑據;每個連線設定只負責登入,不維護頁面點擊路徑。",
|
||||
"credentialsHint": "帳號與密碼只可寫入,頁面及介面不會回傳。",
|
||||
|
||||
Reference in new issue
Block a user