From 09eb944612817e33595e5088e3f3df5f1ebc1b05 Mon Sep 17 00:00:00 2001 From: vertoryao Date: Tue, 17 Jun 2025 15:33:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(@vben/web-antd):=20=E8=A7=A3=E5=86=B3word?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=97=A0=E6=B3=95=E9=A2=84=E8=A7=88=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 加回原来的正则表达式解析 --- .../views/word/components/word-work-view.vue | 53 ++++++++++++++++++- apps/web-antd/vite.config.mts | 4 +- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/apps/web-antd/src/views/word/components/word-work-view.vue b/apps/web-antd/src/views/word/components/word-work-view.vue index f75ab5e..5dcaf9f 100644 --- a/apps/web-antd/src/views/word/components/word-work-view.vue +++ b/apps/web-antd/src/views/word/components/word-work-view.vue @@ -181,6 +181,21 @@ function openPreviewDrawer( } // ==================== Event ==================== +function extractDocxInfo( + markdownLink: string, +): null | { filename: string; url: string } { + const fileRegex = /\[(.*?)\]/; + const urlRegex = /\((.*?)\)/; + const fileMatch = markdownLink.match(fileRegex); + const urlMatch = markdownLink.match(urlRegex); + if (fileMatch && urlMatch) { + const filename = fileMatch[1]; // 提取 [filename] 部分 + const url = urlMatch[1] || ''; // 提取 (url) 部分 + return { filename, url }; + } + return null; +} + const startFetching = async () => { if (projectInfo.value.projectName === '') { open.value = true; @@ -222,7 +237,7 @@ const startFetching = async () => { emit('history', props.item.id); } conversationId.value = res.conversationId; - + const { filename, url } = extractDocxInfo(res.answer); if (res.messageFiles) { const { id, url } = res.messageFiles[0]; resultItems.value.push({ @@ -260,6 +275,42 @@ const startFetching = async () => { ), ]), }); + } else if (filename !== undefined && url !== undefined) { + resultItems.value.push({ + key: resultItems.value.length + 1, + role: 'ai', + content: '文档已生成', + footer: h(Flex, null, [ + h( + Button, + { + size: 'normal', + type: 'primary', + onClick: () => { + openPreviewDrawer('right', url); + }, + }, + '文档预览', + ), + h( + Button, + { + size: 'normal', + type: 'primary', + style: { marginLeft: '10px' }, + onClick: () => { + const link = document.createElement('a'); + link.href = url; + link.download = filename; + document.body.append(link); + link.click(); + link.remove(); + }, + }, + '文档下载', + ), + ]), + }); } else { resultItems.value.push({ key: resultItems.value.length + 1, diff --git a/apps/web-antd/vite.config.mts b/apps/web-antd/vite.config.mts index 47be102..e4ce0a8 100644 --- a/apps/web-antd/vite.config.mts +++ b/apps/web-antd/vite.config.mts @@ -11,8 +11,8 @@ export default defineConfig(async () => { rewrite: (path) => path.replace(/^\/api/, ''), // mock代理目标地址 // target: 'http://172.16.35.190:9090/api', - target: 'http://43.139.10.64:8082/api', - // target: 'http://localhost:8081/api', + // target: 'http://43.139.10.64:8082/api', + target: 'http://localhost:8081/api', // target: 'http://192.168.3.238:8081/api', ws: true, },