feat(shipping-freight-auto-upload): 新增货代发货Excel连接级自动上传全链路功能

为提升货代上传的自动化程度,减少人工操作,本提交实现完整的连接级自动上传功能,包含以下变更:
- 新增数据库迁移与ShippingRpaProfile模型字段,存储连接级上传配置
- 完善RPA自动上传触发、回调与状态管理逻辑,支持三态结果与人工兜底
- 优化聊天界面任务卡片加载与按钮渲染,修复无文案幽灵按钮问题
This commit is contained in:
hugo committed 2026-08-27 12:44:12 +08:00
1 parent 06c18b3c7c
commit 434c04ed2d
30 files changed
+1574 -185

No files matched your search

@@ -98,6 +98,24 @@
<label><span>{{ t('admin.shippingInventory.username') }}</span><input v-model="profile.username" class="input-field" name="shipping-rpa-credential-user" autocomplete="one-time-code" readonly :placeholder="t('admin.shippingInventory.writeOnlyHint')" @focus="unlockCredentialField"></label>
<label><span>{{ t('admin.shippingInventory.password') }}</span><input v-model="profile.password" class="input-field" name="shipping-rpa-credential-password" type="password" autocomplete="new-password" readonly :placeholder="t('admin.shippingInventory.writeOnlyHint')" @focus="unlockCredentialField"></label>
<div class="switch-field"><span>{{ t('admin.shippingInventory.enabled') }}</span><button type="button" class="status-switch" :class="{ on: profile.enabled }" role="switch" :aria-checked="profile.enabled" @click="profile.enabled = !profile.enabled"><i></i><b>{{ profile.enabled ? t('admin.shippingInventory.enabledState') : t('admin.shippingInventory.disabledState') }}</b></button></div>
<section class="upload-config-section full">
<header class="upload-config-heading">
<b>{{ t('admin.shippingInventory.uploadConfigTitle') }}</b>
<small>{{ t('admin.shippingInventory.uploadConfigHint') }}</small>
</header>
<div class="switch-field"><span>{{ t('admin.shippingInventory.uploadAutoEnabled') }}</span><button type="button" class="status-switch" :class="{ on: profile.upload_config_json.enabled }" role="switch" :aria-checked="profile.upload_config_json.enabled" @click="profile.upload_config_json.enabled = !profile.upload_config_json.enabled"><i></i><b>{{ profile.upload_config_json.enabled ? t('admin.shippingInventory.enabledState') : t('admin.shippingInventory.disabledState') }}</b></button></div>
<label><span>{{ t('admin.shippingInventory.uploadEntryUrl') }}</span><input v-model="profile.upload_config_json.entry_url" class="input-field" type="url"></label>
<label><span>{{ t('admin.shippingInventory.uploadFileSelector') }}</span><input v-model="profile.upload_config_json.file_input_selector" class="input-field"></label>
<label><span>{{ t('admin.shippingInventory.uploadSubmitMode') }}</span><select v-model="profile.upload_config_json.submit_mode" class="select-field"><option value="auto_after_file">{{ t('admin.shippingInventory.uploadSubmitAuto') }}</option><option value="click_submit">{{ t('admin.shippingInventory.uploadSubmitClick') }}</option></select></label>
<label v-if="profile.upload_config_json.submit_mode === 'click_submit'"><span>{{ t('admin.shippingInventory.uploadSubmitSelector') }}</span><input v-model="profile.upload_config_json.submit_selector" class="input-field"></label>
<label><span>{{ t('admin.shippingInventory.uploadResultMode') }}</span><select v-model="profile.upload_config_json.result_mode" class="select-field"><option value="page_notice">{{ t('admin.shippingInventory.uploadResultPageNotice') }}</option><option value="history_record">{{ t('admin.shippingInventory.uploadResultHistory') }}</option></select></label>
<label><span>{{ t('admin.shippingInventory.uploadResultSelector') }}</span><input v-model="profile.upload_config_json.result_selector" class="input-field"></label>
<label><span>{{ t('admin.shippingInventory.uploadSuccessTexts') }}</span><textarea v-model="successTextsInput" class="input-field" rows="2" :placeholder="t('admin.shippingInventory.uploadSuccessTextsHint')"></textarea></label>
<label><span>{{ t('admin.shippingInventory.uploadTimeout') }}</span><input v-model.number="profile.upload_config_json.timeout_seconds" class="input-field" type="number" min="1"></label>
<div class="form-tip full">{{ t('admin.shippingInventory.uploadConfigBoundary') }}</div>
</section>
<div class="form-tip full">{{ t('admin.shippingInventory.connectionBoundary') }}</div>
</template>
@@ -565,7 +583,33 @@ const filenameVariableCandidates = computed(() => {
return filenameVariables.filter((item) => item.key.toLowerCase().includes(query) || t(item.labelKey).toLowerCase().includes(query));
});
const profile = reactive({ profile_code: '', display_name: '', connector_type: 'dbs', login_url: '', username: '', password: '', login_config_json: { auth_mode: 'password' }, enabled: true });
/** 连接级“发货 Excel 自动上传”配置的受控 JSON 形状(字段与后端白名单一致)。 */
interface ProfileUploadConfig {
enabled: boolean;
entry_url: string;
file_input_selector: string;
submit_mode: 'auto_after_file' | 'click_submit';
submit_selector: string | null;
result_mode: 'page_notice' | 'history_record';
result_selector: string | null;
success_texts: string[];
timeout_seconds: number;
}
/** 连接级“发货 Excel 自动上传”默认配置:DSV 为已确认 URL+input#file2;Crane 保持未启用待管理员补全。 */
function defaultUploadConfig(connectorType: string): ProfileUploadConfig {
if (connectorType === 'crane') {
return { enabled: false, entry_url: 'https://wms-portal.craneww.com/#/shipping-order-upload', file_input_selector: 'input[name="OrderFileUpload"]', submit_mode: 'click_submit', submit_selector: null, result_mode: 'page_notice', result_selector: null, success_texts: [], timeout_seconds: 120 };
}
return { enabled: true, entry_url: 'https://s360.dbschenker.com/main/portal/frame/WMSUpload2', file_input_selector: 'input#file2', submit_mode: 'auto_after_file', submit_selector: null, result_mode: 'page_notice', result_selector: null, success_texts: [], timeout_seconds: 120 };
}
const profile = reactive({ profile_code: '', display_name: '', connector_type: 'dbs', login_url: '', username: '', password: '', login_config_json: { auth_mode: 'password' }, enabled: true, upload_config_json: defaultUploadConfig('dbs') });
/** 成功文本以换行分隔的输入视图,写回 success_texts 数组。 */
const successTextsInput = computed<string>({
get: () => (profile.upload_config_json.success_texts || []).join('\n'),
set: (value) => { profile.upload_config_json.success_texts = String(value || '').split(/\r?\n/).map((item) => item.trim()).filter(Boolean); },
});
const parsing = reactive({ profile_code: '', display_name: '', file_format: 'xlsx', sheet_name: '', header_row_index: 1, field_mappings: [] as ParsingFieldMapping[], match_keys: [] as ParsingMatchKey[] });
const inventoryField = reactive<InventoryFieldForm>({ display_name: '', description: '', value_type: 'text', usage_type: 'general', sort_order: 100, status: 'active' });
const excelTemplate = reactive({ template_code: '', display_name: '', filename_pattern: '{business_no}.xlsx', mappings: [] as TemplateMapping[], file: null as File | null });
@@ -868,6 +912,14 @@ watch(
{ immediate: true },
);
/** 新建连接时按货代类型切换上传配置默认值;编辑既有连接不覆盖已保存配置。 */
watch(
() => profile.connector_type,
(nextType) => {
if (!selectedId.value) profile.upload_config_json = defaultUploadConfig(nextType);
},
);
/** 在库存映射内切换解析方案与字段目录,保持左侧业务入口不分裂。 */
function selectInventoryMappingTab(tab: 'parsing' | 'inventoryFields'): void {
activeTab.value = tab;
@@ -877,7 +929,7 @@ function selectInventoryMappingTab(tab: 'parsing' | 'inventoryFields'): void {
/** 重置当前工作区的编辑表单,作为创建新对象的入口。 */
function createNew(): void {
selectedId.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 });
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, field_mappings: [], match_keys: [] }); 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' });
if (activeTab.value === 'templates') {
@@ -898,7 +950,7 @@ function createNew(): void {
/** 将列表对象复制到当前编辑表单,凭据字段永远不从列表回填。 */
function selectItem(item: Item): void {
selectedId.value = Number(item.id);
if (activeTab.value === 'profiles') Object.assign(profile, { ...item, username: '', password: '', login_config_json: item.login_config_json || { auth_mode: 'password' } });
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,
sheet_name: item.definition?.sheet_name || '', header_row_index: item.definition?.header_row_index ?? 0,
@@ -1067,7 +1119,7 @@ function closeDrawer(): void {
async function saveCurrent(): Promise<void> {
saving.value = true;
try {
if (activeTab.value === 'profiles') await saveShippingRpaProfile({ ...profile, display_name: profile.display_name || profile.profile_code }, selectedId.value || undefined);
if (activeTab.value === 'profiles') await saveShippingRpaProfile({ ...profile, display_name: profile.display_name || profile.profile_code, upload_config_json: profile.upload_config_json }, selectedId.value || undefined);
if (activeTab.value === 'parsing') {
const payload = {
profile_code: parsing.profile_code, display_name: parsing.display_name || parsing.profile_code, file_format: parsing.file_format,
@@ -1598,6 +1650,7 @@ onMounted(load);
.readiness-optional { border-top: 1px solid #e4edf2; padding-top: 10px; }.readiness-optional summary, .readiness-audit summary { display: flex; align-items: baseline; gap: 8px; color: #61798a; cursor: pointer; list-style: none; }.readiness-optional summary::-webkit-details-marker, .readiness-audit summary::-webkit-details-marker { display: none; }.readiness-optional summary::before, .readiness-audit summary::before { color: #4d849f; content: '›'; font-size: 16px; line-height: .8; transition: transform .15s; }.readiness-optional[open] summary::before, .readiness-audit[open] summary::before { transform: rotate(90deg); }.readiness-optional summary span { color: #516b7d; font-size: 12px; font-weight: 700; }.readiness-optional summary small { color: #8797a5; font-size: 11px; }.readiness-optional .readiness-steps { margin-top: 8px; }
.readiness-action { border: 0; border-radius: 5px; background: #e8f3f9; padding: 6px 8px; color: #16759f; font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; }.readiness-action:hover { background: #d8edf7; }.readiness-run { margin: 0; border-left: 3px solid #74b8d8; background: #f0f8fc; padding: 8px 10px; color: #547185; font-size: 11px; line-height: 1.5; }.readiness-run.failed { border-left-color: #e06a58; background: #fff5f3; color: #9d382b; }.readiness-audit { margin: 0; border-top: 1px solid #e4edf2; padding-top: 10px; }.readiness-audit summary { color: #61798a; font-size: 11px; font-weight: 700; }.readiness-audit dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; margin: 9px 0 0; overflow: hidden; border: 1px solid #dce8ef; border-radius: 7px; background: #dce8ef; }.readiness-audit dl > div { min-width: 0; background: #fff; padding: 8px 9px; }.readiness-audit dt { color: #7b8998; font-size: 11px; font-weight: 700; }.readiness-audit dd { overflow: hidden; margin: 4px 0 0; color: #3d5366; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }.readiness-footer { display: flex; justify-content: flex-end; border-top: 1px solid #e6eef4; padding-top: 11px; }
.form-tip { border-radius: 8px; background: #f1f6fa; padding: 11px; color: #5d7084; font-size: 12px; line-height: 1.55; }
.upload-config-section { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; border: 1px solid #e1edf2; border-radius: 9px; background: #fff; padding: 0 12px 12px; }.upload-config-heading { display: grid; gap: 2px; grid-column: 1 / -1; padding: 11px 0 8px; }.upload-config-heading b { color: #385166; font-size: 12px; }.upload-config-heading small { color: #8192a0; font-size: 11px; }.upload-config-section .full { grid-column: 1 / -1; }.upload-config-section textarea.input-field { resize: vertical; }
.configuration-test-verified { margin: 0; border-left: 3px solid #34a56b; background: #effaf3; padding: 9px 10px; color: #256b43; font-size: 12px; font-weight: 600; line-height: 1.45; }
.sample-evidence-card { display: grid; gap: 12px; border: 1px solid #d7e3ed; border-radius: 8px; background: #f8fbfd; padding: 14px; }
.sample-evidence-card > div { display: grid; gap: 3px; }.sample-evidence-card strong { color: #334155; font-size: 13px; }.sample-evidence-card p, .sample-evidence-card > small { margin: 0; color: #6b7f91; font-size: 12px; line-height: 1.55; }