From 9ad5fd8dd2994748c44295a3b60736f9a441169f Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 22 十月 2026 15:01:42 +0800
Subject: [PATCH] feat(agent): 添加数据补录会话功能
---
src/api/agent/conversation.ts | 324 ++++++++++++++++++
src/views/agent/dataEntry/index.vue | 739 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 1,063 insertions(+), 0 deletions(-)
diff --git a/src/api/agent/conversation.ts b/src/api/agent/conversation.ts
new file mode 100644
index 0000000..9ecd557
--- /dev/null
+++ b/src/api/agent/conversation.ts
@@ -0,0 +1,324 @@
+import type { InternalAxiosRequestConfig } from '@vben/request';
+
+import {
+ defaultResponseInterceptor,
+ RequestClient,
+} from '@vben/request';
+import { useAccessStore } from '@vben/stores';
+
+import {
+ bindImportAttachment,
+ createImportSession,
+} from '#/api/mdm/item/agent';
+import { uploadFile } from '#/api/system/storage';
+
+/**
+ * 妯″潡鏁版嵁琛ュ綍浼氳瘽鏈嶅姟锛圥ython锛変笉鍦� /admin-api 涓嬶紝
+ * 寮�鍙戞湡鐢� Vite 浠g悊 /agent-api 杞彂鍒� 127.0.0.1:8091锛屼笖涓嶈繑鍥� CommonResult 鍖呰銆�
+ */
+const agentClient = new RequestClient({
+ baseURL: '/agent-api',
+ responseReturn: 'body',
+ timeout: 120_000,
+});
+
+agentClient.addRequestInterceptor({
+ fulfilled: (config: InternalAxiosRequestConfig) => {
+ const token = useAccessStore().accessToken;
+ if (token) {
+ config.headers.Authorization = `Bearer ${token}`;
+ }
+ return config;
+ },
+});
+
+// Python 鏈嶅姟鐩存帴杩斿洖涓氬姟 JSON锛屼笉濂� CommonResult锛況esponseReturn: 'body' 鏃跺師鏍疯繑鍥炲搷搴斾綋銆�
+agentClient.addResponseInterceptor(
+ defaultResponseInterceptor({
+ codeField: 'code',
+ dataField: 'data',
+ successCode: 0,
+ }),
+);
+
+export namespace AgentConversationApi {
+ export interface FieldSpec {
+ name: string;
+ label: string;
+ required: boolean;
+ kind: string;
+ }
+
+ export interface ModuleSpec {
+ module_id: string;
+ title: string;
+ capability: string;
+ bridge: string;
+ permission: string;
+ description: string;
+ required_fields: string[];
+ fields: FieldSpec[];
+ }
+
+ export interface Capabilities {
+ version: string;
+ formats: string[];
+ ocr: boolean;
+ cross_file_dedupe: boolean;
+ import_modes: string[];
+ notes: string[];
+ modules: ModuleSpec[];
+ }
+
+ export interface Issue {
+ code?: string;
+ field?: string;
+ message: string;
+ candidate_id?: string;
+ }
+
+ export interface Summary {
+ total?: number;
+ create?: number;
+ skip?: number;
+ blocked?: number;
+ success?: number;
+ failed?: number;
+ skipped?: number;
+ unknown?: number;
+ }
+
+ export interface ReceiptRow {
+ candidate_id: string;
+ row_no?: number;
+ code?: string;
+ name?: string;
+ action: string;
+ status: string;
+ target_item_id?: number;
+ error_code?: string;
+ error_message?: string;
+ }
+
+ export interface Receipt {
+ command_id: string;
+ idempotency_key: string;
+ status: string;
+ attachment_id: number;
+ source_sha256: string;
+ preflight_hash: string;
+ summary: Summary;
+ rows: ReceiptRow[];
+ create_time?: string;
+ completed_time?: string;
+ error_code?: string;
+ error_message?: string;
+ }
+
+ export interface ModuleCandidate {
+ module_id: string;
+ title: string;
+ capability: string;
+ description: string;
+ }
+
+ export interface MissingField {
+ name: string;
+ label: string;
+ }
+
+ /** 鍗$墖瀛楁鎸� kind 澶嶇敤锛屾湭浣跨敤鐨勫瓧娈典负绌恒�� */
+ export interface Card {
+ kind: string;
+ title?: string;
+ body?: string;
+ module_id?: string;
+ module_title?: string;
+ capability?: string;
+ revision?: number;
+ issues?: Issue[];
+ warnings?: Issue[];
+ summary?: Summary;
+ can_commit?: boolean;
+ side_effects?: string[];
+ sync_mes?: boolean | null;
+ total?: number;
+ actions?: string[];
+ notice?: string;
+ candidates?: ModuleCandidate[];
+ missing_fields?: MissingField[];
+ columns?: string[];
+ command_id?: string;
+ status?: string;
+ rows?: ReceiptRow[];
+ }
+
+ export interface Message {
+ message_id: string;
+ role: string;
+ type: string;
+ text: string;
+ cards?: Card[];
+ }
+
+ export interface Interrupt {
+ interrupt_id: string;
+ kind: string;
+ revision: number;
+ validation_revision?: number | null;
+ card: Card;
+ }
+
+ export interface RowView {
+ candidate_id: string;
+ values: Record<string, string>;
+ issues: unknown[];
+ warnings: unknown[];
+ }
+
+ export interface Conversation {
+ conversation_id: string;
+ title: string;
+ status: string;
+ module_id: string;
+ module_title: string;
+ capability: string;
+ revision: number;
+ validation_revision?: number | null;
+ sync_mes?: boolean;
+ total: number;
+ summary: Summary;
+ issues: Issue[];
+ warnings: Issue[];
+ missing_fields: string[];
+ columns: string[];
+ messages: Message[];
+ interrupts: Interrupt[];
+ /** 鏈彁浜ゆ椂鍚庣杩斿洖绌哄璞� {}锛屾彁浜ゅ悗鎵嶆湁瀹屾暣鍥炴墽銆� */
+ receipt?: null | Partial<Receipt>;
+ last_error: string;
+ rows: RowView[];
+ created_at: string;
+ updated_at: string;
+ finished: boolean;
+ commit_enabled: boolean;
+ mes_sync_default: boolean;
+ }
+
+ export interface ConversationSummary {
+ conversation_id: string;
+ title: string;
+ status: string;
+ module_id: string;
+ module_title: string;
+ revision: number;
+ created_at: string;
+ updated_at: string;
+ }
+
+ export interface PageResult {
+ items: ConversationSummary[];
+ total: number;
+ page: number;
+ page_size: number;
+ }
+
+ export interface CreateReq {
+ title?: string;
+ text?: string;
+ attachment_id?: string;
+ module_id?: string;
+ }
+
+ export interface ActionReq {
+ interrupt_id: string;
+ revision: number;
+ action: string;
+ payload: Record<string, unknown>;
+ }
+
+ export interface MessageReq {
+ text?: string;
+ attachment_id?: string;
+ }
+}
+
+/** 鑳藉姏澹版槑锛氭敮鎸佺殑鏍煎紡銆佹ā鍧椾笌闄愬埗 */
+export function getAgentCapabilities() {
+ return agentClient.get<AgentConversationApi.Capabilities>('/v1/capabilities');
+}
+
+/** 浼氳瘽鍒楄〃 */
+export function listAgentConversations(params?: {
+ page?: number;
+ page_size?: number;
+ status?: string;
+}) {
+ return agentClient.get<AgentConversationApi.PageResult>(
+ '/v1/conversations',
+ { params },
+ );
+}
+
+/** 鏂板缓琛ュ綍浼氳瘽 */
+export function createAgentConversation(data: AgentConversationApi.CreateReq) {
+ return agentClient.post<AgentConversationApi.Conversation>(
+ '/v1/conversations',
+ data,
+ );
+}
+
+/** 璇诲彇浼氳瘽 */
+export function getAgentConversation(conversationId: string) {
+ return agentClient.get<AgentConversationApi.Conversation>(
+ `/v1/conversations/${conversationId}`,
+ );
+}
+
+/** 鍙戦�佹枃鏈垨闄勪欢锛堢敤浜庤ˉ鍏呬笂浼犳枃浠讹級 */
+export function sendAgentMessage(
+ conversationId: string,
+ data: AgentConversationApi.MessageReq,
+) {
+ return agentClient.post<AgentConversationApi.Conversation>(
+ `/v1/conversations/${conversationId}/messages`,
+ data,
+ );
+}
+
+/** 鍗$墖鎿嶄綔锛氶�夋嫨鍦烘櫙銆佺‘璁ゆ槧灏勩�佷慨璁€�佺‘璁ゆ垨鍙栨秷 */
+export function sendAgentAction(
+ conversationId: string,
+ data: AgentConversationApi.ActionReq,
+) {
+ return agentClient.post<AgentConversationApi.Conversation>(
+ `/v1/conversations/${conversationId}/actions`,
+ data,
+ );
+}
+
+/** 涓嬭浇瀵煎叆鎶ヨ〃锛坸lsx锛� */
+export function downloadAgentReport(conversationId: string) {
+ return agentClient.download<{
+ data: Blob;
+ headers: Record<string, string>;
+ }>(`/v1/conversations/${conversationId}/report`, {
+ responseReturn: 'raw',
+ });
+}
+
+/**
+ * 涓婁紶闄勪欢鍒� Java 瀛樺偍骞剁粦瀹氳ˉ褰曚細璇濓紝杩斿洖 attachmentId銆�
+ * Python 渚ч�氳繃 Java Bridge 鎸� attachmentId 璇诲彇鏂囦欢銆�
+ */
+export async function uploadAgentAttachment(file: File) {
+ const sessionId = await createImportSession();
+ const blobs = await uploadFile([file]);
+ const blobId = blobs?.[0]?.id;
+ if (!blobId) {
+ throw new Error('鏂囦欢涓婁紶澶辫触锛屾湭鍙栧緱 blobId');
+ }
+ return await bindImportAttachment(sessionId, blobId);
+}
+
+export { agentImportErrorMessage } from '#/api/mdm/item/agent';
diff --git a/src/views/agent/dataEntry/index.vue b/src/views/agent/dataEntry/index.vue
new file mode 100644
index 0000000..77badf8
--- /dev/null
+++ b/src/views/agent/dataEntry/index.vue
@@ -0,0 +1,739 @@
+<script lang="ts" setup>
+import type { FileType } from 'ant-design-vue/es/upload/interface';
+
+import type { AgentConversationApi } from '#/api/agent/conversation';
+
+import { computed, onMounted, ref, watch } from 'vue';
+
+import { Page } from '@vben/common-ui';
+import { downloadFileFromBlobPart } from '@vben/utils';
+
+import { message } from 'ant-design-vue';
+
+import {
+ agentImportErrorMessage,
+ createAgentConversation,
+ downloadAgentReport,
+ getAgentCapabilities,
+ getAgentConversation,
+ listAgentConversations,
+ sendAgentAction,
+ sendAgentMessage,
+ uploadAgentAttachment,
+} from '#/api/agent/conversation';
+
+defineOptions({ name: 'AgentDataEntry' });
+
+const MAX_BYTES = 8 * 1024 * 1024;
+const ACCEPT = '.csv,.xlsx,.docx,.pdf';
+
+const modules = ref<AgentConversationApi.ModuleSpec[]>([]);
+const conversations = ref<AgentConversationApi.ConversationSummary[]>([]);
+const active = ref<AgentConversationApi.Conversation>();
+const loading = ref(false);
+const busy = ref(false);
+const creating = ref(false);
+const newOpen = ref(false);
+const newModule = ref('');
+const newText = ref('');
+const newFile = ref<File>();
+const newFileName = ref('');
+const interruptFile = ref<File>();
+const mappingDraft = ref<Record<string, string>>({});
+const reviseText = ref('');
+const syncMes = ref(true);
+
+const interrupt = computed(() => active.value?.interrupts?.at(-1));
+const card = computed(() => interrupt.value?.card);
+const actions = computed(() => card.value?.actions ?? []);
+const isGatewayModule = computed(() => active.value?.module_id === 'mdm.item');
+
+const moduleOptions = computed(() => [
+ { label: '鑷姩璇嗗埆', value: '' },
+ ...modules.value.map((item) => ({ label: item.title, value: item.module_id })),
+]);
+
+watch(
+ () => interrupt.value?.interrupt_id,
+ () => {
+ reviseText.value = '';
+ mappingDraft.value = {};
+ interruptFile.value = undefined;
+ const value = card.value?.sync_mes;
+ syncMes.value =
+ typeof value === 'boolean'
+ ? value
+ : (active.value?.sync_mes ?? active.value?.mes_sync_default ?? true);
+ },
+);
+
+function statusText(status?: string) {
+ const map: Record<string, string> = {
+ SUCCEEDED: '瀵煎叆鎴愬姛',
+ PARTIAL_FAILED: '閮ㄥ垎澶辫触',
+ FAILED: '澶辫触',
+ UNKNOWN: '缁撴灉鏈煡',
+ RUNNING: '鎻愪氦涓�',
+ attached: '宸蹭笂浼�',
+ blocked: '宸查樆鏂�',
+ cancelled: '宸插彇娑�',
+ classified: '宸茶瘑鍒満鏅�',
+ commit_disabled: '鏈彁浜�',
+ confirmed: '宸茬‘璁�',
+ created: '寰呬笂浼犳枃浠�',
+ error: '鍑洪敊',
+ failed: '澶辫触',
+ mapping_applied: '鏄犲皠宸叉洿鏂�',
+ needs_review: '寰呯‘璁�',
+ parsed: '宸茶В鏋�',
+ preview_ready: '寰呯‘璁�',
+ revise: '寰呴噸鏂版牎楠�',
+ stale: '宸茶繃鏈燂紝闇�閲嶆',
+ validated: '寰呯‘璁�',
+ };
+ return map[status ?? ''] ?? status ?? '杩涜涓�';
+}
+
+function statusColor(status?: string) {
+ if (status === 'SUCCEEDED' || status === 'confirmed') return 'green';
+ if (
+ status === 'PARTIAL_FAILED' ||
+ status === 'revise' ||
+ status === 'stale'
+ ) {
+ return 'orange';
+ }
+ if (
+ status === 'FAILED' ||
+ status === 'failed' ||
+ status === 'error' ||
+ status === 'blocked' ||
+ status === 'cancelled'
+ ) {
+ return 'red';
+ }
+ return 'blue';
+}
+
+function checkFile(raw: File) {
+ const name = raw.name.toLowerCase();
+ if (!ACCEPT.split(',').some((ext) => name.endsWith(ext))) {
+ message.error('浠呮敮鎸� CSV銆乆LSX銆丏OCX 鎴� PDF 鏂囦欢');
+ return false;
+ }
+ if (raw.size > MAX_BYTES) {
+ message.error('鏂囦欢涓嶈兘瓒呰繃 8 MiB');
+ return false;
+ }
+ return true;
+}
+
+function beforeNewUpload(fileInfo: FileType) {
+ const raw = fileInfo as unknown as File;
+ if (!checkFile(raw)) return false;
+ newFile.value = raw;
+ newFileName.value = raw.name;
+ return false;
+}
+
+function beforeInterruptUpload(fileInfo: FileType) {
+ const raw = fileInfo as unknown as File;
+ if (!checkFile(raw)) return false;
+ interruptFile.value = raw;
+ return false;
+}
+
+async function boot() {
+ loading.value = true;
+ try {
+ const [capabilities, list] = await Promise.all([
+ getAgentCapabilities(),
+ listAgentConversations({ page_size: 50 }),
+ ]);
+ modules.value = capabilities.modules ?? [];
+ conversations.value = list.items ?? [];
+ } catch (error) {
+ message.error(agentImportErrorMessage(error));
+ } finally {
+ loading.value = false;
+ }
+}
+
+async function reloadConversations() {
+ try {
+ const list = await listAgentConversations({ page_size: 50 });
+ conversations.value = list.items ?? [];
+ } catch {
+ // 鍒楄〃鍒锋柊澶辫触涓嶉樆濉炰富娴佺▼
+ }
+}
+
+async function openConversation(conversationId: string) {
+ if (busy.value) return;
+ busy.value = true;
+ try {
+ active.value = await getAgentConversation(conversationId);
+ } catch (error) {
+ message.error(agentImportErrorMessage(error));
+ } finally {
+ busy.value = false;
+ }
+}
+
+async function createConversation() {
+ if (!newFile.value && !newText.value.trim()) {
+ message.warning('璇蜂笂浼犳枃浠舵垨濉啓琛ュ綍璇存槑');
+ return;
+ }
+ creating.value = true;
+ try {
+ let attachmentId: number | undefined;
+ if (newFile.value) {
+ attachmentId = await uploadAgentAttachment(newFile.value);
+ }
+ active.value = await createAgentConversation({
+ attachment_id: attachmentId ? String(attachmentId) : undefined,
+ module_id: newModule.value || undefined,
+ text: newText.value.trim() || undefined,
+ title: newFile.value?.name || newText.value.trim().slice(0, 60) || undefined,
+ });
+ newOpen.value = false;
+ newFile.value = undefined;
+ newFileName.value = '';
+ newText.value = '';
+ await reloadConversations();
+ } catch (error) {
+ message.error(agentImportErrorMessage(error));
+ } finally {
+ creating.value = false;
+ }
+}
+
+async function apply(result: AgentConversationApi.Conversation, tip?: string) {
+ active.value = result;
+ if (tip) message.success(tip);
+ await reloadConversations();
+}
+
+async function act(
+ action: string,
+ payload: Record<string, unknown> = {},
+ tip?: string,
+) {
+ const current = active.value;
+ const pending = interrupt.value;
+ if (!current || !pending) return;
+ busy.value = true;
+ try {
+ const result = await sendAgentAction(current.conversation_id, {
+ action,
+ interrupt_id: pending.interrupt_id,
+ payload,
+ revision: pending.revision,
+ });
+ await apply(result, tip);
+ } catch (error) {
+ message.error(agentImportErrorMessage(error));
+ } finally {
+ busy.value = false;
+ }
+}
+
+function chooseModule(moduleId: string) {
+ return act('choose_scenario', { module_id: moduleId }, '宸查�夋嫨涓氬姟鍦烘櫙');
+}
+
+async function confirmMapping() {
+ const missing = card.value?.missing_fields ?? [];
+ const mapping: Record<string, string> = {};
+ for (const field of missing) {
+ const column = mappingDraft.value[field.name];
+ if (!column) {
+ message.warning(`璇蜂负銆�${field.label}銆嶉�夋嫨瀵瑰簲鍒梎);
+ return;
+ }
+ mapping[field.name] = column;
+ }
+ await act('confirm_mapping', { mapping }, '鏄犲皠宸叉彁浜わ紝閲嶆柊鏍¢獙');
+}
+
+async function uploadForFileInterrupt() {
+ const current = active.value;
+ if (!current) return;
+ if (!interruptFile.value) {
+ message.warning('璇峰厛閫夋嫨鏂囦欢');
+ return;
+ }
+ busy.value = true;
+ try {
+ const attachmentId = await uploadAgentAttachment(interruptFile.value);
+ const result = await sendAgentMessage(current.conversation_id, {
+ attachment_id: String(attachmentId),
+ text: '宸蹭笂浼犺琛ュ綍鐨勬枃浠躲��',
+ });
+ interruptFile.value = undefined;
+ await apply(result);
+ } catch (error) {
+ message.error(agentImportErrorMessage(error));
+ } finally {
+ busy.value = false;
+ }
+}
+
+async function revise() {
+ const text = reviseText.value.trim();
+ const payload: Record<string, unknown> = {};
+ if (text) payload.text = text;
+ if (isGatewayModule.value) payload.sync_mes = syncMes.value;
+ if (!text && !isGatewayModule.value) {
+ message.warning('璇疯緭鍏ヤ慨璁㈠唴瀹癸紝渚嬪鈥滅2琛� 鍚嶇О 鏀逛负 XXX鈥�');
+ return;
+ }
+ await act('revise', payload, '宸叉彁浜や慨璁紝閲嶆柊鏍¢獙');
+ reviseText.value = '';
+}
+
+async function toggleSync(value: boolean) {
+ syncMes.value = value;
+ await act('revise', { sync_mes: value }, '宸叉洿鏂板悓姝ラ�夐」锛岄噸鏂版牎楠�');
+}
+
+function confirmImport() {
+ return act('confirm', {}, '宸茬‘璁わ紝姝e湪鎻愪氦');
+}
+
+function cancelConversation() {
+ return act('cancel', {}, '宸插彇娑堟湰娆¤ˉ褰�');
+}
+
+async function downloadReport() {
+ const current = active.value;
+ if (!current) return;
+ try {
+ const response = await downloadAgentReport(current.conversation_id);
+ const disposition = String(
+ response.headers?.['content-disposition'] ?? '',
+ );
+ const match = /filename\*?=(?:UTF-8'')?"?([^";]+)"?/i.exec(disposition);
+ downloadFileFromBlobPart({
+ fileName: match?.[1] || `${current.title || '琛ュ綍鍥炴墽'}.xlsx`,
+ source: response.data,
+ });
+ } catch (error) {
+ message.error(agentImportErrorMessage(error));
+ }
+}
+
+onMounted(boot);
+</script>
+
+<template>
+ <Page auto-content-height>
+ <div class="flex h-full gap-3 p-3">
+ <aside
+ class="flex w-64 shrink-0 flex-col overflow-hidden rounded-lg border border-border bg-card"
+ >
+ <div class="border-b border-border p-3">
+ <a-button type="primary" block @click="newOpen = true">
+ 鏂板缓琛ュ綍
+ </a-button>
+ <div class="mt-2 text-xs text-gray-500">
+ 涓婁紶鏂囦欢鍚庤嚜鍔ㄨ瘑鍒笟鍔″満鏅紝纭鍓嶄細瀹屾暣鏍¢獙銆�
+ </div>
+ </div>
+ <div class="flex-1 overflow-y-auto p-2">
+ <a-spin :spinning="loading">
+ <a-empty
+ v-if="!conversations.length"
+ description="鏆傛棤琛ュ綍浼氳瘽"
+ />
+ <button
+ v-for="item in conversations"
+ :key="item.conversation_id"
+ class="mb-1 w-full rounded-md p-2 text-left transition-colors hover:bg-gray-100 dark:hover:bg-gray-800"
+ :class="{
+ 'bg-blue-50 dark:bg-blue-900/30':
+ item.conversation_id === active?.conversation_id,
+ }"
+ type="button"
+ @click="openConversation(item.conversation_id)"
+ >
+ <div class="truncate text-sm font-medium">
+ {{ item.title || '鏈懡鍚嶈ˉ褰�' }}
+ </div>
+ <div class="mt-1 flex items-center gap-2 text-xs text-gray-500">
+ <a-tag :color="statusColor(item.status)" class="!mr-0">
+ {{ statusText(item.status) }}
+ </a-tag>
+ <span class="truncate">
+ {{ item.module_title || '寰呰瘑鍒�' }}
+ </span>
+ </div>
+ </button>
+ </a-spin>
+ </div>
+ </aside>
+
+ <section
+ class="flex min-w-0 flex-1 flex-col overflow-hidden rounded-lg border border-border bg-card"
+ >
+ <header
+ class="flex items-center justify-between border-b border-border px-4 py-3"
+ >
+ <div class="min-w-0">
+ <div class="truncate text-base font-semibold">
+ {{ active?.title || '妯″潡鏁版嵁琛ュ綍' }}
+ </div>
+ <div class="mt-1 flex items-center gap-2 text-xs text-gray-500">
+ <a-tag :color="statusColor(active?.status)" class="!mr-0">
+ {{ statusText(active?.status) }}
+ </a-tag>
+ <span v-if="active?.module_title">{{ active.module_title }}</span>
+ <span v-if="active?.total">鍏� {{ active.total }} 琛�</span>
+ </div>
+ </div>
+ <a-button
+ v-if="active?.receipt?.command_id"
+ :disabled="busy"
+ @click="downloadReport"
+ >
+ 涓嬭浇鍥炴墽
+ </a-button>
+ </header>
+
+ <div class="flex-1 overflow-y-auto p-4">
+ <a-empty
+ v-if="!active"
+ description="浠庡乏渚ч�夋嫨浼氳瘽锛屾垨鐐瑰嚮銆屾柊寤鸿ˉ褰曘�嶅紑濮�"
+ />
+ <div v-else class="space-y-3">
+ <div
+ v-for="item in active.messages"
+ :key="item.message_id"
+ class="flex"
+ :class="item.role === 'user' ? 'justify-end' : 'justify-start'"
+ >
+ <div
+ class="max-w-[80%] rounded-lg px-3 py-2 text-sm"
+ :class="
+ item.role === 'user'
+ ? 'bg-blue-500 text-white'
+ : 'bg-gray-100 dark:bg-gray-800'
+ "
+ >
+ <div class="whitespace-pre-wrap">{{ item.text }}</div>
+ <div
+ v-for="(msgCard, index) in item.cards || []"
+ :key="`${item.message_id}-${index}`"
+ class="mt-2 rounded-md border border-border bg-card p-2 text-gray-800 dark:text-gray-100"
+ >
+ <template v-if="msgCard.kind === 'receipt'">
+ <div class="mb-1 font-semibold">
+ {{ msgCard.title || '瀵煎叆鍥炴墽' }}
+ </div>
+ <div class="text-xs text-gray-500">
+ 鎴愬姛 {{ msgCard.summary?.success ?? 0 }}锛岃烦杩�
+ {{ msgCard.summary?.skipped ?? 0 }}锛屽け璐�
+ {{ msgCard.summary?.failed ?? 0 }}
+ </div>
+ <a-table
+ class="mt-2"
+ :columns="[
+ { title: '缂栫爜', dataIndex: 'code', width: 160 },
+ { title: '鍚嶇О', dataIndex: 'name' },
+ { title: '缁撴灉', dataIndex: 'status', width: 90 },
+ ]"
+ :data-source="msgCard.rows || []"
+ :pagination="false"
+ row-key="candidate_id"
+ size="small"
+ >
+ <template #bodyCell="{ column, record }">
+ <a-tag
+ v-if="column.dataIndex === 'status'"
+ :color="record.status === 'SUCCESS' ? 'green' : 'red'"
+ >
+ {{ record.status }}
+ </a-tag>
+ </template>
+ </a-table>
+ <a-button
+ class="mt-2"
+ size="small"
+ type="link"
+ @click="downloadReport"
+ >
+ 涓嬭浇鎶ヨ〃
+ </a-button>
+ </template>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <footer v-if="active && interrupt" class="border-t border-border p-3">
+ <a-spin :spinning="busy">
+ <!-- 鍦烘櫙閫夋嫨 -->
+ <div v-if="interrupt.kind === 'scenario'">
+ <div class="mb-2 font-medium">{{ card?.title }}</div>
+ <div class="mb-2 text-xs text-gray-500">{{ card?.body }}</div>
+ <div class="flex flex-wrap gap-2">
+ <a-button
+ v-for="candidate in card?.candidates || []"
+ :key="candidate.module_id"
+ :disabled="busy"
+ @click="chooseModule(candidate.module_id)"
+ >
+ {{ candidate.title }}
+ <a-tag class="ml-1" color="blue">
+ {{ candidate.capability }}
+ </a-tag>
+ </a-button>
+ <a-button
+ v-if="actions.includes('cancel')"
+ danger
+ :disabled="busy"
+ @click="cancelConversation"
+ >
+ 鍙栨秷
+ </a-button>
+ </div>
+ </div>
+
+ <!-- 瀛楁鏄犲皠 -->
+ <div v-else-if="interrupt.kind === 'mapping'">
+ <div class="mb-2 font-medium">{{ card?.title }}</div>
+ <div class="mb-2 text-xs text-gray-500">{{ card?.body }}</div>
+ <div class="space-y-2">
+ <div
+ v-for="field in card?.missing_fields || []"
+ :key="field.name"
+ class="flex items-center gap-2"
+ >
+ <span class="w-28 text-sm">{{ field.label }}</span>
+ <a-select
+ v-model:value="mappingDraft[field.name]"
+ class="min-w-56"
+ placeholder="閫夋嫨鏂囦欢涓搴旂殑鍒�"
+ :options="
+ (card?.columns || []).map((column) => ({
+ label: column,
+ value: column,
+ }))
+ "
+ />
+ </div>
+ </div>
+ <div class="mt-3 flex gap-2">
+ <a-button
+ type="primary"
+ :loading="busy"
+ @click="confirmMapping"
+ >
+ 纭鏄犲皠
+ </a-button>
+ <a-button danger :disabled="busy" @click="cancelConversation">
+ 鍙栨秷
+ </a-button>
+ </div>
+ </div>
+
+ <!-- 琛ヤ紶鏂囦欢 -->
+ <div v-else-if="interrupt.kind === 'file'">
+ <div class="mb-2 font-medium">{{ card?.title }}</div>
+ <div class="mb-2 text-xs text-gray-500">{{ card?.body }}</div>
+ <a-upload
+ accept=".csv,.xlsx,.docx,.pdf"
+ :before-upload="beforeInterruptUpload"
+ :max-count="1"
+ :show-upload-list="false"
+ >
+ <a-button>{{ interruptFile ? '閲嶆柊閫夋嫨' : '閫夋嫨鏂囦欢' }}</a-button>
+ </a-upload>
+ <span v-if="interruptFile" class="ml-2 text-xs text-gray-500">
+ {{ interruptFile.name }}
+ </span>
+ <div class="mt-3">
+ <a-button
+ type="primary"
+ :disabled="!interruptFile"
+ :loading="busy"
+ @click="uploadForFileInterrupt"
+ >
+ 涓婁紶骞剁户缁�
+ </a-button>
+ </div>
+ </div>
+
+ <!-- 鏍¢獙 / 棰勮纭 -->
+ <div v-else-if="['preview', 'validation'].includes(interrupt.kind)">
+ <div class="mb-2 flex items-center justify-between">
+ <span class="font-medium">{{ card?.title }}</span>
+ <span class="text-xs text-gray-500">
+ {{ card?.notice }}
+ </span>
+ </div>
+
+ <a-alert
+ v-if="card?.issues?.length"
+ class="mb-2"
+ type="error"
+ show-icon
+ >
+ <template #message>
+ 闃绘柇椤� {{ card.issues.length }} 鏉★紝闇�淇鍚庨噸鏂版牎楠�
+ </template>
+ <ul class="mt-1 list-decimal pl-4 text-xs">
+ <li v-for="(issue, index) in card.issues" :key="index">
+ {{ issue.message }}
+ <span v-if="issue.code" class="text-gray-400">
+ 锛坽{ issue.code }}锛�
+ </span>
+ </li>
+ </ul>
+ </a-alert>
+
+ <a-alert
+ v-if="card?.warnings?.length"
+ class="mb-2"
+ type="warning"
+ show-icon
+ >
+ <template #message>
+ 鎻愮ず {{ card.warnings.length }} 鏉★紝涓嶉樆鏂彁浜�
+ </template>
+ <ul class="mt-1 list-decimal pl-4 text-xs">
+ <li v-for="(item, index) in card.warnings" :key="index">
+ {{ item.message }}
+ </li>
+ </ul>
+ </a-alert>
+
+ <div
+ v-if="card?.summary"
+ class="mb-2 flex flex-wrap gap-3 text-xs text-gray-600 dark:text-gray-300"
+ >
+ <span>鍏� {{ card.summary.total ?? 0 }} 琛�</span>
+ <span class="text-green-600">
+ 鏂板缓 {{ card.summary.create ?? 0 }}
+ </span>
+ <span class="text-orange-500">
+ 璺宠繃 {{ card.summary.skip ?? 0 }}
+ </span>
+ <span class="text-red-500">
+ 闃绘柇 {{ card.summary.blocked ?? 0 }}
+ </span>
+ </div>
+
+ <div v-if="card?.side_effects?.length" class="mb-2 text-xs text-gray-500">
+ 棰勬湡褰卞搷锛歿{ card.side_effects.join('锛�') }}
+ </div>
+
+ <div
+ v-if="isGatewayModule"
+ class="mb-2 flex items-center gap-2 text-sm"
+ >
+ <span>鍚屾鍒� MES</span>
+ <a-switch
+ :checked="syncMes"
+ :disabled="busy"
+ @change="toggleSync"
+ />
+ <span class="text-xs text-gray-500">
+ 鍏抽棴鍚庝粎鍒涘缓 ERP 鐗╂枡
+ </span>
+ </div>
+
+ <div class="flex gap-2">
+ <a-input
+ v-model:value="reviseText"
+ class="flex-1"
+ placeholder="濡傞渶淇敼锛岃緭鍏ヤ慨璁㈣鏄庯紝渚嬪锛氱2琛� 鍚嶇О 鏀逛负 XXX"
+ :disabled="busy"
+ @press-enter="revise"
+ />
+ <a-button :disabled="busy" @click="revise">淇骞堕噸妫�</a-button>
+ <a-button
+ v-if="actions.includes('confirm')"
+ type="primary"
+ :disabled="busy || card?.can_commit === false"
+ :loading="busy"
+ @click="confirmImport"
+ >
+ 纭瀵煎叆
+ </a-button>
+ <a-button
+ v-if="actions.includes('cancel')"
+ danger
+ :disabled="busy"
+ @click="cancelConversation"
+ >
+ 鍙栨秷
+ </a-button>
+ </div>
+ </div>
+
+ <a-alert
+ v-else
+ type="info"
+ show-icon
+ :message="card?.title || '褰撳墠姝ラ闇�瑕佸鐞�'"
+ :description="card?.body"
+ />
+ </a-spin>
+ </footer>
+ </section>
+
+ <a-modal
+ v-model:open="newOpen"
+ title="鏂板缓琛ュ綍"
+ :confirm-loading="creating"
+ ok-text="寮�濮嬭ˉ褰�"
+ cancel-text="鍙栨秷"
+ :width="560"
+ @ok="createConversation"
+ >
+ <div class="space-y-3">
+ <div>
+ <div class="mb-1 text-sm">涓氬姟鍦烘櫙</div>
+ <a-select
+ v-model:value="newModule"
+ class="w-full"
+ :options="moduleOptions"
+ />
+ <div class="mt-1 text-xs text-gray-500">
+ 涓嶇‘瀹氭椂鍙繚鎸佽嚜鍔ㄨ瘑鍒紝绯荤粺浼氭牴鎹〃澶村拰璇存槑鎺ㄨ崘鍦烘櫙銆�
+ </div>
+ </div>
+ <div>
+ <div class="mb-1 text-sm">琛ュ綍璇存槑锛堝彲閫夛級</div>
+ <a-textarea
+ v-model:value="newText"
+ :rows="2"
+ placeholder="渚嬪锛氬鍏ヤ竴鎵逛緵搴斿晢妗f"
+ />
+ </div>
+ <div>
+ <div class="mb-1 text-sm">鏁版嵁鏂囦欢</div>
+ <a-upload
+ accept=".csv,.xlsx,.docx,.pdf"
+ :before-upload="beforeNewUpload"
+ :max-count="1"
+ :show-upload-list="false"
+ >
+ <a-button>閫夋嫨鏂囦欢</a-button>
+ </a-upload>
+ <span v-if="newFileName" class="ml-2 text-xs text-gray-500">
+ {{ newFileName }}
+ </span>
+ <div class="mt-1 text-xs text-gray-500">
+ 鏀寔 CSV銆乆LSX銆丏OCX 涓庡彲澶嶅埗鏂囨湰鐨� PDF锛屽崟涓枃浠朵笉瓒呰繃 8
+ MiB銆傛壂鎻忎欢鏆備笉鏀寔銆�
+ </div>
+ </div>
+ </div>
+ </a-modal>
+ </div>
+ </Page>
+</template>
--
Gitblit v1.9.3