feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
@@ -1,8 +1,9 @@
|
||||
/**
|
||||
* features/admin/api/shipping-audit.api.ts
|
||||
* 用途:货代统一审计查询/详情/导出 HTTP 客户端。
|
||||
* 用途:货代统一审计查询/详情/关联链/哈希校验/导出 HTTP 客户端。
|
||||
* 依赖:shared/api/client、getAuthHeaders。
|
||||
* 逻辑:由 ShippingAuditCenterPage 调用;导出走 blob 下载并保留服务端文件名。
|
||||
* 逻辑:由 ShippingAuditCenterPage / ShippingAuditEventDetailDrawer 调用;
|
||||
* 导出走 blob 下载;敏感详情由后端按 audit_sensitive_read 裁剪。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
@@ -16,7 +17,8 @@ export type ShippingAuditEventSummary = {
|
||||
task_no?: string | null;
|
||||
document_id?: string | null;
|
||||
conversation_id?: string | null;
|
||||
session_item_id?: string | null;
|
||||
workflow_id?: string | null;
|
||||
workflow_item_id?: string | null;
|
||||
review_case_no?: string | null;
|
||||
owner_user_id?: string | null;
|
||||
actor_type: string;
|
||||
@@ -27,7 +29,11 @@ export type ShippingAuditEventSummary = {
|
||||
action?: string | null;
|
||||
reason_code?: string | null;
|
||||
error_code?: string | null;
|
||||
sensitivity_level?: string | null;
|
||||
previous_event_hash?: string | null;
|
||||
event_hash?: string | null;
|
||||
has_snapshots: boolean;
|
||||
sensitive_redacted?: boolean;
|
||||
created_at?: string | null;
|
||||
};
|
||||
|
||||
@@ -42,6 +48,7 @@ export type ShippingAuditEventDetail = ShippingAuditEventSummary & {
|
||||
before_snapshot?: Record<string, unknown> | null;
|
||||
after_snapshot?: Record<string, unknown> | null;
|
||||
diff?: ShippingAuditDiffRow[];
|
||||
diff_json?: Record<string, unknown> | null;
|
||||
metadata?: Record<string, unknown>;
|
||||
evidence_refs?: Array<Record<string, unknown>>;
|
||||
artifact_refs?: Array<Record<string, unknown>>;
|
||||
@@ -57,13 +64,10 @@ export type ShippingAuditFilters = {
|
||||
document_id?: string;
|
||||
operation_id?: string;
|
||||
request_id?: string;
|
||||
/** 会话 ID;与后端 conversation_id 筛选对齐 */
|
||||
conversation_id?: string;
|
||||
/** 会话 PDF 工作项编号 */
|
||||
session_item_id?: string;
|
||||
/** 人工复核 Case 编号 */
|
||||
workflow_id?: string;
|
||||
workflow_item_id?: string;
|
||||
review_case_no?: string;
|
||||
/** 工作项属主用户 ID */
|
||||
owner_user_id?: string;
|
||||
result?: string;
|
||||
created_from?: string;
|
||||
@@ -71,6 +75,23 @@ export type ShippingAuditFilters = {
|
||||
q?: string;
|
||||
};
|
||||
|
||||
export type ShippingAuditAssociationChain = {
|
||||
items: ShippingAuditEventSummary[];
|
||||
total: number;
|
||||
association_keys: Record<string, string[]>;
|
||||
truncated: boolean;
|
||||
limit: number;
|
||||
};
|
||||
|
||||
export type ShippingAuditHashVerifyResult = {
|
||||
ok: boolean;
|
||||
checked_chains: number;
|
||||
failed_chains: number;
|
||||
failures_sample: Array<Record<string, unknown>>;
|
||||
mode?: string;
|
||||
skipped?: boolean;
|
||||
};
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
|
||||
/**
|
||||
@@ -88,7 +109,7 @@ export function listShippingAuditEvents(page = 1, pageSize = 25, filters: Shippi
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取单条审计详情(含白名单快照与 diff)。
|
||||
* 读取单条审计详情(含白名单快照与 diff;敏感项可能脱敏)。
|
||||
*/
|
||||
export function getShippingAuditEvent(eventId: number) {
|
||||
return requestJson<ShippingAuditEventDetail>(
|
||||
@@ -97,6 +118,40 @@ export function getShippingAuditEvent(eventId: number) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 Workflow / Item / Run / PDF / Case / Task 关联键追溯全链。
|
||||
*/
|
||||
export function listShippingAuditAssociationChain(filters: ShippingAuditFilters = {}, limit = 500) {
|
||||
const params = new URLSearchParams({ limit: String(limit) });
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value) params.set(key, String(value));
|
||||
});
|
||||
return requestJson<ShippingAuditAssociationChain>(
|
||||
`/api/admin/shipping-notice/audit-events/association-chain?${params}`,
|
||||
auth(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验审计哈希链完整性。
|
||||
*/
|
||||
export function verifyShippingAuditHashChain(body: {
|
||||
aggregate_type?: string;
|
||||
aggregate_id?: string;
|
||||
workflow_id?: string;
|
||||
workflow_item_id?: string;
|
||||
sample_limit?: number;
|
||||
} = {}) {
|
||||
return requestJson<ShippingAuditHashVerifyResult>(
|
||||
'/api/admin/shipping-notice/audit-events/verify-hash-chain',
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 受控导出审计 CSV/JSON,并触发浏览器下载。
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import type {
|
||||
ShippingOrderDerivationRule,
|
||||
ShippingOrderDerivationSimulateRequest,
|
||||
ShippingOrderDerivationSimulateResult,
|
||||
ShippingOrderDerivationSimulateSampleItem,
|
||||
ShippingOrderField,
|
||||
ShippingOrderFieldConfig,
|
||||
ShippingOrderSchemaAuditEventPage,
|
||||
@@ -154,12 +158,13 @@ export const getShippingOrderExtractionAudit = (extractionId: number) =>
|
||||
auth(),
|
||||
);
|
||||
|
||||
/** 整体保存草稿字段配置、自动建单策略及每个字段的版本纳入状态。 */
|
||||
/** 整体保存草稿字段配置、自动建单策略、派生规则及每个字段的版本纳入状态。 */
|
||||
export const saveShippingOrderSchemaDraft = (
|
||||
versionId: number,
|
||||
payload: {
|
||||
fields: ShippingOrderFieldConfig[];
|
||||
auto_creation_policy?: { enabled: boolean };
|
||||
derivation_rules?: ShippingOrderDerivationRule[];
|
||||
change_note?: string;
|
||||
expected_lock_version: number;
|
||||
},
|
||||
@@ -172,6 +177,34 @@ export const saveShippingOrderSchemaDraft = (
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* 对 Schema 版本派生规则做样本模拟(不改订单)。
|
||||
* @param versionId - Schema 版本 ID
|
||||
* @param payload - 样本行与可选规则覆盖 / sample_ref
|
||||
*/
|
||||
export const simulateShippingOrderSchemaDerivation = (
|
||||
versionId: number,
|
||||
payload: ShippingOrderDerivationSimulateRequest,
|
||||
) =>
|
||||
requestJson<ShippingOrderDerivationSimulateResult>(
|
||||
`/api/admin/shipping-order-schema/versions/${versionId}/simulate-derivation`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
...jsonAuth(),
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* 列出可供派生规则模拟的历史 Extraction 样本。
|
||||
* @param limit - 返回条数上限
|
||||
*/
|
||||
export const listShippingOrderSchemaDerivationSimulateSamples = (limit = 20) =>
|
||||
requestJson<{ items: ShippingOrderDerivationSimulateSampleItem[] }>(
|
||||
`/api/admin/shipping-order-schema/derivation-simulate-samples?limit=${limit}`,
|
||||
auth(),
|
||||
);
|
||||
|
||||
/** 删除错误草稿;发布版本由服务端拒绝删除。 */
|
||||
export const deleteShippingOrderSchemaDraft = (versionId: number) =>
|
||||
requestJson<void>(`/api/admin/shipping-order-schema/versions/${versionId}`, {
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/**
|
||||
* features/admin/api/shipping-review-supervision.api.ts
|
||||
* 用途:管理员跨用户会话 PDF 工作项监管 HTTP 客户端。
|
||||
* 依赖:shared/api/client、chat 域 ShippingSessionWorkItem 类型。
|
||||
* 逻辑:由 ShippingReviewSupervisionPage 调用;终止/撤销须理由与 confirm_token。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import type { ShippingSessionWorkItem } from '@/features/chat/types/shipping.api.types';
|
||||
|
||||
export type ShippingReviewSupervisionFilters = {
|
||||
lifecycle_status?: string;
|
||||
owner_user_id?: string;
|
||||
conversation_id?: string;
|
||||
q?: string;
|
||||
};
|
||||
|
||||
export type ShippingReviewSupervisionPage = {
|
||||
items: ShippingSessionWorkItem[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
};
|
||||
|
||||
export const SUPERVISION_CONFIRM_TERMINATE = 'CONFIRM_TERMINATE';
|
||||
export const SUPERVISION_CONFIRM_REVOKE = 'CONFIRM_REVOKE';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
|
||||
/**
|
||||
* 分页查询跨用户会话 PDF 工作项;服务端已做管理员鉴权。
|
||||
*/
|
||||
export function listShippingReviewSupervisionItems(
|
||||
page = 1,
|
||||
pageSize = 20,
|
||||
filters: ShippingReviewSupervisionFilters = {},
|
||||
) {
|
||||
const params = new URLSearchParams({
|
||||
page: String(page),
|
||||
page_size: String(pageSize),
|
||||
});
|
||||
if (filters.lifecycle_status) params.set('lifecycle_status', filters.lifecycle_status);
|
||||
if (filters.owner_user_id) params.set('owner_user_id', filters.owner_user_id);
|
||||
if (filters.conversation_id) params.set('conversation_id', filters.conversation_id);
|
||||
if (filters.q) params.set('q', filters.q);
|
||||
return requestJson<ShippingReviewSupervisionPage>(
|
||||
`/api/admin/shipping-notice/session-work-items?${params}`,
|
||||
auth(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员终止工作项;必须填写 reason 且 confirm_token 为 CONFIRM_TERMINATE。
|
||||
*/
|
||||
export function terminateShippingReviewSupervisionItem(
|
||||
itemNo: string,
|
||||
payload: { reason: string; confirm_token: typeof SUPERVISION_CONFIRM_TERMINATE },
|
||||
) {
|
||||
return requestJson<{ item: ShippingSessionWorkItem }>(
|
||||
`/api/admin/shipping-notice/session-work-items/${encodeURIComponent(itemNo)}/terminate`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...getAuthHeaders(),
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员 24 小时内撤销确认;必须填写 reason 且 confirm_token 为 CONFIRM_REVOKE。
|
||||
*/
|
||||
export function revokeShippingReviewSupervisionConfirmation(
|
||||
itemNo: string,
|
||||
payload: { reason: string; confirm_token: typeof SUPERVISION_CONFIRM_REVOKE },
|
||||
) {
|
||||
return requestJson<Record<string, unknown>>(
|
||||
`/api/admin/shipping-notice/session-work-items/${encodeURIComponent(itemNo)}/revoke-confirmation`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...getAuthHeaders(),
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/**
|
||||
* features/admin/api/shipping-review-supervision.spec.ts
|
||||
* 用途:复核监管台 API 契约——confirm_token 与理由必填边界。
|
||||
* 依赖:shipping-review-supervision.api 常量。
|
||||
* 逻辑:断言终止/撤销 token 稳定,便于前后端与 i18n 对齐。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
SUPERVISION_CONFIRM_REVOKE,
|
||||
SUPERVISION_CONFIRM_TERMINATE,
|
||||
} from './shipping-review-supervision.api';
|
||||
|
||||
describe('shipping review supervision api contract', () => {
|
||||
it('requires stable terminate confirm token', () => {
|
||||
expect(SUPERVISION_CONFIRM_TERMINATE).toBe('CONFIRM_TERMINATE');
|
||||
});
|
||||
|
||||
it('requires stable revoke confirm token', () => {
|
||||
expect(SUPERVISION_CONFIRM_REVOKE).toBe('CONFIRM_REVOKE');
|
||||
});
|
||||
|
||||
it('rejects empty reason before submit in UI contract', () => {
|
||||
const reason = ' ';
|
||||
// 关键断言:监管台须在客户端拦截空理由,与服务端校验一致。
|
||||
expect(reason.trim().length).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -22,7 +22,6 @@ export interface ShippingConfigSubModuleMeta {
|
||||
| 'AdminShippingIdentityRules'
|
||||
| 'AdminShippingOrderExtractionRuns'
|
||||
| 'AdminShippingAudit'
|
||||
| 'AdminShippingReviewSupervision'
|
||||
| 'AdminShippingOrderDocumentProfiles';
|
||||
path:
|
||||
| 'shipping-notice'
|
||||
@@ -31,7 +30,6 @@ export interface ShippingConfigSubModuleMeta {
|
||||
| 'shipping-identity-rules'
|
||||
| 'shipping-order-extraction-runs'
|
||||
| 'shipping-audit'
|
||||
| 'shipping-review-supervision'
|
||||
| 'shipping-order-document-profiles';
|
||||
labelKey: string;
|
||||
groupKey: 'admin.nav.shippingOrderRecognition' | 'admin.nav.shippingInventoryManagement' | 'admin.nav.shippingRunAudit';
|
||||
@@ -74,7 +72,6 @@ export const SHIPPING_CONFIG_SUB_MODULE_METAS: ShippingConfigSubModuleMeta[] = [
|
||||
{ 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: 'shipping_audit', routeName: 'AdminShippingAudit', path: 'shipping-audit', labelKey: 'admin.nav.shippingAudit', groupKey: 'admin.nav.shippingRunAudit' },
|
||||
{ id: 'shipping_review_supervision', routeName: 'AdminShippingReviewSupervision', path: 'shipping-review-supervision', labelKey: 'admin.nav.shippingReviewSupervision', groupKey: 'admin.nav.shippingRunAudit' },
|
||||
{ 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' } },
|
||||
];
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
/**
|
||||
* features/admin/e2e/shipping-audit.spec.ts
|
||||
* 用途:阶段 4 管理员审计中心契约冒烟——Diff/导出权限、会话工作项筛选与脱敏边界。
|
||||
* 用途:阶段 4 管理员审计中心契约冒烟——权限脱敏、Diff、关联链与哈希校验 DTO。
|
||||
* 依赖:Vitest、shipping-audit.api 类型约定。
|
||||
* 逻辑:断言列表不含快照字段;详情 Diff 仅白名单键;筛选 DTO 含 session 工作项字段。
|
||||
* 逻辑:断言列表不含快照;筛选含 Workflow/Item/Run/PDF/Case/Task;敏感脱敏字段存在。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type {
|
||||
ShippingAuditAssociationChain,
|
||||
ShippingAuditDiffRow,
|
||||
ShippingAuditEventDetail,
|
||||
ShippingAuditEventSummary,
|
||||
ShippingAuditFilters,
|
||||
ShippingAuditHashVerifyResult,
|
||||
} from '@/features/admin/api/shipping-audit.api';
|
||||
|
||||
describe('shipping audit center e2e contract', () => {
|
||||
@@ -23,6 +25,8 @@ describe('shipping audit center e2e contract', () => {
|
||||
has_snapshots: true,
|
||||
run_no: 'SNER-1',
|
||||
task_no: 'ST-1',
|
||||
workflow_id: 'WF-1',
|
||||
workflow_item_id: 'WFI-1',
|
||||
operation_id: 'op-1',
|
||||
};
|
||||
// 关键断言:列表 DTO 无 before/after 快照字段,避免误渲染正文。
|
||||
@@ -39,6 +43,7 @@ describe('shipping audit center e2e contract', () => {
|
||||
aggregate_id: 'SNER-2',
|
||||
actor_type: 'system',
|
||||
has_snapshots: true,
|
||||
sensitive_redacted: false,
|
||||
before_snapshot: { status: 'queued' },
|
||||
after_snapshot: { status: 'processing' },
|
||||
diff: [
|
||||
@@ -50,43 +55,72 @@ describe('shipping audit center e2e contract', () => {
|
||||
expect(JSON.stringify(detail)).not.toContain('https://');
|
||||
});
|
||||
|
||||
it('sensitive detail can be redacted by permission', () => {
|
||||
const detail: ShippingAuditEventDetail = {
|
||||
id: 4,
|
||||
event_type: 'order_review_confirmed',
|
||||
aggregate_type: 'shipping_order_review_case',
|
||||
aggregate_id: 'SRC-4',
|
||||
actor_type: 'user',
|
||||
has_snapshots: true,
|
||||
sensitivity_level: 'sensitive',
|
||||
sensitive_redacted: true,
|
||||
before_snapshot: null,
|
||||
after_snapshot: null,
|
||||
diff: [],
|
||||
};
|
||||
// 关键断言:无 audit_sensitive_read 时敏感正文脱敏。
|
||||
expect(detail.sensitive_redacted).toBe(true);
|
||||
expect(detail.before_snapshot).toBeNull();
|
||||
expect(detail.diff).toEqual([]);
|
||||
});
|
||||
|
||||
it('export disabled error code is stable for i18n', () => {
|
||||
const code = 'SHIPPING_NOTICE.AUDIT_EXPORT_FEATURE_DISABLED';
|
||||
expect(code.startsWith('SHIPPING_NOTICE.')).toBe(true);
|
||||
});
|
||||
|
||||
it('audit filters carry session work item query keys', () => {
|
||||
it('audit filters carry workflow association query keys', () => {
|
||||
const filters: ShippingAuditFilters = {
|
||||
conversation_id: 'conv-1',
|
||||
session_item_id: 'SPWI-1',
|
||||
workflow_id: 'WF-1',
|
||||
workflow_item_id: 'WFI-1',
|
||||
run_no: 'SNER-1',
|
||||
document_id: '42',
|
||||
review_case_no: 'SRC-1',
|
||||
owner_user_id: '42',
|
||||
task_no: 'ST-1',
|
||||
actor_id: '9',
|
||||
result: 'success',
|
||||
};
|
||||
// 关键断言:前端筛选 DTO 与 admin API _audit_filters_from_request 键对齐。
|
||||
expect(Object.keys(filters).sort()).toEqual([
|
||||
'conversation_id',
|
||||
'owner_user_id',
|
||||
'actor_id',
|
||||
'document_id',
|
||||
'result',
|
||||
'review_case_no',
|
||||
'session_item_id',
|
||||
'run_no',
|
||||
'task_no',
|
||||
'workflow_id',
|
||||
'workflow_item_id',
|
||||
]);
|
||||
});
|
||||
|
||||
it('detail exposes session work item context without snapshots in summary', () => {
|
||||
const detail: ShippingAuditEventDetail = {
|
||||
id: 3,
|
||||
event_type: 'session_work_item_confirmed',
|
||||
aggregate_type: 'shipping_session_pdf_work_item',
|
||||
aggregate_id: 'SPWI-3',
|
||||
actor_type: 'user',
|
||||
has_snapshots: true,
|
||||
conversation_id: 'conv-3',
|
||||
session_item_id: 'SPWI-3',
|
||||
review_case_no: 'SRC-3',
|
||||
owner_user_id: '99',
|
||||
diff: [],
|
||||
it('association chain and hash verify DTOs expose integrity fields', () => {
|
||||
const chain: ShippingAuditAssociationChain = {
|
||||
items: [],
|
||||
total: 0,
|
||||
association_keys: { workflow_id: ['WF-1'], task_no: ['ST-1'] },
|
||||
truncated: false,
|
||||
limit: 500,
|
||||
};
|
||||
expect(detail.session_item_id).toBe('SPWI-3');
|
||||
expect(detail.owner_user_id).toBe('99');
|
||||
expect('before_snapshot' in (detail as ShippingAuditEventSummary)).toBe(false);
|
||||
const verify: ShippingAuditHashVerifyResult = {
|
||||
ok: true,
|
||||
checked_chains: 3,
|
||||
failed_chains: 0,
|
||||
failures_sample: [],
|
||||
mode: 'sample',
|
||||
};
|
||||
expect(chain.association_keys.workflow_id).toEqual(['WF-1']);
|
||||
expect(verify.failed_chains).toBe(0);
|
||||
expect(verify.ok).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-audit/ShippingAuditCenterPage.vue
|
||||
用途:管理员货代统一审计中心——筛选、详情 Diff、受控导出。
|
||||
依赖:shipping-audit.api、Vue I18n、Vue Router。
|
||||
逻辑:列表展示会话/工作项/Case 关联字段;不含快照全文;打开详情才拉取白名单前后差异;导出写服务端访问审计。
|
||||
用途:管理员货代统一审计中心——按 Workflow/Item/Run/PDF/Case/Task 筛选、详情 Diff、关联链、哈希校验、受控导出。
|
||||
依赖:shipping-audit.api、ShippingAuditEventDetailDrawer、Vue I18n。
|
||||
逻辑:列表不含快照全文;详情抽屉按权限脱敏;导出/校验写服务端访问审计。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
@@ -10,32 +10,40 @@ import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
exportShippingAuditEvents,
|
||||
getShippingAuditEvent,
|
||||
listShippingAuditAssociationChain,
|
||||
listShippingAuditEvents,
|
||||
verifyShippingAuditHashChain,
|
||||
type ShippingAuditEventDetail,
|
||||
type ShippingAuditEventSummary,
|
||||
type ShippingAuditFilters,
|
||||
type ShippingAuditHashVerifyResult,
|
||||
} from '@/features/admin/api/shipping-audit.api';
|
||||
import ShippingAuditEventDetailDrawer from './ShippingAuditEventDetailDrawer.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
const loading = ref(false);
|
||||
const detailLoading = ref(false);
|
||||
const exporting = ref(false);
|
||||
const verifying = ref(false);
|
||||
const error = ref('');
|
||||
const page = ref(1);
|
||||
const pageSize = 25;
|
||||
const total = ref(0);
|
||||
const rows = ref<ShippingAuditEventSummary[]>([]);
|
||||
const detail = ref<ShippingAuditEventDetail | null>(null);
|
||||
const chainHint = ref('');
|
||||
const verifyResult = ref<ShippingAuditHashVerifyResult | null>(null);
|
||||
const filters = ref<ShippingAuditFilters>({
|
||||
event_type: '',
|
||||
actor_type: '',
|
||||
actor_id: '',
|
||||
workflow_id: '',
|
||||
workflow_item_id: '',
|
||||
run_no: '',
|
||||
task_no: '',
|
||||
document_id: '',
|
||||
conversation_id: '',
|
||||
session_item_id: '',
|
||||
review_case_no: '',
|
||||
task_no: '',
|
||||
conversation_id: '',
|
||||
owner_user_id: '',
|
||||
operation_id: '',
|
||||
request_id: '',
|
||||
@@ -56,6 +64,17 @@ function normalizeDateTimeFilter(value?: string): string {
|
||||
return date.toISOString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装当前筛选 payload。
|
||||
*/
|
||||
function buildFilterPayload(): ShippingAuditFilters {
|
||||
return {
|
||||
...filters.value,
|
||||
created_from: normalizeDateTimeFilter(filters.value.created_from),
|
||||
created_to: normalizeDateTimeFilter(filters.value.created_to),
|
||||
};
|
||||
}
|
||||
|
||||
const formatTime = (value?: string | null) => (value ? new Date(value).toLocaleString() : '—');
|
||||
|
||||
/**
|
||||
@@ -65,12 +84,7 @@ async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const payload: ShippingAuditFilters = {
|
||||
...filters.value,
|
||||
created_from: normalizeDateTimeFilter(filters.value.created_from),
|
||||
created_to: normalizeDateTimeFilter(filters.value.created_to),
|
||||
};
|
||||
const response = await listShippingAuditEvents(page.value, pageSize, payload);
|
||||
const response = await listShippingAuditEvents(page.value, pageSize, buildFilterPayload());
|
||||
rows.value = response.items;
|
||||
total.value = response.total;
|
||||
} catch {
|
||||
@@ -103,6 +117,56 @@ async function openDetail(eventId: number) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按当前关联种子拉取全链摘要提示。
|
||||
*/
|
||||
async function loadAssociationChain() {
|
||||
error.value = '';
|
||||
chainHint.value = '';
|
||||
try {
|
||||
const payload = buildFilterPayload();
|
||||
const hasSeed = Boolean(
|
||||
payload.workflow_id || payload.workflow_item_id || payload.run_no
|
||||
|| payload.document_id || payload.review_case_no || payload.task_no,
|
||||
);
|
||||
if (!hasSeed) {
|
||||
error.value = t('admin.shippingAudit.chainSeedRequired');
|
||||
return;
|
||||
}
|
||||
const chain = await listShippingAuditAssociationChain(payload, 500);
|
||||
chainHint.value = t('admin.shippingAudit.chainSummary', {
|
||||
total: chain.total,
|
||||
truncated: chain.truncated ? t('admin.shippingAudit.chainTruncated') : '',
|
||||
});
|
||||
rows.value = chain.items.slice().reverse();
|
||||
total.value = chain.total;
|
||||
page.value = 1;
|
||||
} catch {
|
||||
error.value = t('admin.shippingAudit.chainFailed');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发哈希链校验。
|
||||
*/
|
||||
async function runHashVerify() {
|
||||
verifying.value = true;
|
||||
error.value = '';
|
||||
verifyResult.value = null;
|
||||
try {
|
||||
const payload = buildFilterPayload();
|
||||
verifyResult.value = await verifyShippingAuditHashChain({
|
||||
workflow_id: payload.workflow_id || undefined,
|
||||
workflow_item_id: payload.workflow_item_id || undefined,
|
||||
sample_limit: 200,
|
||||
});
|
||||
} catch {
|
||||
error.value = t('admin.shippingAudit.verifyFailed');
|
||||
} finally {
|
||||
verifying.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出当前筛选条件下的 CSV。
|
||||
*/
|
||||
@@ -110,12 +174,7 @@ async function exportCsv() {
|
||||
exporting.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const payload: ShippingAuditFilters = {
|
||||
...filters.value,
|
||||
created_from: normalizeDateTimeFilter(filters.value.created_from),
|
||||
created_to: normalizeDateTimeFilter(filters.value.created_to),
|
||||
};
|
||||
await exportShippingAuditEvents(payload, 'csv');
|
||||
await exportShippingAuditEvents(buildFilterPayload(), 'csv');
|
||||
} catch {
|
||||
error.value = t('admin.shippingAudit.exportFailed');
|
||||
} finally {
|
||||
@@ -135,7 +194,13 @@ onMounted(() => {
|
||||
<h1 class="section-title">{{ t('admin.shippingAudit.title') }}</h1>
|
||||
<p class="section-desc mt-1 max-w-3xl">{{ t('admin.shippingAudit.subtitle') }}</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button type="button" class="btn-secondary btn-sm" :disabled="verifying" @click="runHashVerify">
|
||||
{{ verifying ? t('admin.shippingAudit.verifying') : t('admin.shippingAudit.verifyChain') }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary btn-sm" @click="loadAssociationChain">
|
||||
{{ t('admin.shippingAudit.loadChain') }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary btn-sm" :disabled="exporting" @click="exportCsv">
|
||||
{{ exporting ? t('admin.shippingAudit.exporting') : t('admin.shippingAudit.export') }}
|
||||
</button>
|
||||
@@ -147,8 +212,28 @@ onMounted(() => {
|
||||
|
||||
<div class="grid gap-3 rounded-xl border border-default bg-surface p-3 md:grid-cols-3 lg:grid-cols-4">
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.eventType') }}</span>
|
||||
<input v-model="filters.event_type" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
<span>{{ t('admin.shippingAudit.filters.workflowId') }}</span>
|
||||
<input v-model="filters.workflow_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.workflowItemId') }}</span>
|
||||
<input v-model="filters.workflow_item_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.runNo') }}</span>
|
||||
<input v-model="filters.run_no" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.documentId') }}</span>
|
||||
<input v-model="filters.document_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.reviewCaseNo') }}</span>
|
||||
<input v-model="filters.review_case_no" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.taskNo') }}</span>
|
||||
<input v-model="filters.task_no" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.actorType') }}</span>
|
||||
@@ -165,40 +250,8 @@ onMounted(() => {
|
||||
<input v-model="filters.actor_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.runNo') }}</span>
|
||||
<input v-model="filters.run_no" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.taskNo') }}</span>
|
||||
<input v-model="filters.task_no" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.documentId') }}</span>
|
||||
<input v-model="filters.document_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.conversationId') }}</span>
|
||||
<input v-model="filters.conversation_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.sessionItemId') }}</span>
|
||||
<input v-model="filters.session_item_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.reviewCaseNo') }}</span>
|
||||
<input v-model="filters.review_case_no" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.ownerUserId') }}</span>
|
||||
<input v-model="filters.owner_user_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.operationId') }}</span>
|
||||
<input v-model="filters.operation_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.requestId') }}</span>
|
||||
<input v-model="filters.request_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
<span>{{ t('admin.shippingAudit.filters.eventType') }}</span>
|
||||
<input v-model="filters.event_type" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingAudit.filters.result') }}</span>
|
||||
@@ -221,17 +274,29 @@ onMounted(() => {
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<p v-if="chainHint" class="rounded-lg border border-default bg-surface-soft px-3 py-2 text-xs text-secondary">{{ chainHint }}</p>
|
||||
<p
|
||||
v-if="verifyResult"
|
||||
class="rounded-lg border border-default bg-surface-soft px-3 py-2 text-xs text-secondary"
|
||||
data-testid="shipping-audit-verify-result"
|
||||
>
|
||||
{{ t('admin.shippingAudit.verifySummary', {
|
||||
ok: verifyResult.ok ? t('admin.shippingAudit.verifyOk') : t('admin.shippingAudit.verifyFailedShort'),
|
||||
checked: verifyResult.checked_chains,
|
||||
failed: verifyResult.failed_chains,
|
||||
}) }}
|
||||
</p>
|
||||
<p v-if="error" class="rounded-lg border border-rose-200 bg-rose-50 p-3 text-sm text-rose-700">{{ error }}</p>
|
||||
|
||||
<div class="overflow-x-auto rounded-xl border border-default bg-surface">
|
||||
<table class="min-w-[1280px] w-full text-left text-sm">
|
||||
<table class="min-w-[1360px] w-full text-left text-sm">
|
||||
<thead class="border-b border-default bg-surface-soft text-xs text-muted">
|
||||
<tr>
|
||||
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.time') }}</th>
|
||||
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.event') }}</th>
|
||||
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.actor') }}</th>
|
||||
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.conversation') }}</th>
|
||||
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.sessionItem') }}</th>
|
||||
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.workflow') }}</th>
|
||||
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.workflowItem') }}</th>
|
||||
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.reviewCase') }}</th>
|
||||
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.run') }}</th>
|
||||
<th class="px-3 py-2">{{ t('admin.shippingAudit.columns.task') }}</th>
|
||||
@@ -253,8 +318,8 @@ onMounted(() => {
|
||||
<div class="text-[11px] text-muted">{{ row.action || '—' }}</div>
|
||||
</td>
|
||||
<td class="px-3 py-2 text-xs">{{ row.actor_type }}<span v-if="row.actor_id"> / {{ row.actor_id }}</span></td>
|
||||
<td class="px-3 py-2 font-mono text-xs">{{ row.conversation_id || '—' }}</td>
|
||||
<td class="px-3 py-2 font-mono text-xs">{{ row.session_item_id || '—' }}</td>
|
||||
<td class="px-3 py-2 font-mono text-xs">{{ row.workflow_id || '—' }}</td>
|
||||
<td class="px-3 py-2 font-mono text-xs">{{ row.workflow_item_id || '—' }}</td>
|
||||
<td class="px-3 py-2 font-mono text-xs">{{ row.review_case_no || '—' }}</td>
|
||||
<td class="px-3 py-2 font-mono text-xs">{{ row.run_no || '—' }}</td>
|
||||
<td class="px-3 py-2 font-mono text-xs">{{ row.task_no || '—' }}</td>
|
||||
@@ -276,41 +341,10 @@ onMounted(() => {
|
||||
<button type="button" class="rounded border border-default px-3 py-1.5 disabled:opacity-50" :disabled="page * pageSize >= total || loading" @click="page += 1; load()">{{ t('admin.shippingAudit.next') }}</button>
|
||||
</div>
|
||||
|
||||
<div v-if="detail || detailLoading" class="fixed inset-0 z-50 flex justify-end bg-overlay" @click.self="detail = null">
|
||||
<aside class="h-full w-full max-w-xl overflow-y-auto bg-surface p-6 shadow-2xl">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">{{ t('admin.shippingAudit.detailTitle') }}</h2>
|
||||
<button type="button" class="text-secondary" @click="detail = null">{{ t('admin.close') }}</button>
|
||||
</div>
|
||||
<p v-if="detailLoading" class="mt-6 text-muted">{{ t('admin.shippingAudit.loading') }}</p>
|
||||
<template v-else-if="detail">
|
||||
<dl class="mt-5 grid grid-cols-2 gap-3 text-sm">
|
||||
<dt>{{ t('admin.shippingAudit.columns.event') }}</dt><dd>{{ detail.event_type }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.columns.actor') }}</dt><dd>{{ detail.actor_type }} / {{ detail.actor_id || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.columns.run') }}</dt><dd class="font-mono text-xs">{{ detail.run_no || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.columns.task') }}</dt><dd class="font-mono text-xs">{{ detail.task_no || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.filters.conversationId') }}</dt><dd class="font-mono text-xs">{{ detail.conversation_id || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.filters.sessionItemId') }}</dt><dd class="font-mono text-xs">{{ detail.session_item_id || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.filters.reviewCaseNo') }}</dt><dd class="font-mono text-xs">{{ detail.review_case_no || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.filters.ownerUserId') }}</dt><dd class="font-mono text-xs">{{ detail.owner_user_id || '—' }}</dd>
|
||||
<dt>operation_id</dt><dd class="font-mono text-xs">{{ detail.operation_id || '—' }}</dd>
|
||||
<dt>request_id</dt><dd class="font-mono text-xs">{{ detail.request_id || '—' }}</dd>
|
||||
</dl>
|
||||
<h3 class="mt-6 font-semibold">{{ t('admin.shippingAudit.diff') }}</h3>
|
||||
<div v-if="detail.diff?.length" class="mt-2 space-y-2">
|
||||
<div
|
||||
v-for="row in detail.diff"
|
||||
:key="row.key"
|
||||
class="rounded-lg border border-default p-3 text-xs"
|
||||
>
|
||||
<div class="font-medium">{{ row.key }} · {{ row.change }}</div>
|
||||
<div class="mt-1 text-muted">{{ t('admin.shippingAudit.before') }}: {{ row.before == null ? '—' : JSON.stringify(row.before) }}</div>
|
||||
<div class="text-muted">{{ t('admin.shippingAudit.after') }}: {{ row.after == null ? '—' : JSON.stringify(row.after) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="mt-2 text-sm text-muted">{{ t('admin.shippingAudit.noDiff') }}</p>
|
||||
</template>
|
||||
</aside>
|
||||
</div>
|
||||
<ShippingAuditEventDetailDrawer
|
||||
:detail="detail"
|
||||
:loading="detailLoading"
|
||||
@close="detail = null"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* features/admin/modules/shipping-audit/ShippingAuditEventDetailDrawer.spec.ts
|
||||
* 用途:锁定审计详情抽屉脱敏提示与 Diff 渲染契约。
|
||||
* 依赖:Vitest、@vue/test-utils、ShippingAuditEventDetailDrawer。
|
||||
* 逻辑:敏感脱敏文案可见;Diff 行按 key 渲染;无 Diff 显示空态。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import ShippingAuditEventDetailDrawer from './ShippingAuditEventDetailDrawer.vue';
|
||||
import type { ShippingAuditEventDetail } from '@/features/admin/api/shipping-audit.api';
|
||||
|
||||
const messages = {
|
||||
'zh-CN': {
|
||||
admin: {
|
||||
close: '关闭',
|
||||
shippingAudit: {
|
||||
detailTitle: '审计详情',
|
||||
loading: '正在加载...',
|
||||
sensitiveRedacted: '敏感快照已按权限脱敏',
|
||||
diff: '前后差异',
|
||||
before: '变更前',
|
||||
after: '变更后',
|
||||
noDiff: '无可展示的白名单差异',
|
||||
eventHash: '事件哈希',
|
||||
previousEventHash: '前序哈希',
|
||||
columns: { event: '事件', actor: '操作者', run: 'Run', task: 'Task', result: '结果' },
|
||||
filters: {
|
||||
workflowId: 'Workflow',
|
||||
workflowItemId: 'Workflow Item',
|
||||
documentId: 'PDF/文档',
|
||||
reviewCaseNo: 'Case',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 挂载详情抽屉。
|
||||
*/
|
||||
function mountDrawer(detail: ShippingAuditEventDetail | null, loading = false) {
|
||||
const i18n = createI18n({ legacy: false, locale: 'zh-CN', messages });
|
||||
return mount(ShippingAuditEventDetailDrawer, {
|
||||
props: { detail, loading },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
}
|
||||
|
||||
describe('ShippingAuditEventDetailDrawer', () => {
|
||||
it('shows sensitive redaction banner when snapshots are trimmed', () => {
|
||||
const detail: ShippingAuditEventDetail = {
|
||||
id: 1,
|
||||
event_type: 'order_review_confirmed',
|
||||
aggregate_type: 'shipping_order_review_case',
|
||||
aggregate_id: 'SRC-1',
|
||||
actor_type: 'user',
|
||||
has_snapshots: true,
|
||||
sensitive_redacted: true,
|
||||
diff: [],
|
||||
};
|
||||
const wrapper = mountDrawer(detail);
|
||||
// 关键断言:无敏感读权限时展示脱敏提示。
|
||||
expect(wrapper.find('[data-testid="shipping-audit-sensitive-redacted"]').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain('敏感快照已按权限脱敏');
|
||||
});
|
||||
|
||||
it('renders whitelist diff rows', () => {
|
||||
const detail: ShippingAuditEventDetail = {
|
||||
id: 2,
|
||||
event_type: 'status_changed',
|
||||
aggregate_type: 'order_extraction_run',
|
||||
aggregate_id: 'SNER-1',
|
||||
actor_type: 'system',
|
||||
has_snapshots: true,
|
||||
sensitive_redacted: false,
|
||||
diff: [{ key: 'status', change: 'changed', before: 'queued', after: 'processing' }],
|
||||
};
|
||||
const wrapper = mountDrawer(detail);
|
||||
// 关键断言:Diff 仅展示白名单键变化。
|
||||
expect(wrapper.find('[data-testid="shipping-audit-diff-rows"]').text()).toContain('status');
|
||||
expect(wrapper.text()).toContain('queued');
|
||||
expect(wrapper.text()).toContain('processing');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-audit/ShippingAuditEventDetailDrawer.vue
|
||||
用途:审计事件详情抽屉——元数据、敏感脱敏提示、白名单 Diff、哈希摘要。
|
||||
依赖:shipping-audit.api 类型、Vue I18n。
|
||||
逻辑:由 ShippingAuditCenterPage 传入 detail;关闭时 emit close;不自行拉接口。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingAuditEventDetail } from '@/features/admin/api/shipping-audit.api';
|
||||
|
||||
const props = defineProps<{
|
||||
detail: ShippingAuditEventDetail | null;
|
||||
loading?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const open = computed(() => Boolean(props.detail || props.loading));
|
||||
|
||||
/**
|
||||
* 关闭抽屉。
|
||||
*/
|
||||
function onClose() {
|
||||
emit('close');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="open"
|
||||
class="fixed inset-0 z-50 flex justify-end bg-overlay"
|
||||
data-testid="shipping-audit-detail-drawer"
|
||||
@click.self="onClose"
|
||||
>
|
||||
<aside class="h-full w-full max-w-xl overflow-y-auto bg-surface p-6 shadow-2xl">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-lg font-bold">{{ t('admin.shippingAudit.detailTitle') }}</h2>
|
||||
<button type="button" class="text-secondary" @click="onClose">{{ t('admin.close') }}</button>
|
||||
</div>
|
||||
<p v-if="loading" class="mt-6 text-muted">{{ t('admin.shippingAudit.loading') }}</p>
|
||||
<template v-else-if="detail">
|
||||
<p
|
||||
v-if="detail.sensitive_redacted"
|
||||
class="mt-4 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800"
|
||||
data-testid="shipping-audit-sensitive-redacted"
|
||||
>
|
||||
{{ t('admin.shippingAudit.sensitiveRedacted') }}
|
||||
</p>
|
||||
<dl class="mt-5 grid grid-cols-2 gap-3 text-sm">
|
||||
<dt>{{ t('admin.shippingAudit.columns.event') }}</dt>
|
||||
<dd>{{ detail.event_type }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.columns.actor') }}</dt>
|
||||
<dd>{{ detail.actor_type }} / {{ detail.actor_id || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.filters.workflowId') }}</dt>
|
||||
<dd class="font-mono text-xs">{{ detail.workflow_id || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.filters.workflowItemId') }}</dt>
|
||||
<dd class="font-mono text-xs">{{ detail.workflow_item_id || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.columns.run') }}</dt>
|
||||
<dd class="font-mono text-xs">{{ detail.run_no || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.filters.documentId') }}</dt>
|
||||
<dd class="font-mono text-xs">{{ detail.document_id || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.filters.reviewCaseNo') }}</dt>
|
||||
<dd class="font-mono text-xs">{{ detail.review_case_no || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.columns.task') }}</dt>
|
||||
<dd class="font-mono text-xs">{{ detail.task_no || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.columns.result') }}</dt>
|
||||
<dd>{{ detail.result || '—' }}</dd>
|
||||
<dt>operation_id</dt>
|
||||
<dd class="font-mono text-xs">{{ detail.operation_id || '—' }}</dd>
|
||||
<dt>request_id</dt>
|
||||
<dd class="font-mono text-xs">{{ detail.request_id || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.eventHash') }}</dt>
|
||||
<dd class="font-mono text-[10px] break-all">{{ detail.event_hash || '—' }}</dd>
|
||||
<dt>{{ t('admin.shippingAudit.previousEventHash') }}</dt>
|
||||
<dd class="font-mono text-[10px] break-all">{{ detail.previous_event_hash || '—' }}</dd>
|
||||
</dl>
|
||||
<h3 class="mt-6 font-semibold">{{ t('admin.shippingAudit.diff') }}</h3>
|
||||
<div v-if="detail.diff?.length" class="mt-2 space-y-2" data-testid="shipping-audit-diff-rows">
|
||||
<div
|
||||
v-for="row in detail.diff"
|
||||
:key="row.key"
|
||||
class="rounded-lg border border-default p-3 text-xs"
|
||||
>
|
||||
<div class="font-medium">{{ row.key }} · {{ row.change }}</div>
|
||||
<div class="mt-1 text-muted">{{ t('admin.shippingAudit.before') }}: {{ row.before == null ? '—' : JSON.stringify(row.before) }}</div>
|
||||
<div class="text-muted">{{ t('admin.shippingAudit.after') }}: {{ row.after == null ? '—' : JSON.stringify(row.after) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="mt-2 text-sm text-muted">{{ t('admin.shippingAudit.noDiff') }}</p>
|
||||
</template>
|
||||
</aside>
|
||||
</div>
|
||||
</template>
|
||||
+34
-20
@@ -48,7 +48,7 @@ const hasTrainingSample = ref(false);
|
||||
const availableSamplesLoaded = ref(false);
|
||||
const availableSamplesLoading = ref(false);
|
||||
const uploadingSample = ref(false);
|
||||
const pendingUpload = ref<{ intakeNo: string; filename: string; state: 'parsing' | 'failed' } | null>(null);
|
||||
const pendingUpload = ref<{ intakeNo: string; filename: string; state: 'parsing' | 'failed'; errorCode?: string | null } | null>(null);
|
||||
let uploadPollingTimer: number | null = null;
|
||||
let availableSamplesController: AbortController | null = null;
|
||||
let availableSamplesTimeout: number | null = null;
|
||||
@@ -86,12 +86,16 @@ const failureDetails = computed(() => (suite.value?.latest_run?.failure_codes ||
|
||||
return { code, message: t('admin.shippingOrderProfiles.blindTest.failure.unknown', { sample: sampleName }) };
|
||||
}));
|
||||
/** 读取订单字段复核状态;候选加载完成时会初始化,默认值仅用于渲染过程中的安全兜底。 */
|
||||
function orderFieldReview(fieldCode: string): { correct: boolean; value: string } {
|
||||
return orderFieldReviews.value[fieldCode] || { correct: true, value: '' };
|
||||
function orderFieldReview(fieldKey: string): { correct: boolean; value: string } {
|
||||
return orderFieldReviews.value[fieldKey] || { correct: true, value: '' };
|
||||
}
|
||||
/** 更新单个订单字段的人工复核状态,保持其他字段复核结果不被输入事件覆盖。 */
|
||||
function updateOrderFieldReview(fieldCode: string, patch: Partial<{ correct: boolean; value: string }>): void {
|
||||
orderFieldReviews.value[fieldCode] = { ...orderFieldReview(fieldCode), ...patch };
|
||||
function updateOrderFieldReview(fieldKey: string, patch: Partial<{ correct: boolean; value: string }>): void {
|
||||
orderFieldReviews.value[fieldKey] = { ...orderFieldReview(fieldKey), ...patch };
|
||||
}
|
||||
/** 复核与服务端使用同一个 scope:field_code 键,避免同名 Header/Line 字段覆盖。 */
|
||||
function orderFieldKey(field: { scope: 'header'; field_code: string }): string {
|
||||
return `${field.scope}:${field.field_code}`;
|
||||
}
|
||||
|
||||
/** 将统一业务错误转换为安全的界面提示,不暴露盲测真值或内部布局数据。 */
|
||||
@@ -99,6 +103,15 @@ function report(error: unknown): void {
|
||||
const code = error instanceof BusinessError ? error.code : '';
|
||||
message.error(code ? t(`errors.${code}`, code) : t('admin.orderProfileValidation.failed'));
|
||||
}
|
||||
/** 将模板布局失败码转成盲测页可执行的提示,不向管理员回显内部快照数据。 */
|
||||
function sampleFailureMessage(errorCode?: string | null): string {
|
||||
const key = errorCode === 'mineru_cell_coordinates_missing'
|
||||
? 'sampleLayoutCoordinatesMissing'
|
||||
: errorCode === 'shipping_document_layout_snapshot_size_exceeded'
|
||||
? 'sampleLayoutSnapshotTooLarge'
|
||||
: 'sampleParseFailed';
|
||||
return t(`admin.shippingOrderProfiles.wizard.${key}`);
|
||||
}
|
||||
|
||||
/** 创建或读取当前草稿 checksum 对应的盲测集;候选样本按需加载,避免进入页面时扫描全部历史样本。 */
|
||||
async function loadSuite(): Promise<void> {
|
||||
@@ -174,7 +187,9 @@ async function pollUploadedSample(intakeNo: string): Promise<void> {
|
||||
return;
|
||||
}
|
||||
if (['failed', 'error'].includes(result.parse_status)) {
|
||||
pendingUpload.value = { intakeNo, filename: pendingUpload.value?.filename || '', state: 'failed' };
|
||||
pendingUpload.value = {
|
||||
intakeNo, filename: pendingUpload.value?.filename || '', state: 'failed', errorCode: result.error_code,
|
||||
};
|
||||
return;
|
||||
}
|
||||
uploadPollingTimer = window.setTimeout(() => void pollUploadedSample(intakeNo), 1500);
|
||||
@@ -215,7 +230,7 @@ async function previewSample(): Promise<void> {
|
||||
candidate.value = await previewOrderProfileBlindTestCandidate(suite.value.id, selectedSample.value);
|
||||
rowReviews.value = candidate.value.rows.map(() => ({ correct: true, correction: '' }));
|
||||
orderFieldReviews.value = Object.fromEntries(candidate.value.order_fields.map((field) => [
|
||||
field.field_code,
|
||||
orderFieldKey(field),
|
||||
{ correct: true, value: field.value == null ? '' : String(field.value) },
|
||||
]));
|
||||
} catch (error) {
|
||||
@@ -256,8 +271,8 @@ async function confirmReview(): Promise<void> {
|
||||
document_id: candidate.value.document_id,
|
||||
table_id: candidate.value.table_id,
|
||||
row_reviews: reviews,
|
||||
order_field_reviews: Object.fromEntries(Object.entries(orderFieldReviews.value).map(([fieldCode, review]) => [
|
||||
fieldCode,
|
||||
order_field_reviews: Object.fromEntries(Object.entries(orderFieldReviews.value).map(([fieldKey, review]) => [
|
||||
fieldKey,
|
||||
review.correct ? { correct: true } : { correct: false, value: review.value },
|
||||
])),
|
||||
});
|
||||
@@ -356,11 +371,10 @@ onBeforeUnmount(() => {
|
||||
</section>
|
||||
|
||||
<section v-if="suite.status === 'draft'" class="card">
|
||||
<h2>{{ t('admin.shippingOrderProfiles.blindTest.selectIndependentSample') }}</h2>
|
||||
<p v-if="!availableSamplesLoaded">{{ t('admin.shippingOrderProfiles.blindTest.loadIndependentSamplesHint') }}</p>
|
||||
<p v-else-if="!availableSamples.length">{{ t('admin.shippingOrderProfiles.blindTest.noIndependentSamples') }}</p>
|
||||
<div class="sample-picker"><label class="btn-secondary upload-sample"><input type="file" accept=".pdf,.eml,application/pdf,message/rfc822" :disabled="uploadingSample" @change="uploadIndependentSample"><span>{{ uploadingSample ? t('admin.shippingOrderProfiles.wizard.uploading') : t('admin.shippingOrderProfiles.wizard.uploadNewSample') }}</span></label><button v-if="!availableSamplesLoaded" type="button" class="btn-secondary" :disabled="availableSamplesLoading" @click="() => void loadAvailableSamples()">{{ availableSamplesLoading ? t('admin.shippingOrderProfiles.blindTest.loadingIndependentSamples') : t('admin.shippingOrderProfiles.blindTest.loadIndependentSamples') }}</button><template v-else-if="availableSamples.length"><select v-model="selectedSampleKey" class="select-field"><option value="">{{ t('admin.shippingOrderProfiles.blindTest.selectSamplePlaceholder') }}</option><option v-for="sample in availableSamples" :key="`${sample.document_id}:${sample.table_id}`" :value="`${sample.document_id}:${sample.table_id}`">{{ sampleLabel(sample) }}</option></select><button type="button" class="btn-primary" :disabled="!selectedSample || working" @click="previewSample">{{ t('admin.shippingOrderProfiles.blindTest.addCurrentSample') }}</button></template></div>
|
||||
<p v-if="pendingUpload" class="upload-status" :class="{ failed: pendingUpload.state === 'failed' }">{{ pendingUpload.filename }} · {{ pendingUpload.state === 'parsing' ? t('admin.shippingOrderProfiles.wizard.sampleParsing') : t('admin.shippingOrderProfiles.wizard.sampleParseFailed') }}</p>
|
||||
<div class="sample-heading"><h2>{{ t('admin.shippingOrderProfiles.blindTest.selectIndependentSample') }}</h2><label class="btn-secondary upload-sample"><input type="file" accept=".pdf,.eml,application/pdf,message/rfc822" :disabled="uploadingSample" @change="uploadIndependentSample"><span>{{ uploadingSample ? t('admin.shippingOrderProfiles.wizard.uploading') : t('admin.shippingOrderProfiles.blindTest.uploadSample') }}</span></label></div>
|
||||
<p v-if="availableSamplesLoaded && !availableSamples.length">{{ t('admin.shippingOrderProfiles.blindTest.noIndependentSamples') }}</p>
|
||||
<div class="sample-picker"><button v-if="!availableSamplesLoaded" type="button" class="btn-secondary" :disabled="availableSamplesLoading" @click="() => void loadAvailableSamples()">{{ availableSamplesLoading ? t('admin.shippingOrderProfiles.blindTest.loadingIndependentSamples') : t('admin.shippingOrderProfiles.blindTest.loadIndependentSamples') }}</button><template v-else-if="availableSamples.length"><select v-model="selectedSampleKey" class="select-field"><option value="">{{ t('admin.shippingOrderProfiles.blindTest.selectSamplePlaceholder') }}</option><option v-for="sample in availableSamples" :key="`${sample.document_id}:${sample.table_id}`" :value="`${sample.document_id}:${sample.table_id}`">{{ sampleLabel(sample) }}</option></select><button type="button" class="btn-primary" :disabled="!selectedSample || working" @click="previewSample">{{ t('admin.shippingOrderProfiles.blindTest.previewAndReview') }}</button></template></div>
|
||||
<p v-if="pendingUpload" class="upload-status" :class="{ failed: pendingUpload.state === 'failed' }">{{ pendingUpload.filename }} · {{ pendingUpload.state === 'parsing' ? t('admin.shippingOrderProfiles.wizard.sampleParsing') : sampleFailureMessage(pendingUpload.errorCode) }}</p>
|
||||
</section>
|
||||
|
||||
<section v-if="candidate" class="card candidate-card">
|
||||
@@ -373,10 +387,10 @@ onBeforeUnmount(() => {
|
||||
<textarea v-if="!rowReviews[index].correct" v-model="rowReviews[index].correction" class="input-field" :placeholder="t('admin.shippingOrderProfiles.blindTest.expectedRowsPlaceholder')" />
|
||||
</template>
|
||||
</article>
|
||||
<article v-for="field in candidate.order_fields" :key="field.field_code" class="review-item">
|
||||
<article v-for="field in candidate.order_fields" :key="field.field_id" class="review-item">
|
||||
<h3>{{ field.field_code }}</h3><code>{{ field.value ?? t('admin.shippingOrderProfiles.emptyCandidateValue') }}</code>
|
||||
<label><input :checked="orderFieldReview(field.field_code).correct" type="checkbox" @change="updateOrderFieldReview(field.field_code, { correct: ($event.target as HTMLInputElement).checked })">{{ t('admin.shippingOrderProfiles.blindTest.correct') }}</label>
|
||||
<input v-if="!orderFieldReview(field.field_code).correct" class="input-field" :value="orderFieldReview(field.field_code).value" :placeholder="t('admin.shippingOrderProfiles.blindTest.correctedValue')" @input="updateOrderFieldReview(field.field_code, { value: ($event.target as HTMLInputElement).value })">
|
||||
<label><input :checked="orderFieldReview(orderFieldKey(field)).correct" type="checkbox" @change="updateOrderFieldReview(orderFieldKey(field), { correct: ($event.target as HTMLInputElement).checked })">{{ t('admin.shippingOrderProfiles.blindTest.correct') }}</label>
|
||||
<input v-if="!orderFieldReview(orderFieldKey(field)).correct" class="input-field" :value="orderFieldReview(orderFieldKey(field)).value" :placeholder="t('admin.shippingOrderProfiles.blindTest.correctedValue')" @input="updateOrderFieldReview(orderFieldKey(field), { value: ($event.target as HTMLInputElement).value })">
|
||||
</article>
|
||||
<button type="button" class="btn-primary" :disabled="working || !candidate.rows.length" @click="confirmReview">{{ t('admin.shippingOrderProfiles.blindTest.confirmReview') }}</button>
|
||||
</section>
|
||||
@@ -390,16 +404,16 @@ onBeforeUnmount(() => {
|
||||
|
||||
<style scoped>
|
||||
.blind-test-page { padding: 24px; color: var(--text-secondary); }
|
||||
header, .suite-summary, .execution, .actions, .sample-picker, li { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||||
header, .suite-summary, .execution, .actions, .sample-heading, .sample-picker, li { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||||
header { align-items: flex-start; margin-bottom: 24px; } h1, h2, h3, p { margin: 0; } h2 { font-size: 16px; } h3 { font-size: 14px; } p:not(.section-desc) { margin-top: 6px; color: var(--text-muted); font-size: 13px; line-height: 1.5; }
|
||||
.card { display: grid; gap: 14px; margin-top: 14px; border: 1px solid var(--border-default); border-radius: 12px; background: var(--bg-surface); padding: 18px; }
|
||||
.status { color: var(--status-warning-fg); font-weight: 700; } .status.approved { color: var(--status-success-fg); } .status.superseded { color: var(--status-error-fg); }
|
||||
.sample-picker .select-field { min-width: 260px; } .candidate-card .input-field { padding: 8px; border-radius: 6px; } textarea.input-field { min-height: 72px; font-family: ui-monospace, monospace; }
|
||||
.sample-heading { align-items: center; }.sample-picker { justify-content: flex-start; }.sample-picker .select-field { flex: 1; min-width: 0; } .sample-picker button, .upload-sample { flex: 0 0 auto; white-space: nowrap; } .candidate-card .input-field { padding: 8px; border-radius: 6px; } textarea.input-field { min-height: 72px; font-family: ui-monospace, monospace; }
|
||||
.upload-sample { position: relative; cursor: pointer; }.upload-sample input { position: absolute; width: 1px; height: 1px; opacity: 0; }.upload-status { margin: 10px 0 0; color: var(--status-info-fg); font-size: .85rem; }.upload-status.failed { color: var(--status-error-fg); }
|
||||
.candidate-card { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); } .candidate-card > h2, .candidate-card > p, .candidate-card > button { grid-column: 1 / -1; }
|
||||
.review-item { display: grid; gap: 8px; border: 1px solid var(--border-default); border-radius: 8px; padding: 12px; } code { overflow-wrap: anywhere; white-space: pre-wrap; color: var(--text-primary); font-size: 12px; } label { display: flex; gap: 6px; align-items: center; }
|
||||
ul { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; } li { border-top: 1px solid var(--border-default); padding-top: 8px; }
|
||||
.failure-details { border-color: var(--status-error-border); background: var(--status-error-bg); }.failure-details h2 { color: var(--status-error-fg); }.failure-details li { display: grid; gap: 4px; color: var(--status-error-fg); }.failure-details code { color: var(--status-error-fg); }
|
||||
.training-required { color: var(--status-warning-fg) !important; font-weight: 600; }
|
||||
@media (max-width: 700px) { header, .suite-summary, .execution, .sample-picker { align-items: stretch; flex-direction: column; } .sample-picker .select-field { min-width: 0; width: 100%; } }
|
||||
@media (max-width: 700px) { header, .suite-summary, .execution, .sample-heading, .sample-picker { align-items: stretch; flex-direction: column; } .sample-picker .select-field { min-width: 0; width: 100%; } }
|
||||
</style>
|
||||
+22
-4
@@ -5,7 +5,7 @@
|
||||
逻辑:首步仅收集业务名称和 Schema;最后一步由服务端生成系统编码并原子创建草稿、样本绑定、Revision 与 Lease。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue';
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ArrowLeft, ArrowRight, Check, FileText, Layers3, Sparkles } from 'lucide-vue-next';
|
||||
@@ -33,6 +33,7 @@ const identity = reactive<Identity>({ displayName: '', schemaId: 0 });
|
||||
const documentId = ref(0);
|
||||
const tableId = ref('');
|
||||
const browserSessionId = crypto.randomUUID();
|
||||
let sampleRefreshTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
const publishedSchemas = computed(() => schemas.value.filter((item) => item.status === 'published'));
|
||||
const canNext = computed(() => step.value === 1
|
||||
? Boolean(identity.displayName.trim() && identity.schemaId)
|
||||
@@ -59,10 +60,22 @@ async function loadContext(): Promise<void> {
|
||||
message.error(error instanceof BusinessError ? error.message : t('admin.shippingOrderProfiles.wizard.loadFailed'));
|
||||
}
|
||||
}
|
||||
/** 刷新上传后的样本库;样本解析未完成时只会留在样本库,不能产出半成品模板。 */
|
||||
async function refreshSamples(): Promise<void> {
|
||||
/** 刷新上传后的样本库;轮询失败静默处理,避免短暂网络异常持续弹出提示。 */
|
||||
async function refreshSamples(showError = true): Promise<void> {
|
||||
try { samples.value = await listOrderProfileSamples(); }
|
||||
catch { message.error(t('admin.shippingOrderProfiles.wizard.loadFailed')); }
|
||||
catch { if (showError) message.error(t('admin.shippingOrderProfiles.wizard.loadFailed')); }
|
||||
}
|
||||
/** 仅在第二步保持已解析文档列表为最新,离开步骤后立即停止。 */
|
||||
function stopSampleRefresh(): void {
|
||||
if (sampleRefreshTimer !== null) clearTimeout(sampleRefreshTimer);
|
||||
sampleRefreshTimer = null;
|
||||
}
|
||||
function scheduleSampleRefresh(): void {
|
||||
stopSampleRefresh();
|
||||
if (step.value !== 2) return;
|
||||
void refreshSamples(false).finally(() => {
|
||||
if (step.value === 2) sampleRefreshTimer = setTimeout(scheduleSampleRefresh, 2000);
|
||||
});
|
||||
}
|
||||
/** 加载选定样本的可用表格;单表场景由下一步直接作为订单明细表。 */
|
||||
async function loadTables(id: number): Promise<void> {
|
||||
@@ -75,6 +88,10 @@ watch(documentId, async (id) => {
|
||||
if (!id) return;
|
||||
await loadTables(id);
|
||||
});
|
||||
watch(step, (currentStep) => {
|
||||
if (currentStep === 2) scheduleSampleRefresh();
|
||||
else stopSampleRefresh();
|
||||
});
|
||||
/** 前进仅校验当前步骤;单表直接创建,多表才要求管理员确认订单明细表。 */
|
||||
async function next(): Promise<void> {
|
||||
if (!canNext.value) {
|
||||
@@ -117,6 +134,7 @@ async function finish(enterEditor: boolean): Promise<void> {
|
||||
} finally { saving.value = false; }
|
||||
}
|
||||
onMounted(loadContext);
|
||||
onBeforeUnmount(stopSampleRefresh);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
+221
-82
@@ -1,8 +1,9 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-order-document-profiles/OrderProfileEditorPage.vue
|
||||
用途:订单坐标 Profile v2 的独立草稿标注编辑页。
|
||||
依赖:受控预览 API、Schema API、DocumentCanvas、IssuePanel。
|
||||
逻辑:仅编辑由向导创建的草稿;撤销/重做、自动保存和建议决定均受当前标签租约保护。
|
||||
依赖:受控预览 API、Schema API、DocumentCanvas、IssuePanel、shippingOrderField.utils。
|
||||
逻辑:仅编辑由向导创建的草稿;起行锚点默认 customer_po_line_no(内部项次 line_no 亦可绑定);
|
||||
撤销/重做、自动保存和建议决定均受当前标签租约保护。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
@@ -59,7 +60,10 @@ import {
|
||||
suggestFieldCodeFromHeaders,
|
||||
toOrderProfileAnchorId,
|
||||
buildOrderProfileRecognitionResults,
|
||||
groupUniqueOrderProfileLineFields,
|
||||
isOrderProfileAnchorRelativeCandidate,
|
||||
normalizeOrderProfileRelativeRegion,
|
||||
toOrderProfileAnchorRelativeRegion,
|
||||
} from "./orderProfileForm.utils";
|
||||
|
||||
const { t } = useI18n();
|
||||
@@ -94,6 +98,7 @@ const sampleTables = ref<
|
||||
const preview = ref<CoordinateReconstructionPreview | null>(null);
|
||||
const orderFieldValuePreviews = ref<OrderFieldValuePreview[]>([]);
|
||||
const orderFieldValueState = ref<'idle' | 'loading' | 'ready' | 'failed'>('idle');
|
||||
const orderFieldValueError = ref('');
|
||||
const previewError = ref("");
|
||||
const headerSuggestions = ref<
|
||||
Array<{
|
||||
@@ -141,6 +146,7 @@ let previewTimer: number | null = null;
|
||||
let orderFieldValueTimer: number | null = null;
|
||||
let pendingGestureId: string | null = null;
|
||||
let pendingFormEdit: OrderProfileCanvasRegion[] | null = null;
|
||||
let restoringProfile = false;
|
||||
|
||||
const form = reactive({
|
||||
profileCode: "",
|
||||
@@ -169,9 +175,22 @@ const lineFields = computed<ShippingOrderFieldConfig[]>(
|
||||
(item) =>
|
||||
item.enabled !== false &&
|
||||
item.scope === "line" &&
|
||||
item.field_code != null &&
|
||||
item.allowed_sources?.includes("pdf_coordinate"),
|
||||
) || [],
|
||||
);
|
||||
/** 根据当前主行映射自动选择起行字段,优先客户 PO 行号,避免暴露内部配置。 */
|
||||
const resolveLineStartFieldCode = (mainLineFieldCodes: Set<string>): string => {
|
||||
const availableFieldCodes = new Set(
|
||||
lineFields.value.map((field) => field.field_code).filter(Boolean),
|
||||
);
|
||||
const validMainLineCodes = [...mainLineFieldCodes].filter((fieldCode) =>
|
||||
availableFieldCodes.has(fieldCode),
|
||||
);
|
||||
return validMainLineCodes.includes("customer_po_line_no")
|
||||
? "customer_po_line_no"
|
||||
: validMainLineCodes[0] || "customer_po_line_no";
|
||||
};
|
||||
/** 订单单头区域只能绑定 Schema 中声明为 header 的坐标字段。 */
|
||||
const headerFields = computed<ShippingOrderFieldConfig[]>(
|
||||
() =>
|
||||
@@ -193,7 +212,7 @@ const selectedRegion = computed(
|
||||
/** 当前样本值只能来自本次按画布坐标回读的结果,禁止回退到旧的自动建议缓存。 */
|
||||
const selectedRegionSampleValue = computed(() => {
|
||||
const region = selectedRegion.value;
|
||||
if (!region || !['order_field', 'header_field'].includes(region.kind)) return null;
|
||||
if (!region || region.kind !== 'order_field') return null;
|
||||
if (region.suggestedValue) return region.suggestedValue;
|
||||
if (!region.fieldCode) return null;
|
||||
return orderFieldValuePreviews.value.find((item) => item.field_code === region.fieldCode)?.value || null;
|
||||
@@ -201,7 +220,7 @@ const selectedRegionSampleValue = computed(() => {
|
||||
/** 右侧选区值与画布标签共享同一个读取状态,禁止以旧建议值回退。 */
|
||||
const selectedRegionSampleDisplay = computed(() => {
|
||||
if (orderFieldValueState.value === 'loading') return t('admin.shippingOrderProfiles.workbench.orderFieldValueReading');
|
||||
if (orderFieldValueState.value === 'failed') return t('admin.shippingOrderProfiles.workbench.orderFieldValueFailed');
|
||||
if (orderFieldValueState.value === 'failed') return orderFieldValueError.value || t('admin.shippingOrderProfiles.workbench.orderFieldValueFailed');
|
||||
return selectedRegionSampleValue.value || t('admin.shippingOrderProfiles.workbench.sampleValueUnavailable');
|
||||
});
|
||||
const orderFieldValues = computed<Record<string, string | null>>(() => Object.fromEntries(
|
||||
@@ -311,6 +330,23 @@ const issues = computed(() => {
|
||||
if (duplicateOrderFieldCodes.length) {
|
||||
result.push(`订单字段 ${[...new Set(duplicateOrderFieldCodes)].join(", ")} 已在其他区域绑定;请编辑原区域或先解除原绑定。`);
|
||||
}
|
||||
const pageNos = [...new Set(regions.value.filter((item) => item.kind === "line").map((item) => item.pageNo))];
|
||||
for (const regionPageNo of pageNos) {
|
||||
const pageLines = regions.value
|
||||
.filter((item) => item.pageNo === regionPageNo && item.kind === "line")
|
||||
.sort((left, right) => left.region.y0 - right.region.y0);
|
||||
const mainLine = pageLines[0];
|
||||
if (!mainLine) continue;
|
||||
const mainLineFieldCodes = regions.value
|
||||
.filter((item) => item.kind === "field" && item.parentId === mainLine.id && item.fieldCode)
|
||||
.map((item) => item.fieldCode!);
|
||||
if (!mainLineFieldCodes.length) continue;
|
||||
const startFieldCode = resolveLineStartFieldCode(new Set(mainLineFieldCodes));
|
||||
if (!mainLineFieldCodes.includes(startFieldCode)) {
|
||||
result.push(t("admin.shippingOrderProfiles.workbench.issues.lineStartAnchorRequired"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
/** 将 API 业务错误转换为工作台消息,避免内部错误详情出现在页面。 */
|
||||
@@ -341,6 +377,18 @@ const checkpoint = () => {
|
||||
markLocalChange();
|
||||
scheduleAutosave();
|
||||
};
|
||||
/**
|
||||
* 为订单字段及其标签锚点分配同一命名空间内的唯一序号。
|
||||
* 直接框选值和“标签 + 值”两种标注方式会共同写入 order_field_layouts,不能各自从 1 编号。
|
||||
*/
|
||||
const nextOrderFieldSequence = (targetPageNo: number): number => {
|
||||
const occupiedIds = new Set(
|
||||
regions.value.flatMap((region) => [region.id, region.orderFieldId].filter(Boolean)),
|
||||
);
|
||||
let sequence = 1;
|
||||
while (occupiedIds.has(`order_field_${targetPageNo}_${sequence}`)) sequence += 1;
|
||||
return sequence;
|
||||
};
|
||||
/** 记录输入控件编辑前的状态;只有值实际变化时才写入撤销历史。 */
|
||||
const beginFormEdit = () => {
|
||||
pendingFormEdit = snapshot();
|
||||
@@ -356,6 +404,17 @@ const finishFormEdit = () => {
|
||||
scheduleOrderFieldSuggestionValues();
|
||||
scheduleAutosave();
|
||||
};
|
||||
/**
|
||||
* 同步订单字段的可见标签与其 Schema 绑定,避免字段已改为送货地址而画布仍显示账款地址。
|
||||
* 表头/明细列保留原始文档文字,只有订单字段使用 Schema 业务名称作为稳定展示标签。
|
||||
*/
|
||||
const finishFieldBindingEdit = () => {
|
||||
const target = selectedRegion.value;
|
||||
if (target?.kind === 'order_field' && target.fieldCode) {
|
||||
target.label = schemaFieldLabel(target.fieldCode);
|
||||
}
|
||||
finishFormEdit();
|
||||
};
|
||||
/** 撤销上一项区域、字段或删除操作。 */
|
||||
const undo = () => {
|
||||
const prior = history.value.pop();
|
||||
@@ -439,7 +498,9 @@ const addRegion = (
|
||||
y1: 0.35 + count * 0.06,
|
||||
});
|
||||
// layout_id is persisted, so generate a contract-safe and non-reused identifier rather than using a timestamp.
|
||||
let sequence = count;
|
||||
let sequence = effectiveKind === 'order_field'
|
||||
? nextOrderFieldSequence(pageNo.value)
|
||||
: count;
|
||||
while (
|
||||
regions.value.some(
|
||||
(entry) => entry.id === `${effectiveKind}_${pageNo.value}_${sequence}`,
|
||||
@@ -554,7 +615,7 @@ const createDrawnRegion = async (region: OrderProfileRelativeRegion) => {
|
||||
}
|
||||
history.value.push(snapshot());
|
||||
future.value = [];
|
||||
const sequence = pageRegions.value.filter((item) => item.kind === 'order_anchor').length + 1;
|
||||
const sequence = nextOrderFieldSequence(pageNo.value);
|
||||
const orderFieldId = `order_field_${pageNo.value}_${sequence}`;
|
||||
const anchor: OrderProfileCanvasRegion = {
|
||||
id: `${orderFieldId}_anchor`, kind, label, region, orderFieldId, pageNo: pageNo.value,
|
||||
@@ -576,7 +637,10 @@ const createDrawnRegion = async (region: OrderProfileRelativeRegion) => {
|
||||
const anchor = pendingOrderFieldAnchor.value;
|
||||
const valueRegion: OrderProfileCanvasRegion = {
|
||||
id: anchor.orderFieldId!, kind, label: value, region, parentId: anchor.id,
|
||||
orderFieldId: anchor.orderFieldId, valueMode: 'single_line', suggestedValue: value, pageNo: pageNo.value,
|
||||
// The Schema selector uses null for its explicit "unbound" option. Do not
|
||||
// leave this undefined, otherwise a newly drawn value box can retain the
|
||||
// previous selected address field in the browser control.
|
||||
fieldCode: null, orderFieldId: anchor.orderFieldId, valueMode: 'single_line', suggestedValue: value, pageNo: pageNo.value,
|
||||
};
|
||||
regions.value.push(valueRegion);
|
||||
pendingOrderFieldAnchor.value = null;
|
||||
@@ -685,47 +749,39 @@ const updateRegion = (id: string, region: OrderProfileRelativeRegion) => {
|
||||
};
|
||||
/** 将区域编辑器转换为严格 v2 定义;浏览器只发送白名单 field_code/解析器和相对区域。 */
|
||||
const definition = () => {
|
||||
// 自动建议和历史草稿可能带有浮点边界误差;保存前统一裁剪,保证绝对值框合法。
|
||||
regions.value = regions.value.map((item) => ({
|
||||
// Build a normalized payload without mutating canvas state. Preview requests must
|
||||
// not turn an unsaved relative value box into a different local annotation.
|
||||
const normalizedRegions = regions.value.map((item) => ({
|
||||
...item,
|
||||
region: normalizedCanvasRegion(item.region) || item.region,
|
||||
}));
|
||||
const tableRegions = [...new Set(
|
||||
regions.value
|
||||
normalizedRegions
|
||||
.filter((item) => item.kind === "line" || item.kind === "header_field")
|
||||
.map((item) => item.pageNo),
|
||||
)]
|
||||
.sort((left, right) => left - right)
|
||||
.map((regionPageNo) => {
|
||||
const pageItems = regions.value.filter(
|
||||
const pageItems = normalizedRegions.filter(
|
||||
(item) => item.pageNo === regionPageNo,
|
||||
);
|
||||
const lineRegions = pageItems.filter((item) => item.kind === "line");
|
||||
const boundLineFieldRegionIds = new Set<string>();
|
||||
const boundLineFieldCodes = new Set<string>();
|
||||
const groupedLineFields = groupUniqueOrderProfileLineFields(
|
||||
pageItems,
|
||||
lineRegions.map((item) => item.id),
|
||||
);
|
||||
const boundLineFieldRegionIds = groupedLineFields.boundRegionIds;
|
||||
/** 将已分组的画布字段转换为 v2 字段区域;重复读取不会改变后续保存内容。 */
|
||||
const fieldRegionsFor = (layoutId: string): OrderProfileFieldRegion[] =>
|
||||
pageItems
|
||||
.filter(
|
||||
(item) =>
|
||||
item.kind === "field" &&
|
||||
item.parentId === layoutId &&
|
||||
item.fieldCode &&
|
||||
!boundLineFieldCodes.has(item.fieldCode),
|
||||
)
|
||||
.map((item) => {
|
||||
// The v2 contract assigns each Schema line field one coordinate source.
|
||||
// Continuation-row frames remain visible, but cannot duplicate that binding.
|
||||
boundLineFieldCodes.add(item.fieldCode!);
|
||||
boundLineFieldRegionIds.add(item.id);
|
||||
return {
|
||||
(groupedLineFields.fieldsByLayout.get(layoutId) || []).map((item) => ({
|
||||
field_id: "",
|
||||
field_code: item.fieldCode!,
|
||||
scope: "line" as const,
|
||||
region: item.region,
|
||||
extractor_key: "direct",
|
||||
allowed_sources: ["pdf_coordinate"],
|
||||
minimum_evidence_level: "coordinate",
|
||||
};
|
||||
});
|
||||
}));
|
||||
const headerLayouts = pageItems
|
||||
.filter((item) => item.kind === "header_field" && item.parentId)
|
||||
.reduce<string[]>((layoutIds, item) => {
|
||||
@@ -750,6 +806,7 @@ const definition = () => {
|
||||
.map((field) => ({
|
||||
field_id: "",
|
||||
field_code: field.fieldCode!,
|
||||
scope: "line" as const,
|
||||
region: field.region,
|
||||
extractor_key: "direct" as const,
|
||||
allowed_sources: ["pdf_coordinate" as const],
|
||||
@@ -769,11 +826,18 @@ const definition = () => {
|
||||
y1: Math.max(...layoutRegions.map((item) => item.region.y1)),
|
||||
}
|
||||
: { x0: 0.1, y0: 0.25, x1: 0.9, y1: 0.85 };
|
||||
const firstLineRegion = lineRegions[0];
|
||||
const mainLineFieldCodes = new Set(
|
||||
firstLineRegion
|
||||
? fieldRegionsFor(firstLineRegion.id).map((item) => item.field_code)
|
||||
: [],
|
||||
);
|
||||
return {
|
||||
region_id: `main_lines_page_${regionPageNo}`,
|
||||
page_scope: "exact_page" as const,
|
||||
page_no: regionPageNo,
|
||||
region: tableRegion,
|
||||
line_start_field_code: resolveLineStartFieldCode(mainLineFieldCodes),
|
||||
header_layouts: headerLayouts,
|
||||
line_layouts: lineRegions.map((line, index) => {
|
||||
const fieldRegions = fieldRegionsFor(line.id);
|
||||
@@ -821,19 +885,25 @@ const definition = () => {
|
||||
minimum_margin: documentMatch.minimumMargin,
|
||||
},
|
||||
table_regions: tableRegions,
|
||||
order_field_layouts: regions.value
|
||||
order_field_layouts: normalizedRegions
|
||||
.filter((item) => item.kind === "order_field" && item.fieldCode)
|
||||
.map((item) => {
|
||||
const anchor = regions.value.find(
|
||||
const anchor = normalizedRegions.find(
|
||||
(candidate) =>
|
||||
candidate.kind === "order_anchor" &&
|
||||
(candidate.id === item.parentId || candidate.orderFieldId === item.orderFieldId),
|
||||
);
|
||||
const anchorId = toOrderProfileAnchorId(anchor);
|
||||
const isAnchorRelative = Boolean(anchor && anchorId && ["right_of_anchor", "below_anchor"].includes(item.valueMode || "")
|
||||
&& isOrderProfileAnchorRelativeCandidate(item.region, anchor.region));
|
||||
const relativeValueRegion = isAnchorRelative && anchor
|
||||
? toOrderProfileAnchorRelativeRegion(item.region, anchor.region)
|
||||
: null;
|
||||
return {
|
||||
layout_id: item.orderFieldId || item.id,
|
||||
field_id: "",
|
||||
field_code: item.fieldCode!,
|
||||
scope: "header" as const,
|
||||
page_scope: "exact_page" as const,
|
||||
page_no: item.pageNo,
|
||||
// Historical unbound labels can lack a usable canvas ID. In that case,
|
||||
@@ -845,12 +915,13 @@ const definition = () => {
|
||||
aliases: [],
|
||||
match_mode: "exact" as const,
|
||||
region: anchor.region,
|
||||
position_locked: !isAnchorRelative,
|
||||
minimum_evidence_level: "coordinate" as const,
|
||||
}
|
||||
: null,
|
||||
// 画布框是读取边界;锚点只用于定位字段,不能再参与值框二次投影。
|
||||
value_region: null,
|
||||
absolute_value_region: anchor && anchorId ? item.region : null,
|
||||
value_region: relativeValueRegion,
|
||||
absolute_value_region: anchor && anchorId && !relativeValueRegion ? item.region : null,
|
||||
fallback_value_region: anchor && anchorId ? null : item.region,
|
||||
value_mode: item.valueMode || "single_line",
|
||||
stop_anchors:
|
||||
@@ -868,7 +939,7 @@ const definition = () => {
|
||||
minimum_evidence_level: item.evidenceSource === "ocr_coordinate" ? "ocr_coordinate" as const : "coordinate" as const,
|
||||
};
|
||||
}),
|
||||
draft_unbound_order_field_layouts: regions.value
|
||||
draft_unbound_order_field_layouts: normalizedRegions
|
||||
.filter(
|
||||
(item) =>
|
||||
item.kind === "order_field" &&
|
||||
@@ -876,11 +947,16 @@ const definition = () => {
|
||||
)
|
||||
.map((item) => {
|
||||
const layoutId = item.orderFieldId || item.id.replace(/^unbound-/, "");
|
||||
const anchor = regions.value.find(
|
||||
const anchor = normalizedRegions.find(
|
||||
(candidate) =>
|
||||
candidate.kind === "order_anchor" &&
|
||||
(candidate.id === item.parentId || candidate.orderFieldId === layoutId),
|
||||
);
|
||||
const isAnchorRelative = Boolean(anchor && ["right_of_anchor", "below_anchor"].includes(item.valueMode || "")
|
||||
&& isOrderProfileAnchorRelativeCandidate(item.region, anchor.region));
|
||||
const relativeValueRegion = isAnchorRelative && anchor
|
||||
? toOrderProfileAnchorRelativeRegion(item.region, anchor.region)
|
||||
: null;
|
||||
return {
|
||||
layout_id: layoutId,
|
||||
label: item.label,
|
||||
@@ -893,11 +969,12 @@ const definition = () => {
|
||||
aliases: [],
|
||||
match_mode: "exact" as const,
|
||||
region: anchor.region,
|
||||
position_locked: !isAnchorRelative,
|
||||
minimum_evidence_level: "coordinate" as const,
|
||||
}
|
||||
: null,
|
||||
value_region: null,
|
||||
absolute_value_region: anchor ? item.region : null,
|
||||
value_region: relativeValueRegion,
|
||||
absolute_value_region: anchor && !relativeValueRegion ? item.region : null,
|
||||
fallback_value_region: anchor ? null : item.region,
|
||||
value_mode: item.valueMode || "single_line",
|
||||
stop_anchors:
|
||||
@@ -972,7 +1049,13 @@ const save = async (automatic = false) => {
|
||||
} else {
|
||||
fail(error);
|
||||
}
|
||||
if (automatic && autosaveFailures < 3 && navigator.onLine) {
|
||||
// A definition validation error cannot recover without an administrator edit.
|
||||
// Retrying it only produces repeated toast notifications for the same canvas state.
|
||||
const retryable = !(error instanceof BusinessError && [
|
||||
'SHIPPING.ORDER_DOCUMENT_PROFILE_INVALID',
|
||||
'SHIPPING.ORDER_DOCUMENT_PROFILE_FIELD_INVALID',
|
||||
].includes(error.code));
|
||||
if (automatic && retryable && autosaveFailures < 3 && navigator.onLine) {
|
||||
if (retryTimer) window.clearTimeout(retryTimer);
|
||||
retryTimer = window.setTimeout(() => void save(true), 1500 * autosaveFailures);
|
||||
}
|
||||
@@ -1048,6 +1131,7 @@ const suggestRegions = async () => {
|
||||
parentId: headerId,
|
||||
label: field.field_code || field.text || t("admin.shippingOrderProfiles.workbench.unboundColumn", { count: fieldIndex + 1 }),
|
||||
region: field.region,
|
||||
// 表头绑定表达列语义;运行期仅从明细行字段框读取实际业务值。
|
||||
fieldCode: field.field_code || null,
|
||||
pageNo: pageNo.value,
|
||||
});
|
||||
@@ -1157,7 +1241,10 @@ const suggestRegions = async () => {
|
||||
suggestingRegions.value = false;
|
||||
}
|
||||
};
|
||||
/** 接受、调整接受或拒绝当前待确认建议;重建议不会覆盖当前人工区域。 */
|
||||
/**
|
||||
* 接受、调整接受或拒绝当前待确认建议;重建议替换同页旧的自动表格区域,保留人工区域。
|
||||
* 自动区域 ID 使用稳定的 header_/line_ 前缀,借此避免重复自动标记叠加为无效 Profile。
|
||||
*/
|
||||
const decidePendingSuggestion = async (decision: 'accepted' | 'accepted_adjusted' | 'rejected') => {
|
||||
if (!pendingSuggestion.value || !active.value || !editLeaseToken.value) return;
|
||||
const item = pendingSuggestion.value;
|
||||
@@ -1175,8 +1262,39 @@ const decidePendingSuggestion = async (decision: 'accepted' | 'accepted_adjusted
|
||||
});
|
||||
if (decision !== 'rejected') {
|
||||
checkpoint();
|
||||
const suggestionPages = new Set(item.regions.map((region) => region.pageNo));
|
||||
const isReplaceableAutoTableRegion = (region: OrderProfileCanvasRegion) =>
|
||||
suggestionPages.has(region.pageNo) &&
|
||||
(region.id.startsWith(`header_${region.pageNo}_`) ||
|
||||
region.id.startsWith(`line_${region.pageNo}_`));
|
||||
// A new suggestion is a complete table layout for its page. Replace its
|
||||
// previous generated header/line frames before appending it, otherwise a
|
||||
// changed suggestion ID leaves geometrically overlapping regions behind.
|
||||
regions.value = regions.value.filter(
|
||||
(region) => !isReplaceableAutoTableRegion(region),
|
||||
);
|
||||
const existingIds = new Set(regions.value.map((region) => region.id));
|
||||
const acceptedRegions = item.regions.filter((region) => !existingIds.has(region.id)).map((region) => ({ ...region, fieldCode: decision === 'accepted_adjusted' && region.id === firstSuggestedField?.id ? replacementFieldCode : region.fieldCode }));
|
||||
const suggestedLines = acceptedRegions.filter((region) => region.kind === 'line');
|
||||
if (suggestedLines.length) {
|
||||
const fieldParentIds = new Set(
|
||||
regions.value
|
||||
.filter((region) => region.kind === 'field' && region.parentId)
|
||||
.map((region) => region.parentId!),
|
||||
);
|
||||
// The wizard starts with one full-table empty line purely to make a legal
|
||||
// draft. Once coordinate suggestion provides real rows, keeping it makes
|
||||
// the v2 non-overlap contract unsavable.
|
||||
regions.value = regions.value.filter((region) => !(
|
||||
region.kind === 'line' &&
|
||||
!fieldParentIds.has(region.id) &&
|
||||
suggestedLines.some((suggested) =>
|
||||
region.pageNo === suggested.pageNo &&
|
||||
region.region.x0 <= suggested.region.x0 && region.region.y0 <= suggested.region.y0 &&
|
||||
region.region.x1 >= suggested.region.x1 && region.region.y1 >= suggested.region.y1
|
||||
)
|
||||
));
|
||||
}
|
||||
regions.value.push(...acceptedRegions);
|
||||
selectedId.value = item.regions.find((region) => region.fieldCode)?.id || item.regions[0]?.id || null;
|
||||
}
|
||||
@@ -1193,6 +1311,7 @@ let orderFieldValueRequest = 0;
|
||||
const clearOrderFieldValuePreview = (state: 'idle' | 'loading' | 'failed') => {
|
||||
orderFieldValuePreviews.value = [];
|
||||
orderFieldValueState.value = state;
|
||||
orderFieldValueError.value = '';
|
||||
};
|
||||
/** 根据当前画布定义读取订单字段;过期请求不得覆盖更新后的值框结果。 */
|
||||
const refreshOrderFieldSuggestionValues = async () => {
|
||||
@@ -1212,8 +1331,13 @@ const refreshOrderFieldSuggestionValues = async () => {
|
||||
if (request !== orderFieldValueRequest) return;
|
||||
orderFieldValuePreviews.value = result.fields;
|
||||
orderFieldValueState.value = 'ready';
|
||||
} catch {
|
||||
if (request === orderFieldValueRequest) clearOrderFieldValuePreview('failed');
|
||||
} catch (error) {
|
||||
if (request === orderFieldValueRequest) {
|
||||
clearOrderFieldValuePreview('failed');
|
||||
orderFieldValueError.value = error instanceof BusinessError
|
||||
? error.message
|
||||
: t('admin.shippingOrderProfiles.workbench.orderFieldValueFailed');
|
||||
}
|
||||
}
|
||||
};
|
||||
/** 订单字段框或读取方式变化后延迟回读整页字符证据,避免地址字段停留在旧的空候选。 */
|
||||
@@ -1587,6 +1711,9 @@ const renewLeaseOnVisibility = (): void => {
|
||||
};
|
||||
/** 打开路由指定草稿并恢复冻结的标注上下文。 */
|
||||
const edit = async (profile: ShippingOrderDocumentProfile) => {
|
||||
// Suppress document/table watchers until both restored canvas regions and the
|
||||
// bound sample are ready; otherwise an old preview request can win the race.
|
||||
restoringProfile = true;
|
||||
active.value = profile;
|
||||
form.profileCode = profile.profile_code;
|
||||
form.displayName = profile.display_name;
|
||||
@@ -1616,9 +1743,13 @@ const edit = async (profile: ShippingOrderDocumentProfile) => {
|
||||
boundSamples.value.find((item) => item.sample_role === "annotation")?.document_id || 0;
|
||||
await loadSampleTables();
|
||||
await loadPages();
|
||||
await refreshOrderFieldSuggestionValues();
|
||||
} catch (error) {
|
||||
fail(error);
|
||||
} finally {
|
||||
restoringProfile = false;
|
||||
// Page preview grants are independent from coordinate extraction. A grant
|
||||
// failure must not leave the right-hand recognition panel at "waiting".
|
||||
await refreshOrderFieldSuggestionValues();
|
||||
}
|
||||
};
|
||||
/** 跳转到独立验证页;页面仍需当前标签持有租约,不能绕过草稿单写者保护。 */
|
||||
@@ -1712,11 +1843,14 @@ watch(
|
||||
pageGrant.value = null;
|
||||
pageGrants.value = [];
|
||||
canvasUnavailable.value = false;
|
||||
if (restoringProfile) return;
|
||||
void loadSampleTables();
|
||||
if (active.value) void loadPages();
|
||||
},
|
||||
);
|
||||
watch(() => form.tableId, schedulePreview);
|
||||
watch(() => form.tableId, () => {
|
||||
if (!restoringProfile) schedulePreview();
|
||||
});
|
||||
const beforeUnload = (event: BeforeUnloadEvent) => {
|
||||
if (!dirty.value) return;
|
||||
event.preventDefault();
|
||||
@@ -1841,38 +1975,35 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<output class="save-status" :class="`save-status--${saveState}`">{{ t(`admin.shippingOrderProfiles.workbench.saveStatus.${saveState}`) }}</output>
|
||||
<template v-if="saveState === 'readonly'">
|
||||
<button type="button" class="btn-secondary" @click="downloadLocalDraft">{{ t('admin.shippingOrderProfiles.workbench.exportLocalDraft') }}</button>
|
||||
<button type="button" class="btn-secondary" @click="() => void recoverEditLease()">{{ t('admin.shippingOrderProfiles.workbench.recoverLease') }}</button>
|
||||
<button type="button" class="btn-secondary" @click="() => void recoverEditLease(true)">{{ t('admin.shippingOrderProfiles.workbench.takeOverLease') }}</button>
|
||||
</template>
|
||||
<div v-if="saveState === 'readonly'" class="header-actions__lease">
|
||||
<button type="button" class="btn-secondary" @click="downloadLocalDraft">{{ t('admin.shippingOrderProfiles.workbench.headerExport') }}</button>
|
||||
<button type="button" class="btn-secondary" @click="() => void recoverEditLease()">{{ t('admin.shippingOrderProfiles.workbench.headerRecoverLease') }}</button>
|
||||
<button type="button" class="btn-secondary" @click="() => void recoverEditLease(true)">{{ t('admin.shippingOrderProfiles.workbench.headerTakeOverLease') }}</button>
|
||||
</div>
|
||||
<output v-if="active && currentSampleIsTraining" class="training-sample-status">{{ t('admin.shippingOrderProfiles.workbench.headerTrainingSample') }}</output>
|
||||
<button
|
||||
v-if="active"
|
||||
v-else-if="active"
|
||||
type="button"
|
||||
class="btn-secondary"
|
||||
:disabled="!form.documentId || !form.tableId || currentSampleIsTraining || saveState === 'readonly'"
|
||||
:disabled="!form.documentId || !form.tableId || saveState === 'readonly'"
|
||||
@click="() => void addCurrentTrainingSample()"
|
||||
>{{ currentSampleIsTraining ? t('admin.shippingOrderProfiles.blindTest.trainingAdded') : t('admin.shippingOrderProfiles.blindTest.addTrainingSample') }}</button>
|
||||
<button
|
||||
v-if="active"
|
||||
type="button"
|
||||
:disabled="issues.length > 0 || saving || saveState === 'readonly'"
|
||||
class="btn-primary"
|
||||
@click="() => void save()"
|
||||
>
|
||||
{{
|
||||
saving
|
||||
? t("admin.shippingOrderProfiles.saving")
|
||||
: t("admin.shippingOrderProfiles.updateDraft")
|
||||
}}
|
||||
</button>
|
||||
<button
|
||||
v-if="active"
|
||||
type="button"
|
||||
class="btn-secondary"
|
||||
@click="validateProfile(active)"
|
||||
>{{ t('admin.orderProfileValidation.validateTemplate') }}</button>
|
||||
<button type="button" class="btn-secondary" @click="router.push({ name: 'AdminShippingOrderDocumentProfiles' })">{{ t('admin.shippingOrderProfiles.workbench.returnToLibrary') }}</button>
|
||||
>{{ t('admin.shippingOrderProfiles.workbench.headerAddTrainingSample') }}</button>
|
||||
<div class="header-actions__flow">
|
||||
<button
|
||||
v-if="active"
|
||||
type="button"
|
||||
:disabled="issues.length > 0 || saving || saveState === 'readonly'"
|
||||
class="btn-primary"
|
||||
@click="() => void save()"
|
||||
>{{ saving ? t("admin.shippingOrderProfiles.saving") : t("admin.shippingOrderProfiles.workbench.headerSaveDraft") }}</button>
|
||||
<button
|
||||
v-if="active"
|
||||
type="button"
|
||||
class="btn-secondary"
|
||||
@click="validateProfile(active)"
|
||||
>{{ t('admin.shippingOrderProfiles.workbench.headerValidate') }}</button>
|
||||
<button type="button" class="btn-secondary" @click="router.push({ name: 'AdminShippingOrderDocumentProfiles' })">{{ t('admin.shippingOrderProfiles.workbench.headerReturnToLibrary') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="desk editor-desk">
|
||||
@@ -1935,7 +2066,7 @@ onBeforeUnmount(() => {
|
||||
<header>
|
||||
<span>{{ t("admin.shippingOrderProfiles.workbench.currentConfiguration") }}</span>
|
||||
</header>
|
||||
<section class="document-match-editor">
|
||||
<section v-if="!documentMatch.requiredAnchors.length || documentAnchorNotice" class="document-match-editor">
|
||||
<div class="document-match-editor__heading">
|
||||
<div>
|
||||
<strong>{{ t('admin.shippingOrderProfiles.workbench.documentMatchAnchorTool') }}</strong>
|
||||
@@ -1944,10 +2075,6 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
<p v-if="!documentMatch.requiredAnchors.length" class="document-match-editor__warning">{{ t('admin.shippingOrderProfiles.workbench.documentMatchAnchorEmpty') }}</p>
|
||||
<p v-if="documentAnchorNotice" class="document-match-editor__warning">{{ documentAnchorNotice }}</p>
|
||||
<article v-for="(anchor, index) in documentMatch.requiredAnchors" :key="`required-${index}`" class="document-match-editor__row">
|
||||
<b>{{ t('common.required') }}</b>
|
||||
<span>{{ anchor.label }}</span><span>{{ anchor.value }}</span>
|
||||
</article>
|
||||
</section>
|
||||
<section v-if="selectedRegion" class="editor">
|
||||
<div class="selected-region-meta">
|
||||
@@ -1995,7 +2122,7 @@ onBeforeUnmount(() => {
|
||||
class="select-field"
|
||||
:disabled="compactEditor || saveState === 'readonly'"
|
||||
@focus="beginFormEdit"
|
||||
@change="finishFormEdit"
|
||||
@change="finishFieldBindingEdit"
|
||||
>
|
||||
<option :value="null">
|
||||
{{ t("admin.shippingOrderProfiles.workbench.selectField") }}
|
||||
@@ -2174,6 +2301,14 @@ onBeforeUnmount(() => {
|
||||
.schema-warning { color: #b91c1c; }
|
||||
.schema-hint { color: #047857; }
|
||||
.header-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.header-actions__lease,
|
||||
.header-actions__flow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
@@ -2377,9 +2512,6 @@ onBeforeUnmount(() => {
|
||||
.document-match-editor__heading strong { font-size: 0.84rem; }
|
||||
.document-match-editor__heading p { margin: 0.3rem 0 0; font-size: 0.72rem; color: #64748b; }
|
||||
.document-match-editor__warning { margin: 0.6rem 0; color: #b45309; font-size: 0.75rem; }
|
||||
.document-match-editor__row { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1.4fr); gap: 0.35rem; align-items: center; margin-top: 0.45rem; }
|
||||
.document-match-editor__row b { font-size: 0.7rem; color: #0f766e; }
|
||||
.document-match-editor__row span { overflow: hidden; color: #475569; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.selected-region-meta { display: grid; gap: .2rem; margin-bottom: .8rem; border-bottom: 1px solid #dbe4ef; padding-bottom: .75rem; }
|
||||
.selected-region-meta span { color: #64748b; font-size: .7rem; font-weight: 700; }
|
||||
.selected-region-meta strong { color: #0f172a; font-size: .82rem; }
|
||||
@@ -2509,8 +2641,10 @@ onBeforeUnmount(() => {
|
||||
background: rgb(15 23 42 / .48);
|
||||
padding: 1.5rem;
|
||||
}
|
||||
.save-status { border-radius: 999px; background: #e2e8f0; padding: .4rem .6rem; color: #334155; font-size: .72rem; }
|
||||
.save-status,
|
||||
.training-sample-status { border-radius: 999px; background: #e2e8f0; padding: .4rem .6rem; color: #334155; font-size: .72rem; }
|
||||
.save-status--saving { background: #dbeafe; color: #1d4ed8; }.save-status--failed,.save-status--readonly { background: #fee2e2; color: #b91c1c; }.save-status--saved { background: #dcfce7; color: #166534; }
|
||||
.training-sample-status { background: #dcfce7; color: #166534; }
|
||||
.editor-workbench { padding: 0; background: #0f172a; }
|
||||
.editor-workbench .bench-header { max-width: none; padding: .7rem 1rem; color: #e2e8f0; }
|
||||
.editor-workbench .bench-header p { color: #94a3b8; }
|
||||
@@ -2659,8 +2793,13 @@ onBeforeUnmount(() => {
|
||||
}
|
||||
.header-actions {
|
||||
width: 100%;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.header-actions > button {
|
||||
.header-actions__lease,
|
||||
.header-actions__flow {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.header-actions button {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
+25
-1
@@ -34,6 +34,13 @@ const filteredFamilies = computed(() => {
|
||||
return families.value.filter((item) => `${item.profile_code} ${item.display_name}`.toLowerCase().includes(keyword));
|
||||
});
|
||||
|
||||
/** 仅以服务端返回的不可变 Schema 身份决定复制或迁移,列表页不猜测兼容性。 */
|
||||
function schemaMigrationRequired(item: OrderProfileVersionFamilySummary): boolean {
|
||||
return item.published_schema_version_id != null
|
||||
&& item.current_schema_version_id != null
|
||||
&& item.published_schema_version_id !== item.current_schema_version_id;
|
||||
}
|
||||
|
||||
/** 加载模板族摘要;列表只显示聚合结果,不能将每个版本扁平为独立模板。 */
|
||||
async function loadFamilies(): Promise<void> {
|
||||
loading.value = true;
|
||||
@@ -88,6 +95,16 @@ function viewVersion(item: OrderProfileVersionFamilySummary): void {
|
||||
router.push({ name: 'AdminShippingOrderDocumentProfileVersionDetail', params: { profileCode: item.profile_code, version: item.default_version } });
|
||||
}
|
||||
|
||||
/** 打开已发布版本的 Schema 迁移决策;字段兼容性只能由详情接口安全计算。 */
|
||||
function openSchemaMigration(item: OrderProfileVersionFamilySummary): void {
|
||||
if (!item.published_version) return;
|
||||
router.push({
|
||||
name: 'AdminShippingOrderDocumentProfileVersionDetail',
|
||||
params: { profileCode: item.profile_code, version: item.published_version },
|
||||
query: { migrate: '1' },
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(loadFamilies);
|
||||
</script>
|
||||
|
||||
@@ -128,11 +145,17 @@ onMounted(loadFamilies);
|
||||
<span class="status-badge" :class="{ draft: item.draft_profile_id, published: !item.draft_profile_id && item.published_profile_id }">
|
||||
{{ item.draft_profile_id ? t('admin.shippingOrderProfiles.library.draft') : item.published_profile_id ? t('admin.shippingOrderProfiles.library.published', { version: item.published_version }) : t('admin.shippingOrderProfiles.library.retired') }}
|
||||
</span>
|
||||
<small v-if="item.published_profile_id && item.current_schema_version" class="schema-status" :class="{ warning: schemaMigrationRequired(item) }">
|
||||
{{ schemaMigrationRequired(item)
|
||||
? t('admin.shippingOrderProfiles.schemaMigration.versionMismatch', { bound: item.published_schema_version, current: item.current_schema_version })
|
||||
: t('admin.shippingOrderProfiles.schemaMigration.versionMatched', { version: item.current_schema_version }) }}
|
||||
</small>
|
||||
</td>
|
||||
<td class="profile-library__actions">
|
||||
<button v-if="item.draft_profile_id" class="btn-ghost btn-sm" type="button" @click="continueEditing(item)">{{ t('admin.shippingOrderProfiles.versionCenter.continueEditing') }}</button>
|
||||
<button v-if="item.draft_profile_id" class="btn-danger btn-sm" type="button" @click="requestDeleteDraft(item)">{{ t('admin.delete') }}</button>
|
||||
<button v-else-if="item.published_profile_id" class="btn-secondary btn-sm" type="button" @click="createNewVersion(item)">{{ t('admin.shippingOrderProfiles.newVersion') }}</button>
|
||||
<button v-else-if="item.published_profile_id && !schemaMigrationRequired(item)" class="btn-secondary btn-sm" type="button" @click="createNewVersion(item)">{{ t('admin.shippingOrderProfiles.newVersion') }}</button>
|
||||
<button v-if="!item.draft_profile_id && item.published_profile_id && schemaMigrationRequired(item)" class="btn-secondary btn-sm" type="button" @click="openSchemaMigration(item)">{{ t('admin.shippingOrderProfiles.schemaMigration.listAction') }}</button>
|
||||
<button class="btn-ghost btn-sm" type="button" @click="viewVersion(item)">{{ t('admin.shippingOrderProfiles.versionCenter.viewVersion') }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -171,6 +194,7 @@ onMounted(loadFamilies);
|
||||
.status-badge { display: inline-flex; border: 1px solid #cbd5e1; border-radius: 999px; background: #f8fafc; padding: 3px 8px; color: #64748b; font-size: 11px; font-weight: 600; white-space: nowrap; }
|
||||
.status-badge.draft { border-color: #bae6fd; background: #f0f9ff; color: #0369a1; }
|
||||
.status-badge.published { border-color: #bbf7d0; background: #f0fdf4; color: #15803d; }
|
||||
.schema-status { display: block; margin-top: 5px; color: #64748b; font-size: 11px; white-space: nowrap; }.schema-status.warning { color: #b45309; }
|
||||
.actions-heading { min-width: 190px; }
|
||||
.profile-library__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
|
||||
|
||||
|
||||
+139
-2
@@ -5,12 +5,17 @@
|
||||
逻辑:当前已接入配置概览、只读样本画布、服务端语义 diff、审计时间线与实际使用;后续仅剩盲测隔离与发布治理收口。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { BusinessError } from "@/shared/api/client";
|
||||
import { useMessage } from "@/shared/composables/useMessage";
|
||||
import { cloneOrderDocumentProfile } from "@/features/admin/api/shipping-order-document-profile.api";
|
||||
import {
|
||||
cloneOrderDocumentProfile,
|
||||
migrateOrderDocumentProfileSchema,
|
||||
} from "@/features/admin/api/shipping-order-document-profile.api";
|
||||
import { getShippingOrderSchemaState } from "@/features/admin/api/shipping-order-schema.api";
|
||||
import type { ShippingOrderSchemaVersion } from "@/features/admin/types/shipping-order-schema.types";
|
||||
import OrderProfileReadOnlyCanvas from "./components/OrderProfileReadOnlyCanvas.vue";
|
||||
import OrderProfileAuditTimeline from "./components/OrderProfileAuditTimeline.vue";
|
||||
import OrderProfileVersionDiff from "./components/OrderProfileVersionDiff.vue";
|
||||
@@ -26,6 +31,10 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
const message = useMessage();
|
||||
const cloning = ref(false);
|
||||
const migrating = ref(false);
|
||||
const migrationOpen = ref(false);
|
||||
const publishedSchema = ref<ShippingOrderSchemaVersion | null>(null);
|
||||
const migrationResolutions = ref<Record<string, { action: "unbind" } | { replacement_field_id: string }>>({});
|
||||
const {
|
||||
activeTab,
|
||||
detail,
|
||||
@@ -36,6 +45,92 @@ const {
|
||||
versions,
|
||||
} = useOrderProfileVersionDetail();
|
||||
|
||||
const canMigrateSchema = computed(() =>
|
||||
detail.value?.status === "published"
|
||||
&& publishedSchema.value !== null
|
||||
&& detail.value.schema_version_id !== publishedSchema.value.id,
|
||||
);
|
||||
|
||||
const breakingChanges = computed(() => detail.value?.schema_compatibility?.breaking_changes || []);
|
||||
|
||||
const loadPublishedSchema = async () => {
|
||||
try {
|
||||
const state = await getShippingOrderSchemaState();
|
||||
publishedSchema.value = state.versions.find((item) => item.status === "published") || null;
|
||||
} catch {
|
||||
publishedSchema.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
const openSchemaMigration = () => {
|
||||
migrationResolutions.value = Object.fromEntries(
|
||||
breakingChanges.value.map((change) => [change.field_id, { action: "unbind" }]),
|
||||
);
|
||||
migrationOpen.value = true;
|
||||
};
|
||||
|
||||
const setMigrationResolution = (fieldId: string, replacementId: string) => {
|
||||
migrationResolutions.value[fieldId] = replacementId
|
||||
? { replacement_field_id: replacementId }
|
||||
: { action: "unbind" };
|
||||
};
|
||||
|
||||
const migrationReplacementId = (fieldId: string): string => {
|
||||
const resolution = migrationResolutions.value[fieldId];
|
||||
return resolution && "replacement_field_id" in resolution ? resolution.replacement_field_id : "";
|
||||
};
|
||||
|
||||
const migrationErrorMessage = (error: unknown): string => {
|
||||
if (!(error instanceof BusinessError)) return t("admin.shippingOrderProfiles.loadFailed");
|
||||
const reason = String(error.details.reason || "");
|
||||
if (reason === "duplicate_field_code") {
|
||||
return t("admin.shippingOrderProfiles.schemaMigration.duplicateSchemaField", {
|
||||
field: error.details.field_code || "-",
|
||||
existingScope: error.details.existing_scope || "-",
|
||||
duplicateScope: error.details.duplicate_scope || "-",
|
||||
});
|
||||
}
|
||||
if (reason === "line_start_field_unbound") {
|
||||
return t("admin.shippingOrderProfiles.schemaMigration.lineStartRequired", {
|
||||
field: error.details.line_start_field_code || "-",
|
||||
});
|
||||
}
|
||||
const fieldPath = String(error.details.field_path || "");
|
||||
return fieldPath
|
||||
? `${error.message} (${t("admin.shippingOrderProfiles.schemaMigration.invalidPath", { path: fieldPath })})`
|
||||
: error.message;
|
||||
};
|
||||
|
||||
const migrateSchema = async () => {
|
||||
if (!detail.value || !publishedSchema.value || migrating.value) return;
|
||||
migrating.value = true;
|
||||
try {
|
||||
const draft = await migrateOrderDocumentProfileSchema(
|
||||
detail.value.id,
|
||||
publishedSchema.value.id,
|
||||
migrationResolutions.value,
|
||||
);
|
||||
message.success(t("admin.shippingOrderProfiles.schemaMigration.created"));
|
||||
migrationOpen.value = false;
|
||||
void router.push({
|
||||
name: "AdminShippingOrderDocumentProfiles",
|
||||
query: { profileCode: draft.profile_code, profileId: String(draft.id) },
|
||||
});
|
||||
} catch (error) {
|
||||
message.error(migrationErrorMessage(error));
|
||||
} finally {
|
||||
migrating.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => { void loadPublishedSchema(); });
|
||||
|
||||
watch([detail, publishedSchema, () => route.query.migrate], () => {
|
||||
if (route.query.migrate !== "1" || !canMigrateSchema.value || migrationOpen.value) return;
|
||||
openSchemaMigration();
|
||||
void router.replace({ query: { ...route.query, migrate: undefined } });
|
||||
});
|
||||
|
||||
const pageTitle = computed(() => {
|
||||
if (!detail.value) {
|
||||
return `${profileCode.value} · v${route.params.version || ""}`;
|
||||
@@ -153,6 +248,14 @@ const createNewVersion = async () => {
|
||||
: t("admin.shippingOrderProfiles.newVersion")
|
||||
}}
|
||||
</button>
|
||||
<button
|
||||
v-if="canMigrateSchema"
|
||||
type="button"
|
||||
class="btn-primary"
|
||||
@click="openSchemaMigration"
|
||||
>
|
||||
{{ t("admin.shippingOrderProfiles.schemaMigration.action", { version: publishedSchema?.version }) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
@@ -209,6 +312,36 @@ const createNewVersion = async () => {
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="migrationOpen" class="migration-backdrop" role="presentation" @click.self="migrationOpen = false">
|
||||
<section class="migration-dialog" role="dialog" aria-modal="true" :aria-label="t('admin.shippingOrderProfiles.schemaMigration.title')">
|
||||
<h2>{{ t("admin.shippingOrderProfiles.schemaMigration.title") }}</h2>
|
||||
<p>{{ t("admin.shippingOrderProfiles.schemaMigration.description", { from: detail?.schema_version, to: publishedSchema?.version }) }}</p>
|
||||
<p class="migration-note">{{ t("admin.shippingOrderProfiles.schemaMigration.revalidation") }}</p>
|
||||
<div v-if="breakingChanges.length" class="migration-changes">
|
||||
<article v-for="change in breakingChanges" :key="change.field_id">
|
||||
<strong>{{ change.before || change.field_id }}</strong>
|
||||
<span>{{ t("admin.shippingOrderProfiles.schemaMigration.reason", { reason: change.reason }) }}</span>
|
||||
<label>
|
||||
{{ t("admin.shippingOrderProfiles.schemaMigration.resolution") }}
|
||||
<select
|
||||
:value="migrationReplacementId(change.field_id)"
|
||||
@change="setMigrationResolution(change.field_id, ($event.target as HTMLSelectElement).value)"
|
||||
>
|
||||
<option value="">{{ t("admin.shippingOrderProfiles.schemaMigration.unbind") }}</option>
|
||||
<option v-for="candidate in change.replacement_candidates || []" :key="candidate.field_id" :value="candidate.field_id">
|
||||
{{ candidate.display_name || candidate.field_code || candidate.field_id }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
</article>
|
||||
</div>
|
||||
<p v-else class="migration-note">{{ t("admin.shippingOrderProfiles.schemaMigration.noBreakingChanges") }}</p>
|
||||
<footer>
|
||||
<button type="button" class="btn-secondary" :disabled="migrating" @click="migrationOpen = false">{{ t("admin.shippingOrderProfiles.schemaMigration.cancel") }}</button>
|
||||
<button type="button" class="btn-primary" :disabled="migrating" @click="migrateSchema">{{ migrating ? t("admin.shippingOrderProfiles.saving") : t("admin.shippingOrderProfiles.schemaMigration.confirm") }}</button>
|
||||
</footer>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -349,6 +482,10 @@ const createNewVersion = async () => {
|
||||
color: var(--status-error-fg);
|
||||
}
|
||||
|
||||
.migration-backdrop { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 1rem; background: rgb(15 23 42 / 45%); }
|
||||
.migration-dialog { display: grid; width: min(100%, 42rem); max-height: min(44rem, calc(100vh - 2rem)); gap: 1rem; overflow: auto; padding: 1.5rem; border-radius: 1rem; background: var(--bg-surface); box-shadow: 0 20px 40px rgb(15 23 42 / 25%); }
|
||||
.migration-dialog h2,.migration-dialog p { margin: 0; }.migration-note { color: var(--text-muted); font-size: .875rem; }.migration-changes { display: grid; gap: .75rem; }.migration-changes article { display: grid; gap: .45rem; padding: .85rem; border: 1px solid var(--border-default); border-radius: .75rem; }.migration-changes span { color: var(--text-muted); font-size: .8125rem; }.migration-changes label { display: grid; gap: .3rem; color: var(--text-secondary); font-size: .8125rem; font-weight: 600; }.migration-changes select { min-height: 2.25rem; border: 1px solid var(--border-default); border-radius: .5rem; background: var(--bg-surface); color: var(--text-primary); font: inherit; }.migration-dialog footer { display: flex; justify-content: flex-end; gap: .5rem; }
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.header-main,
|
||||
.version-switcher {
|
||||
|
||||
+14
-3
@@ -19,12 +19,21 @@ const emit = defineEmits<{ 'update:modelValue': [value: number]; uploaded: []; }
|
||||
const { t } = useI18n();
|
||||
const message = useMessage();
|
||||
const uploading = ref(false);
|
||||
const pendingIntake = ref<{ intakeNo: string; filename: string; state: 'parsing' | 'failed' } | null>(null);
|
||||
const pendingIntake = ref<{ intakeNo: string; filename: string; state: 'parsing' | 'failed'; errorCode?: string | null } | null>(null);
|
||||
let pollingTimer: number | null = null;
|
||||
const selectedSample = computed(() => props.samples.find((item) => item.document_id === props.modelValue) || null);
|
||||
|
||||
/** 停止当前轮询;离开步骤或开始新上传时都不保留后台计时器。 */
|
||||
function stopPolling(): void { if (pollingTimer) window.clearTimeout(pollingTimer); pollingTimer = null; }
|
||||
/** 将模板布局失败码转成管理员可执行的提示,不把内部快照内容暴露到页面。 */
|
||||
function sampleFailureMessage(errorCode?: string | null): string {
|
||||
const key = errorCode === 'mineru_cell_coordinates_missing'
|
||||
? 'sampleLayoutCoordinatesMissing'
|
||||
: errorCode === 'shipping_document_layout_snapshot_size_exceeded'
|
||||
? 'sampleLayoutSnapshotTooLarge'
|
||||
: 'sampleParseFailed';
|
||||
return t(`admin.shippingOrderProfiles.wizard.${key}`);
|
||||
}
|
||||
/** 刷新样本列表后按 Intake 精确定位新文档,防止同名历史文件被误选。 */
|
||||
function selectUploadedSample(intakeNo: string): boolean {
|
||||
const sample = props.samples.find((item) => item.intake_no === intakeNo);
|
||||
@@ -46,7 +55,9 @@ async function pollIntake(intakeNo: string): Promise<void> {
|
||||
return;
|
||||
}
|
||||
if (['failed', 'error'].includes(result.parse_status)) {
|
||||
pendingIntake.value = { intakeNo, filename: pendingIntake.value?.filename || '', state: 'failed' };
|
||||
pendingIntake.value = {
|
||||
intakeNo, filename: pendingIntake.value?.filename || '', state: 'failed', errorCode: result.error_code,
|
||||
};
|
||||
return;
|
||||
}
|
||||
pollingTimer = window.setTimeout(() => void pollIntake(intakeNo), 1500);
|
||||
@@ -85,7 +96,7 @@ onBeforeUnmount(stopPolling);
|
||||
|
||||
<div v-if="pendingIntake" class="parse-status" :class="{ failed: pendingIntake.state === 'failed' }">
|
||||
<Clock3 v-if="pendingIntake.state === 'parsing'" :size="19" /><span v-else>!</span>
|
||||
<div><strong>{{ pendingIntake.filename }}</strong><p>{{ pendingIntake.state === 'parsing' ? t('admin.shippingOrderProfiles.wizard.sampleParsing') : t('admin.shippingOrderProfiles.wizard.sampleParseFailed') }}</p></div>
|
||||
<div><strong>{{ pendingIntake.filename }}</strong><p>{{ pendingIntake.state === 'parsing' ? t('admin.shippingOrderProfiles.wizard.sampleParsing') : sampleFailureMessage(pendingIntake.errorCode) }}</p></div>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedSample" class="selected-sample"><CheckCircle2 :size="20" /><div><strong>{{ t('admin.shippingOrderProfiles.wizard.sampleSelected') }}</strong><span>{{ selectedSample.filename || selectedSample.intake_no }} · {{ selectedSample.table_count }} {{ t('admin.shippingOrderProfiles.tablesUnit') }}</span></div></div>
|
||||
|
||||
+49
-1
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.spec.ts
|
||||
* 用途:验证可视化订单模板表单生成受控规则,并确保切换样本时配置入口不会消失。
|
||||
* 用途:验证可视化订单模板表单生成受控规则、明细字段分组,并确保切换样本时配置入口不会消失。
|
||||
* 依赖:Vitest、orderProfileForm.utils。
|
||||
* 逻辑:覆盖 direct、复合解析器开关及跨列冲突,避免无效配置进入后端。
|
||||
*/
|
||||
@@ -15,10 +15,37 @@ import {
|
||||
shouldShowStandardOrderProfilePreview,
|
||||
toOrderProfileAnchorId,
|
||||
buildOrderProfileRecognitionResults,
|
||||
isOrderProfileAnchorRelativeCandidate,
|
||||
normalizeOrderProfileRelativeRegion,
|
||||
toOrderProfileAnchorRelativeRegion,
|
||||
groupUniqueOrderProfileLineFields,
|
||||
} from './orderProfileForm.utils';
|
||||
|
||||
describe('order profile form rules', () => {
|
||||
it.each(['line_no', 'customer_po_line_no'])(
|
||||
'keeps %s available after resolving the main-line fields',
|
||||
(startFieldCode) => {
|
||||
const regions = [
|
||||
{ id: 'main', kind: 'line' as const, label: 'Main', pageNo: 1, region: { x0: .1, y0: .3, x1: .9, y1: .4 } },
|
||||
{ id: 'start', kind: 'field' as const, label: 'Start', fieldCode: startFieldCode, parentId: 'main', pageNo: 1, region: { x0: .1, y0: .3, x1: .2, y1: .4 } },
|
||||
{ id: 'part', kind: 'field' as const, label: 'Part', fieldCode: 'part_number', parentId: 'main', pageNo: 1, region: { x0: .2, y0: .3, x1: .5, y1: .4 } },
|
||||
];
|
||||
|
||||
const grouped = groupUniqueOrderProfileLineFields(regions, ['main']);
|
||||
|
||||
// 关键断言:起行字段选择和 line_layout 序列化复用同一结果时,字段不会被第一次读取消费。
|
||||
expect(grouped.fieldsByLayout.get('main')?.map((item) => item.fieldCode)).toEqual([
|
||||
startFieldCode,
|
||||
'part_number',
|
||||
]);
|
||||
expect(grouped.fieldsByLayout.get('main')?.map((item) => item.fieldCode)).toEqual([
|
||||
startFieldCode,
|
||||
'part_number',
|
||||
]);
|
||||
expect(grouped.boundRegionIds).toEqual(new Set(['start', 'part']));
|
||||
},
|
||||
);
|
||||
|
||||
it('builds only registered direct and composite rules', () => {
|
||||
const rules = buildOrderProfileColumnRules([
|
||||
{ extractor_key: 'direct', target: 'qty' },
|
||||
@@ -198,4 +225,25 @@ describe('order profile form rules', () => {
|
||||
// 完全落在页面外或零面积的框没有可解释的读取边界,必须由管理员重画。
|
||||
expect(normalizeOrderProfileRelativeRegion({ x0: 1.1, y0: .2, x1: 1.2, y1: .3 })).toBeNull();
|
||||
});
|
||||
|
||||
it('serializes a right-of-anchor value box as a movable anchor-relative region', () => {
|
||||
expect(toOrderProfileAnchorRelativeRegion(
|
||||
{ x0: .42, y0: .80, x1: .50, y1: .82 },
|
||||
{ x0: .30, y0: .80, x1: .41, y1: .82 },
|
||||
)).toEqual({ x0: expect.closeTo(1.090909), y0: 0, x1: expect.closeTo(1.818181), y1: 1 });
|
||||
});
|
||||
|
||||
it('keeps a remote legacy value box absolute instead of creating invalid relative offsets', () => {
|
||||
expect(isOrderProfileAnchorRelativeCandidate(
|
||||
{ x0: .33, y0: .58, x1: .72, y1: .60 },
|
||||
{ x0: .02, y0: .10, x1: .15, y1: .12 },
|
||||
)).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps a same-row auto suggestion absolute when its tiny label makes the relative span exceed the contract', () => {
|
||||
expect(isOrderProfileAnchorRelativeCandidate(
|
||||
{ x0: .30, y0: .40, x1: .95, y1: .42 },
|
||||
{ x0: .20, y0: .40, x1: .21, y1: .42 },
|
||||
)).toBe(false);
|
||||
});
|
||||
});
|
||||
+70
-1
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* features/admin/modules/shipping-order-document-profiles/orderProfileForm.utils.ts
|
||||
* 用途:构造可视化订单模板的白名单列规则,并控制样本表格配置区的安全显示。
|
||||
* 用途:构造可视化订单模板的白名单列规则、明细字段分组,并控制样本表格配置区的安全显示。
|
||||
* 依赖:订单 Profile DTO。
|
||||
* 逻辑:页面状态只允许 direct 或已注册复合解析器;同一目标字段跨列只能出现一次。
|
||||
*/
|
||||
@@ -19,6 +19,38 @@ export interface OrderProfileColumnSelection {
|
||||
target: string;
|
||||
}
|
||||
|
||||
export interface OrderProfileLineFieldGroups {
|
||||
fieldsByLayout: Map<string, OrderProfileCanvasRegion[]>;
|
||||
boundRegionIds: Set<string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按物理行顺序收集唯一的明细字段绑定,供起行字段选择和最终定义复用同一份结果。
|
||||
* 核心逻辑:每个 Schema 字段只归属首个物理行;返回结果可重复读取,不会因预览起行字段而消费绑定。
|
||||
* @param regions - 当前页面全部画布区域。
|
||||
* @param layoutIds - 按主行到续行排列的物理行 ID。
|
||||
* @returns 每个物理行的字段区域,以及已进入正式绑定的区域 ID。
|
||||
*/
|
||||
export const groupUniqueOrderProfileLineFields = (
|
||||
regions: OrderProfileCanvasRegion[],
|
||||
layoutIds: string[],
|
||||
): OrderProfileLineFieldGroups => {
|
||||
const claimedFieldCodes = new Set<string>();
|
||||
const boundRegionIds = new Set<string>();
|
||||
const fieldsByLayout = new Map<string, OrderProfileCanvasRegion[]>();
|
||||
layoutIds.forEach((layoutId) => {
|
||||
const fields = regions.filter((item) => {
|
||||
if (item.kind !== 'field' || item.parentId !== layoutId || !item.fieldCode) return false;
|
||||
if (claimedFieldCodes.has(item.fieldCode)) return false;
|
||||
claimedFieldCodes.add(item.fieldCode);
|
||||
boundRegionIds.add(item.id);
|
||||
return true;
|
||||
});
|
||||
fieldsByLayout.set(layoutId, fields);
|
||||
});
|
||||
return { fieldsByLayout, boundRegionIds };
|
||||
};
|
||||
|
||||
/**
|
||||
* 将画布或历史草稿的区域限制为页面归一化坐标。
|
||||
* @param region - 可能来自拖拽、自动建议或历史模板的页面区域。
|
||||
@@ -36,6 +68,43 @@ export const normalizeOrderProfileRelativeRegion = (
|
||||
return x0 < x1 && y0 < y1 ? { x0, y0, x1, y1 } : null;
|
||||
};
|
||||
|
||||
/** 将页面值框换算为锚点尺寸的相对偏移,供标签右侧字段随标签移动读取。 */
|
||||
export const toOrderProfileAnchorRelativeRegion = (
|
||||
valueRegion: OrderProfileRelativeRegion,
|
||||
anchorRegion: OrderProfileRelativeRegion,
|
||||
): OrderProfileRelativeRegion | null => {
|
||||
const width = anchorRegion.x1 - anchorRegion.x0;
|
||||
const height = anchorRegion.y1 - anchorRegion.y0;
|
||||
if (width <= 0 || height <= 0) return null;
|
||||
const relative = {
|
||||
x0: (valueRegion.x0 - anchorRegion.x0) / width,
|
||||
y0: (valueRegion.y0 - anchorRegion.y0) / height,
|
||||
x1: (valueRegion.x1 - anchorRegion.x0) / width,
|
||||
y1: (valueRegion.y1 - anchorRegion.y0) / height,
|
||||
};
|
||||
return Number.isFinite(relative.x0) && Number.isFinite(relative.y0)
|
||||
&& Number.isFinite(relative.x1) && Number.isFinite(relative.y1)
|
||||
&& relative.x0 < relative.x1 && relative.y0 < relative.y1 ? relative : null;
|
||||
};
|
||||
|
||||
/** 判断标签和值框是否是同一视觉行,只有这种画布关系可安全改为随标签移动。 */
|
||||
export const isOrderProfileAnchorRelativeCandidate = (
|
||||
valueRegion: OrderProfileRelativeRegion,
|
||||
anchorRegion: OrderProfileRelativeRegion,
|
||||
): boolean => {
|
||||
const anchorHeight = anchorRegion.y1 - anchorRegion.y0;
|
||||
const valueHeight = valueRegion.y1 - valueRegion.y0;
|
||||
if (anchorHeight <= 0 || valueHeight <= 0) return false;
|
||||
const tolerance = Math.max(anchorHeight, valueHeight) * 2;
|
||||
if (!(valueRegion.y0 <= anchorRegion.y1 + tolerance
|
||||
&& anchorRegion.y0 <= valueRegion.y1 + tolerance)) return false;
|
||||
const relative = toOrderProfileAnchorRelativeRegion(valueRegion, anchorRegion);
|
||||
// Backend intentionally bounds offsets to prevent a tiny auto-detected label
|
||||
// from producing an unbounded template rule. Fall back to the page box here.
|
||||
return relative !== null && [relative.x0, relative.y0, relative.x1, relative.y1]
|
||||
.every((value) => value >= -12 && value <= 12);
|
||||
};
|
||||
|
||||
/**
|
||||
* 判断是否显示普通表格预览;可直接创建 Profile 的表格不受上一张表多物理行状态影响。
|
||||
* @param profileCreationAllowed - 当前表格是否可直接创建 Profile
|
||||
|
||||
+348
-27
@@ -3,7 +3,7 @@
|
||||
用途:单一发货订单 Schema 的版本采用与版本级识别规则编辑;字段身份由全局字段资产库维护。
|
||||
依赖:shipping-order-schema.api、shipping-field-assets.api、FieldImpactDrawer、版本/审计抽屉组件、Vue I18n。
|
||||
逻辑:左侧勾选采用资产目录,右侧编辑已采用字段规则;草稿保存/发布与历史追溯由服务端冻结。无多族切换。
|
||||
自动建单总开关仅草稿可改,二次确认后写入本地,随保存草稿/发布版本生效。
|
||||
「Schema 级策略」分组收纳自动建单总开关与字段派生规则;仅草稿可改,随保存/发布生效;支持样本模拟。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue';
|
||||
@@ -26,6 +26,8 @@ import {
|
||||
listShippingOrderSchemaVersions,
|
||||
publishShippingOrderSchemaDraft,
|
||||
saveShippingOrderSchemaDraft,
|
||||
simulateShippingOrderSchemaDerivation,
|
||||
listShippingOrderSchemaDerivationSimulateSamples,
|
||||
} from '@/features/admin/api/shipping-order-schema.api';
|
||||
import FieldImpactDrawer from '@/features/admin/modules/shipping-field-assets/components/FieldImpactDrawer.vue';
|
||||
import SchemaExtractionAuditDrawer from '@/features/admin/modules/shipping-order-schema/components/SchemaExtractionAuditDrawer.vue';
|
||||
@@ -34,6 +36,9 @@ import SchemaVersionHistoryDrawer from '@/features/admin/modules/shipping-order-
|
||||
import SchemaVersionUsageDrawer from '@/features/admin/modules/shipping-order-schema/components/SchemaVersionUsageDrawer.vue';
|
||||
import type { ShippingFieldAsset, ShippingFieldAssetImpact } from '@/features/admin/types/shipping-field-assets.types';
|
||||
import type {
|
||||
ShippingOrderDerivationRule,
|
||||
ShippingOrderDerivationSimulateResult,
|
||||
ShippingOrderDerivationSimulateSampleItem,
|
||||
ShippingOrderField,
|
||||
ShippingOrderFieldConfig,
|
||||
ShippingOrderExtractionAudit,
|
||||
@@ -70,6 +75,20 @@ const autoCreationConfirmOpen = ref(false);
|
||||
const pendingAutoCreationEnabled = ref(false);
|
||||
const changeNote = ref('');
|
||||
const selectedDraftFieldId = ref<string | null>(null);
|
||||
const derivationRules = ref<ShippingOrderDerivationRule[]>([]);
|
||||
const derivationPanelOpen = ref(true);
|
||||
const simulateOpen = ref(false);
|
||||
const simulating = ref(false);
|
||||
const simulateMode = ref<'history' | 'inline'>('history');
|
||||
const simulateSamples = ref<ShippingOrderDerivationSimulateSampleItem[]>([]);
|
||||
const simulateSampleRef = ref('');
|
||||
const simulateSamplesLoading = ref(false);
|
||||
const simulateSampleJson = ref(`[
|
||||
{"customer_po_line_no": "00010", "line_no": null},
|
||||
{"customer_po_line_no": "00020", "line_no": "20"},
|
||||
{"customer_po_line_no": "ABC", "line_no": null}
|
||||
]`);
|
||||
const simulateResult = ref<ShippingOrderDerivationSimulateResult | null>(null);
|
||||
const fieldSearch = ref('');
|
||||
const expandedGroups = reactive<Record<AdoptionGroupKey, boolean>>({
|
||||
headerStandard: true,
|
||||
@@ -252,6 +271,19 @@ const syncDraftFields = (): void => {
|
||||
autoCreationEnabled.value = typeof draftPolicy === 'boolean'
|
||||
? draftPolicy
|
||||
: state.value?.schema?.auto_creation_policy?.enabled === true;
|
||||
const sourceRules = draft.value?.definition?.derivation_rules
|
||||
|| published.value?.definition?.derivation_rules
|
||||
|| [];
|
||||
derivationRules.value = sourceRules.length
|
||||
? sourceRules.map((rule) => ({ ...rule }))
|
||||
: [{
|
||||
rule_id: 'R-LINE-NO-FROM-CUSTOMER-PO',
|
||||
enabled: false,
|
||||
source_field_code: 'customer_po_line_no',
|
||||
target_field_code: 'line_no',
|
||||
strategy: 'copy_if_empty',
|
||||
scope: 'line',
|
||||
}];
|
||||
const existing = draft.value?.definition?.fields || published.value?.definition?.fields || [];
|
||||
const byId = new Map(existing.map((item) => [item.field_id, item]));
|
||||
draftFields.value = (state.value?.fields || [])
|
||||
@@ -409,7 +441,7 @@ const toggleAdoption = (field: ShippingOrderField, enabled: boolean): void => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 保存草稿的全部已采用字段规则与自动建单策略;未采用字段不会进入发布契约。 */
|
||||
/** 保存草稿的全部已采用字段规则、派生规则与自动建单策略;未采用字段不会进入发布契约。 */
|
||||
const saveDraft = async (): Promise<void> => {
|
||||
if (!draft.value) return;
|
||||
saving.value = true;
|
||||
@@ -418,12 +450,16 @@ const saveDraft = async (): Promise<void> => {
|
||||
const saved = await saveShippingOrderSchemaDraft(draft.value.id, {
|
||||
fields,
|
||||
auto_creation_policy: { enabled: autoCreationEnabled.value },
|
||||
derivation_rules: derivationRules.value.map((item) => ({ ...item })),
|
||||
change_note: changeNote.value,
|
||||
expected_lock_version: draft.value.lock_version,
|
||||
});
|
||||
if (state.value) {
|
||||
state.value.versions = state.value.versions.map((item) => (item.id === saved.id ? saved : item));
|
||||
}
|
||||
if (saved.definition?.derivation_rules) {
|
||||
derivationRules.value = saved.definition.derivation_rules.map((item) => ({ ...item }));
|
||||
}
|
||||
message.success(t('admin.shippingOrderSchema.draftSaved'));
|
||||
} catch (error) {
|
||||
await handleWriteError(error);
|
||||
@@ -432,6 +468,82 @@ const saveDraft = async (): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换派生规则启用状态(仅草稿可改)。
|
||||
* @param index - 规则下标
|
||||
* @param event - checkbox 事件
|
||||
*/
|
||||
const onDerivationEnabledChange = (index: number, event: Event): void => {
|
||||
if (!draft.value) return;
|
||||
const checked = (event.target as HTMLInputElement).checked;
|
||||
const current = derivationRules.value[index];
|
||||
if (!current) return;
|
||||
derivationRules.value[index] = { ...current, enabled: checked };
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开派生规则模拟弹窗并加载历史 Extraction 样本列表。
|
||||
*/
|
||||
const openDerivationSimulate = async (): Promise<void> => {
|
||||
simulateResult.value = null;
|
||||
simulateMode.value = 'history';
|
||||
simulateOpen.value = true;
|
||||
simulateSamplesLoading.value = true;
|
||||
try {
|
||||
const response = await listShippingOrderSchemaDerivationSimulateSamples(20);
|
||||
simulateSamples.value = response.items || [];
|
||||
simulateSampleRef.value = simulateSamples.value[0]?.sample_ref || '';
|
||||
if (!simulateSamples.value.length) {
|
||||
simulateMode.value = 'inline';
|
||||
}
|
||||
} catch (error) {
|
||||
await handleWriteError(error);
|
||||
simulateMode.value = 'inline';
|
||||
} finally {
|
||||
simulateSamplesLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 运行派生规则模拟:优先使用历史 Extraction 样本,亦可手工 JSON。
|
||||
*/
|
||||
const runDerivationSimulate = async (): Promise<void> => {
|
||||
if (!draft.value && !published.value) return;
|
||||
const versionId = draft.value?.id || published.value?.id;
|
||||
if (!versionId) return;
|
||||
simulating.value = true;
|
||||
try {
|
||||
if (simulateMode.value === 'history') {
|
||||
if (!simulateSampleRef.value) {
|
||||
message.error(t('admin.shippingOrderSchema.derivationSimulateSampleRequired'));
|
||||
return;
|
||||
}
|
||||
simulateResult.value = await simulateShippingOrderSchemaDerivation(versionId, {
|
||||
sample_ref: simulateSampleRef.value,
|
||||
derivation_rules: derivationRules.value,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const lines = JSON.parse(simulateSampleJson.value) as Array<Record<string, string | number | null>>;
|
||||
if (!Array.isArray(lines)) {
|
||||
throw new Error('invalid sample');
|
||||
}
|
||||
simulateResult.value = await simulateShippingOrderSchemaDerivation(versionId, {
|
||||
lines,
|
||||
derivation_rules: derivationRules.value,
|
||||
sample_ref: 'schema-admin-inline-sample',
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof SyntaxError || (error instanceof Error && error.message === 'invalid sample')) {
|
||||
message.error(t('admin.shippingOrderSchema.derivationSimulateSampleInvalid'));
|
||||
} else {
|
||||
await handleWriteError(error);
|
||||
}
|
||||
} finally {
|
||||
simulating.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 拦截自动建单开关变更:仅草稿可改,且须二次确认;确认后仅写入本地,随保存草稿/发布生效。
|
||||
* @param event - checkbox change 事件
|
||||
@@ -895,32 +1007,91 @@ onMounted(async () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="auto-creation-switch">
|
||||
<input
|
||||
:checked="autoCreationEnabled"
|
||||
:disabled="saving || !draft"
|
||||
type="checkbox"
|
||||
@change="onAutoCreationToggle"
|
||||
>
|
||||
<span>
|
||||
<strong>{{ t('admin.shippingOrderSchema.autoCreationEnabled') }}</strong>
|
||||
<small>{{ t('admin.shippingOrderSchema.autoCreationHint') }}</small>
|
||||
<small class="auto-creation-effective">
|
||||
{{ t('admin.shippingOrderSchema.autoCreationPublished', {
|
||||
state: publishedAutoCreationEnabled
|
||||
? t('admin.shippingOrderSchema.autoCreationOn')
|
||||
: t('admin.shippingOrderSchema.autoCreationOff'),
|
||||
}) }}
|
||||
<template v-if="autoCreationPendingPublish">
|
||||
· {{ t('admin.shippingOrderSchema.autoCreationDraftPending', {
|
||||
state: autoCreationEnabled
|
||||
<section class="schema-policy-group" data-testid="schema-policy-group">
|
||||
<header class="schema-policy-heading">
|
||||
<div>
|
||||
<h2>{{ t('admin.shippingOrderSchema.schemaPolicyGroupTitle') }}</h2>
|
||||
<p>{{ t('admin.shippingOrderSchema.schemaPolicyGroupHint') }}</p>
|
||||
</div>
|
||||
<span v-if="draft" class="schema-policy-badge">
|
||||
{{ t('admin.shippingOrderSchema.schemaPolicyDraftBadge') }}
|
||||
</span>
|
||||
<span v-else class="schema-policy-badge is-readonly">
|
||||
{{ t('admin.shippingOrderSchema.schemaPolicyPublishedBadge') }}
|
||||
</span>
|
||||
</header>
|
||||
|
||||
<label class="auto-creation-switch">
|
||||
<input
|
||||
:checked="autoCreationEnabled"
|
||||
:disabled="saving || !draft"
|
||||
type="checkbox"
|
||||
@change="onAutoCreationToggle"
|
||||
>
|
||||
<span>
|
||||
<strong>{{ t('admin.shippingOrderSchema.autoCreationEnabled') }}</strong>
|
||||
<small>{{ t('admin.shippingOrderSchema.autoCreationHint') }}</small>
|
||||
<small class="auto-creation-effective">
|
||||
{{ t('admin.shippingOrderSchema.autoCreationPublished', {
|
||||
state: publishedAutoCreationEnabled
|
||||
? t('admin.shippingOrderSchema.autoCreationOn')
|
||||
: t('admin.shippingOrderSchema.autoCreationOff'),
|
||||
}) }}
|
||||
</template>
|
||||
</small>
|
||||
</span>
|
||||
</label>
|
||||
<template v-if="autoCreationPendingPublish">
|
||||
· {{ t('admin.shippingOrderSchema.autoCreationDraftPending', {
|
||||
state: autoCreationEnabled
|
||||
? t('admin.shippingOrderSchema.autoCreationOn')
|
||||
: t('admin.shippingOrderSchema.autoCreationOff'),
|
||||
}) }}
|
||||
</template>
|
||||
</small>
|
||||
</span>
|
||||
</label>
|
||||
<p class="schema-gate-note">{{ t('admin.shippingOrderSchema.effectiveReservationGate') }}</p>
|
||||
|
||||
<details class="derivation-panel" :open="derivationPanelOpen" @toggle="derivationPanelOpen = ($event.target as HTMLDetailsElement).open">
|
||||
<summary>
|
||||
<strong>{{ t('admin.shippingOrderSchema.derivationRulesTitle') }}</strong>
|
||||
<span>{{ t('admin.shippingOrderSchema.derivationRulesHint') }}</span>
|
||||
</summary>
|
||||
<div class="derivation-toolbar">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-secondary btn-sm"
|
||||
:disabled="simulating || (!draft && !published)"
|
||||
@click="openDerivationSimulate"
|
||||
>
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulate') }}
|
||||
</button>
|
||||
</div>
|
||||
<table class="derivation-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationEnabled') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationSource') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationTarget') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationStrategy') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(rule, index) in derivationRules" :key="rule.rule_id">
|
||||
<td>
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="rule.enabled"
|
||||
:disabled="!draft || saving"
|
||||
@change="onDerivationEnabledChange(index, $event)"
|
||||
>
|
||||
</td>
|
||||
<td><code>{{ rule.source_field_code }}</code></td>
|
||||
<td><code>{{ rule.target_field_code }}</code></td>
|
||||
<td>{{ t('admin.shippingOrderSchema.derivationStrategyCopyIfEmpty') }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="derivation-note">{{ t('admin.shippingOrderSchema.derivationRulesNote') }}</p>
|
||||
</details>
|
||||
</section>
|
||||
|
||||
<div class="schema-workbench">
|
||||
<aside class="field-panel">
|
||||
@@ -1337,6 +1508,97 @@ onMounted(async () => {
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div v-if="simulateOpen" class="impact-overlay" @click.self="simulateOpen = false">
|
||||
<section class="impact-dialog derivation-simulate-dialog">
|
||||
<header>
|
||||
<h2>{{ t('admin.shippingOrderSchema.derivationSimulateTitle') }}</h2>
|
||||
<button type="button" class="btn-ghost btn-sm" @click="simulateOpen = false">{{ t('common.close') }}</button>
|
||||
</header>
|
||||
<p class="simulate-hint">{{ t('admin.shippingOrderSchema.derivationSimulateNoMutate') }}</p>
|
||||
<div class="simulate-mode-row">
|
||||
<label>
|
||||
<input v-model="simulateMode" type="radio" value="history">
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulateModeHistory') }}
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="simulateMode" type="radio" value="inline">
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulateModeInline') }}
|
||||
</label>
|
||||
</div>
|
||||
<label v-if="simulateMode === 'history'" class="simulate-sample">
|
||||
<span>{{ t('admin.shippingOrderSchema.derivationSimulateHistorySample') }}</span>
|
||||
<select v-model="simulateSampleRef" :disabled="simulateSamplesLoading || !simulateSamples.length">
|
||||
<option disabled value="">
|
||||
{{ simulateSamplesLoading
|
||||
? t('admin.shippingOrderSchema.derivationSimulateSamplesLoading')
|
||||
: t('admin.shippingOrderSchema.derivationSimulateSamplesEmpty') }}
|
||||
</option>
|
||||
<option
|
||||
v-for="item in simulateSamples"
|
||||
:key="item.sample_ref"
|
||||
:value="item.sample_ref"
|
||||
>
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulateSampleOption', {
|
||||
id: item.extraction_id,
|
||||
lines: item.line_count,
|
||||
status: item.status,
|
||||
}) }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label v-else class="simulate-sample">
|
||||
<span>{{ t('admin.shippingOrderSchema.derivationSimulateSample') }}</span>
|
||||
<textarea v-model="simulateSampleJson" rows="8" />
|
||||
</label>
|
||||
<footer>
|
||||
<button type="button" class="btn-secondary" @click="simulateOpen = false">{{ t('common.cancel') }}</button>
|
||||
<button type="button" class="btn-primary" :disabled="simulating" @click="runDerivationSimulate">
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulateRun') }}
|
||||
</button>
|
||||
</footer>
|
||||
<div v-if="simulateResult" class="simulate-result">
|
||||
<p>
|
||||
{{ t('admin.shippingOrderSchema.derivationSimulateSummary', {
|
||||
version: simulateResult.schema_version,
|
||||
checksum: simulateResult.rules_checksum.slice(0, 12),
|
||||
derived: simulateResult.derived_count,
|
||||
skipped: simulateResult.skipped_count,
|
||||
}) }}
|
||||
</p>
|
||||
<div class="simulate-result-scroll" data-testid="derivation-simulate-result-scroll">
|
||||
<table class="derivation-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationSource') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationBefore') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationAfter') }}</th>
|
||||
<th>{{ t('admin.shippingOrderSchema.derivationResult') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in simulateResult.results" :key="`${row.line_index}-${row.rule_id}`">
|
||||
<td>{{ row.line_index + 1 }}</td>
|
||||
<td>{{ row.before_source ?? '—' }}</td>
|
||||
<td>{{ row.before_target ?? '—' }}</td>
|
||||
<td>{{ row.after_target ?? '—' }}</td>
|
||||
<td>
|
||||
<template v-if="row.status === 'derived'">
|
||||
{{ t('admin.shippingOrderSchema.derivationStatusDerived') }}
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ t('admin.shippingOrderSchema.derivationStatusSkipped', { reason: row.skip_reason || '' }) }}
|
||||
</template>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="muted">{{ t('admin.shippingOrderSchema.derivationSimulateNoMutate') }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div v-if="profileImpactOpen && profileImpact" class="impact-overlay" @click.self="profileImpactOpen = false">
|
||||
<section class="impact-dialog">
|
||||
<header>
|
||||
@@ -1430,12 +1692,71 @@ onMounted(async () => {
|
||||
.schema-toolbar span { color: #94a3b8; font-size: 12px; }
|
||||
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.schema-workbench { display: grid; height: min(700px, calc(100vh - 280px)); min-height: 540px; grid-template-columns: 320px minmax(0, 1fr); overflow: hidden; border: 1px solid #dfe7ef; border-radius: 10px; background: #fff; box-shadow: 0 1px 2px rgb(15 23 42 / 3%); }
|
||||
.auto-creation-switch { display: flex; align-items: center; gap: 9px; margin: 0 0 16px; border: 1px solid #dbe6ef; border-radius: 8px; background: #fbfdff; padding: 11px 14px; color: #475569; cursor: pointer; }
|
||||
.schema-policy-group {
|
||||
margin: 0 0 18px;
|
||||
border: 1px solid #cfe0ef;
|
||||
border-radius: 10px;
|
||||
background: linear-gradient(180deg, #f8fbff 0%, #f3f8fc 100%);
|
||||
padding: 14px 14px 8px;
|
||||
}
|
||||
.schema-policy-heading {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.schema-policy-heading h2 { margin: 0; color: #0f172a; font-size: 14px; }
|
||||
.schema-policy-heading p { margin: 4px 0 0; color: #64748b; font-size: 12px; line-height: 1.45; }
|
||||
.schema-policy-badge {
|
||||
flex-shrink: 0;
|
||||
border-radius: 999px;
|
||||
background: #e0f2fe;
|
||||
color: #0369a1;
|
||||
font-size: 11px;
|
||||
padding: 4px 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.schema-policy-badge.is-readonly { background: #e2e8f0; color: #475569; }
|
||||
.auto-creation-switch { display: flex; align-items: center; gap: 9px; margin: 0 0 12px; border: 1px solid #dbe6ef; border-radius: 8px; background: #fff; padding: 11px 14px; color: #475569; cursor: pointer; }
|
||||
.auto-creation-switch input { width: 16px; height: 16px; margin: 0; accent-color: #0ea5e9; }
|
||||
.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; }
|
||||
.auto-creation-effective { display: block; color: #0f766e; }
|
||||
.schema-gate-note { margin: 0 0 12px; color: #475569; font-size: 12px; line-height: 1.5; }
|
||||
.derivation-panel { margin: 0 0 8px; border: 1px solid #dbe6ef; border-radius: 8px; background: #fff; padding: 12px 14px; }
|
||||
.derivation-panel summary { cursor: pointer; display: grid; gap: 4px; color: #334155; }
|
||||
.derivation-panel summary span { color: #64748b; font-size: 12px; }
|
||||
.derivation-toolbar { display: flex; justify-content: flex-end; margin: 12px 0; }
|
||||
.derivation-table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
||||
.derivation-table th, .derivation-table td { border-bottom: 1px solid #e2e8f0; padding: 8px 6px; text-align: left; vertical-align: middle; }
|
||||
.derivation-note { margin: 10px 0 0; color: #64748b; font-size: 12px; }
|
||||
.simulate-hint { margin: 0 0 10px; color: #64748b; font-size: 12px; }
|
||||
.simulate-mode-row { display: flex; gap: 16px; margin-bottom: 10px; font-size: 13px; color: #334155; }
|
||||
.simulate-mode-row label { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.derivation-simulate-dialog {
|
||||
max-width: 760px;
|
||||
width: min(760px, 92vw);
|
||||
overflow: auto;
|
||||
align-content: start;
|
||||
}
|
||||
.simulate-sample { display: grid; gap: 8px; margin: 12px 0; color: #475569; font-size: 13px; }
|
||||
.simulate-sample textarea,
|
||||
.simulate-sample select { width: 100%; font-size: 12px; border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px; box-sizing: border-box; }
|
||||
.simulate-sample textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
||||
.simulate-result { margin-top: 14px; display: grid; gap: 10px; min-width: 0; }
|
||||
.simulate-result-scroll {
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.simulate-result-scroll .derivation-table {
|
||||
margin: 0;
|
||||
min-width: 520px;
|
||||
}
|
||||
.muted { margin: 0; color: #64748b; font-size: 12px; }
|
||||
.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; }
|
||||
@@ -1480,7 +1801,7 @@ onMounted(async () => {
|
||||
.field-title-line { display: flex; min-width: 0; align-items: baseline; gap: 10px; }
|
||||
.field-title-line h2 { overflow: hidden; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.field-title-line code { color: #64748b; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
|
||||
.read-only-badge { border: 1px solid #cbd5e1; border-radius: 999px; background: #f8fafc; padding: 4px 9px; color: #64748b; font-size: 11px; font-weight: 600; }
|
||||
.read-only-badge,
|
||||
.rule-body { display: grid; min-height: 0; flex: 1 1 auto; align-content: start; gap: 12px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 14px 18px 20px; scrollbar-gutter: stable; }
|
||||
.rule-basics, .rule-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
|
||||
.rule-basics .span-two { grid-column: 1 / -1; }
|
||||
|
||||
-339
@@ -1,339 +0,0 @@
|
||||
<!--
|
||||
features/admin/modules/shipping-review-supervision/ShippingReviewSupervisionPage.vue
|
||||
用途:管理员跨用户会话 PDF 工作项监管台——筛选、终止、撤销确认。
|
||||
依赖:shipping-review-supervision.api、Vue I18n、useMessage。
|
||||
逻辑:终止/撤销须填写理由与 confirm_token;成功后刷新列表。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import type { ShippingSessionWorkItem } from '@/features/chat/types/shipping.api.types';
|
||||
import {
|
||||
SUPERVISION_CONFIRM_REVOKE,
|
||||
SUPERVISION_CONFIRM_TERMINATE,
|
||||
listShippingReviewSupervisionItems,
|
||||
revokeShippingReviewSupervisionConfirmation,
|
||||
terminateShippingReviewSupervisionItem,
|
||||
type ShippingReviewSupervisionFilters,
|
||||
} from '@/features/admin/api/shipping-review-supervision.api';
|
||||
|
||||
type SupervisionAction = 'terminate' | 'revoke';
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const msg = useMessage();
|
||||
const loading = ref(false);
|
||||
const submitting = ref(false);
|
||||
const error = ref('');
|
||||
const page = ref(1);
|
||||
const pageSize = 20;
|
||||
const total = ref(0);
|
||||
const rows = ref<ShippingSessionWorkItem[]>([]);
|
||||
const filters = ref<ShippingReviewSupervisionFilters>({
|
||||
lifecycle_status: '',
|
||||
owner_user_id: '',
|
||||
conversation_id: '',
|
||||
q: '',
|
||||
});
|
||||
const actionDialogOpen = ref(false);
|
||||
const actionKind = ref<SupervisionAction>('terminate');
|
||||
const actionTarget = ref<ShippingSessionWorkItem | null>(null);
|
||||
const actionReason = ref('');
|
||||
const actionConfirmChecked = ref(false);
|
||||
const reasonMissing = ref(false);
|
||||
const confirmMissing = ref(false);
|
||||
|
||||
const formatTime = (value?: string | null) => (value ? new Date(value).toLocaleString() : '—');
|
||||
|
||||
/**
|
||||
* 解析生命周期状态文案。
|
||||
*/
|
||||
function lifecycleLabel(status: string): string {
|
||||
const key = `chat.shippingSessionWorkItem.status.${status}`;
|
||||
return te(key) ? t(key) : status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载监管列表。
|
||||
*/
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const response = await listShippingReviewSupervisionItems(page.value, pageSize, filters.value);
|
||||
rows.value = response.items;
|
||||
total.value = response.total;
|
||||
} catch {
|
||||
error.value = t('admin.shippingReviewSupervision.loadFailed');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function applyFilters() {
|
||||
page.value = 1;
|
||||
await load();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开终止或撤销确认弹窗。
|
||||
*/
|
||||
function openAction(kind: SupervisionAction, item: ShippingSessionWorkItem) {
|
||||
actionKind.value = kind;
|
||||
actionTarget.value = item;
|
||||
actionReason.value = '';
|
||||
actionConfirmChecked.value = false;
|
||||
reasonMissing.value = false;
|
||||
confirmMissing.value = false;
|
||||
actionDialogOpen.value = true;
|
||||
}
|
||||
|
||||
function closeActionDialog() {
|
||||
actionDialogOpen.value = false;
|
||||
actionTarget.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交监管写操作;校验理由与 confirm_token。
|
||||
*/
|
||||
async function submitAction() {
|
||||
const item = actionTarget.value;
|
||||
if (!item?.item_no) return;
|
||||
const reason = actionReason.value.trim();
|
||||
if (!reason) {
|
||||
reasonMissing.value = true;
|
||||
return;
|
||||
}
|
||||
if (!actionConfirmChecked.value) {
|
||||
confirmMissing.value = true;
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
if (actionKind.value === 'terminate') {
|
||||
await terminateShippingReviewSupervisionItem(item.item_no, {
|
||||
reason,
|
||||
confirm_token: SUPERVISION_CONFIRM_TERMINATE,
|
||||
});
|
||||
msg.success(t('admin.shippingReviewSupervision.terminateSuccess'));
|
||||
} else {
|
||||
await revokeShippingReviewSupervisionConfirmation(item.item_no, {
|
||||
reason,
|
||||
confirm_token: SUPERVISION_CONFIRM_REVOKE,
|
||||
});
|
||||
msg.success(t('admin.shippingReviewSupervision.revokeSuccess'));
|
||||
}
|
||||
closeActionDialog();
|
||||
await load();
|
||||
} catch (err) {
|
||||
const message = err instanceof BusinessError ? err.message : t('admin.shippingReviewSupervision.actionFailed');
|
||||
msg.error(message);
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const canTerminate = (item: ShippingSessionWorkItem) =>
|
||||
item.lifecycle_status !== 'closed' && (item.available_actions || []).includes('admin_terminate');
|
||||
|
||||
const canRevoke = (item: ShippingSessionWorkItem) =>
|
||||
item.lifecycle_status === 'closed'
|
||||
&& item.closed_reason === 'confirmed'
|
||||
&& (item.available_actions || []).includes('admin_revoke_confirmation');
|
||||
|
||||
onMounted(() => {
|
||||
void load();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="space-y-5 p-5 md:p-7" data-testid="shipping-review-supervision-page">
|
||||
<header class="flex flex-wrap items-start justify-between gap-4">
|
||||
<div>
|
||||
<h1 class="section-title">{{ t('admin.shippingReviewSupervision.title') }}</h1>
|
||||
<p class="section-desc mt-1 max-w-3xl">{{ t('admin.shippingReviewSupervision.subtitle') }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary btn-sm" :disabled="loading" @click="load">
|
||||
{{ t('admin.shippingReviewSupervision.refresh') }}
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div class="grid gap-3 rounded-xl border border-default bg-surface p-3 md:grid-cols-2 lg:grid-cols-4">
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingReviewSupervision.filters.lifecycleStatus') }}</span>
|
||||
<select v-model="filters.lifecycle_status" class="input-field text-sm">
|
||||
<option value="">{{ t('admin.shippingReviewSupervision.filters.all') }}</option>
|
||||
<option value="pending_review">{{ lifecycleLabel('pending_review') }}</option>
|
||||
<option value="extracting">{{ lifecycleLabel('extracting') }}</option>
|
||||
<option value="reparse_failed">{{ lifecycleLabel('reparse_failed') }}</option>
|
||||
<option value="closed">{{ lifecycleLabel('closed') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingReviewSupervision.filters.ownerUserId') }}</span>
|
||||
<input v-model="filters.owner_user_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingReviewSupervision.filters.conversationId') }}</span>
|
||||
<input v-model="filters.conversation_id" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
<label class="space-y-1 text-xs text-secondary">
|
||||
<span>{{ t('admin.shippingReviewSupervision.filters.q') }}</span>
|
||||
<input v-model="filters.q" class="input-field text-sm" @keyup.enter="applyFilters">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<button type="button" class="btn-primary btn-sm" :disabled="loading" @click="applyFilters">
|
||||
{{ t('admin.shippingReviewSupervision.apply') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="error" class="text-sm text-rose-600 dark:text-rose-400">{{ error }}</p>
|
||||
|
||||
<div class="overflow-x-auto rounded-xl border border-default bg-surface">
|
||||
<table class="min-w-full text-left text-sm">
|
||||
<thead class="border-b border-default bg-muted/40 text-xs text-secondary">
|
||||
<tr>
|
||||
<th class="px-3 py-2 font-medium">{{ t('admin.shippingReviewSupervision.columns.itemNo') }}</th>
|
||||
<th class="px-3 py-2 font-medium">{{ t('admin.shippingReviewSupervision.columns.owner') }}</th>
|
||||
<th class="px-3 py-2 font-medium">{{ t('admin.shippingReviewSupervision.columns.conversation') }}</th>
|
||||
<th class="px-3 py-2 font-medium">{{ t('admin.shippingReviewSupervision.columns.document') }}</th>
|
||||
<th class="px-3 py-2 font-medium">{{ t('admin.shippingReviewSupervision.columns.status') }}</th>
|
||||
<th class="px-3 py-2 font-medium">{{ t('admin.shippingReviewSupervision.columns.updated') }}</th>
|
||||
<th class="px-3 py-2 font-medium">{{ t('admin.shippingReviewSupervision.columns.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="loading">
|
||||
<td colspan="7" class="px-3 py-6 text-center text-secondary">{{ t('admin.shippingReviewSupervision.loading') }}</td>
|
||||
</tr>
|
||||
<tr v-else-if="!rows.length">
|
||||
<td colspan="7" class="px-3 py-6 text-center text-secondary">{{ t('admin.shippingReviewSupervision.empty') }}</td>
|
||||
</tr>
|
||||
<tr v-for="item in rows" :key="item.item_no" class="border-b border-default last:border-0">
|
||||
<td class="px-3 py-2 font-mono text-xs">{{ item.item_no }}</td>
|
||||
<td class="px-3 py-2">{{ item.owner_user_id }}</td>
|
||||
<td class="max-w-40 truncate px-3 py-2 font-mono text-xs" :title="item.conversation_id">{{ item.conversation_id }}</td>
|
||||
<td class="max-w-48 truncate px-3 py-2" :title="item.current_document_filename || ''">
|
||||
{{ item.current_document_filename || '—' }}
|
||||
</td>
|
||||
<td class="px-3 py-2">
|
||||
<span class="rounded-full bg-muted px-2 py-0.5 text-xs">{{ lifecycleLabel(String(item.lifecycle_status)) }}</span>
|
||||
</td>
|
||||
<td class="px-3 py-2 text-xs text-secondary">{{ formatTime(item.updated_at) }}</td>
|
||||
<td class="px-3 py-2">
|
||||
<div class="flex flex-wrap gap-1">
|
||||
<button
|
||||
v-if="canTerminate(item)"
|
||||
type="button"
|
||||
class="btn-danger btn-xs"
|
||||
data-testid="supervision-terminate-btn"
|
||||
@click="openAction('terminate', item)"
|
||||
>
|
||||
{{ t('admin.shippingReviewSupervision.terminate') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="canRevoke(item)"
|
||||
type="button"
|
||||
class="btn-secondary btn-xs"
|
||||
data-testid="supervision-revoke-btn"
|
||||
@click="openAction('revoke', item)"
|
||||
>
|
||||
{{ t('admin.shippingReviewSupervision.revoke') }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<footer class="flex items-center justify-between text-sm text-secondary">
|
||||
<span>{{ t('admin.shippingReviewSupervision.total', { count: total }) }}</span>
|
||||
<div class="flex gap-2">
|
||||
<button type="button" class="btn-secondary btn-sm" :disabled="loading || page <= 1" @click="page -= 1; load()">
|
||||
{{ t('admin.shippingReviewSupervision.previous') }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary btn-sm" :disabled="loading || page * pageSize >= total" @click="page += 1; load()">
|
||||
{{ t('admin.shippingReviewSupervision.next') }}
|
||||
</button>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="actionDialogOpen && actionTarget"
|
||||
class="dialog-overlay z-50 flex items-center justify-center p-4"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
data-testid="supervision-action-dialog"
|
||||
@click.self="closeActionDialog"
|
||||
>
|
||||
<div class="dialog-panel w-full max-w-md space-y-4 p-5">
|
||||
<header>
|
||||
<h2 class="text-base font-semibold text-primary">
|
||||
{{ actionKind === 'terminate'
|
||||
? t('admin.shippingReviewSupervision.terminateTitle')
|
||||
: t('admin.shippingReviewSupervision.revokeTitle') }}
|
||||
</h2>
|
||||
<p class="mt-2 text-sm text-secondary">
|
||||
{{ actionKind === 'terminate'
|
||||
? t('admin.shippingReviewSupervision.terminateImpact', { itemNo: actionTarget.item_no })
|
||||
: t('admin.shippingReviewSupervision.revokeImpact', { itemNo: actionTarget.item_no }) }}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<label class="block space-y-1 text-sm">
|
||||
<span class="text-secondary">{{ t('admin.shippingReviewSupervision.reasonLabel') }}</span>
|
||||
<textarea
|
||||
v-model="actionReason"
|
||||
rows="3"
|
||||
class="input-field w-full resize-y text-sm"
|
||||
data-testid="supervision-reason-input"
|
||||
@input="reasonMissing = false"
|
||||
/>
|
||||
<p v-if="reasonMissing" class="text-xs text-rose-600 dark:text-rose-400">
|
||||
{{ t('admin.shippingReviewSupervision.reasonRequired') }}
|
||||
</p>
|
||||
</label>
|
||||
|
||||
<label class="flex items-start gap-2 text-sm">
|
||||
<input
|
||||
v-model="actionConfirmChecked"
|
||||
type="checkbox"
|
||||
class="mt-0.5"
|
||||
data-testid="supervision-confirm-checkbox"
|
||||
@change="confirmMissing = false"
|
||||
>
|
||||
<span class="text-secondary">
|
||||
{{ actionKind === 'terminate'
|
||||
? t('admin.shippingReviewSupervision.confirmTerminate')
|
||||
: t('admin.shippingReviewSupervision.confirmRevoke') }}
|
||||
</span>
|
||||
</label>
|
||||
<p v-if="confirmMissing" class="text-xs text-rose-600 dark:text-rose-400">
|
||||
{{ t('admin.shippingReviewSupervision.confirmRequired') }}
|
||||
</p>
|
||||
|
||||
<footer class="flex justify-end gap-2">
|
||||
<button type="button" class="btn-secondary btn-sm" :disabled="submitting" @click="closeActionDialog">
|
||||
{{ t('common.deleteDialog.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:class="actionKind === 'terminate' ? 'btn-danger btn-sm' : 'btn-primary btn-sm'"
|
||||
:disabled="submitting"
|
||||
data-testid="supervision-action-submit"
|
||||
@click="submitAction"
|
||||
>
|
||||
{{ submitting ? t('admin.shippingReviewSupervision.submitting') : t('admin.shippingReviewSupervision.submit') }}
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</section>
|
||||
</template>
|
||||
@@ -17,7 +17,6 @@ const shippingRoutes = adminRoutes[0].children?.filter((route) =>
|
||||
|| route.name === 'AdminShippingIdentityRules'
|
||||
|| route.name === 'AdminShippingOrderExtractionRuns'
|
||||
|| route.name === 'AdminShippingAudit'
|
||||
|| route.name === 'AdminShippingReviewSupervision'
|
||||
|| route.name === 'AdminShippingOrderDocumentProfiles',
|
||||
) ?? [];
|
||||
|
||||
@@ -33,7 +32,7 @@ describe('shipping configuration navigation contract', () => {
|
||||
});
|
||||
|
||||
it('registers all shipping configuration subpages with discoverable deep links', () => {
|
||||
// 关键断言:导航注册表与深链路由必须一一对应,避免后台入口不可发现。
|
||||
// 关键断言:导航注册表与深链路由必须一一对应,避免后台入口不可发现;复核监管台已移除。
|
||||
expect(SHIPPING_CONFIG_SUB_MODULE_METAS).toEqual([
|
||||
{ id: 'field_assets', routeName: 'AdminShippingFieldAssets', path: 'shipping-field-assets', labelKey: 'admin.nav.shippingFieldAssets', groupKey: 'admin.nav.shippingOrderRecognition' },
|
||||
{ id: 'order_schema', routeName: 'AdminShippingOrderSchema', path: 'shipping-order-schema', labelKey: 'admin.nav.shippingOrderSchema', groupKey: 'admin.nav.shippingOrderRecognition' },
|
||||
@@ -47,11 +46,11 @@ describe('shipping configuration navigation contract', () => {
|
||||
{ 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: 'shipping_audit', routeName: 'AdminShippingAudit', path: 'shipping-audit', labelKey: 'admin.nav.shippingAudit', groupKey: 'admin.nav.shippingRunAudit' },
|
||||
{ id: 'shipping_review_supervision', routeName: 'AdminShippingReviewSupervision', path: 'shipping-review-supervision', labelKey: 'admin.nav.shippingReviewSupervision', groupKey: 'admin.nav.shippingRunAudit' },
|
||||
{ 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(8);
|
||||
expect(shippingRoutes).toHaveLength(7);
|
||||
expect(shippingRoutes.some((route) => route.name === 'AdminShippingReviewSupervision')).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps exactly three ordered accordion groups', () => {
|
||||
@@ -73,7 +72,6 @@ describe('shipping configuration navigation contract', () => {
|
||||
expect.objectContaining({ requiresAdmin: true, adminModule: 'shipping_inventory', adminSubModule: 'identity_rules' }),
|
||||
expect.objectContaining({ requiresAdmin: true, adminModule: 'shipping_inventory', adminSubModule: 'order_extraction_runs' }),
|
||||
expect.objectContaining({ requiresAdmin: true, adminModule: 'shipping_inventory', adminSubModule: 'shipping_audit' }),
|
||||
expect.objectContaining({ requiresAdmin: true, adminModule: 'shipping_inventory', adminSubModule: 'shipping_review_supervision' }),
|
||||
expect.objectContaining({ requiresAdmin: true, adminModule: 'shipping_inventory', adminSubModule: 'order_document_profiles' }),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -28,7 +28,6 @@ export type ShippingConfigSubModuleId =
|
||||
| 'identity_rules'
|
||||
| 'order_extraction_runs'
|
||||
| 'shipping_audit'
|
||||
| 'shipping_review_supervision'
|
||||
| 'inventory_fields'
|
||||
| 'connections'
|
||||
| 'inventory_sites'
|
||||
|
||||
@@ -27,13 +27,13 @@ export type OrderProfileGovernanceErrorCode =
|
||||
export interface OrderProfileRelativeRegion { x0: number; y0: number; x1: number; y1: number; }
|
||||
export interface OrderProfileAnchorRelativeRegion { x0: number; y0: number; x1: number; y1: number; }
|
||||
export interface OrderProfileDocumentMatchAnchor { anchor_id: string; label: string; value: string; value_position: 'right' | 'below'; page_no?: number | null; label_region?: OrderProfileRelativeRegion | null; value_region?: OrderProfileRelativeRegion | null; minimum_evidence_level: OrderProfileEvidenceLevel; }
|
||||
export interface OrderProfileAnchorRule { anchor_id: string; text: string; aliases?: string[]; match_mode: 'exact' | 'contains'; region?: OrderProfileRelativeRegion | null; minimum_evidence_level: OrderProfileEvidenceLevel; }
|
||||
export interface OrderProfileFieldRegion { field_id: string; field_code: string; region: OrderProfileRelativeRegion; extractor_key: OrderProfileExtractorKey; allowed_sources: OrderProfileAllowedSource[]; minimum_evidence_level: OrderProfileEvidenceLevel; target_fields?: Array<{ field_id: string; field_code: string }>; }
|
||||
export interface OrderProfileOrderFieldLayout { layout_id: string; field_id: string; field_code: string; page_scope: 'first_page' | 'all_pages' | 'exact_page'; page_no?: number | null; anchor?: OrderProfileAnchorRule | null; value_region?: OrderProfileAnchorRelativeRegion | null; absolute_value_region?: OrderProfileRelativeRegion | null; fallback_value_region?: OrderProfileRelativeRegion | null; value_mode: 'single_line' | 'multi_line' | 'right_of_anchor' | 'below_anchor'; stop_anchors: OrderProfileAnchorRule[]; normalizer_key?: string | null; required: boolean; minimum_evidence_level: OrderProfileEvidenceLevel; }
|
||||
export interface OrderProfileAnchorRule { anchor_id: string; text: string; aliases?: string[]; match_mode: 'exact' | 'contains'; region?: OrderProfileRelativeRegion | null; position_locked?: boolean; minimum_evidence_level: OrderProfileEvidenceLevel; }
|
||||
export interface OrderProfileFieldRegion { field_id: string; field_code: string; scope: 'header' | 'line'; region: OrderProfileRelativeRegion; extractor_key: OrderProfileExtractorKey; allowed_sources: OrderProfileAllowedSource[]; minimum_evidence_level: OrderProfileEvidenceLevel; target_fields?: Array<{ field_id: string; field_code: string; scope: 'header' | 'line' }>; }
|
||||
export interface OrderProfileOrderFieldLayout { layout_id: string; field_id: string; field_code: string; scope: 'header'; page_scope: 'first_page' | 'all_pages' | 'exact_page'; page_no?: number | null; anchor?: OrderProfileAnchorRule | null; value_region?: OrderProfileAnchorRelativeRegion | null; absolute_value_region?: OrderProfileRelativeRegion | null; fallback_value_region?: OrderProfileRelativeRegion | null; value_mode: 'single_line' | 'multi_line' | 'right_of_anchor' | 'below_anchor'; stop_anchors: OrderProfileAnchorRule[]; normalizer_key?: string | null; required: boolean; minimum_evidence_level: OrderProfileEvidenceLevel; }
|
||||
export interface OrderProfileDraftUnboundOrderFieldLayout { layout_id: string; label: string; page_scope: 'first_page' | 'all_pages' | 'exact_page'; page_no?: number | null; anchor?: OrderProfileAnchorRule | null; value_region?: OrderProfileAnchorRelativeRegion | null; absolute_value_region?: OrderProfileRelativeRegion | null; fallback_value_region?: OrderProfileRelativeRegion | null; value_mode: 'single_line' | 'multi_line' | 'right_of_anchor' | 'below_anchor'; stop_anchors: OrderProfileAnchorRule[]; minimum_evidence_level: OrderProfileEvidenceLevel; }
|
||||
export interface OrderProfileHeaderLayout { layout_id: string; region: OrderProfileRelativeRegion; field_regions: OrderProfileFieldRegion[]; }
|
||||
export interface OrderProfileLineLayout { layout_id: string; row_offset: number; role: 'main' | 'continuation'; region: OrderProfileRelativeRegion; field_regions: OrderProfileFieldRegion[]; new_line_anchor?: OrderProfileAnchorRule | null; continuation_conditions: OrderProfileAnchorRule[]; required_fields: string[]; allowed_empty_fields: string[]; }
|
||||
export interface OrderProfileTableRegion { region_id: string; page_scope: 'first_page' | 'all_pages' | 'continuation_pages' | 'exact_page'; page_no?: number | null; region: OrderProfileRelativeRegion; header_layouts: OrderProfileHeaderLayout[]; line_layouts: OrderProfileLineLayout[]; continuation_rule: { allow_cross_page: boolean; required_anchor_ids: string[] }; termination_rules: Array<{ rule_id: string; anchor: OrderProfileAnchorRule }>; exclusion_regions: OrderProfileRelativeRegion[]; draft_unbound_field_regions?: Array<{ region_id: string; parent_layout_id: string; label: string; region: OrderProfileRelativeRegion }>; }
|
||||
export interface OrderProfileTableRegion { region_id: string; page_scope: 'first_page' | 'all_pages' | 'continuation_pages' | 'exact_page'; page_no?: number | null; region: OrderProfileRelativeRegion; /** 逻辑明细起行锚点;默认 customer_po_line_no;line_no 为可识别内部项次亦可绑定。 */ line_start_field_code?: string; header_layouts: OrderProfileHeaderLayout[]; line_layouts: OrderProfileLineLayout[]; continuation_rule: { allow_cross_page: boolean; required_anchor_ids: string[] }; termination_rules: Array<{ rule_id: string; anchor: OrderProfileAnchorRule }>; exclusion_regions: OrderProfileRelativeRegion[]; draft_unbound_field_regions?: Array<{ region_id: string; parent_layout_id: string; label: string; region: OrderProfileRelativeRegion }>; }
|
||||
export interface OrderProfileDocumentMatch { document_type: 'purchase_order'; page_pattern: 'one_or_more'; required_anchors: OrderProfileDocumentMatchAnchor[]; optional_anchors: OrderProfileDocumentMatchAnchor[]; minimum_score: number; minimum_margin: number; }
|
||||
|
||||
/** 阶段 3 重构前仅用于让旧工作台编译;不能作为 v2 API 请求或持久化定义。 */
|
||||
@@ -199,6 +199,10 @@ export interface OrderProfileVersionFamilySummary {
|
||||
draft_version?: number | null;
|
||||
published_profile_id?: number | null;
|
||||
published_version?: number | null;
|
||||
published_schema_version_id?: number | null;
|
||||
published_schema_version?: number | null;
|
||||
current_schema_version_id?: number | null;
|
||||
current_schema_version?: number | null;
|
||||
latest_profile_id: number;
|
||||
latest_version: number;
|
||||
default_profile_id: number;
|
||||
@@ -403,7 +407,7 @@ export interface OrderProfileBlindTestAvailableSample {
|
||||
}
|
||||
export interface OrderProfileBlindTestCandidate {
|
||||
document_id: number; table_id: string; rows: Array<Record<string, unknown>>;
|
||||
order_fields: Array<{ field_code: string; value: unknown; status: 'confirmed' | 'needs_review' | 'unavailable'; page_no: number | null; issues: string[] }>;
|
||||
order_fields: Array<{ field_id: string; field_code: string; scope: 'header'; value: unknown; status: 'confirmed' | 'needs_review' | 'unavailable'; page_no: number | null; issues: string[] }>;
|
||||
}
|
||||
|
||||
/** 工作台的本地几何状态;保存前转为 v2 相对区域定义。 */
|
||||
|
||||
@@ -91,9 +91,69 @@ export interface ShippingOrderSchemaVersion {
|
||||
definition?: {
|
||||
fields: ShippingOrderFieldConfig[];
|
||||
auto_creation_policy?: { enabled: boolean };
|
||||
derivation_rules?: ShippingOrderDerivationRule[];
|
||||
derivation_rules_checksum?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** Schema 级明细字段派生规则(首期仅 copy_if_empty → line_no)。 */
|
||||
export interface ShippingOrderDerivationRule {
|
||||
rule_id: string;
|
||||
enabled: boolean;
|
||||
source_field_code: string;
|
||||
target_field_code: string;
|
||||
strategy: 'copy_if_empty';
|
||||
scope: 'line';
|
||||
}
|
||||
|
||||
export interface ShippingOrderDerivationSimulateRequest {
|
||||
lines?: Array<Record<string, string | number | null | undefined>>;
|
||||
derivation_rules?: ShippingOrderDerivationRule[];
|
||||
/** 可追溯样本;`extraction:<id>` 时后端加载历史明细,可省略 lines。 */
|
||||
sample_ref?: string;
|
||||
}
|
||||
|
||||
export interface ShippingOrderDerivationSimulateSampleItem {
|
||||
sample_ref: string;
|
||||
extraction_id: number;
|
||||
line_count: number;
|
||||
status: string;
|
||||
schema_version_id: number;
|
||||
created_at?: string | null;
|
||||
}
|
||||
|
||||
export interface ShippingOrderDerivationSimulateResult {
|
||||
schema_version_id: number;
|
||||
schema_version: number;
|
||||
schema_version_status: string;
|
||||
rules_checksum: string;
|
||||
rules: ShippingOrderDerivationRule[];
|
||||
derived_count: number;
|
||||
skipped_count: number;
|
||||
results: Array<{
|
||||
line_index: number;
|
||||
rule_id: string;
|
||||
source_field_code: string;
|
||||
target_field_code: string;
|
||||
strategy: string;
|
||||
before_source: unknown;
|
||||
before_target: unknown;
|
||||
after_target: unknown;
|
||||
status: 'derived' | 'skipped';
|
||||
skip_reason: string | null;
|
||||
}>;
|
||||
lines_after: Array<Record<string, unknown>>;
|
||||
sample_ref?: string | null;
|
||||
sample_source?: {
|
||||
kind?: string;
|
||||
extraction_id?: number;
|
||||
schema_version_id?: number;
|
||||
intake_id?: number;
|
||||
status?: string;
|
||||
} | null;
|
||||
mutates_orders: boolean;
|
||||
}
|
||||
|
||||
export interface SchemaVersionActor {
|
||||
id: number;
|
||||
display_name: string;
|
||||
|
||||
Reference in new issue
Block a user