feat(shipping-notice): 添加货代履约策略管理功能,支持策略创建、发布及版本控制,增强订单冻结和预约管理逻辑
This commit is contained in:
1 parent
abd8fc1e16
commit
d62f5107b2
82 files changed
+4914
-514
No files matched your search
@@ -10,6 +10,9 @@ import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import type {
|
||||
CreateOrderProfileFromSampleInput,
|
||||
OrderProfileSampleDocument,
|
||||
CoordinateReconstructionPreview,
|
||||
CoordinateReconstructionSuggestion,
|
||||
CoordinateReconstructionSettings,
|
||||
OrderProfileSampleIntake,
|
||||
OrderProfileSamplePreview,
|
||||
ShippingOrderDocumentProfile,
|
||||
@@ -39,12 +42,50 @@ export const getOrderProfileSampleStatus = (intakeNo: string) =>
|
||||
auth(),
|
||||
);
|
||||
|
||||
/** 删除可安全回收的专用模板样本;历史业务附件与盲测样本由服务端保护。 */
|
||||
export const deleteOrderProfileSample = (intakeNo: string) =>
|
||||
requestJson<void>(
|
||||
`/api/admin/shipping-notice/order-document-profile-samples/intakes/${encodeURIComponent(intakeNo)}`,
|
||||
{ method: 'DELETE', ...auth() },
|
||||
);
|
||||
|
||||
/** 读取一个样本文档的网格预览,不返回 HTML 或 bbox。 */
|
||||
export const getOrderProfileSampleTables = (documentId: number) =>
|
||||
requestJson<OrderProfileSamplePreview>(
|
||||
`/api/admin/shipping-notice/order-document-profile-samples/${documentId}/tables`, auth(),
|
||||
);
|
||||
|
||||
/** 以管理员确认的相对列边界生成坐标重建候选;结果始终待人工审核。 */
|
||||
export const previewOrderProfileCoordinateReconstruction = (
|
||||
documentId: number, tableId: string, coordinateReconstruction: CoordinateReconstructionSettings,
|
||||
) => requestJson<CoordinateReconstructionPreview>(
|
||||
'/api/admin/shipping-notice/order-document-profile-samples/coordinate-reconstruction-preview', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ document_id: documentId, table_id: tableId, coordinate_reconstruction: coordinateReconstruction }),
|
||||
...jsonAuth(),
|
||||
},
|
||||
);
|
||||
|
||||
/** 从冻结字符坐标建议全部或指定物理行;rowOffset 省略时保持原有全量识别。 */
|
||||
export const suggestOrderProfileCoordinateReconstruction = (
|
||||
documentId: number, tableId: string, rowOffset?: number,
|
||||
) =>
|
||||
requestJson<CoordinateReconstructionSuggestion>(
|
||||
'/api/admin/shipping-notice/order-document-profile-samples/coordinate-reconstruction-suggestion', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ document_id: documentId, table_id: tableId, row_offset: rowOffset }),
|
||||
...jsonAuth(),
|
||||
},
|
||||
);
|
||||
|
||||
/** 为扫描 PDF 生成 OCR 坐标证据;随后仍必须由管理员审核重建网格。 */
|
||||
export const generateOrderProfileOcrCoordinateEvidence = (documentId: number, tableId: string) =>
|
||||
requestJson<{ document_id: number; table_id: string; source: 'ocr' }>(
|
||||
'/api/admin/shipping-notice/order-document-profile-samples/ocr-coordinate-evidence', {
|
||||
method: 'POST', body: JSON.stringify({ document_id: documentId, table_id: tableId }), ...jsonAuth(),
|
||||
},
|
||||
);
|
||||
|
||||
/** 由真实样本和结构化列选择创建 Profile 草稿。 */
|
||||
export const createOrderProfileFromSample = (payload: CreateOrderProfileFromSampleInput) =>
|
||||
requestJson<ShippingOrderDocumentProfile>('/api/admin/shipping-notice/order-document-profiles/from-sample', {
|
||||
|
||||
@@ -16,6 +16,8 @@ import type {
|
||||
ShippingOrderSchemaVersionDiff,
|
||||
ShippingOrderSchemaVersionPage,
|
||||
ShippingOrderSchemaVersionUsage,
|
||||
ShippingFulfillmentPolicy,
|
||||
ShippingFulfillmentPolicyState,
|
||||
} from '../types/shipping-order-schema.types';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
@@ -143,3 +145,21 @@ export const publishShippingOrderSchemaDraft = (versionId: number, expectedLockV
|
||||
`/api/admin/shipping-order-schema/versions/${versionId}/publish`,
|
||||
{ method: 'POST', body: JSON.stringify({ expected_lock_version: expectedLockVersion }), ...jsonAuth() },
|
||||
);
|
||||
|
||||
/** 读取受控履约能力目录及策略版本,页面不提供任意表达式配置。 */
|
||||
export const getShippingFulfillmentPolicyState = () =>
|
||||
requestJson<ShippingFulfillmentPolicyState>('/api/admin/shipping-fulfillment-policies', auth());
|
||||
|
||||
/** 创建按稳定字段 ID 绑定的下一履约策略草稿。 */
|
||||
export const createShippingFulfillmentPolicyDraft = (payload: {
|
||||
field_bindings: Array<{ capability_code: string; field_id: string }>;
|
||||
change_note?: string;
|
||||
}) => requestJson<ShippingFulfillmentPolicy>('/api/admin/shipping-fulfillment-policies', {
|
||||
method: 'POST', body: JSON.stringify(payload), ...jsonAuth(),
|
||||
});
|
||||
|
||||
/** 显式发布策略草稿;服务端原子退役上一发布版本。 */
|
||||
export const publishShippingFulfillmentPolicy = (policyId: number, expectedLockVersion: number) =>
|
||||
requestJson<ShippingFulfillmentPolicy>(`/api/admin/shipping-fulfillment-policies/${policyId}/publish`, {
|
||||
method: 'POST', body: JSON.stringify({ expected_lock_version: expectedLockVersion }), ...jsonAuth(),
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* features/admin/components/AdminNav.vue
|
||||
* 管理后台左侧导航,使用子路由跳转。
|
||||
* 管理后台左侧导航,在模块原始顺序中渲染货代手风琴、企微和报表二级菜单。
|
||||
* 依赖:admin-nav.store、modules 常量、vue-router。
|
||||
* 逻辑:报表/企微子菜单默认折叠;当前路由落在对应模块时自动展开以便看到激活项。
|
||||
*/
|
||||
@@ -10,13 +10,15 @@ import { useI18n } from 'vue-i18n';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import {
|
||||
LayoutDashboard, UserPlus, UserCog, Building, Bot, FileText,
|
||||
Settings2, Megaphone, MessageCircleQuestion, Link2, Users, ShieldCheck, BarChart2, AppWindow, Warehouse
|
||||
Settings2, Megaphone, MessageCircleQuestion, Link2, Users, ShieldCheck, BarChart2, AppWindow, Warehouse,
|
||||
ChevronDown, ChevronRight
|
||||
} from 'lucide-vue-next';
|
||||
import type { Component } from 'vue';
|
||||
import { config } from '@/config';
|
||||
import { ADMIN_MODULE_METAS, ADMIN_REPORT_TABLES, SHIPPING_CONFIG_SUB_MODULE_METAS } from '../constants/modules';
|
||||
import { useAdminNavStore } from '../stores/admin-nav.store';
|
||||
import type { AdminModuleId, ShippingConfigSubModuleId } from '../types/admin.types';
|
||||
import type { ShippingManagementGroupKey } from '../stores/admin-nav.store';
|
||||
import type { AdminModuleId } from '../types/admin.types';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
@@ -45,18 +47,13 @@ const visibleModules = computed(() =>
|
||||
ADMIN_MODULE_METAS.filter((item) => config.admin.modules[item.configKey] !== false),
|
||||
);
|
||||
|
||||
const standardModules = computed(() =>
|
||||
visibleModules.value.filter((item) => item.id !== 'wecom' && item.id !== 'shipping_inventory'),
|
||||
);
|
||||
|
||||
const isModuleActive = (moduleId: AdminModuleId): boolean =>
|
||||
route.meta.adminModule === moduleId;
|
||||
|
||||
const isReportsActive = computed(() => route.meta.adminModule === 'reports');
|
||||
const isWecomActive = computed(() => route.meta.adminModule === 'wecom');
|
||||
const isShippingConfigActive = computed(() => route.meta.adminModule === 'shipping_inventory');
|
||||
const isShippingConfigSubModuleActive = (subModule: ShippingConfigSubModuleId): boolean =>
|
||||
route.meta.adminSubModule === subModule;
|
||||
const isShippingManagementActive = computed(() => route.meta.adminModule === 'shipping_inventory');
|
||||
const shippingNavGroups = [...new Set(SHIPPING_CONFIG_SUB_MODULE_METAS.map((item) => item.groupKey))];
|
||||
|
||||
const wecomSubRoutes = [
|
||||
{ name: 'AdminWecomSettings', labelKey: 'admin.wecom.nav.settings' },
|
||||
@@ -68,8 +65,24 @@ const navigateWecom = (routeName: string): void => {
|
||||
router.push({ name: routeName });
|
||||
};
|
||||
|
||||
const navigateShippingConfig = (routeName: string): void => {
|
||||
router.push({ name: routeName });
|
||||
/** 判断货代二级菜单当前项;综合工作台按 section 深链高亮,库存字段目录归入库存解析。 */
|
||||
const isShippingNavActive = (item: typeof SHIPPING_CONFIG_SUB_MODULE_METAS[number]): boolean => {
|
||||
if (route.name !== item.routeName) return false;
|
||||
if (!item.query) return true;
|
||||
const section = typeof route.query.section === 'string' ? route.query.section : 'orderSchema';
|
||||
if (item.query.section === 'parsing') return section === 'parsing' || section === 'inventoryFields';
|
||||
return section === item.query.section;
|
||||
};
|
||||
|
||||
/** 打开货代独立页面或综合工作台区段,保留可收藏的 section 深链。 */
|
||||
const navigateShipping = (item: typeof SHIPPING_CONFIG_SUB_MODULE_METAS[number]): void => {
|
||||
router.push({ name: item.routeName, query: item.query });
|
||||
};
|
||||
|
||||
/** 返回当前货代页面所在分组,用于路由进入时只展开对应手风琴。 */
|
||||
const currentShippingGroup = (): ShippingManagementGroupKey | null => {
|
||||
const currentItem = SHIPPING_CONFIG_SUB_MODULE_METAS.find(isShippingNavActive);
|
||||
return currentItem?.groupKey ?? null;
|
||||
};
|
||||
|
||||
const getReportTableLabel = (table: string): string => {
|
||||
@@ -88,7 +101,7 @@ const navigateReport = (table: string): void => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 进入报表/企微模块时自动展开子菜单,避免当前页在折叠状态下不可见。
|
||||
* 进入报表、企微或货代模块时自动展开子菜单,避免当前页在折叠状态下不可见。
|
||||
*/
|
||||
watch(
|
||||
isReportsActive,
|
||||
@@ -107,12 +120,22 @@ watch(
|
||||
);
|
||||
|
||||
watch(
|
||||
isShippingConfigActive,
|
||||
isShippingManagementActive,
|
||||
(active) => {
|
||||
if (active) navStore.shippingConfigExpanded = true;
|
||||
if (!active) return;
|
||||
navStore.shippingManagementExpanded = true;
|
||||
navStore.shippingManagementGroup = currentShippingGroup();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
() => [route.name, route.query.section],
|
||||
() => {
|
||||
if (isShippingManagementActive.value) navStore.shippingManagementGroup = currentShippingGroup();
|
||||
},
|
||||
);
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -121,91 +144,106 @@ watch(
|
||||
:class="navStore.sidebarCollapsed ? 'w-0 md:w-20' : 'w-full md:w-64'"
|
||||
>
|
||||
<nav class="flex md:flex-col p-3 gap-1 overflow-x-auto md:overflow-visible no-scrollbar">
|
||||
<button
|
||||
v-for="item in standardModules"
|
||||
:key="item.id"
|
||||
type="button"
|
||||
class="admin-nav-btn group"
|
||||
:class="{ 'admin-nav-btn--active': isModuleActive(item.id) }"
|
||||
:title="navStore.sidebarCollapsed ? t(item.labelKey) : ''"
|
||||
@click="navigateModule(item.routeName)"
|
||||
>
|
||||
<component
|
||||
:is="iconMap[item.id]"
|
||||
class="w-5 h-5 transition-transform group-hover:scale-110 flex-shrink-0"
|
||||
:class="isModuleActive(item.id) ? 'text-brand-600' : 'text-muted group-hover:text-secondary'"
|
||||
/>
|
||||
<span :class="navStore.sidebarCollapsed ? 'md:hidden' : ''">{{ t(item.labelKey) }}</span>
|
||||
<span
|
||||
v-if="navStore.badgeForModule(item.id) && !navStore.sidebarCollapsed"
|
||||
class="ml-auto bg-red-500 text-white text-[10px] font-bold px-2 py-0.5 rounded-full shadow-sm"
|
||||
>
|
||||
{{ navStore.badgeForModule(item.id) }}
|
||||
</span>
|
||||
<div
|
||||
v-if="isModuleActive(item.id)"
|
||||
class="absolute left-0 top-1/2 -translate-y-1/2 w-1 h-6 bg-brand-600 rounded-r-full"
|
||||
/>
|
||||
</button>
|
||||
|
||||
<div v-if="config.admin.modules.wecom !== false" class="flex flex-col flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
class="admin-nav-btn group justify-between"
|
||||
:class="{ 'admin-nav-btn--active': isWecomActive }"
|
||||
@click="navStore.wecomExpanded = !navStore.wecomExpanded"
|
||||
>
|
||||
<div class="flex items-center gap-3">
|
||||
<Link2 class="w-5 h-5 flex-shrink-0" :class="isWecomActive ? 'text-brand-600' : 'text-muted'" />
|
||||
<span :class="navStore.sidebarCollapsed ? 'md:hidden' : ''">{{ t('admin.nav.wecom') }}</span>
|
||||
</div>
|
||||
</button>
|
||||
<div
|
||||
v-if="navStore.wecomExpanded && !navStore.sidebarCollapsed"
|
||||
class="pl-4 space-y-1 mt-1 border-l-2 border-subtle ml-6"
|
||||
>
|
||||
<template v-for="item in visibleModules" :key="item.id">
|
||||
<div v-if="item.id === 'shipping_inventory'" class="flex flex-col flex-shrink-0">
|
||||
<button
|
||||
v-for="sub in wecomSubRoutes"
|
||||
:key="sub.name"
|
||||
type="button"
|
||||
class="admin-nav-subitem"
|
||||
:class="{ 'admin-nav-subitem--active': route.name === sub.name }"
|
||||
@click="navigateWecom(sub.name)"
|
||||
class="admin-nav-btn group justify-between"
|
||||
:class="{ 'admin-nav-btn--active': isShippingManagementActive }"
|
||||
:title="navStore.sidebarCollapsed ? t(item.labelKey) : ''"
|
||||
@click="navStore.shippingManagementExpanded = !navStore.shippingManagementExpanded"
|
||||
>
|
||||
{{ t(sub.labelKey) }}
|
||||
<div class="flex items-center gap-3">
|
||||
<Warehouse class="w-5 h-5 flex-shrink-0" :class="isShippingManagementActive ? 'text-brand-600' : 'text-muted'" />
|
||||
<span :class="navStore.sidebarCollapsed ? 'md:hidden' : ''">{{ t(item.labelKey) }}</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="config.admin.modules.shipping_inventory !== false" class="flex flex-col flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
class="admin-nav-btn group justify-between"
|
||||
:class="{ 'admin-nav-btn--active': isShippingConfigActive }"
|
||||
:title="navStore.sidebarCollapsed ? t('admin.nav.shippingConfig') : ''"
|
||||
@click="navStore.shippingConfigExpanded = !navStore.shippingConfigExpanded"
|
||||
>
|
||||
<div class="flex items-center gap-3">
|
||||
<Warehouse class="w-5 h-5 flex-shrink-0" :class="isShippingConfigActive ? 'text-brand-600' : 'text-muted'" />
|
||||
<span :class="navStore.sidebarCollapsed ? 'md:hidden' : ''">{{ t('admin.nav.shippingConfig') }}</span>
|
||||
<div
|
||||
v-if="navStore.shippingManagementExpanded && !navStore.sidebarCollapsed"
|
||||
class="mt-1 ml-6 space-y-1 border-l-2 border-subtle pl-3 pb-1"
|
||||
>
|
||||
<section v-for="groupKey in shippingNavGroups" :key="groupKey" class="shipping-nav-group">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full items-center justify-between rounded-lg px-3 py-2 text-left text-xs font-semibold text-secondary transition-colors hover:bg-surface-soft"
|
||||
:aria-expanded="navStore.shippingManagementGroup === groupKey"
|
||||
@click="navStore.toggleShippingManagementGroup(groupKey)"
|
||||
>
|
||||
<span>{{ t(groupKey) }}</span>
|
||||
<ChevronDown v-if="navStore.shippingManagementGroup === groupKey" class="h-3.5 w-3.5 text-muted" />
|
||||
<ChevronRight v-else class="h-3.5 w-3.5 text-muted" />
|
||||
</button>
|
||||
<div v-if="navStore.shippingManagementGroup === groupKey" class="ml-2 border-l border-subtle pl-2 py-1 space-y-0.5">
|
||||
<button
|
||||
v-for="sub in SHIPPING_CONFIG_SUB_MODULE_METAS.filter((entry) => entry.groupKey === groupKey)"
|
||||
:key="sub.id"
|
||||
type="button"
|
||||
class="admin-nav-subitem py-1.5 pl-3"
|
||||
:class="{ 'admin-nav-subitem--active': isShippingNavActive(sub) }"
|
||||
@click="navigateShipping(sub)"
|
||||
>
|
||||
{{ t(sub.labelKey) }}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</button>
|
||||
<div
|
||||
v-if="navStore.shippingConfigExpanded && !navStore.sidebarCollapsed"
|
||||
class="pl-4 space-y-1 mt-1 border-l-2 border-subtle ml-6"
|
||||
>
|
||||
<button
|
||||
v-for="sub in SHIPPING_CONFIG_SUB_MODULE_METAS"
|
||||
:key="sub.id"
|
||||
type="button"
|
||||
class="admin-nav-subitem"
|
||||
:class="{ 'admin-nav-subitem--active': isShippingConfigSubModuleActive(sub.id) }"
|
||||
@click="navigateShippingConfig(sub.routeName)"
|
||||
>
|
||||
{{ t(sub.labelKey) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="item.id === 'wecom'" class="flex flex-col flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
class="admin-nav-btn group justify-between"
|
||||
:class="{ 'admin-nav-btn--active': isWecomActive }"
|
||||
@click="navStore.wecomExpanded = !navStore.wecomExpanded"
|
||||
>
|
||||
<div class="flex items-center gap-3">
|
||||
<Link2 class="w-5 h-5 flex-shrink-0" :class="isWecomActive ? 'text-brand-600' : 'text-muted'" />
|
||||
<span :class="navStore.sidebarCollapsed ? 'md:hidden' : ''">{{ t(item.labelKey) }}</span>
|
||||
</div>
|
||||
</button>
|
||||
<div
|
||||
v-if="navStore.wecomExpanded && !navStore.sidebarCollapsed"
|
||||
class="pl-4 space-y-1 mt-1 border-l-2 border-subtle ml-6"
|
||||
>
|
||||
<button
|
||||
v-for="sub in wecomSubRoutes"
|
||||
:key="sub.name"
|
||||
type="button"
|
||||
class="admin-nav-subitem"
|
||||
:class="{ 'admin-nav-subitem--active': route.name === sub.name }"
|
||||
@click="navigateWecom(sub.name)"
|
||||
>
|
||||
{{ t(sub.labelKey) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="admin-nav-btn group"
|
||||
:class="{ 'admin-nav-btn--active': isModuleActive(item.id) }"
|
||||
:title="navStore.sidebarCollapsed ? t(item.labelKey) : ''"
|
||||
@click="navigateModule(item.routeName)"
|
||||
>
|
||||
<component
|
||||
:is="iconMap[item.id]"
|
||||
class="w-5 h-5 transition-transform group-hover:scale-110 flex-shrink-0"
|
||||
:class="isModuleActive(item.id) ? 'text-brand-600' : 'text-muted group-hover:text-secondary'"
|
||||
/>
|
||||
<span :class="navStore.sidebarCollapsed ? 'md:hidden' : ''">{{ t(item.labelKey) }}</span>
|
||||
<span
|
||||
v-if="navStore.badgeForModule(item.id) && !navStore.sidebarCollapsed"
|
||||
class="ml-auto bg-red-500 text-white text-[10px] font-bold px-2 py-0.5 rounded-full shadow-sm"
|
||||
>
|
||||
{{ navStore.badgeForModule(item.id) }}
|
||||
</span>
|
||||
<div
|
||||
v-if="isModuleActive(item.id)"
|
||||
class="absolute left-0 top-1/2 -translate-y-1/2 w-1 h-6 bg-brand-600 rounded-r-full"
|
||||
/>
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<div v-if="config.admin.modules.reports !== false" class="flex flex-col flex-shrink-0">
|
||||
<button
|
||||
|
||||
@@ -18,6 +18,8 @@ export interface ShippingConfigSubModuleMeta {
|
||||
routeName: 'AdminShippingInventory' | 'AdminShippingIdentityRules' | 'AdminShippingOrderExtractionRuns' | 'AdminShippingOrderDocumentProfiles';
|
||||
path: 'shipping-notice' | 'shipping-identity-rules' | 'shipping-order-extraction-runs' | 'shipping-order-document-profiles';
|
||||
labelKey: string;
|
||||
groupKey: 'admin.nav.shippingOrderRecognition' | 'admin.nav.shippingInventoryManagement' | 'admin.nav.shippingRunAudit';
|
||||
query?: { section: 'orderSchema' | 'parsing' | 'profiles' | 'sources' | 'mappings' | 'rules' | 'templates' | 'snapshots' | 'exports' };
|
||||
}
|
||||
|
||||
/** 已独立拆分的模块(全部 admin 模块均已拆分) */
|
||||
@@ -33,21 +35,29 @@ export const ADMIN_MODULE_METAS: AdminModuleMeta[] = [
|
||||
{ id: 'agents', routeName: 'AdminAgents', path: 'agents', labelKey: 'admin.nav.agents', configKey: 'agents' },
|
||||
{ id: 'knowledge_base', routeName: 'AdminKnowledgeBase', path: 'knowledge-base', labelKey: 'admin.nav.knowledgeBase', configKey: 'knowledge_base' },
|
||||
{ id: 'schedules', routeName: 'AdminSchedules', path: 'schedules', labelKey: 'admin.nav.schedules', configKey: 'schedules' },
|
||||
{ id: 'shipping_inventory', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.nav.shippingConfig', configKey: 'shipping_inventory' },
|
||||
{ id: 'announcements', routeName: 'AdminAnnouncements', path: 'announcements', labelKey: 'admin.nav.announcements', configKey: 'announcements' },
|
||||
{ id: 'questions', routeName: 'AdminQuestions', path: 'questions', labelKey: 'admin.nav.questions', configKey: 'questions' },
|
||||
{ id: 'wecom', routeName: 'AdminWecom', path: 'wecom', labelKey: 'admin.nav.wecom', configKey: 'wecom' },
|
||||
{ id: 'permissions', routeName: 'AdminPermissions', path: 'permissions', labelKey: 'admin.nav.permissions', configKey: 'permissions' },
|
||||
{ id: 'platform_apps', routeName: 'AdminPlatformApps', path: 'platform-apps', labelKey: 'admin.nav.platformApps', configKey: 'platform_apps' },
|
||||
{ id: 'shipping_inventory', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.nav.shippingInventory', configKey: 'shipping_inventory' },
|
||||
{ id: 'requests', routeName: 'AdminRequests', path: 'requests', labelKey: 'admin.nav.requests', configKey: 'requests' },
|
||||
];
|
||||
|
||||
/** 货代配置的二级导航唯一真相源;各页面共用父模块权限与可见性开关。 */
|
||||
/** 货代管理的业务导航唯一真相源;按基础定义、适配规则、运行任务的依赖顺序排列。 */
|
||||
export const SHIPPING_CONFIG_SUB_MODULE_METAS: ShippingConfigSubModuleMeta[] = [
|
||||
{ id: 'inventory', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.nav.shippingInventory' },
|
||||
{ id: 'identity_rules', routeName: 'AdminShippingIdentityRules', path: 'shipping-identity-rules', labelKey: 'admin.nav.shippingIdentityRules' },
|
||||
{ id: 'order_extraction_runs', routeName: 'AdminShippingOrderExtractionRuns', path: 'shipping-order-extraction-runs', labelKey: 'admin.nav.shippingOrderExtractionRuns' },
|
||||
{ id: 'order_document_profiles', routeName: 'AdminShippingOrderDocumentProfiles', path: 'shipping-order-document-profiles', labelKey: 'admin.nav.shippingOrderDocumentProfiles' },
|
||||
{ id: 'order_fields', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.nav.shippingOrderFields', groupKey: 'admin.nav.shippingOrderRecognition', query: { section: 'orderSchema' } },
|
||||
{ id: 'order_document_profiles', routeName: 'AdminShippingOrderDocumentProfiles', path: 'shipping-order-document-profiles', labelKey: 'admin.nav.shippingOrderDocumentProfiles', groupKey: 'admin.nav.shippingOrderRecognition' },
|
||||
{ id: 'identity_rules', routeName: 'AdminShippingIdentityRules', path: 'shipping-identity-rules', labelKey: 'admin.nav.shippingIdentityRules', groupKey: 'admin.nav.shippingOrderRecognition' },
|
||||
{ id: 'order_extraction_runs', routeName: 'AdminShippingOrderExtractionRuns', path: 'shipping-order-extraction-runs', labelKey: 'admin.nav.shippingOrderExtractionRuns', groupKey: 'admin.nav.shippingOrderRecognition' },
|
||||
{ id: 'inventory_fields', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.parsingProfiles', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'parsing' } },
|
||||
{ id: 'connections', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.connections', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'profiles' } },
|
||||
{ id: 'inventory_sites', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.sources', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'sources' } },
|
||||
{ id: 'warehouse_mappings', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.externalMappings', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'mappings' } },
|
||||
{ id: 'routing_rules', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.rules', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'rules' } },
|
||||
{ id: 'shipping_templates', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.excelTemplates', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'templates' } },
|
||||
{ id: 'inventory_snapshots', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.snapshots', groupKey: 'admin.nav.shippingRunAudit', query: { section: 'snapshots' } },
|
||||
{ id: 'export_records', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.exports', groupKey: 'admin.nav.shippingRunAudit', query: { section: 'exports' } },
|
||||
];
|
||||
|
||||
export const ADMIN_REPORT_TABLES: AdminReportTableId[] = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-inventory/ShippingInventoryPage.vue
|
||||
用途:以统一配置工作台维护订单字段、库存接入、Excel 导出和运行审计。
|
||||
依赖:admin.api、ShippingOrderSchemaPage、Vue Composition API、Vue I18n。
|
||||
逻辑:按订单字段到库存路由的业务链路组织配置;订单字段复用同一页面内的 Schema 编辑器,避免形成割裂入口。
|
||||
用途:以统一货代管理工作台维护订单字段、库存接入、Excel 导出和运行审计。
|
||||
依赖:admin.api、ShippingOrderSchemaPage、Vue Router、Vue Composition API、Vue I18n。
|
||||
逻辑:由 AdminLayout 统一业务目录选择工作区;section 深链与当前工作区双向同步。
|
||||
-->
|
||||
<template>
|
||||
<section class="inventory-console">
|
||||
@@ -21,22 +21,6 @@
|
||||
</header>
|
||||
|
||||
<div class="console-layout">
|
||||
<aside class="section-nav" aria-label="Shipping configuration sections">
|
||||
<section v-for="group in tabGroups" :key="group.labelKey" class="nav-group">
|
||||
<p>{{ t(group.labelKey) }}</p>
|
||||
<button
|
||||
v-for="tab in group.tabs"
|
||||
:key="tab.key"
|
||||
type="button"
|
||||
:class="{ active: activeTab === tab.key || (tab.key === 'parsing' && activeTab === 'inventoryFields') }"
|
||||
@click="selectTab(tab.key)"
|
||||
>
|
||||
<span>{{ t(tab.labelKey) }}</span>
|
||||
<small v-if="tab.count !== null">{{ tab.count }}</small>
|
||||
</button>
|
||||
</section>
|
||||
</aside>
|
||||
|
||||
<main class="workbench">
|
||||
<div v-if="activeTab !== 'orderSchema'" class="workbench-heading">
|
||||
<div>
|
||||
@@ -435,8 +419,9 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
/** 加载六个库存管理工作区,并将每个工作区限制在各自的真实配置或运行数据边界内。 */
|
||||
import { computed, nextTick, onMounted, reactive, ref } from 'vue';
|
||||
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import * as XLSX from 'xlsx';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
@@ -504,6 +489,8 @@ type InventoryFieldForm = { display_name: string; description: string; value_typ
|
||||
type SourceActivation = { ready: boolean; checks: ShippingInventoryReadinessCheck[]; missing_requirements: string[] };
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const message = useMessage();
|
||||
const activeTab = ref<TabKey>('orderSchema');
|
||||
const selectedId = ref<number | null>(null);
|
||||
@@ -639,13 +626,13 @@ const operators = [
|
||||
];
|
||||
|
||||
const tabs = computed(() => [
|
||||
{ key: 'orderSchema' as const, group: 'foundation', labelKey: 'admin.shippingInventory.orderFields', helpKey: '', count: null },
|
||||
{ key: 'parsing' as const, group: 'foundation', labelKey: 'admin.shippingInventory.parsingProfiles', helpKey: 'admin.shippingInventory.parsingProfilesHelp', count: parsingProfiles.value.length },
|
||||
{ key: 'templates' as const, group: 'foundation', labelKey: 'admin.shippingInventory.excelTemplates', helpKey: 'admin.shippingInventory.excelTemplatesHelp', count: excelTemplates.value.length },
|
||||
{ key: 'orderSchema' as const, group: 'order', labelKey: 'admin.shippingInventory.orderFields', helpKey: '', count: null },
|
||||
{ key: 'parsing' as const, group: 'inventory', labelKey: 'admin.shippingInventory.parsingProfiles', helpKey: 'admin.shippingInventory.parsingProfilesHelp', count: parsingProfiles.value.length },
|
||||
{ key: 'profiles' as const, group: 'inventory', labelKey: 'admin.shippingInventory.connections', helpKey: 'admin.shippingInventory.connectionsHelp', count: profiles.value.length },
|
||||
{ key: 'sources' as const, group: 'inventory', labelKey: 'admin.shippingInventory.sources', helpKey: 'admin.shippingInventory.sourcesHelp', count: sources.value.length },
|
||||
{ key: 'rules' as const, group: 'inventory', labelKey: 'admin.shippingInventory.rules', helpKey: 'admin.shippingInventory.rulesHelp', count: rules.value.length },
|
||||
{ key: 'mappings' as const, group: 'inventory', labelKey: 'admin.shippingInventory.externalMappings', helpKey: 'admin.shippingInventory.mappingsHelp', count: mappings.value.length },
|
||||
{ key: 'rules' as const, group: 'inventory', labelKey: 'admin.shippingInventory.rules', helpKey: 'admin.shippingInventory.rulesHelp', count: rules.value.length },
|
||||
{ key: 'templates' as const, group: 'inventory', labelKey: 'admin.shippingInventory.excelTemplates', helpKey: 'admin.shippingInventory.excelTemplatesHelp', count: excelTemplates.value.length },
|
||||
{ key: 'snapshots' as const, group: 'audit', labelKey: 'admin.shippingInventory.snapshots', helpKey: 'admin.shippingInventory.snapshotsHelp', count: snapshots.value.length },
|
||||
{ key: 'exports' as const, group: 'audit', labelKey: 'admin.shippingInventory.exports', helpKey: 'admin.shippingInventory.exportsHelp', count: exports.value.length },
|
||||
]);
|
||||
@@ -653,11 +640,6 @@ const snapshotColumnLabels = computed(() => [t('admin.shippingInventory.snapshot
|
||||
const exportColumnLabels = computed(() => [t('admin.shippingInventory.runNo'), t('admin.shippingInventory.source'), t('admin.shippingInventory.connection'), t('admin.shippingInventory.triggerMode'), t('admin.shippingInventory.startedAt'), t('admin.shippingInventory.duration'), t('admin.shippingInventory.exportResult'), t('admin.shippingInventory.status'), t('admin.shippingInventory.actions')]);
|
||||
const snapshotTableWidth = computed(() => snapshotColumnWidths.value.reduce((total, width) => total + width, 0));
|
||||
const exportTableWidth = computed(() => exportColumnWidths.value.reduce((total, width) => total + width, 0));
|
||||
const tabGroups = computed(() => [
|
||||
{ labelKey: 'admin.shippingInventory.groupFoundation', tabs: tabs.value.filter((tab) => tab.group === 'foundation') },
|
||||
{ labelKey: 'admin.shippingInventory.groupInventory', tabs: tabs.value.filter((tab) => tab.group === 'inventory') },
|
||||
{ labelKey: 'admin.shippingInventory.groupAudit', tabs: tabs.value.filter((tab) => tab.group === 'audit') },
|
||||
]);
|
||||
const currentTab = computed(() => tabs.value.find((item) => item.key === activeTab.value) ?? tabs.value[0]!);
|
||||
const currentSection = computed(() => activeTab.value === 'inventoryFields'
|
||||
? { labelKey: 'admin.shippingInventory.parsingProfiles', helpKey: 'admin.shippingInventory.parsingProfilesHelp' }
|
||||
@@ -801,14 +783,26 @@ async function load(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 切换管理对象时清空选择,避免不同对象的数据残留在编辑器中。 */
|
||||
/** 切换管理对象时同步深链并清空选择,避免不同对象的数据残留在编辑器中。 */
|
||||
function selectTab(tab: TabKey): void {
|
||||
activeTab.value = tab;
|
||||
void router.replace({ query: { ...route.query, section: tab } });
|
||||
if (tab === 'snapshots') snapshotPage.value = 1;
|
||||
if (tab === 'exports') exportPage.value = 1;
|
||||
closeDrawer();
|
||||
}
|
||||
|
||||
/** 接收侧栏或书签中的 section 深链,仅允许打开工作台已注册区段。 */
|
||||
watch(
|
||||
() => route.query.section,
|
||||
(section) => {
|
||||
if (typeof section === 'string' && tabs.value.some((tab) => tab.key === section)) {
|
||||
activeTab.value = section as TabKey;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/** 在库存映射内切换解析方案与字段目录,保持左侧业务入口不分裂。 */
|
||||
function selectInventoryMappingTab(tab: 'parsing' | 'inventoryFields'): void {
|
||||
activeTab.value = tab;
|
||||
@@ -1465,7 +1459,7 @@ function openAuditDetail(item: Item, kind: 'snapshot' | 'export'): void { auditD
|
||||
function paginate(items: Item[], page: number): Item[] { const start = (page - 1) * auditPageSize.value; return items.slice(start, start + auditPageSize.value); }
|
||||
function downloadSnapshot(item: Item): void { void downloadShippingInventorySnapshot(Number(item.id), `${item.inventory_file_no || 'inventory'}.xlsx`).catch((cause) => { showError(cause, 'downloadFailed'); }); }
|
||||
|
||||
/** 将货代配置的操作失败交给平台统一消息弹窗,禁止跨工作区保留页面级错误。 */
|
||||
/** 将货代管理操作失败交给平台统一消息弹窗,禁止跨工作区保留页面级错误。 */
|
||||
function showError(cause: unknown, fallbackKey: 'loadFailed' | 'saveFailed' | 'deleteFailed' | 'downloadFailed' | 'inventoryAnalysisFailed' | 'configurationTestFailed' | 'templateLayoutReadFailed'): void {
|
||||
message.error(cause instanceof Error ? cause.message : t(`admin.shippingInventory.${fallbackKey}`));
|
||||
}
|
||||
@@ -1495,15 +1489,7 @@ onMounted(load);
|
||||
.flow-strip { align-self: center; display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid #e0f2fe; border-radius: 6px; background: #f0f9ff; color: #0369a1; font-size: 12px; font-weight: 500; }
|
||||
.flow-strip i { color: #7dd3fc; font-style: normal; }
|
||||
.schema-prerequisite { margin: 0 0 14px; border: 1px solid #fde68a; border-radius: 6px; background: #fffbeb; padding: 10px 12px; color: #92400e; font-size: 13px; }
|
||||
.console-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 22px; padding-top: 20px; }
|
||||
.section-nav { display: flex; flex-direction: column; gap: 16px; }
|
||||
.nav-group { display: grid; gap: 3px; }
|
||||
.nav-group > p { margin: 0 10px 3px; color: #94a3b8; font-size: 11px; font-weight: 600; }
|
||||
.section-nav button { display: flex; align-items: center; justify-content: space-between; border: 0; border-left: 2px solid transparent; border-radius: 4px; background: transparent; padding: 9px 10px; color: #64748b; font-size: 13px; text-align: left; cursor: pointer; }
|
||||
.section-nav button:hover { background: #f8fafc; color: #334155; }
|
||||
.section-nav button.active { border-left-color: #0ea5e9; background: #f0f9ff; color: #0369a1; font-weight: 600; }
|
||||
.section-nav small { min-width: 20px; border-radius: 999px; background: #f1f5f9; padding: 2px 5px; color: #94a3b8; font-size: 11px; text-align: center; }
|
||||
.section-nav .active small { background: #e0f2fe; color: #0284c7; }
|
||||
.console-layout { padding-top: 20px; }
|
||||
.workbench-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
|
||||
.workbench-heading h2 { margin: 0; color: #1e293b; font-size: 16px; font-weight: 600; letter-spacing: 0; }
|
||||
.workbench-heading p { max-width: 660px; margin: 5px 0 0; color: #64748b; font-size: 13px; }
|
||||
@@ -1602,6 +1588,6 @@ onMounted(load);
|
||||
.audit-detail dl { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 0; margin: 0; padding: 18px 20px; }.audit-detail dt, .audit-detail dd { margin: 0; padding: 11px 0; border-bottom: 1px solid #edf2f7; font-size: 13px; }.audit-detail dt { color: #64748b; }.audit-detail dd { overflow-wrap: anywhere; color: #334155; }
|
||||
.object-list .empty-state { grid-column: 1 / -1; display: grid; min-height: 260px; place-items: center; }
|
||||
.empty-state { border: 1px dashed #c9d7e5; border-radius: 10px; background: #f9fbfd; padding: 38px 18px; color: #7b899a; font-size: 13px; text-align: center; }
|
||||
@media (max-width: 980px) { .console-header { display: block; } .flow-strip { display: inline-flex; margin-top: 18px; } .console-layout { grid-template-columns: 1fr; } .section-nav { flex-direction: row; gap: 12px; overflow-x: auto; } .nav-group { display: flex; align-items: center; gap: 4px; } .nav-group > p { display: none; } .section-nav button { min-width: max-content; border-bottom: 3px solid transparent; border-left: 0; } .section-nav button.active { border-bottom-color: #16877f; border-left: 0; } .parameter-row, .condition-row, .mapping-row, .template-mapping, .record-card { grid-template-columns: 1fr 1fr; } .mapping-value-row { grid-template-columns: minmax(0, 1.6fr) minmax(180px, 1fr); }.readiness-audit { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
||||
@media (max-width: 980px) { .console-header { display: block; } .flow-strip { display: inline-flex; margin-top: 18px; } .parameter-row, .condition-row, .mapping-row, .template-mapping, .record-card { grid-template-columns: 1fr 1fr; } .mapping-value-row { grid-template-columns: minmax(0, 1.6fr) minmax(180px, 1fr); }.readiness-audit { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
||||
@media (max-width: 640px) { .inventory-console { padding: 18px; } .editor-form, .parameter-row, .condition-row, .mapping-row, .template-mapping, .record-card, .mapping-value-row, .parsing-mapping-card, .readonly-mapping-section .parsing-mapping-card, .parsing-summary { grid-template-columns: 1fr; } .mapping-arrow { transform: rotate(90deg); }.workbench-heading { display: block; } .workbench-heading .primary-action { margin-top: 12px; }.batch-source-list { grid-template-columns: 1fr; }.batch-stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }.batch-run { grid-template-columns: 9px minmax(0, 1fr); }.batch-run-error { grid-column: 2; }.readiness-heading { display: grid; }.readiness-count { justify-self: start; }.readiness-steps li { grid-template-columns: 24px minmax(0, 1fr); }.readiness-action { grid-column: 2; justify-self: start; }.readiness-footer { justify-content: stretch; }.readiness-footer .primary-action { width: 100%; } }
|
||||
</style>
|
||||
+653
-72
@@ -1,8 +1,8 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/ShippingOrderDocumentProfilesPage.vue
|
||||
用途:通过 MinerU 样本表格可视化创建和发布订单文档 Profile。
|
||||
用途:通过 MinerU/PDF 坐标样本工作台创建、复核和发布订单文档 Profile。
|
||||
依赖:Profile/Schema API、BusinessError、useMessage、Vue I18n。
|
||||
逻辑:管理员选择真实样本、表格、表头行和列目标;浏览器不展示 HTML,也不编辑 JSON/结构指纹。
|
||||
逻辑:管理员选择样本并按物理行编辑列边界和字段;后端提供全量/当前行建议及最终候选,浏览器不展示 HTML 或结构指纹。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue';
|
||||
@@ -14,12 +14,16 @@ import {
|
||||
createOrderProfileSample,
|
||||
createOrderProfileFromSample,
|
||||
deleteOrderDocumentProfile,
|
||||
deleteOrderProfileSample,
|
||||
getOrderProfileSampleTables,
|
||||
getOrderProfileSampleStatus,
|
||||
generateOrderProfileOcrCoordinateEvidence,
|
||||
listOrderDocumentProfiles,
|
||||
listOrderProfileSamples,
|
||||
publishOrderDocumentProfile,
|
||||
retireOrderDocumentProfile,
|
||||
previewOrderProfileCoordinateReconstruction,
|
||||
suggestOrderProfileCoordinateReconstruction,
|
||||
updateOrderProfileFromSample,
|
||||
} from '@/features/admin/api/shipping-order-document-profile.api';
|
||||
import { uploadFileAsset } from '@/shared/api/file-assets.api';
|
||||
@@ -28,11 +32,16 @@ import type {
|
||||
OrderProfileSampleDocument,
|
||||
OrderProfileSamplePreview,
|
||||
OrderProfileSampleTable,
|
||||
CoordinateReconstructionPreview,
|
||||
CoordinateReconstructionSettings,
|
||||
CoordinateSubrowLayout,
|
||||
ShippingOrderDocumentProfile,
|
||||
} from '@/features/admin/types/shipping-order-document-profile.types';
|
||||
import {
|
||||
buildOrderProfileColumnRules,
|
||||
findDuplicateOrderProfileTargets,
|
||||
mergeOrderProfileHeaderLabels,
|
||||
shouldShowStandardOrderProfilePreview,
|
||||
} from './orderProfileForm.utils';
|
||||
import type {
|
||||
ShippingOrderFieldConfig,
|
||||
@@ -49,7 +58,27 @@ const editingProfileId = ref<number | null>(null);
|
||||
const editingLockVersion = ref<number | null>(null);
|
||||
const profiles = ref<ShippingOrderDocumentProfile[]>([]);
|
||||
const samples = ref<OrderProfileSampleDocument[]>([]);
|
||||
const sampleSearch = ref('');
|
||||
const preview = ref<OrderProfileSamplePreview | null>(null);
|
||||
const reconstructionPreview = ref<CoordinateReconstructionPreview | null>(null);
|
||||
const reconstructing = ref(false);
|
||||
const reconstructionPreviewFailed = ref(false);
|
||||
const suggesting = ref(false);
|
||||
const suggestingSubrowIndex = ref<number | null>(null);
|
||||
const ocrGenerating = ref(false);
|
||||
const reconstructionMethod = ref<CoordinateReconstructionSettings['method']>('native_pdf_coordinates.v1');
|
||||
const reconstructionConfirmed = ref(false);
|
||||
const reconstructionFieldSignature = ref('');
|
||||
const columnBoundaryInput = ref('0, 0.10, 0.25, 0.33, 0.52, 0.65, 0.77, 0.88, 0.94, 1');
|
||||
const multiSubrowEnabled = ref(false);
|
||||
type SubrowEditor = {
|
||||
role: CoordinateSubrowLayout['role']; row_offset: number; boundaries: string;
|
||||
fields: Array<string | null>; samples: string[][];
|
||||
};
|
||||
const subrowEditors = ref<SubrowEditor[]>([
|
||||
{ role: 'main', row_offset: 0, boundaries: '0, 1', fields: [null], samples: [] },
|
||||
]);
|
||||
const selectedSubrowIndex = ref(0);
|
||||
const publishedSchemas = ref<ShippingOrderSchemaVersion[]>([]);
|
||||
const form = reactive({
|
||||
profile_code: '', display_name: '', schema_version_id: 0,
|
||||
@@ -62,6 +91,32 @@ const columnRules = ref<Array<{ extractor_key: 'direct' | 'temp_internal_parts';
|
||||
const selectedTable = computed<OrderProfileSampleTable | null>(() => (
|
||||
preview.value?.tables.find((item) => item.table_id === form.table_id) || null
|
||||
));
|
||||
const showStandardPreview = computed(() => shouldShowStandardOrderProfilePreview(
|
||||
Boolean(selectedTable.value?.profile_creation_allowed),
|
||||
multiSubrowEnabled.value,
|
||||
Boolean(selectedTable.value?.coordinate_reconstruction_available),
|
||||
));
|
||||
const displayedTable = computed<OrderProfileSampleTable | CoordinateReconstructionPreview | null>(() => (
|
||||
reconstructionPreview.value || selectedTable.value
|
||||
));
|
||||
const mergedHeaderLabels = computed(() => mergeOrderProfileHeaderLabels(
|
||||
displayedTable.value?.rows || [],
|
||||
form.header_row_index,
|
||||
displayedTable.value?.column_count || 0,
|
||||
));
|
||||
const displayedRowRole = (rowIndex: number) => (
|
||||
reconstructionPreview.value?.row_roles[rowIndex] || (rowIndex <= form.header_row_index ? 'header' : 'data')
|
||||
);
|
||||
const displayedSourceRows = (rowIndex: number) => reconstructionPreview.value?.source_row_indices[rowIndex] || [];
|
||||
const visibleSamples = computed(() => {
|
||||
const keyword = sampleSearch.value.trim().toLowerCase();
|
||||
return samples.value.filter((sample) => !keyword || String(sample.filename || '').toLowerCase().includes(keyword));
|
||||
});
|
||||
const selectedSample = computed(() => samples.value.find((sample) => sample.document_id === form.document_id) || null);
|
||||
const selectedSubrow = computed(() => subrowEditors.value[selectedSubrowIndex.value] || subrowEditors.value[0]);
|
||||
const currentProfileIds = computed(() => new Set(
|
||||
profiles.value.filter((profile) => profile.status === 'published').map((profile) => profile.id),
|
||||
));
|
||||
const selectedSchema = computed(() => publishedSchemas.value.find((item) => item.id === form.schema_version_id) || null);
|
||||
const lineFields = computed<ShippingOrderFieldConfig[]>(() => (
|
||||
selectedSchema.value?.definition?.fields.filter((item) => item.enabled !== false && item.scope === 'line') || []
|
||||
@@ -77,14 +132,25 @@ const duplicateTargets = computed(() => {
|
||||
if (form.row_structure !== 'preserved') return [];
|
||||
return findDuplicateOrderProfileTargets(normalizedRules());
|
||||
});
|
||||
const reconstructionMatchesFields = computed(() => (
|
||||
!reconstructionPreview.value || reconstructionFieldSignature.value === coordinateFieldSignature()
|
||||
));
|
||||
const livePreviewStatusKey = computed(() => {
|
||||
if (reconstructing.value) return 'livePreviewUpdating';
|
||||
if (!subrowEditors.value[0]?.fields.includes('line_no')) return 'livePreviewWaitingLineNo';
|
||||
if (reconstructionPreviewFailed.value) return 'livePreviewFailed';
|
||||
if (reconstructionPreview.value && reconstructionMatchesFields.value) return 'livePreviewReady';
|
||||
return 'livePreviewEmpty';
|
||||
});
|
||||
const canSave = computed(() => Boolean(
|
||||
form.profile_code.trim() && form.display_name.trim() && form.schema_version_id
|
||||
&& form.document_id && form.table_id && selectedTable.value
|
||||
&& selectedTable.value.profile_creation_allowed
|
||||
&& form.document_id && form.table_id && displayedTable.value
|
||||
&& (selectedTable.value?.profile_creation_allowed || reconstructionConfirmed.value)
|
||||
&& form.data_start_row_index > form.header_row_index
|
||||
&& form.header_row_index >= 0
|
||||
&& form.data_start_row_index < (selectedTable.value?.row_count || 0)
|
||||
&& form.data_start_row_index < (displayedTable.value?.row_count || 0)
|
||||
&& duplicateTargets.value.length === 0
|
||||
&& reconstructionMatchesFields.value
|
||||
&& (form.row_structure === 'unsupported_row_structure' || hasConfiguredColumn.value),
|
||||
));
|
||||
|
||||
@@ -115,6 +181,8 @@ const load = async () => {
|
||||
/** 选择样本文档后读取由后端展开的网格。 */
|
||||
const loadPreview = async () => {
|
||||
preview.value = null;
|
||||
reconstructionPreview.value = null;
|
||||
reconstructionConfirmed.value = false;
|
||||
form.table_id = '';
|
||||
if (!form.document_id) return;
|
||||
try {
|
||||
@@ -145,6 +213,8 @@ const uploadSample = async (event: Event) => {
|
||||
await new Promise((resolve) => window.setTimeout(resolve, 1000));
|
||||
}
|
||||
await load();
|
||||
const uploadedSample = samples.value.find((sample) => sample.intake_no === intake.intake_no);
|
||||
if (uploadedSample) form.document_id = uploadedSample.document_id;
|
||||
message.success(t('admin.shippingOrderProfiles.sampleUploaded'));
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
@@ -156,10 +226,274 @@ const uploadSample = async (event: Event) => {
|
||||
|
||||
/** 表格变化时按真实列数初始化受控列映射。 */
|
||||
const resetColumns = () => {
|
||||
const count = selectedTable.value?.column_count || 0;
|
||||
const count = displayedTable.value?.column_count || 0;
|
||||
columnRules.value = Array.from({ length: count }, () => ({ extractor_key: 'direct', target: '' }));
|
||||
form.header_row_index = 0;
|
||||
form.data_start_row_index = Math.min(1, Math.max((selectedTable.value?.row_count || 1) - 1, 0));
|
||||
form.data_start_row_index = Math.min(1, Math.max((displayedTable.value?.row_count || 1) - 1, 0));
|
||||
};
|
||||
|
||||
/** 清理上一张表的坐标重建编辑状态,避免切换样本后隐藏或污染当前配置区。 */
|
||||
const resetCoordinateReconstructionState = () => {
|
||||
if (reconstructionPreviewTimer) window.clearTimeout(reconstructionPreviewTimer);
|
||||
reconstructionPreviewTimer = null;
|
||||
reconstructionPreviewRequestId += 1;
|
||||
multiSubrowEnabled.value = false;
|
||||
subrowEditors.value = [
|
||||
{ role: 'main', row_offset: 0, boundaries: '0, 1', fields: [null], samples: [] },
|
||||
];
|
||||
selectedSubrowIndex.value = 0;
|
||||
reconstructionPreview.value = null;
|
||||
reconstructionPreviewFailed.value = false;
|
||||
reconstructionConfirmed.value = false;
|
||||
reconstructionFieldSignature.value = '';
|
||||
};
|
||||
|
||||
/** 按重建列数保留已有字段映射,并只补齐或裁掉实际变化的列。 */
|
||||
const resizeColumns = (count: number) => {
|
||||
columnRules.value = Array.from({ length: count }, (_, index) => (
|
||||
columnRules.value[index] || { extractor_key: 'direct', target: '' }
|
||||
));
|
||||
};
|
||||
|
||||
/** 解析 0..1 严格递增边界;单内容块物理行允许只使用 0,1。 */
|
||||
const parseBoundaryInput = (raw: string): number[] | null => {
|
||||
const values = raw.split(',').map((item) => Number(item.trim()));
|
||||
if (values.length < 2 || values.some((value) => !Number.isFinite(value)) || values[0] !== 0 || values[values.length - 1] !== 1
|
||||
|| values.some((value, index) => index > 0 && value <= values[index - 1]!)) return null;
|
||||
return values;
|
||||
};
|
||||
|
||||
/** 边界数量变化时保留已有子行字段映射,并补齐新的列。 */
|
||||
const syncSubrowFields = (editor: SubrowEditor) => {
|
||||
const count = Math.max((parseBoundaryInput(editor.boundaries)?.length || 1) - 1, 0);
|
||||
editor.fields = Array.from({ length: count }, (_, index) => editor.fields[index] || null);
|
||||
};
|
||||
|
||||
/** 返回边界尺的有效刻度;输入异常时保留最小可编辑区间。 */
|
||||
const subrowBoundaries = (editor: SubrowEditor) => parseBoundaryInput(editor.boundaries) || [0, 1];
|
||||
|
||||
/** 拖动内部刻度时限制其不能越过相邻边界,并同步字段列数。 */
|
||||
const updateSubrowBoundary = (editor: SubrowEditor, boundaryIndex: number, rawValue: string) => {
|
||||
const values = [...subrowBoundaries(editor)];
|
||||
const previous = values[boundaryIndex - 1] ?? 0;
|
||||
const next = values[boundaryIndex + 1] ?? 1;
|
||||
values[boundaryIndex] = Math.min(next - 0.01, Math.max(previous + 0.01, Number(rawValue)));
|
||||
editor.boundaries = values.map((value) => Number(value.toFixed(2))).join(', ');
|
||||
syncSubrowFields(editor);
|
||||
};
|
||||
|
||||
/** 只有区间宽度足够容纳两个最小 1% 列时才允许继续拆分。 */
|
||||
const canSplitSubrowColumn = (editor: SubrowEditor, columnIndex: number) => {
|
||||
const boundaries = subrowBoundaries(editor);
|
||||
return boundaries[columnIndex + 1]! - boundaries[columnIndex]! >= 0.02;
|
||||
};
|
||||
|
||||
/** 在当前逻辑明细末尾增加任意一条物理子行配置。 */
|
||||
const addSubrow = () => {
|
||||
subrowEditors.value.push({
|
||||
role: 'continuation', row_offset: subrowEditors.value.length,
|
||||
boundaries: '0, 1', fields: [null], samples: [],
|
||||
});
|
||||
selectedSubrowIndex.value = subrowEditors.value.length - 1;
|
||||
};
|
||||
|
||||
/** 删除指定续行并重排 row_offset;首行是新明细锚点,禁止删除。 */
|
||||
const removeSubrow = (index: number) => {
|
||||
if (index <= 0) return;
|
||||
subrowEditors.value.splice(index, 1);
|
||||
subrowEditors.value.forEach((item, rowIndex) => {
|
||||
item.row_offset = rowIndex;
|
||||
item.role = rowIndex === 0 ? 'main' : 'continuation';
|
||||
});
|
||||
selectedSubrowIndex.value = Math.min(selectedSubrowIndex.value, subrowEditors.value.length - 1);
|
||||
};
|
||||
|
||||
/** 在指定列区间中点插入新边界;原列配置保留,新列插入其后等待映射。 */
|
||||
const addSubrowColumn = (editor: SubrowEditor, columnIndex: number) => {
|
||||
const boundaries = [...subrowBoundaries(editor)];
|
||||
const midpoint = Number(((boundaries[columnIndex]! + boundaries[columnIndex + 1]!) / 2).toFixed(2));
|
||||
boundaries.splice(columnIndex + 1, 0, midpoint);
|
||||
editor.boundaries = boundaries.join(', ');
|
||||
editor.fields.splice(columnIndex + 1, 0, null);
|
||||
editor.samples.splice(columnIndex + 1, 0, []);
|
||||
};
|
||||
|
||||
/** 删除当前物理行的一列并合并相邻边界;每行至少保留一列。 */
|
||||
const removeSubrowColumn = (editor: SubrowEditor, columnIndex: number) => {
|
||||
if (editor.fields.length <= 1) return;
|
||||
const boundaries = [...subrowBoundaries(editor)];
|
||||
boundaries.splice(columnIndex === 0 ? 1 : columnIndex, 1);
|
||||
editor.boundaries = boundaries.join(', ');
|
||||
editor.fields.splice(columnIndex, 1);
|
||||
editor.samples.splice(columnIndex, 1);
|
||||
};
|
||||
|
||||
/** 将多子行编辑器转换为严格契约;主行必须映射 line_no 才能识别新明细。 */
|
||||
const multiSubrowLayouts = (): CoordinateSubrowLayout[] | null => {
|
||||
const result: CoordinateSubrowLayout[] = [];
|
||||
for (const editor of subrowEditors.value) {
|
||||
const boundaries = parseBoundaryInput(editor.boundaries);
|
||||
if (!boundaries) return null;
|
||||
const columnCount = boundaries.length - 1;
|
||||
result.push({
|
||||
role: editor.role, row_offset: editor.row_offset,
|
||||
column_boundaries: boundaries,
|
||||
column_field_codes: Array.from({ length: columnCount }, (_, index) => editor.fields[index] || null),
|
||||
});
|
||||
}
|
||||
const main = result.find((item) => item.role === 'main');
|
||||
return main?.column_field_codes.includes('line_no') ? result : null;
|
||||
};
|
||||
|
||||
/** 将管理员确认的相对列边界转为受控坐标重建参数。 */
|
||||
const coordinateReconstructionSettings = (includeFieldRules = false): CoordinateReconstructionSettings | null => {
|
||||
if (multiSubrowEnabled.value) {
|
||||
const layouts = multiSubrowLayouts();
|
||||
return layouts ? { method: reconstructionMethod.value, column_boundaries: [], subrow_layouts: layouts } : null;
|
||||
}
|
||||
const values = parseBoundaryInput(columnBoundaryInput.value);
|
||||
if (!values) return null;
|
||||
const fieldCodes = includeFieldRules ? columnRules.value.map((item) => (
|
||||
item.extractor_key === 'direct' ? (item.target || null) : 'customer_part_number'
|
||||
)) : [];
|
||||
const lineStartColumn = fieldCodes.findIndex((code) => code === 'line_no');
|
||||
return {
|
||||
method: reconstructionMethod.value,
|
||||
column_boundaries: values,
|
||||
column_field_codes: fieldCodes.some(Boolean) ? fieldCodes : [],
|
||||
line_start_column_index: lineStartColumn >= 0 ? lineStartColumn : 0,
|
||||
};
|
||||
};
|
||||
|
||||
/** 生成影响内容适配和新行判断的列映射签名,用于阻止未复核配置直接保存。 */
|
||||
const coordinateFieldSignature = () => JSON.stringify({
|
||||
columnRules: columnRules.value.map((item) => ({ extractor_key: item.extractor_key, target: item.target })),
|
||||
multiSubrowEnabled: multiSubrowEnabled.value,
|
||||
subrows: subrowEditors.value,
|
||||
});
|
||||
|
||||
/** 用后端冻结坐标生成行版式和边界建议;仅确定性行号自动绑定,其余字段由管理员确认。 */
|
||||
const suggestLayouts = async () => {
|
||||
if (!form.document_id || !form.table_id) return;
|
||||
suggesting.value = true;
|
||||
reconstructionPreview.value = null;
|
||||
reconstructionConfirmed.value = false;
|
||||
try {
|
||||
const suggestion = await suggestOrderProfileCoordinateReconstruction(form.document_id, form.table_id);
|
||||
multiSubrowEnabled.value = true;
|
||||
subrowEditors.value = suggestion.subrow_layouts.map((item) => ({
|
||||
role: item.role,
|
||||
row_offset: item.row_offset,
|
||||
boundaries: item.column_boundaries.join(', '),
|
||||
fields: [...item.suggested_field_codes],
|
||||
samples: item.column_samples,
|
||||
}));
|
||||
selectedSubrowIndex.value = 0;
|
||||
message.success(t('admin.shippingOrderProfiles.layoutSuggestionReady'));
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
} finally {
|
||||
suggesting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 仅重新识别当前物理行,按列位置保留已确认字段,不覆盖其他行版式。 */
|
||||
const suggestCurrentSubrow = async () => {
|
||||
const editor = selectedSubrow.value;
|
||||
if (!editor || !form.document_id || !form.table_id) return;
|
||||
suggestingSubrowIndex.value = editor.row_offset;
|
||||
try {
|
||||
const suggestion = await suggestOrderProfileCoordinateReconstruction(
|
||||
form.document_id, form.table_id, editor.row_offset,
|
||||
);
|
||||
const current = suggestion.subrow_layouts[0];
|
||||
if (!current) return;
|
||||
const previousFields = [...editor.fields];
|
||||
editor.boundaries = current.column_boundaries.join(', ');
|
||||
editor.samples = current.column_samples;
|
||||
editor.fields = current.suggested_field_codes.map((code, index) => code || previousFields[index] || null);
|
||||
message.success(t('admin.shippingOrderProfiles.currentRowSuggestionReady'));
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
} finally {
|
||||
suggestingSubrowIndex.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
/** 对扫描 PDF 生成 OCR 字符坐标,随后重新加载表格并继续人工审核。 */
|
||||
const generateOcrEvidence = async () => {
|
||||
if (!form.document_id || !form.table_id) return;
|
||||
const tableId = form.table_id;
|
||||
ocrGenerating.value = true;
|
||||
try {
|
||||
await generateOrderProfileOcrCoordinateEvidence(form.document_id, form.table_id);
|
||||
reconstructionMethod.value = 'ocr_pdf_coordinates.v1';
|
||||
await loadPreview();
|
||||
form.table_id = preview.value?.tables.some((table) => table.table_id === tableId)
|
||||
? tableId : (preview.value?.tables[0]?.table_id || '');
|
||||
message.success(t('admin.shippingOrderProfiles.ocrEvidenceReady'));
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
} finally {
|
||||
ocrGenerating.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
let reconstructionPreviewTimer: ReturnType<typeof window.setTimeout> | null = null;
|
||||
let reconstructionPreviewRequestId = 0;
|
||||
|
||||
/** 请求只读重建候选;自动刷新静默校验,手动刷新继续给出明确错误。 */
|
||||
const runReconstructionPreview = async (silent = false) => {
|
||||
if (multiSubrowEnabled.value && !subrowEditors.value[0]?.fields.includes('line_no')) {
|
||||
if (!silent) message.error(t('admin.shippingOrderProfiles.lineNoRequired'));
|
||||
return;
|
||||
}
|
||||
const settings = coordinateReconstructionSettings(true);
|
||||
if (!settings || !form.document_id || !form.table_id) {
|
||||
if (!silent) message.error(t('admin.shippingOrderProfiles.reconstructionBoundariesInvalid'));
|
||||
return;
|
||||
}
|
||||
const requestId = ++reconstructionPreviewRequestId;
|
||||
reconstructing.value = true;
|
||||
reconstructionPreviewFailed.value = false;
|
||||
reconstructionConfirmed.value = false;
|
||||
try {
|
||||
const result = await previewOrderProfileCoordinateReconstruction(form.document_id, form.table_id, settings);
|
||||
if (requestId !== reconstructionPreviewRequestId) return;
|
||||
reconstructionPreview.value = result;
|
||||
resizeColumns(reconstructionPreview.value.column_count);
|
||||
if (multiSubrowEnabled.value) {
|
||||
const fieldCodes = multiSubrowLayouts()?.flatMap((item) => item.column_field_codes.filter((code): code is string => Boolean(code))) || [];
|
||||
const uniqueCodes = [...new Set(fieldCodes)];
|
||||
columnRules.value = uniqueCodes.map((target) => ({ extractor_key: 'direct', target }));
|
||||
}
|
||||
reconstructionFieldSignature.value = coordinateFieldSignature();
|
||||
form.header_row_index = 0;
|
||||
form.data_start_row_index = Math.min(1, Math.max(reconstructionPreview.value.row_count - 1, 0));
|
||||
} catch (error) {
|
||||
if (requestId !== reconstructionPreviewRequestId) return;
|
||||
reconstructionPreviewFailed.value = true;
|
||||
if (!silent) showError(error);
|
||||
} finally {
|
||||
if (requestId === reconstructionPreviewRequestId) reconstructing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 手动重建用于显式复核,并保留完整错误反馈。 */
|
||||
const reconstructTable = () => runReconstructionPreview(false);
|
||||
|
||||
/** 映射编辑停止后自动刷新右侧候选,避免每次选择都产生请求。 */
|
||||
const scheduleReconstructionPreview = () => {
|
||||
if (reconstructionPreviewTimer) window.clearTimeout(reconstructionPreviewTimer);
|
||||
reconstructionPreviewFailed.value = false;
|
||||
reconstructionConfirmed.value = false;
|
||||
if (!multiSubrowEnabled.value || !selectedTable.value?.coordinate_reconstruction_available) return;
|
||||
if (!form.document_id || !form.table_id || !subrowEditors.value[0]?.fields.includes('line_no')) return;
|
||||
if (!coordinateReconstructionSettings(true)) return;
|
||||
reconstructionPreviewTimer = window.setTimeout(() => {
|
||||
reconstructionPreviewTimer = null;
|
||||
void runReconstructionPreview(true);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
/** 转换结构化表单为后端白名单列规则,不提交结构指纹或 HTML。 */
|
||||
@@ -185,6 +519,7 @@ const saveDraft = async () => {
|
||||
profile_code: form.profile_code.trim().toUpperCase(),
|
||||
display_name: form.display_name.trim(),
|
||||
column_rules: form.row_structure === 'preserved' ? normalizedRules() : [],
|
||||
coordinate_reconstruction: reconstructionConfirmed.value ? coordinateReconstructionSettings(true) : null,
|
||||
};
|
||||
if (editingProfileId.value && editingLockVersion.value !== null) {
|
||||
await updateOrderProfileFromSample(editingProfileId.value, {
|
||||
@@ -266,6 +601,26 @@ const removeProfile = async (profile: ShippingOrderDocumentProfile) => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 删除前端专用样本;后端再次校验解析状态、所有权与盲测引用。 */
|
||||
const removeSample = async () => {
|
||||
const sample = selectedSample.value;
|
||||
if (!sample?.can_delete || !window.confirm(t('admin.shippingOrderProfiles.deleteSampleConfirm'))) return;
|
||||
try {
|
||||
await deleteOrderProfileSample(sample.intake_no);
|
||||
await load();
|
||||
form.document_id = samples.value[0]?.document_id || 0;
|
||||
if (!form.document_id) preview.value = null;
|
||||
message.success(t('admin.shippingOrderProfiles.sampleDeleted'));
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
}
|
||||
};
|
||||
|
||||
/** 统一显示上传时间,避免同名样本在下拉框中不可区分。 */
|
||||
const formatSampleTime = (value?: string | null) => (
|
||||
value ? new Intl.DateTimeFormat(undefined, { dateStyle: 'short', timeStyle: 'short' }).format(new Date(value)) : '-'
|
||||
);
|
||||
|
||||
/** 退役当前发布版本;历史运行继续使用冻结快照。 */
|
||||
const retireProfile = async (profile: ShippingOrderDocumentProfile) => {
|
||||
if (!window.confirm(t('admin.shippingOrderProfiles.retireConfirm'))) return;
|
||||
@@ -279,7 +634,29 @@ const retireProfile = async (profile: ShippingOrderDocumentProfile) => {
|
||||
};
|
||||
|
||||
watch(() => form.document_id, loadPreview);
|
||||
watch(() => form.table_id, resetColumns);
|
||||
watch(() => form.table_id, () => {
|
||||
resetCoordinateReconstructionState();
|
||||
resetColumns();
|
||||
});
|
||||
watch(() => form.header_row_index, (headerRowIndex) => {
|
||||
if (form.data_start_row_index <= headerRowIndex) form.data_start_row_index = headerRowIndex + 1;
|
||||
});
|
||||
watch(columnRules, () => {
|
||||
if (reconstructionConfirmed.value && reconstructionFieldSignature.value !== coordinateFieldSignature()) {
|
||||
reconstructionConfirmed.value = false;
|
||||
}
|
||||
}, { deep: true });
|
||||
watch(multiSubrowEnabled, (enabled) => {
|
||||
if (enabled) subrowEditors.value.forEach(syncSubrowFields);
|
||||
reconstructionPreview.value = null;
|
||||
reconstructionPreviewFailed.value = false;
|
||||
reconstructionConfirmed.value = false;
|
||||
scheduleReconstructionPreview();
|
||||
});
|
||||
watch(subrowEditors, () => {
|
||||
if (reconstructionPreview.value) reconstructionConfirmed.value = false;
|
||||
scheduleReconstructionPreview();
|
||||
}, { deep: true });
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
@@ -291,83 +668,242 @@ onMounted(load);
|
||||
<p class="mt-1 text-sm text-slate-500">{{ t('admin.shippingOrderProfiles.subtitle') }}</p>
|
||||
</header>
|
||||
|
||||
<div class="grid gap-6 xl:grid-cols-[420px_minmax(0,1fr)]">
|
||||
<form class="space-y-4 rounded-xl border border-slate-200 bg-white p-5 shadow-sm" @submit.prevent="saveDraft">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div class="space-y-6">
|
||||
<form class="space-y-5 rounded-xl border border-slate-200 bg-white p-5 shadow-sm" @submit.prevent="saveDraft">
|
||||
<div class="flex items-center justify-between gap-3 border-b border-slate-100 pb-4">
|
||||
<h2 class="font-semibold">{{ t(editingProfileId ? 'admin.shippingOrderProfiles.editTitle' : 'admin.shippingOrderProfiles.createTitle') }}</h2>
|
||||
<button v-if="editingProfileId" type="button" class="text-sm text-slate-500" @click="cancelEdit">{{ t('common.cancel') }}</button>
|
||||
<div class="flex items-center gap-2">
|
||||
<button v-if="editingProfileId" type="button" class="h-9 rounded-lg px-3 text-sm text-slate-600 hover:bg-slate-100" @click="cancelEdit">{{ t('common.cancel') }}</button>
|
||||
<button type="submit" :disabled="!canSave || saving" class="h-9 rounded-lg bg-blue-600 px-4 text-sm font-medium text-white hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50">
|
||||
{{ saving ? t('admin.shippingOrderProfiles.saving') : t(editingProfileId ? 'admin.shippingOrderProfiles.updateDraft' : 'admin.shippingOrderProfiles.createDraft') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.sample') }}</span>
|
||||
<select v-model.number="form.document_id" class="w-full rounded-lg border border-slate-300 px-3 py-2">
|
||||
<option :value="0">{{ t('admin.shippingOrderProfiles.selectSample') }}</option>
|
||||
<option v-for="sample in samples" :key="sample.document_id" :value="sample.document_id">
|
||||
{{ sample.filename || `Document ${sample.document_id}` }} ({{ sample.table_count }})
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="rounded-lg border border-dashed border-slate-300 p-3">
|
||||
<p class="text-sm text-slate-600">{{ t('admin.shippingOrderProfiles.uploadSampleHint') }}</p>
|
||||
<input ref="sampleInput" class="sr-only" type="file" accept=".pdf,.eml,application/pdf,message/rfc822" @change="uploadSample" />
|
||||
<button type="button" :disabled="sampleUploading" class="mt-2 rounded border border-blue-300 px-3 py-1.5 text-sm text-blue-700 disabled:opacity-50" @click="sampleInput?.click()">
|
||||
{{ sampleUploading ? t('common.loading') : t('admin.shippingOrderProfiles.uploadSample') }}
|
||||
</button>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div class="max-w-[980px]">
|
||||
<label class="block text-xs font-medium text-slate-600">{{ t('admin.shippingOrderProfiles.sample') }}</label>
|
||||
<div class="mt-1.5 flex flex-wrap items-center gap-2">
|
||||
<input v-model="sampleSearch" class="h-9 w-52 rounded-lg border border-slate-300 px-3 text-sm" :placeholder="t('admin.shippingOrderProfiles.searchSample')" />
|
||||
<select v-model.number="form.document_id" class="h-9 min-w-0 flex-1 rounded-lg border border-slate-300 bg-white px-3 text-sm">
|
||||
<option :value="0">{{ t('admin.shippingOrderProfiles.selectSample') }}</option>
|
||||
<option v-for="sample in visibleSamples" :key="sample.document_id" :value="sample.document_id">
|
||||
{{ sample.filename || `Document ${sample.document_id}` }} · {{ formatSampleTime(sample.created_at) }} · {{ sample.parse_status }} · {{ sample.table_count }} {{ t('admin.shippingOrderProfiles.tablesUnit') }}
|
||||
</option>
|
||||
</select>
|
||||
<input ref="sampleInput" class="sr-only" type="file" accept=".pdf,.eml,application/pdf,message/rfc822" @change="uploadSample" />
|
||||
<button type="button" :disabled="sampleUploading" class="h-9 shrink-0 rounded-lg border border-blue-200 px-3 text-sm font-medium text-blue-700 hover:bg-blue-50 disabled:opacity-50" @click="sampleInput?.click()">
|
||||
{{ sampleUploading ? t('common.loading') : t('admin.shippingOrderProfiles.uploadSample') }}
|
||||
</button>
|
||||
<button type="button" :disabled="!selectedSample?.can_delete" class="h-9 shrink-0 rounded-lg border border-red-200 px-3 text-sm font-medium text-red-600 hover:bg-red-50 disabled:cursor-not-allowed disabled:border-slate-200 disabled:text-slate-400" @click="removeSample">
|
||||
{{ t('admin.shippingOrderProfiles.deleteSample') }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="selectedSample" class="mt-1.5 text-xs text-slate-500">
|
||||
{{ t('admin.shippingOrderProfiles.sampleDetails', { time: formatSampleTime(selectedSample.created_at), status: selectedSample.parse_status }) }}
|
||||
· {{ selectedSample.is_template_sample ? t('admin.shippingOrderProfiles.templateSampleOnly') : t('admin.shippingOrderProfiles.businessSampleProtected') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-end gap-x-3 gap-y-3">
|
||||
<label class="w-44 text-xs font-medium text-slate-600">
|
||||
<span class="mb-1.5 block">{{ t('admin.shippingOrderProfiles.table') }}</span>
|
||||
<select v-model="form.table_id" class="h-9 w-full rounded-lg border border-slate-300 bg-white px-2.5 text-sm" :disabled="!preview">
|
||||
<option value="">{{ t('admin.shippingOrderProfiles.selectTable') }}</option>
|
||||
<option v-for="table in preview?.tables || []" :key="table.table_id" :value="table.table_id">P{{ table.page_no }} · {{ table.row_count }}×{{ table.column_count }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="w-52 text-xs font-medium text-slate-600">
|
||||
<span class="mb-1.5 block">{{ t('admin.shippingOrderProfiles.schema') }}</span>
|
||||
<select v-model.number="form.schema_version_id" :disabled="Boolean(editingProfileId)" class="h-9 w-full rounded-lg border border-slate-300 bg-white px-2.5 text-sm disabled:bg-slate-100">
|
||||
<option v-for="schema in publishedSchemas" :key="schema.id" :value="schema.id">v{{ schema.version }} · {{ schema.status }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="w-44 text-xs font-medium text-slate-600">
|
||||
<span class="mb-1.5 block">{{ t('admin.shippingOrderProfiles.code') }}</span>
|
||||
<input v-model="form.profile_code" :disabled="Boolean(editingProfileId)" class="h-9 w-full rounded-lg border border-slate-300 px-2.5 text-sm disabled:bg-slate-100" />
|
||||
</label>
|
||||
<label class="w-72 text-xs font-medium text-slate-600">
|
||||
<span class="mb-1.5 block">{{ t('admin.shippingOrderProfiles.name') }}</span>
|
||||
<input v-model="form.display_name" class="h-9 w-full rounded-lg border border-slate-300 px-2.5 text-sm" />
|
||||
</label>
|
||||
<label class="mb-2 flex items-center gap-2 whitespace-nowrap text-sm text-slate-700"><input v-model="form.drop_zero_qty" type="checkbox" />{{ t('admin.shippingOrderProfiles.dropZeroQty') }}</label>
|
||||
</div>
|
||||
|
||||
<details class="max-w-[980px] rounded-lg border border-slate-200 bg-slate-50 px-3 py-2">
|
||||
<summary class="cursor-pointer text-sm font-medium text-slate-700">{{ t('admin.shippingOrderProfiles.advancedSettings') }}</summary>
|
||||
<div class="mt-3 flex flex-wrap items-end gap-3 border-t border-slate-200 pt-3">
|
||||
<label class="w-72 text-xs font-medium text-slate-600"><span class="mb-1.5 block">{{ t('admin.shippingOrderProfiles.rowStructure') }}</span><select v-model="form.row_structure" class="h-9 w-full rounded-lg border border-slate-300 bg-white px-2.5 text-sm"><option value="preserved">{{ t('admin.shippingOrderProfiles.rowPreserved') }}</option><option value="unsupported_row_structure">{{ t('admin.shippingOrderProfiles.rowUnsupported') }}</option></select></label>
|
||||
<label class="w-36 text-xs font-medium text-slate-600"><span class="mb-1.5 block">{{ t('admin.shippingOrderProfiles.headerRow') }}</span><input v-model.number="form.header_row_index" type="number" min="0" :max="Math.max((displayedTable?.row_count || 1) - 2, 0)" class="h-9 w-full rounded-lg border border-slate-300 px-2.5 text-sm" /></label>
|
||||
<label class="w-32 text-xs font-medium text-slate-600"><span class="mb-1.5 block">{{ t('admin.shippingOrderProfiles.dataRow') }}</span><input v-model.number="form.data_start_row_index" type="number" :min="form.header_row_index + 1" :max="Math.max((displayedTable?.row_count || 1) - 1, 0)" class="h-9 w-full rounded-lg border border-slate-300 px-2.5 text-sm" /></label>
|
||||
<label v-if="editingProfileId" class="w-80 text-xs font-medium text-slate-600"><span class="mb-1.5 block">{{ t('admin.shippingOrderProfiles.changeNote') }}</span><input v-model="form.change_note" class="h-9 w-full rounded-lg border border-slate-300 px-2.5 text-sm" /></label>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.table') }}</span>
|
||||
<select v-model="form.table_id" class="w-full rounded-lg border border-slate-300 px-3 py-2" :disabled="!preview">
|
||||
<option value="">{{ t('admin.shippingOrderProfiles.selectTable') }}</option>
|
||||
<option v-for="table in preview?.tables || []" :key="table.table_id" :value="table.table_id">
|
||||
P{{ table.page_no }} · {{ table.row_count }}×{{ table.column_count }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<label class="text-sm"><span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.code') }}</span><input v-model="form.profile_code" :disabled="Boolean(editingProfileId)" class="w-full rounded-lg border border-slate-300 px-3 py-2 disabled:bg-slate-100" /></label>
|
||||
<label class="text-sm"><span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.name') }}</span><input v-model="form.display_name" class="w-full rounded-lg border border-slate-300 px-3 py-2" /></label>
|
||||
|
||||
<div v-if="selectedTable && !selectedTable.profile_creation_allowed" class="overflow-hidden rounded-xl border border-slate-200 bg-slate-50">
|
||||
<div class="flex items-start gap-3 border-b border-slate-200 bg-white px-4 py-3">
|
||||
<span class="mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-amber-100 text-sm font-bold text-amber-700">!</span>
|
||||
<div>
|
||||
<p class="text-sm font-semibold text-slate-900">{{ t('admin.shippingOrderProfiles.reconstructionRequired') }}</p>
|
||||
<p v-if="selectedTable.coordinate_reconstruction_available" class="mt-1 text-xs leading-5 text-slate-500">{{ t('admin.shippingOrderProfiles.autoSuggestLayoutHint') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<template v-if="selectedTable.coordinate_reconstruction_available">
|
||||
<label class="flex items-center gap-2 border-b border-slate-200 px-4 py-2.5 text-sm font-medium text-slate-700">
|
||||
<input v-model="multiSubrowEnabled" type="checkbox" />
|
||||
{{ t('admin.shippingOrderProfiles.multiSubrowEnabled') }}
|
||||
</label>
|
||||
<label v-if="!multiSubrowEnabled" class="block p-4 text-xs"><span class="mb-1 block">{{ t('admin.shippingOrderProfiles.columnBoundaries') }}</span><input v-model="columnBoundaryInput" class="w-full rounded-lg border border-slate-300 bg-white px-3 py-2" /></label>
|
||||
<div v-else class="p-3">
|
||||
<div class="grid min-w-0 gap-3 lg:grid-cols-[180px_minmax(0,1fr)]">
|
||||
<aside class="overflow-hidden rounded-lg border border-slate-200 bg-white">
|
||||
<div class="border-b border-slate-200 px-3 py-2 text-xs font-semibold text-slate-600">{{ t('admin.shippingOrderProfiles.physicalRows') }}</div>
|
||||
<div class="p-1.5">
|
||||
<button v-for="(editor, editorIndex) in subrowEditors" :key="editor.row_offset" type="button" class="mb-1 flex h-9 w-full items-center justify-between rounded-md px-2.5 text-left text-sm last:mb-0" :class="selectedSubrowIndex === editorIndex ? 'bg-blue-50 font-medium text-blue-700' : 'text-slate-700 hover:bg-slate-50'" @click="selectedSubrowIndex = editorIndex">
|
||||
<span>{{ t(editorIndex === 0 ? 'admin.shippingOrderProfiles.firstSubrow' : 'admin.shippingOrderProfiles.followingSubrow', { index: editorIndex + 1 }) }}</span>
|
||||
<span class="text-xs opacity-60">{{ editor.fields.length }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex border-t border-slate-200 p-1.5">
|
||||
<button type="button" class="h-8 flex-1 rounded-md text-xs font-medium text-blue-700 hover:bg-blue-50" @click="addSubrow">+ {{ t('admin.shippingOrderProfiles.addSubrow') }}</button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<section v-if="selectedSubrow" class="min-w-0 overflow-hidden rounded-lg border border-slate-200 bg-white">
|
||||
<div class="flex flex-wrap items-center justify-between gap-2 border-b border-slate-200 px-3 py-2">
|
||||
<div><span class="text-sm font-semibold text-slate-900">{{ t(selectedSubrowIndex === 0 ? 'admin.shippingOrderProfiles.firstSubrow' : 'admin.shippingOrderProfiles.followingSubrow', { index: selectedSubrowIndex + 1 }) }}</span><span class="ml-2 text-xs text-slate-400">{{ selectedSubrow.fields.length }} {{ t('admin.shippingOrderProfiles.columnsUnit') }}</span></div>
|
||||
<div class="flex items-center gap-1.5">
|
||||
<button type="button" :disabled="suggestingSubrowIndex !== null" class="h-8 rounded-md border border-blue-200 px-2.5 text-xs font-medium text-blue-700 hover:bg-blue-50 disabled:opacity-50" @click="suggestCurrentSubrow">{{ suggestingSubrowIndex === selectedSubrow.row_offset ? t('common.loading') : t('admin.shippingOrderProfiles.suggestCurrentRow') }}</button>
|
||||
<button v-if="selectedSubrowIndex > 0" type="button" class="h-8 rounded-md px-2.5 text-xs font-medium text-red-600 hover:bg-red-50" @click="removeSubrow(selectedSubrowIndex)">{{ t('common.delete') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-3">
|
||||
<div class="mb-2 flex items-center justify-between text-[11px] font-medium text-slate-500">
|
||||
<span>{{ t('admin.shippingOrderProfiles.visualBoundaries') }}</span>
|
||||
<span>{{ t('admin.shippingOrderProfiles.dragBoundaryHint') }}</span>
|
||||
</div>
|
||||
<div class="relative h-12 rounded-md border border-slate-300 bg-slate-50 px-1 pt-1">
|
||||
<div class="flex h-7 overflow-hidden rounded border border-white bg-white shadow-sm">
|
||||
<div v-for="(_, index) in selectedSubrow.fields" :key="index" class="flex min-w-0 items-center justify-center border-r border-blue-100 bg-blue-50/60 px-1 text-[10px] font-medium text-blue-700 last:border-r-0" :style="{ width: `${(subrowBoundaries(selectedSubrow)[index + 1]! - subrowBoundaries(selectedSubrow)[index]!) * 100}%` }">
|
||||
<span class="truncate">{{ index + 1 }} · {{ Math.round((subrowBoundaries(selectedSubrow)[index + 1]! - subrowBoundaries(selectedSubrow)[index]!) * 100) }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
<template v-for="(boundary, boundaryIndex) in subrowBoundaries(selectedSubrow).slice(1, -1)" :key="boundaryIndex">
|
||||
<span class="pointer-events-none absolute bottom-1 top-1 w-px bg-blue-500" :style="{ left: `${boundary * 100}%` }" />
|
||||
<input :value="boundary" type="range" min="0.01" max="0.99" step="0.01" class="boundary-slider absolute inset-x-0 top-5 h-5 w-full" :aria-label="t('admin.shippingOrderProfiles.boundaryHandle', { index: boundaryIndex + 1 })" @input="updateSubrowBoundary(selectedSubrow, boundaryIndex + 1, ($event.target as HTMLInputElement).value)" />
|
||||
</template>
|
||||
</div>
|
||||
<div class="mt-3 flex gap-2 overflow-x-auto pb-2">
|
||||
<article v-for="(_, index) in selectedSubrow.fields" :key="index" class="w-52 shrink-0 rounded-lg border border-slate-200 bg-slate-50 p-2.5">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="text-xs font-semibold text-slate-700">{{ t('admin.shippingOrderProfiles.subrowColumn', { index: index + 1 }) }}</span>
|
||||
<div class="flex items-center gap-1">
|
||||
<button type="button" :disabled="!canSplitSubrowColumn(selectedSubrow, index)" class="rounded px-1.5 py-0.5 text-[11px] font-medium text-blue-700 hover:bg-blue-50 disabled:cursor-not-allowed disabled:text-slate-300 disabled:hover:bg-transparent" @click="addSubrowColumn(selectedSubrow, index)">+ {{ t('admin.shippingOrderProfiles.insertColumnAfter') }}</button>
|
||||
<button v-if="selectedSubrow.fields.length > 1" type="button" class="rounded px-1.5 py-0.5 text-[11px] text-red-600 hover:bg-red-50" @click="removeSubrowColumn(selectedSubrow, index)">{{ t('common.delete') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2 truncate rounded-md bg-white px-2 py-1.5 text-xs text-slate-500" :title="selectedSubrow.samples[index]?.join(' / ') || '-'">{{ selectedSubrow.samples[index]?.join(' / ') || '-' }}</div>
|
||||
<select v-model="selectedSubrow.fields[index]" class="mt-2 h-8 w-full rounded-md border border-slate-300 bg-white px-2 text-xs">
|
||||
<option :value="null">{{ t('admin.shippingOrderProfiles.ignoreColumn') }}</option>
|
||||
<option v-for="field in lineFields" :key="field.field_id" :value="field.field_code">{{ field.display_name }} · {{ field.field_code }}</option>
|
||||
</select>
|
||||
<div class="mt-2 font-mono text-[10px] text-slate-400">{{ Math.round(subrowBoundaries(selectedSubrow)[index]! * 100) }}%–{{ Math.round(subrowBoundaries(selectedSubrow)[index + 1]! * 100) }}%</div>
|
||||
</article>
|
||||
</div>
|
||||
<details class="mt-2 text-[11px] text-slate-500">
|
||||
<summary class="cursor-pointer select-none font-medium">{{ t('admin.shippingOrderProfiles.preciseBoundaryValues') }}</summary>
|
||||
<input v-model="selectedSubrow.boundaries" class="mt-1.5 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 font-mono text-[11px]" @change="syncSubrowFields(selectedSubrow)" />
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div class="mt-3 flex flex-wrap items-center gap-2 rounded-lg border border-slate-200 bg-white p-2">
|
||||
<button type="button" :disabled="suggesting" class="h-8 rounded-md border border-blue-200 px-2.5 text-xs font-medium text-blue-700 hover:bg-blue-50 disabled:opacity-50" @click="suggestLayouts">{{ suggesting ? t('common.loading') : t('admin.shippingOrderProfiles.autoSuggestAllRows') }}</button>
|
||||
<button type="button" :disabled="reconstructing" class="h-8 rounded-md bg-blue-600 px-3 text-xs font-medium text-white hover:bg-blue-700 disabled:opacity-50" @click="reconstructTable">{{ t('admin.shippingOrderProfiles.reconstructTable') }}</button>
|
||||
</div>
|
||||
<aside class="mt-3 min-w-0 overflow-hidden rounded-lg border border-slate-200 bg-white">
|
||||
<div class="flex items-center justify-between gap-3 border-b border-slate-200 px-3 py-2">
|
||||
<div>
|
||||
<h3 class="text-sm font-semibold text-slate-900">{{ t('admin.shippingOrderProfiles.livePreview') }}</h3>
|
||||
<p class="mt-0.5 text-[11px]" :class="reconstructionPreviewFailed ? 'text-red-600' : reconstructing ? 'text-blue-600' : 'text-slate-500'">{{ t(`admin.shippingOrderProfiles.${livePreviewStatusKey}`) }}</p>
|
||||
</div>
|
||||
<label v-if="reconstructionPreview" class="flex shrink-0 items-center gap-1.5 text-xs font-medium text-slate-700"><input v-model="reconstructionConfirmed" type="checkbox" />{{ t('admin.shippingOrderProfiles.confirmPreview') }}</label>
|
||||
</div>
|
||||
<div class="max-h-[52vh] min-h-56 overflow-auto">
|
||||
<table v-if="reconstructionPreview" class="min-w-full border-collapse text-xs">
|
||||
<tbody>
|
||||
<tr v-for="(row, rowIndex) in reconstructionPreview.rows" :key="rowIndex" :class="displayedRowRole(rowIndex) === 'deleted' ? 'bg-red-50 text-slate-500' : rowIndex === form.header_row_index ? 'bg-blue-50 font-semibold' : ''">
|
||||
<td class="sticky left-0 min-w-20 border border-slate-200 bg-slate-50 px-2 py-1.5 text-[11px] text-slate-500">
|
||||
<div>{{ t(`admin.shippingOrderProfiles.rowRole.${displayedRowRole(rowIndex)}`) }}</div>
|
||||
<div v-if="displayedSourceRows(rowIndex).length" class="mt-0.5">{{ displayedSourceRows(rowIndex).map((value) => value + 1).join(', ') }}</div>
|
||||
</td>
|
||||
<td v-for="(cell, columnIndex) in row" :key="columnIndex" class="max-w-52 whitespace-nowrap border border-slate-200 px-2 py-1.5" :title="cell">{{ cell }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div v-else class="flex min-h-56 items-center justify-center px-6 text-center text-xs leading-5 text-slate-500">{{ t(`admin.shippingOrderProfiles.${livePreviewStatusKey}`) }}</div>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2 border-t border-slate-200 bg-white px-4 py-2.5">
|
||||
<p class="text-[11px] text-slate-500">{{ t('admin.shippingOrderProfiles.multiSubrowHint') }}</p>
|
||||
<p v-if="reconstructionPreview && !reconstructionMatchesFields" class="text-[11px] font-medium text-amber-700">{{ t('admin.shippingOrderProfiles.rebuildAfterFieldMapping') }}</p>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 p-4">
|
||||
<p class="text-xs text-amber-900">{{ t('admin.shippingOrderProfiles.reconstructionUnavailable') }}</p>
|
||||
<button type="button" :disabled="ocrGenerating" class="rounded-lg border border-amber-500 bg-white px-3 py-2 text-sm text-amber-900 disabled:opacity-50" @click="generateOcrEvidence">{{ ocrGenerating ? t('common.loading') : t('admin.shippingOrderProfiles.generateOcrEvidence') }}</button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.schema') }}</span>
|
||||
<select v-model.number="form.schema_version_id" :disabled="Boolean(editingProfileId)" class="w-full rounded-lg border border-slate-300 px-3 py-2 disabled:bg-slate-100">
|
||||
<option v-for="schema in publishedSchemas" :key="schema.id" :value="schema.id">v{{ schema.version }} · {{ schema.status }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.rowStructure') }}</span>
|
||||
<select v-model="form.row_structure" class="w-full rounded-lg border border-slate-300 px-3 py-2">
|
||||
<option value="preserved">{{ t('admin.shippingOrderProfiles.rowPreserved') }}</option>
|
||||
<option value="unsupported_row_structure">{{ t('admin.shippingOrderProfiles.rowUnsupported') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<label class="text-sm"><span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.headerRow') }}</span><input v-model.number="form.header_row_index" type="number" min="0" class="w-full rounded-lg border border-slate-300 px-3 py-2" /></label>
|
||||
<label class="text-sm"><span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.dataRow') }}</span><input v-model.number="form.data_start_row_index" type="number" min="1" class="w-full rounded-lg border border-slate-300 px-3 py-2" /></label>
|
||||
</div>
|
||||
<label class="flex items-center gap-2 text-sm"><input v-model="form.drop_zero_qty" type="checkbox" />{{ t('admin.shippingOrderProfiles.dropZeroQty') }}</label>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block text-slate-600">{{ t('admin.shippingOrderProfiles.changeNote') }}</span>
|
||||
<textarea v-model="form.change_note" rows="2" class="w-full rounded-lg border border-slate-300 px-3 py-2" />
|
||||
</label>
|
||||
<p v-if="duplicateTargets.length" class="rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700">
|
||||
{{ t('admin.shippingOrderProfiles.duplicateTargets', { fields: duplicateTargets.join(', ') }) }}
|
||||
</p>
|
||||
<p v-if="selectedTable && !selectedTable.profile_creation_allowed" class="rounded-lg bg-amber-50 px-3 py-2 text-sm text-amber-800">
|
||||
<p v-if="selectedTable && !selectedTable.profile_creation_allowed && !reconstructionConfirmed" class="rounded-lg bg-amber-50 px-3 py-2 text-sm text-amber-800">
|
||||
{{ t('admin.shippingOrderProfiles.structureBlocked') }}
|
||||
</p>
|
||||
<button type="submit" :disabled="!canSave || saving" class="w-full rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white disabled:opacity-50">
|
||||
{{ saving ? t('admin.shippingOrderProfiles.saving') : t(editingProfileId ? 'admin.shippingOrderProfiles.updateDraft' : 'admin.shippingOrderProfiles.createDraft') }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="min-w-0 space-y-4">
|
||||
<div class="overflow-auto rounded-xl border border-slate-200 bg-white shadow-sm">
|
||||
<table v-if="selectedTable" class="min-w-full border-collapse text-sm">
|
||||
<div v-if="showStandardPreview" class="min-w-0 space-y-4">
|
||||
<section v-if="displayedTable && form.header_row_index > 0 && form.row_structure === 'preserved'" class="overflow-hidden rounded-xl border border-blue-200 bg-white shadow-sm">
|
||||
<div class="border-b border-blue-100 bg-blue-50 px-4 py-3">
|
||||
<h3 class="text-sm font-semibold text-slate-900">{{ t('admin.shippingOrderProfiles.multiRowHeaderMapping') }}</h3>
|
||||
<p class="mt-1 text-xs text-slate-600">{{ t('admin.shippingOrderProfiles.multiRowHeaderHint', { end: form.header_row_index }) }}</p>
|
||||
</div>
|
||||
<div class="flex gap-2 overflow-x-auto p-3">
|
||||
<article v-for="(label, columnIndex) in mergedHeaderLabels" :key="columnIndex" class="w-52 shrink-0 rounded-lg border border-slate-200 bg-slate-50 p-2.5">
|
||||
<div class="text-[11px] font-semibold text-slate-500">{{ t('admin.shippingOrderProfiles.mergedHeaderColumn', { index: columnIndex + 1 }) }}</div>
|
||||
<div class="mt-1 min-h-10 break-words text-xs font-medium leading-5 text-slate-800">{{ label || '-' }}</div>
|
||||
<select v-model="columnRule(columnIndex).target" class="mt-2 h-8 w-full rounded-md border border-slate-300 bg-white px-2 text-xs">
|
||||
<option value="">{{ t('admin.shippingOrderProfiles.ignoreColumn') }}</option>
|
||||
<option v-for="field in lineFields" :key="field.field_id" :value="field.field_code">{{ field.display_name }} · {{ field.field_code }}</option>
|
||||
</select>
|
||||
<select v-model="columnRule(columnIndex).extractor_key" class="mt-2 h-8 w-full rounded-md border border-slate-300 bg-white px-2 text-xs">
|
||||
<option value="direct">{{ t('admin.shippingOrderProfiles.direct') }}</option>
|
||||
<option value="temp_internal_parts" :disabled="!compositeExtractorAvailable">{{ t('admin.shippingOrderProfiles.compositePart') }}</option>
|
||||
</select>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
<div class="max-h-[70vh] overflow-auto rounded-xl border border-slate-200 bg-white shadow-sm">
|
||||
<div v-if="reconstructionPreview" class="border-b border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900">{{ t('admin.shippingOrderProfiles.reconstructionPreview') }}</div>
|
||||
<table v-if="displayedTable" class="min-w-full border-collapse text-sm">
|
||||
<tbody>
|
||||
<tr v-for="(row, rowIndex) in selectedTable.rows" :key="rowIndex" :class="rowIndex === form.header_row_index ? 'bg-blue-50 font-semibold' : ''">
|
||||
<td class="sticky left-0 border border-slate-200 bg-slate-50 px-2 py-2 text-xs text-slate-500">{{ rowIndex }}</td>
|
||||
<tr v-for="(row, rowIndex) in displayedTable.rows" :key="rowIndex" :class="rowIndex <= form.header_row_index ? 'bg-blue-50 font-semibold' : displayedRowRole(rowIndex) === 'deleted' ? 'bg-red-50 text-slate-500' : ''">
|
||||
<td class="sticky left-0 min-w-24 border border-slate-200 bg-slate-50 px-2 py-2 text-xs text-slate-500">
|
||||
<div>{{ rowIndex }}</div>
|
||||
<div v-if="reconstructionPreview" class="mt-1 font-medium" :class="displayedRowRole(rowIndex) === 'deleted' ? 'text-red-600' : 'text-emerald-700'">
|
||||
{{ t(`admin.shippingOrderProfiles.rowRole.${displayedRowRole(rowIndex)}`) }}
|
||||
</div>
|
||||
<div v-if="displayedSourceRows(rowIndex).length" class="mt-1 text-[11px]">
|
||||
{{ t('admin.shippingOrderProfiles.sourceRows', { rows: displayedSourceRows(rowIndex).map((value) => value + 1).join(', ') }) }}
|
||||
</div>
|
||||
</td>
|
||||
<td v-for="(cell, columnIndex) in row" :key="columnIndex" class="max-w-[260px] border border-slate-200 px-3 py-2 align-top">
|
||||
<div class="break-words">{{ cell }}</div>
|
||||
<div v-if="rowIndex === form.header_row_index && form.row_structure === 'preserved'" class="mt-2 space-y-1">
|
||||
<div v-if="rowIndex === form.header_row_index && form.header_row_index === 0 && form.row_structure === 'preserved' && !multiSubrowEnabled" class="mt-2 space-y-1">
|
||||
<div v-if="columnRule(columnIndex).extractor_key === 'temp_internal_parts'" class="rounded bg-slate-100 px-2 py-1 text-xs text-slate-600">
|
||||
customer_part_number + part_number
|
||||
</div>
|
||||
@@ -380,6 +916,9 @@ onMounted(load);
|
||||
<option value="temp_internal_parts" :disabled="!compositeExtractorAvailable">{{ t('admin.shippingOrderProfiles.compositePart') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div v-else-if="rowIndex === form.header_row_index && multiSubrowEnabled" class="mt-2 rounded bg-slate-100 px-2 py-1 text-xs text-slate-600">
|
||||
{{ cell }}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -394,7 +933,7 @@ onMounted(load);
|
||||
<div v-if="loading" class="p-6 text-sm text-slate-500">{{ t('common.loading') }}</div>
|
||||
<div v-else class="divide-y divide-slate-100">
|
||||
<div v-for="profile in profiles" :key="profile.id" class="flex flex-wrap items-center justify-between gap-3 px-5 py-4">
|
||||
<div><div class="font-medium">{{ profile.display_name }} · v{{ profile.version }}</div><div class="text-xs text-slate-500">{{ profile.profile_code }} · Schema v{{ profile.schema_version }} · {{ profile.status }}<span v-if="profile.change_note"> · {{ profile.change_note }}</span></div></div>
|
||||
<div><div class="font-medium">{{ profile.display_name }} · v{{ profile.version }} <span v-if="currentProfileIds.has(profile.id)" class="rounded bg-emerald-100 px-2 py-0.5 text-xs font-medium text-emerald-800">{{ t('admin.shippingOrderProfiles.currentVersion') }}</span></div><div class="text-xs text-slate-500">{{ profile.profile_code }} · Schema v{{ profile.schema_version }} · {{ profile.status }}<span v-if="profile.published_at"> · {{ t('admin.shippingOrderProfiles.publishedAt', { time: formatSampleTime(profile.published_at) }) }}</span><span v-if="profile.change_note"> · {{ profile.change_note }}</span></div></div>
|
||||
<div class="flex gap-2">
|
||||
<button v-if="profile.status === 'draft'" class="rounded border border-slate-300 px-3 py-1.5 text-sm text-slate-700" @click="editDraft(profile)">{{ t('common.edit') }}</button>
|
||||
<button v-if="profile.status === 'draft'" class="rounded border border-blue-300 px-3 py-1.5 text-sm text-blue-700" @click="publishProfile(profile)">{{ t('admin.shippingOrderProfiles.publish') }}</button>
|
||||
@@ -408,3 +947,45 @@ onMounted(load);
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.boundary-slider {
|
||||
appearance: none;
|
||||
background: transparent;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.boundary-slider::-webkit-slider-runnable-track {
|
||||
height: 1px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.boundary-slider::-webkit-slider-thumb {
|
||||
width: 12px;
|
||||
height: 20px;
|
||||
margin-top: -10px;
|
||||
appearance: none;
|
||||
border: 2px solid white;
|
||||
border-radius: 4px;
|
||||
background: #2563eb;
|
||||
box-shadow: 0 0 0 1px #2563eb;
|
||||
cursor: ew-resize;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.boundary-slider::-moz-range-track {
|
||||
height: 1px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.boundary-slider::-moz-range-thumb {
|
||||
width: 10px;
|
||||
height: 18px;
|
||||
border: 2px solid white;
|
||||
border-radius: 4px;
|
||||
background: #2563eb;
|
||||
box-shadow: 0 0 0 1px #2563eb;
|
||||
cursor: ew-resize;
|
||||
pointer-events: auto;
|
||||
}
|
||||
</style>
|
||||
+24
-1
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.spec.ts
|
||||
* 用途:验证可视化订单模板表单只生成受控规则并阻止目标字段重复映射。
|
||||
* 用途:验证可视化订单模板表单生成受控规则,并确保切换样本时配置入口不会消失。
|
||||
* 依赖:Vitest、orderProfileForm.utils。
|
||||
* 逻辑:覆盖 direct、复合解析器开关及跨列冲突,避免无效配置进入后端。
|
||||
*/
|
||||
@@ -9,6 +9,8 @@ import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
buildOrderProfileColumnRules,
|
||||
findDuplicateOrderProfileTargets,
|
||||
mergeOrderProfileHeaderLabels,
|
||||
shouldShowStandardOrderProfilePreview,
|
||||
} from './orderProfileForm.utils';
|
||||
|
||||
describe('order profile form rules', () => {
|
||||
@@ -45,4 +47,25 @@ describe('order profile form rules', () => {
|
||||
{ extractor_key: 'temp_internal_parts', target: '' },
|
||||
], false)).toEqual([]);
|
||||
});
|
||||
|
||||
it('keeps directly configurable tables visible despite stale multi-row state', () => {
|
||||
// 断言上一张表残留的多物理行开关不能隐藏当前可直接配置的表格。
|
||||
expect(shouldShowStandardOrderProfilePreview(true, true, true)).toBe(true);
|
||||
expect(shouldShowStandardOrderProfilePreview(false, true, true)).toBe(false);
|
||||
});
|
||||
|
||||
it('merges every physical header row into stable logical column labels', () => {
|
||||
const labels = mergeOrderProfileHeaderLabels([
|
||||
['Item', 'Material', 'Vendor Part Number'],
|
||||
['Item', 'Description', ''],
|
||||
['IncoTerm', '', 'Manufacturer Part'],
|
||||
], 2, 3);
|
||||
|
||||
// 断言同列跨行文字按顺序合并,并去掉展开 rowspan 产生的重复标签。
|
||||
expect(labels).toEqual([
|
||||
'Item / IncoTerm',
|
||||
'Material / Description',
|
||||
'Vendor Part Number / Manufacturer Part',
|
||||
]);
|
||||
});
|
||||
});
|
||||
+34
-1
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.ts
|
||||
* 用途:构造可视化订单模板的白名单列规则,并在提交前发现目标字段冲突。
|
||||
* 用途:构造可视化订单模板的白名单列规则,并控制样本表格配置区的安全显示。
|
||||
* 依赖:订单 Profile DTO。
|
||||
* 逻辑:页面状态只允许 direct 或已注册复合解析器;同一目标字段跨列只能出现一次。
|
||||
*/
|
||||
@@ -12,6 +12,39 @@ export interface OrderProfileColumnSelection {
|
||||
target: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否显示普通表格预览;可直接创建 Profile 的表格不受上一张表多物理行状态影响。
|
||||
* @param profileCreationAllowed - 当前表格是否可直接创建 Profile
|
||||
* @param multiSubrowEnabled - 当前是否启用多物理行坐标重建
|
||||
* @param coordinateReconstructionAvailable - 当前表格是否具备坐标重建证据
|
||||
* @returns 为 true 时显示普通表格及字段配置入口
|
||||
*/
|
||||
export const shouldShowStandardOrderProfilePreview = (
|
||||
profileCreationAllowed: boolean,
|
||||
multiSubrowEnabled: boolean,
|
||||
coordinateReconstructionAvailable: boolean,
|
||||
): boolean => (
|
||||
profileCreationAllowed || !multiSubrowEnabled || !coordinateReconstructionAvailable
|
||||
);
|
||||
|
||||
/**
|
||||
* 将表头区域内同一逻辑列的多行文字合并为虚拟列头,重复的 rowspan/colspan 文本只保留一次。
|
||||
* @param rows - 后端展开后的样本表格行
|
||||
* @param headerRowIndex - 最后一行表头的零基索引
|
||||
* @param columnCount - 表格逻辑列数
|
||||
* @returns 与逻辑列一一对应的合并表头文字
|
||||
*/
|
||||
export const mergeOrderProfileHeaderLabels = (
|
||||
rows: string[][], headerRowIndex: number, columnCount: number,
|
||||
): string[] => Array.from({ length: columnCount }, (_, columnIndex) => {
|
||||
const labels: string[] = [];
|
||||
rows.slice(0, Math.max(headerRowIndex + 1, 0)).forEach((row) => {
|
||||
const label = String(row[columnIndex] || '').replace(/\s+/g, ' ').trim();
|
||||
if (label && !labels.some((item) => item.toLowerCase() === label.toLowerCase())) labels.push(label);
|
||||
});
|
||||
return labels.join(' / ');
|
||||
});
|
||||
|
||||
/** 将逐列选择转换为后端白名单规则;不可用的复合解析器不会进入请求。 */
|
||||
export const buildOrderProfileColumnRules = (
|
||||
selections: OrderProfileColumnSelection[], compositeExtractorAvailable: boolean,
|
||||
|
||||
+104
-1
@@ -15,6 +15,7 @@ import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
createShippingOrderField,
|
||||
createShippingOrderSchemaDraft,
|
||||
createShippingFulfillmentPolicyDraft,
|
||||
deleteShippingOrderField,
|
||||
deleteShippingOrderSchemaDraft,
|
||||
getShippingOrderSchemaVersion,
|
||||
@@ -22,10 +23,12 @@ import {
|
||||
getShippingOrderSchemaVersionUsage,
|
||||
getShippingOrderExtractionAudit,
|
||||
getShippingOrderSchemaState,
|
||||
getShippingFulfillmentPolicyState,
|
||||
initializeShippingOrderSchema,
|
||||
listShippingOrderSchemaVersions,
|
||||
listShippingOrderSchemaAuditEvents,
|
||||
publishShippingOrderSchemaDraft,
|
||||
publishShippingFulfillmentPolicy,
|
||||
reorderShippingOrderFields,
|
||||
saveShippingOrderSchemaDraft,
|
||||
saveShippingOrderAutoCreationPolicy,
|
||||
@@ -48,6 +51,7 @@ import type {
|
||||
ShippingOrderSchemaVersionDiff,
|
||||
ShippingOrderSchemaVersionUsage,
|
||||
ShippingOrderExtractionAudit,
|
||||
ShippingFulfillmentPolicyState,
|
||||
} from '@/features/admin/types/shipping-order-schema.types';
|
||||
|
||||
type DraftFieldEditor = ShippingOrderFieldConfig & { enabled: boolean };
|
||||
@@ -100,6 +104,9 @@ const selectedVersionUsage = ref<ShippingOrderSchemaVersionUsage | null>(null);
|
||||
const extractionAuditOpen = ref(false);
|
||||
const extractionAuditLoading = ref(false);
|
||||
const selectedExtractionAudit = ref<ShippingOrderExtractionAudit | null>(null);
|
||||
const fulfillmentPolicyState = ref<ShippingFulfillmentPolicyState | null>(null);
|
||||
const fulfillmentPolicyNote = ref('');
|
||||
const fulfillmentBindings = reactive<Record<string, string>>({});
|
||||
|
||||
const draft = computed(() => state.value?.versions.find((item) => item.status === 'draft') || null);
|
||||
const published = computed(() => state.value?.versions.find((item) => item.status === 'published') || null);
|
||||
@@ -125,6 +132,14 @@ const selectedContextOption = computed(() => activeContextOptions.value.find(
|
||||
const selectedExposurePolicies = computed(() => (
|
||||
selectedContextOption.value?.allowed_dify_exposure_policies || ['never']
|
||||
));
|
||||
const publishedPolicy = computed(() => fulfillmentPolicyState.value?.policies.find((item) => item.status === 'published') || null);
|
||||
const draftPolicy = computed(() => fulfillmentPolicyState.value?.policies.find((item) => item.status === 'draft') || null);
|
||||
const policyFieldsFor = (capability: { scope: string; value_type: string }) => (state.value?.fields || []).filter((field) => (
|
||||
field.status === 'active'
|
||||
&& published.value?.definition?.fields.some((config) => config.field_id === field.id && config.enabled !== false)
|
||||
&& field.scope === capability.scope
|
||||
&& field.value_type === capability.value_type
|
||||
));
|
||||
|
||||
/** 左侧字段字典按显示名称和字段编号搜索,并保持通用上下文/订单信息/货品明细分组。 */
|
||||
const groupedFields = computed(() => {
|
||||
@@ -482,7 +497,13 @@ const syncDraftFields = (): void => {
|
||||
const load = async (): Promise<void> => {
|
||||
loading.value = true;
|
||||
try {
|
||||
state.value = await getShippingOrderSchemaState();
|
||||
const schemaState = await getShippingOrderSchemaState();
|
||||
state.value = schemaState;
|
||||
fulfillmentPolicyState.value = schemaState.schema ? await getShippingFulfillmentPolicyState() : null;
|
||||
const source = draftPolicy.value || publishedPolicy.value;
|
||||
for (const binding of source?.definition.field_bindings || []) {
|
||||
fulfillmentBindings[binding.capability_code] = binding.field_id;
|
||||
}
|
||||
syncDraftFields();
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
@@ -491,6 +512,43 @@ const load = async (): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 创建策略草稿前只提交受控能力与兼容的已发布字段,服务端继续执行最终校验。 */
|
||||
const createFulfillmentPolicyDraft = async (): Promise<void> => {
|
||||
if (!fulfillmentPolicyState.value || draftPolicy.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
await createShippingFulfillmentPolicyDraft({
|
||||
field_bindings: fulfillmentPolicyState.value.capabilities.flatMap((capability) => {
|
||||
const fieldId = fulfillmentBindings[capability.capability_code];
|
||||
return fieldId ? [{ capability_code: capability.capability_code, field_id: fieldId }] : [];
|
||||
}),
|
||||
change_note: fulfillmentPolicyNote.value,
|
||||
});
|
||||
message.success(t('admin.shippingOrderSchema.fulfillmentDraftCreated'));
|
||||
await load();
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 发布前使用草稿锁版本,避免两个管理员相互覆盖字段能力定义。 */
|
||||
const publishFulfillmentPolicyDraft = async (): Promise<void> => {
|
||||
if (!draftPolicy.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
await publishShippingFulfillmentPolicy(draftPolicy.value.id, draftPolicy.value.lock_version);
|
||||
message.success(t('admin.shippingOrderSchema.fulfillmentPublished'));
|
||||
fulfillmentPolicyNote.value = '';
|
||||
await load();
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 初始化唯一订单 Schema。 */
|
||||
const initialize = async (): Promise<void> => {
|
||||
saving.value = true;
|
||||
@@ -793,6 +851,35 @@ onMounted(async () => {
|
||||
<span><strong>{{ t('admin.shippingOrderSchema.autoCreationEnabled') }}</strong><small>{{ t('admin.shippingOrderSchema.autoCreationHint') }}</small></span>
|
||||
</label>
|
||||
|
||||
<section class="fulfillment-policy-card">
|
||||
<header>
|
||||
<div>
|
||||
<p>{{ t('admin.shippingOrderSchema.fulfillmentEyebrow') }}</p>
|
||||
<h2>{{ t('admin.shippingOrderSchema.fulfillmentTitle') }}</h2>
|
||||
<small>{{ t('admin.shippingOrderSchema.fulfillmentHint') }}</small>
|
||||
</div>
|
||||
<span class="read-only-badge">
|
||||
{{ publishedPolicy ? t('admin.shippingOrderSchema.fulfillmentPublishedVersion', { version: publishedPolicy.version }) : t('admin.shippingOrderSchema.fulfillmentNotPublished') }}
|
||||
</span>
|
||||
</header>
|
||||
<p v-if="!published" class="fulfillment-warning">{{ t('admin.shippingOrderSchema.fulfillmentSchemaRequired') }}</p>
|
||||
<div v-else class="fulfillment-bindings">
|
||||
<label v-for="capability in fulfillmentPolicyState?.capabilities || []" :key="capability.capability_code">
|
||||
<span><strong>{{ t(`admin.shippingOrderSchema.fulfillmentCapability.${capability.capability_code}`) }}</strong><small>{{ capability.required ? t('admin.shippingOrderSchema.fulfillmentRequired') : t('admin.shippingOrderSchema.fulfillmentOptional') }}</small></span>
|
||||
<select v-model="fulfillmentBindings[capability.capability_code]" :disabled="saving || Boolean(draftPolicy)">
|
||||
<option value="">{{ t('admin.shippingOrderSchema.fulfillmentSelectField') }}</option>
|
||||
<option v-for="field in policyFieldsFor(capability)" :key="field.id" :value="field.id">{{ displayNameForField(field, 0) }} ({{ field.field_code }})</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<footer v-if="published">
|
||||
<label v-if="!draftPolicy"><span>{{ t('admin.shippingOrderSchema.fulfillmentChangeNote') }}</span><input v-model="fulfillmentPolicyNote" :disabled="saving" :placeholder="t('admin.shippingOrderSchema.fulfillmentChangeNotePlaceholder')"></label>
|
||||
<p v-else>{{ t('admin.shippingOrderSchema.fulfillmentDraftHint', { version: draftPolicy.version }) }}</p>
|
||||
<button v-if="!draftPolicy" type="button" class="secondary-button" :disabled="saving" @click="createFulfillmentPolicyDraft">{{ t('admin.shippingOrderSchema.fulfillmentCreateDraft') }}</button>
|
||||
<button v-else type="button" class="primary-button" :disabled="saving" @click="publishFulfillmentPolicyDraft">{{ t('admin.shippingOrderSchema.fulfillmentPublish') }}</button>
|
||||
</footer>
|
||||
</section>
|
||||
|
||||
<div class="schema-workbench">
|
||||
<aside class="field-panel">
|
||||
<div class="panel-heading">
|
||||
@@ -964,6 +1051,22 @@ onMounted(async () => {
|
||||
.auto-creation-switch span { display: grid; gap: 3px; }
|
||||
.auto-creation-switch strong { color: #334155; font-size: 13px; }
|
||||
.auto-creation-switch small { color: #64748b; font-size: 11px; }
|
||||
.fulfillment-policy-card { display: grid; gap: 14px; margin: 0 0 16px; border: 1px solid #dbe6ef; border-radius: 10px; background: #fff; padding: 16px; }
|
||||
.fulfillment-policy-card > header, .fulfillment-policy-card > footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
|
||||
.fulfillment-policy-card h2, .fulfillment-policy-card p { margin: 0; }
|
||||
.fulfillment-policy-card header p { color: #0284c7; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
|
||||
.fulfillment-policy-card h2 { margin-top: 3px; color: #1e293b; font-size: 14px; }
|
||||
.fulfillment-policy-card header small, .fulfillment-policy-card footer p { color: #64748b; font-size: 12px; }
|
||||
.fulfillment-warning { border-radius: 7px; background: #fff7ed; padding: 9px 11px; color: #9a3412; font-size: 12px; }
|
||||
.fulfillment-bindings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
|
||||
.fulfillment-bindings label, .fulfillment-policy-card footer label { display: grid; gap: 5px; color: #64748b; font-size: 12px; }
|
||||
.fulfillment-bindings label { grid-template-columns: minmax(0, 1fr) minmax(180px, .8fr); align-items: center; border: 1px solid #edf1f5; border-radius: 7px; padding: 10px; }
|
||||
.fulfillment-bindings span { display: grid; gap: 2px; }
|
||||
.fulfillment-bindings strong { color: #334155; font-weight: 600; }
|
||||
.fulfillment-bindings small { color: #94a3b8; font-size: 10px; }
|
||||
.fulfillment-bindings select, .fulfillment-policy-card footer input { min-width: 0; border: 1px solid #d9e2ec; border-radius: 6px; background: #fff; padding: 8px 9px; color: #334155; font: inherit; font-size: 12px; }
|
||||
.fulfillment-policy-card footer label { flex: 1; }
|
||||
@media (max-width: 900px) { .fulfillment-bindings { grid-template-columns: 1fr; } }
|
||||
.field-panel { display: flex; min-width: 0; min-height: 0; flex-direction: column; border-right: 1px solid #e5ebf1; background: #fbfcfe; }
|
||||
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 16px 10px; }
|
||||
.panel-heading h2, .rule-heading h2 { margin: 0; color: #1e293b; font-size: 15px; font-weight: 600; }
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
/**
|
||||
* features/admin/shippingConfigNavigation.spec.ts
|
||||
* 用途:锁定货代配置二级导航与后台路由的注册契约。
|
||||
* 依赖:货代配置子模块注册表、后台路由、Vitest。
|
||||
* 用途:锁定货代管理业务分组、深链与后台路由的注册契约。
|
||||
* 依赖:货代管理业务目录注册表、后台路由、Vitest。
|
||||
* 逻辑:防止新增或调整子页面时丢失深链、权限复用或当前子项高亮标识。
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { adminRoutes } from '@/app/router/routes/admin.routes';
|
||||
import { SHIPPING_CONFIG_SUB_MODULE_METAS } from './constants/modules';
|
||||
import { ADMIN_MODULE_METAS, SHIPPING_CONFIG_SUB_MODULE_METAS } from './constants/modules';
|
||||
import type { ShippingManagementGroupKey } from './stores/admin-nav.store';
|
||||
|
||||
const shippingRoutes = adminRoutes[0].children?.filter((route) =>
|
||||
route.name === 'AdminShippingInventory'
|
||||
@@ -17,17 +18,45 @@ const shippingRoutes = adminRoutes[0].children?.filter((route) =>
|
||||
) ?? [];
|
||||
|
||||
describe('shipping configuration navigation contract', () => {
|
||||
it('keeps shipping management between schedules and announcements', () => {
|
||||
// 关键断言:货代管理必须保持在排程管理之后、公告管理之前,匹配后台约定的信息架构。
|
||||
const moduleIds = ADMIN_MODULE_METAS.map((item) => item.id);
|
||||
expect(moduleIds.slice(moduleIds.indexOf('schedules'), moduleIds.indexOf('announcements') + 1)).toEqual([
|
||||
'schedules',
|
||||
'shipping_inventory',
|
||||
'announcements',
|
||||
]);
|
||||
});
|
||||
|
||||
it('registers all shipping configuration subpages with discoverable deep links', () => {
|
||||
// 关键断言:导航注册表与深链路由必须一一对应,避免后台入口不可发现。
|
||||
expect(SHIPPING_CONFIG_SUB_MODULE_METAS).toEqual([
|
||||
{ id: 'inventory', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.nav.shippingInventory' },
|
||||
{ id: 'identity_rules', routeName: 'AdminShippingIdentityRules', path: 'shipping-identity-rules', labelKey: 'admin.nav.shippingIdentityRules' },
|
||||
{ id: 'order_extraction_runs', routeName: 'AdminShippingOrderExtractionRuns', path: 'shipping-order-extraction-runs', labelKey: 'admin.nav.shippingOrderExtractionRuns' },
|
||||
{ id: 'order_document_profiles', routeName: 'AdminShippingOrderDocumentProfiles', path: 'shipping-order-document-profiles', labelKey: 'admin.nav.shippingOrderDocumentProfiles' },
|
||||
{ id: 'order_fields', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.nav.shippingOrderFields', groupKey: 'admin.nav.shippingOrderRecognition', query: { section: 'orderSchema' } },
|
||||
{ id: 'order_document_profiles', routeName: 'AdminShippingOrderDocumentProfiles', path: 'shipping-order-document-profiles', labelKey: 'admin.nav.shippingOrderDocumentProfiles', groupKey: 'admin.nav.shippingOrderRecognition' },
|
||||
{ id: 'identity_rules', routeName: 'AdminShippingIdentityRules', path: 'shipping-identity-rules', labelKey: 'admin.nav.shippingIdentityRules', groupKey: 'admin.nav.shippingOrderRecognition' },
|
||||
{ id: 'order_extraction_runs', routeName: 'AdminShippingOrderExtractionRuns', path: 'shipping-order-extraction-runs', labelKey: 'admin.nav.shippingOrderExtractionRuns', groupKey: 'admin.nav.shippingOrderRecognition' },
|
||||
{ id: 'inventory_fields', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.parsingProfiles', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'parsing' } },
|
||||
{ id: 'connections', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.connections', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'profiles' } },
|
||||
{ id: 'inventory_sites', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.sources', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'sources' } },
|
||||
{ id: 'warehouse_mappings', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.externalMappings', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'mappings' } },
|
||||
{ id: 'routing_rules', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.rules', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'rules' } },
|
||||
{ id: 'shipping_templates', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.excelTemplates', groupKey: 'admin.nav.shippingInventoryManagement', query: { section: 'templates' } },
|
||||
{ id: 'inventory_snapshots', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.snapshots', groupKey: 'admin.nav.shippingRunAudit', query: { section: 'snapshots' } },
|
||||
{ id: 'export_records', routeName: 'AdminShippingInventory', path: 'shipping-notice', labelKey: 'admin.shippingInventory.exports', groupKey: 'admin.nav.shippingRunAudit', query: { section: 'exports' } },
|
||||
]);
|
||||
expect(shippingRoutes).toHaveLength(4);
|
||||
});
|
||||
|
||||
it('keeps exactly three ordered accordion groups', () => {
|
||||
// 关键断言:货代功能量较大,侧栏必须保持三组手风琴,避免所有入口同时平铺。
|
||||
const groups = [...new Set(SHIPPING_CONFIG_SUB_MODULE_METAS.map((item) => item.groupKey))] satisfies ShippingManagementGroupKey[];
|
||||
expect(groups).toEqual([
|
||||
'admin.nav.shippingOrderRecognition',
|
||||
'admin.nav.shippingInventoryManagement',
|
||||
'admin.nav.shippingRunAudit',
|
||||
]);
|
||||
});
|
||||
|
||||
it('keeps all deep links behind the shared shipping inventory admin boundary', () => {
|
||||
// 关键断言:菜单可见性不是授权;所有页面均须保留 requiresAdmin 和共享模块权限标识。
|
||||
expect(shippingRoutes.map((route) => route.meta)).toEqual([
|
||||
|
||||
@@ -11,6 +11,11 @@ import { ref } from 'vue';
|
||||
import { getAdminDashboardBadges } from '@/features/admin/api/admin.api';
|
||||
import type { AdminModuleId } from '../types/admin.types';
|
||||
|
||||
export type ShippingManagementGroupKey =
|
||||
| 'admin.nav.shippingOrderRecognition'
|
||||
| 'admin.nav.shippingInventoryManagement'
|
||||
| 'admin.nav.shippingRunAudit';
|
||||
|
||||
/** 角标缓存有效期(毫秒):此时间内 ensureBadges 直接复用内存中的计数 */
|
||||
const BADGE_CACHE_TTL_MS = 60_000;
|
||||
|
||||
@@ -20,8 +25,10 @@ export const useAdminNavStore = defineStore('adminNav', () => {
|
||||
const reportsExpanded = ref(false);
|
||||
/** 企业微信子菜单:默认折叠 */
|
||||
const wecomExpanded = ref(false);
|
||||
/** 货代配置子菜单:默认折叠,进入库存或识别规则页时由导航自动展开。 */
|
||||
const shippingConfigExpanded = ref(false);
|
||||
/** 货代管理二级菜单:默认折叠,进入货代页面时自动展开。 */
|
||||
const shippingManagementExpanded = ref(false);
|
||||
/** 货代手风琴当前展开分组;单值约束保证同一时间最多展开一组。 */
|
||||
const shippingManagementGroup = ref<ShippingManagementGroupKey | null>(null);
|
||||
/** 「用户审批」导航角标:pending 注册用户数 */
|
||||
const pendingApprovalsCount = ref(0);
|
||||
/** 「权限申请」导航角标:pending 权限申请数 */
|
||||
@@ -36,6 +43,11 @@ export const useAdminNavStore = defineStore('adminNav', () => {
|
||||
sidebarCollapsed.value = !sidebarCollapsed.value;
|
||||
};
|
||||
|
||||
/** 展开指定货代分组;再次点击当前分组时收起全部功能项。 */
|
||||
const toggleShippingManagementGroup = (groupKey: ShippingManagementGroupKey): void => {
|
||||
shippingManagementGroup.value = shippingManagementGroup.value === groupKey ? null : groupKey;
|
||||
};
|
||||
|
||||
const setBadgeCounts = (approvals: number, requests: number): void => {
|
||||
pendingApprovalsCount.value = approvals;
|
||||
pendingRequestsCount.value = requests;
|
||||
@@ -90,10 +102,12 @@ export const useAdminNavStore = defineStore('adminNav', () => {
|
||||
sidebarCollapsed,
|
||||
reportsExpanded,
|
||||
wecomExpanded,
|
||||
shippingConfigExpanded,
|
||||
shippingManagementExpanded,
|
||||
shippingManagementGroup,
|
||||
pendingApprovalsCount,
|
||||
pendingRequestsCount,
|
||||
toggleSidebar,
|
||||
toggleShippingManagementGroup,
|
||||
setBadgeCounts,
|
||||
badgeForModule,
|
||||
ensureBadges,
|
||||
|
||||
@@ -20,8 +20,20 @@ export type AdminModuleId =
|
||||
| 'shipping_inventory'
|
||||
| 'reports';
|
||||
|
||||
/** 货代配置领域下可由侧栏展示和高亮的稳定子页面。 */
|
||||
export type ShippingConfigSubModuleId = 'inventory' | 'identity_rules' | 'order_extraction_runs' | 'order_document_profiles';
|
||||
/** 货代管理领域下可由侧栏展示和高亮的稳定业务页面。 */
|
||||
export type ShippingConfigSubModuleId =
|
||||
| 'order_fields'
|
||||
| 'order_document_profiles'
|
||||
| 'identity_rules'
|
||||
| 'order_extraction_runs'
|
||||
| 'inventory_fields'
|
||||
| 'connections'
|
||||
| 'inventory_sites'
|
||||
| 'warehouse_mappings'
|
||||
| 'routing_rules'
|
||||
| 'shipping_templates'
|
||||
| 'inventory_snapshots'
|
||||
| 'export_records';
|
||||
|
||||
export type AdminReportTableId =
|
||||
| 'usage_analysis'
|
||||
|
||||
@@ -32,6 +32,7 @@ export interface ShippingOrderDocumentProfile {
|
||||
row_structure: 'preserved' | 'unsupported_row_structure';
|
||||
column_rules: OrderProfileColumnRule[];
|
||||
drop_zero_qty: boolean;
|
||||
coordinate_reconstruction?: CoordinateReconstructionSettings | null;
|
||||
};
|
||||
checksum?: string | null;
|
||||
lock_version: number;
|
||||
@@ -44,12 +45,18 @@ export interface ShippingOrderDocumentProfile {
|
||||
export interface OrderProfileSampleDocument {
|
||||
document_id: number;
|
||||
intake_id: number;
|
||||
intake_no: string;
|
||||
filename?: string | null;
|
||||
content_hash?: string | null;
|
||||
provider?: string | null;
|
||||
provider_version?: string | null;
|
||||
table_count: number;
|
||||
created_at?: string | null;
|
||||
purpose: 'shipping_notice' | 'order_document_profile_sample';
|
||||
parse_status: string;
|
||||
is_template_sample: boolean;
|
||||
can_delete: boolean;
|
||||
delete_block_reason?: 'blind_test_referenced' | null;
|
||||
}
|
||||
|
||||
export interface OrderProfileSampleTable {
|
||||
@@ -60,6 +67,44 @@ export interface OrderProfileSampleTable {
|
||||
rows: string[][];
|
||||
issues: string[];
|
||||
profile_creation_allowed: boolean;
|
||||
coordinate_reconstruction_available?: boolean;
|
||||
ocr_coordinate_reconstruction_available?: boolean;
|
||||
}
|
||||
|
||||
export interface CoordinateReconstructionSettings {
|
||||
method: 'native_pdf_coordinates.v1' | 'ocr_pdf_coordinates.v1';
|
||||
column_boundaries: number[];
|
||||
column_field_codes?: Array<string | null>;
|
||||
line_start_column_index?: number;
|
||||
subrow_layouts?: CoordinateSubrowLayout[];
|
||||
}
|
||||
|
||||
export interface CoordinateSubrowLayout {
|
||||
role: 'main' | 'continuation';
|
||||
row_offset: number;
|
||||
column_boundaries: number[];
|
||||
column_field_codes: Array<string | null>;
|
||||
}
|
||||
|
||||
export interface CoordinateReconstructionPreview {
|
||||
table_id: string;
|
||||
row_count: number;
|
||||
column_count: number;
|
||||
rows: string[][];
|
||||
row_roles: Array<'header' | 'data' | 'deleted'>;
|
||||
source_row_indices: number[][];
|
||||
status: 'needs_review';
|
||||
}
|
||||
|
||||
export interface CoordinateSubrowSuggestion extends CoordinateSubrowLayout {
|
||||
column_samples: string[][];
|
||||
suggested_field_codes: Array<string | null>;
|
||||
}
|
||||
|
||||
export interface CoordinateReconstructionSuggestion {
|
||||
table_id: string;
|
||||
subrow_layouts: CoordinateSubrowSuggestion[];
|
||||
status: 'needs_review';
|
||||
}
|
||||
|
||||
export interface OrderProfileSamplePreview {
|
||||
@@ -85,5 +130,6 @@ export interface CreateOrderProfileFromSampleInput {
|
||||
row_structure: 'preserved' | 'unsupported_row_structure';
|
||||
column_rules: OrderProfileColumnRule[];
|
||||
drop_zero_qty: boolean;
|
||||
coordinate_reconstruction?: CoordinateReconstructionSettings | null;
|
||||
change_note?: string;
|
||||
}
|
||||
@@ -214,3 +214,36 @@ export interface ShippingOrderSchemaState {
|
||||
}>;
|
||||
}>;
|
||||
}
|
||||
|
||||
/** 受控货代履约能力及其版本化字段绑定。 */
|
||||
export interface ShippingFulfillmentCapability {
|
||||
capability_code: string;
|
||||
scope: ShippingOrderField['scope'];
|
||||
value_type: ShippingOrderField['value_type'];
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
export interface ShippingFulfillmentPolicyBinding {
|
||||
capability_code: string;
|
||||
field_id: string;
|
||||
field_code: string;
|
||||
scope: ShippingOrderField['scope'];
|
||||
value_type: ShippingOrderField['value_type'];
|
||||
}
|
||||
|
||||
export interface ShippingFulfillmentPolicy {
|
||||
id: number;
|
||||
policy_code: 'SHIP_AVAILABLE_ROLLING_V1';
|
||||
version: number;
|
||||
status: 'draft' | 'published' | 'retired';
|
||||
definition: { field_bindings: ShippingFulfillmentPolicyBinding[] };
|
||||
checksum: string | null;
|
||||
lock_version: number;
|
||||
change_note: string | null;
|
||||
published_at: string | null;
|
||||
}
|
||||
|
||||
export interface ShippingFulfillmentPolicyState {
|
||||
capabilities: ShippingFulfillmentCapability[];
|
||||
policies: ShippingFulfillmentPolicy[];
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* features/admin/views/AdminLayout.vue
|
||||
* 管理后台壳层:顶栏 + AdminNav + 子路由出口。
|
||||
* 角标仅在 Layout 首次挂载时 ensureBadges(store 内 60s TTL 缓存)。
|
||||
* 管理后台壳层:顶栏 + 左侧导航 + 子路由出口。
|
||||
* 依赖:AdminNav、vue-router、admin-nav.store。
|
||||
* 逻辑:AdminNav 统一承担模块和二级目录导航,内容区保持全宽展示当前页面。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
@@ -44,7 +45,7 @@ onMounted(() => {
|
||||
|
||||
<main class="flex-1 w-full mx-auto px-4 md:px-8 py-6 md:py-8 flex flex-col md:flex-row gap-8 items-start">
|
||||
<AdminNav />
|
||||
<section class="flex-1 min-w-0 space-y-8 w-full">
|
||||
<section class="flex-1 min-w-0 w-full space-y-8">
|
||||
<router-view />
|
||||
</section>
|
||||
</main>
|
||||
|
||||
Reference in new issue
Block a user