feat(@vben/web-antd): 解决word文档无法预览问题
- 加回原来的正则表达式解析
This commit is contained in:
parent
71590645cd
commit
09eb944612
@ -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,
|
||||
|
@ -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,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user