feat(@vben/web-antd): 解决word文档无法预览问题

- 加回原来的正则表达式解析
This commit is contained in:
vertoryao 2025-06-17 15:33:47 +08:00
parent 71590645cd
commit 09eb944612
2 changed files with 54 additions and 3 deletions

View File

@ -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,

View File

@ -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,
},