2025-05-05 23:35:12 +08:00
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import type { BubbleListProps } from 'ant-design-x-vue';
|
|
|
|
|
|
2025-05-06 01:46:24 +08:00
|
|
|
|
import type { DrawerPlacement } from '@vben/common-ui';
|
|
|
|
|
|
2025-05-05 23:35:12 +08:00
|
|
|
|
import type { PPTTempItem } from './typing';
|
|
|
|
|
|
2025-05-06 20:47:11 +08:00
|
|
|
|
import { h, ref, watch } from 'vue';
|
2025-05-05 23:35:12 +08:00
|
|
|
|
|
2025-05-06 01:46:24 +08:00
|
|
|
|
import { useVbenDrawer } from '@vben/common-ui';
|
|
|
|
|
|
2025-05-05 23:35:12 +08:00
|
|
|
|
import { Card } from '@vben-core/shadcn-ui';
|
|
|
|
|
|
|
|
|
|
import { UserOutlined } from '@ant-design/icons-vue';
|
2025-05-12 19:52:53 +08:00
|
|
|
|
import { Button, Flex, Typography } from 'ant-design-vue';
|
2025-05-05 23:35:12 +08:00
|
|
|
|
import { Attachments, BubbleList, Sender } from 'ant-design-x-vue';
|
2025-05-12 19:52:53 +08:00
|
|
|
|
import markdownit from 'markdown-it';
|
2025-05-05 23:35:12 +08:00
|
|
|
|
|
2025-05-06 01:46:24 +08:00
|
|
|
|
import PptPreview from './ppt-perview.vue';
|
|
|
|
|
|
2025-05-05 23:35:12 +08:00
|
|
|
|
interface WorkflowParams {
|
|
|
|
|
appid: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface WorkflowContext {
|
|
|
|
|
userId: string;
|
|
|
|
|
conversationId: string;
|
|
|
|
|
files: unknown[];
|
|
|
|
|
inputs: Record<string, unknown>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface WorkflowResult {
|
|
|
|
|
data: {
|
|
|
|
|
outputs: {
|
|
|
|
|
result: string;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 20:47:11 +08:00
|
|
|
|
interface ResultItem {
|
|
|
|
|
key: number;
|
|
|
|
|
role: 'ai' | 'user';
|
|
|
|
|
content: string;
|
|
|
|
|
footer?: any;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 23:35:12 +08:00
|
|
|
|
interface Props {
|
2025-05-06 20:47:11 +08:00
|
|
|
|
itemMessage?: ResultItem;
|
2025-05-05 23:35:12 +08:00
|
|
|
|
item?: PPTTempItem;
|
|
|
|
|
runWorkflow?: (
|
|
|
|
|
params: WorkflowParams,
|
|
|
|
|
context: WorkflowContext,
|
|
|
|
|
) => Promise<WorkflowResult>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineOptions({
|
|
|
|
|
name: 'SpiderWorkView',
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-06 16:50:28 +08:00
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
2025-05-06 20:47:11 +08:00
|
|
|
|
itemMessage: () => null,
|
2025-05-05 23:35:12 +08:00
|
|
|
|
item: () => null,
|
|
|
|
|
runWorkflow: () => async () => ({
|
|
|
|
|
data: {
|
|
|
|
|
outputs: {
|
|
|
|
|
result: '',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-12 19:52:53 +08:00
|
|
|
|
// 初始化 markdown 解析器
|
|
|
|
|
const md = markdownit({ html: true, breaks: true });
|
|
|
|
|
|
|
|
|
|
const renderMarkdown: BubbleListProps['roles'][string]['messageRender'] = (
|
|
|
|
|
content: string,
|
|
|
|
|
) => {
|
|
|
|
|
return h(Typography, [
|
|
|
|
|
h('div', {
|
|
|
|
|
innerHTML: content,
|
|
|
|
|
style: {
|
|
|
|
|
padding: '8px',
|
|
|
|
|
lineHeight: '1.6',
|
|
|
|
|
whiteSpace: 'break-spaces',
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-06 01:46:24 +08:00
|
|
|
|
const [PreviewDrawer, previewDrawerApi] = useVbenDrawer({
|
|
|
|
|
// 连接抽离的组件
|
|
|
|
|
connectedComponent: PptPreview,
|
|
|
|
|
// placement: 'left',
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-06 16:50:28 +08:00
|
|
|
|
function openPreviewDrawer(
|
|
|
|
|
placement: DrawerPlacement = 'right',
|
|
|
|
|
filename?: string,
|
|
|
|
|
) {
|
|
|
|
|
const fileData = filename.value;
|
|
|
|
|
previewDrawerApi.setState({ placement }).setData(fileData).open();
|
2025-05-06 01:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 20:47:11 +08:00
|
|
|
|
// 判断是否是以 .pptx 结尾的 URL
|
|
|
|
|
function isPptxURL(str: string): boolean {
|
|
|
|
|
return str.endsWith('.pptx');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用正则提取 /static/ 后面的文件名部分
|
|
|
|
|
function extractPptxFilename(url: string): null | string {
|
|
|
|
|
const match = url.match(/\/static\/([a-f0-9-]+\.pptx)$/i);
|
|
|
|
|
if (match) {
|
|
|
|
|
return match[1]; // 返回类似:9e1c421e-991c-411f-8176-6350a97e70f3.pptx
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 23:35:12 +08:00
|
|
|
|
const startFetching = async () => {
|
|
|
|
|
isFetching.value = true;
|
|
|
|
|
fetchStatus.value = 'fetching';
|
|
|
|
|
|
|
|
|
|
try {
|
2025-05-06 16:50:28 +08:00
|
|
|
|
const res = await props.runWorkflow(
|
|
|
|
|
{
|
|
|
|
|
appid: 'ee3889b6-50fa-463e-b956-3b93447727fc',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
userId: '1562',
|
|
|
|
|
conversationId: '',
|
|
|
|
|
files: [],
|
|
|
|
|
inputs: {
|
|
|
|
|
declarationDoc: value.value,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
const { result } = res.data.outputs;
|
|
|
|
|
|
|
|
|
|
const filename = ref('');
|
|
|
|
|
|
|
|
|
|
if (result && isPptxURL(result)) {
|
|
|
|
|
filename.value = extractPptxFilename(result);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-06 10:28:44 +08:00
|
|
|
|
// 保存抓取结果 url http://47.112.173.8:6802/static/66f3cfd95e364a239d8036390db658ae.pptx
|
2025-05-06 16:50:28 +08:00
|
|
|
|
fetchResult.value = `/static/${filename.value}`;
|
2025-05-05 23:35:12 +08:00
|
|
|
|
resultItems.value.push({
|
|
|
|
|
key: resultItems.value.length + 1,
|
|
|
|
|
role: 'ai',
|
|
|
|
|
content: '文档已生成',
|
|
|
|
|
footer: h(Flex, null, [
|
|
|
|
|
h(
|
|
|
|
|
Button,
|
|
|
|
|
{
|
|
|
|
|
size: 'nomarl',
|
|
|
|
|
type: 'primary',
|
2025-05-06 01:46:24 +08:00
|
|
|
|
onClick: () => {
|
2025-05-06 16:50:28 +08:00
|
|
|
|
openPreviewDrawer('right', filename);
|
2025-05-06 01:46:24 +08:00
|
|
|
|
},
|
2025-05-05 23:35:12 +08:00
|
|
|
|
},
|
|
|
|
|
'文档预览',
|
|
|
|
|
),
|
|
|
|
|
h(
|
|
|
|
|
Button,
|
|
|
|
|
{
|
|
|
|
|
size: 'nomarl',
|
|
|
|
|
type: 'primary',
|
|
|
|
|
style: {
|
|
|
|
|
marginLeft: '10px',
|
|
|
|
|
},
|
2025-05-06 16:50:28 +08:00
|
|
|
|
onClick: () => {
|
|
|
|
|
// 创建隐藏的 <a> 标签用于触发下载
|
|
|
|
|
const link = document.createElement('a');
|
|
|
|
|
link.href = result; // 设置下载链接
|
|
|
|
|
link.download = filename; // 设置下载文件名
|
|
|
|
|
document.body.append(link); // 将 <a> 标签添加到页面中
|
|
|
|
|
link.click(); // 触发点击事件开始下载
|
|
|
|
|
link.remove(); // 下载完成后移除 <a> 标签
|
|
|
|
|
},
|
2025-05-05 23:35:12 +08:00
|
|
|
|
},
|
|
|
|
|
'文档下载',
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 模拟抓取完成
|
|
|
|
|
isFetching.value = false;
|
|
|
|
|
fetchStatus.value = 'completed';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const roles: BubbleListProps['roles'] = {
|
|
|
|
|
user: {
|
|
|
|
|
placement: 'end',
|
|
|
|
|
typing: false,
|
|
|
|
|
avatar: { icon: h(UserOutlined), style: { background: '#87d068' } },
|
|
|
|
|
},
|
|
|
|
|
ai: {
|
|
|
|
|
placement: 'start',
|
|
|
|
|
typing: false,
|
|
|
|
|
style: {
|
|
|
|
|
maxWidth: 600,
|
|
|
|
|
marginInlineEnd: 44,
|
|
|
|
|
},
|
|
|
|
|
styles: {
|
|
|
|
|
footer: {
|
|
|
|
|
width: '100%',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
avatar: { icon: h(UserOutlined), style: { background: '#fde3cf' } },
|
2025-05-12 19:52:53 +08:00
|
|
|
|
messageRender: (content) =>
|
|
|
|
|
h(Typography, [
|
|
|
|
|
h('div', {
|
|
|
|
|
innerHTML: md.render(content),
|
|
|
|
|
style: {
|
|
|
|
|
padding: '8px',
|
|
|
|
|
lineHeight: '1.6',
|
|
|
|
|
whiteSpace: 'break-spaces',
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
]),
|
2025-05-05 23:35:12 +08:00
|
|
|
|
},
|
|
|
|
|
file: {
|
|
|
|
|
placement: 'start',
|
|
|
|
|
avatar: { icon: h(UserOutlined), style: { visibility: 'hidden' } },
|
|
|
|
|
variant: 'borderless',
|
|
|
|
|
messageRender: (items: any) =>
|
|
|
|
|
h(
|
|
|
|
|
Flex,
|
|
|
|
|
{ vertical: true, gap: 'middle' },
|
|
|
|
|
items.map((item: any) =>
|
|
|
|
|
h(Attachments.FileCard, { key: item.uid, item }),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const isFetching = ref(false);
|
|
|
|
|
const fetchResult = ref('');
|
|
|
|
|
const fetchStatus = ref('');
|
|
|
|
|
const value = ref('');
|
2025-05-05 23:39:17 +08:00
|
|
|
|
|
2025-05-05 23:35:12 +08:00
|
|
|
|
const resultItems = ref<ResultItem[]>([]);
|
2025-05-06 20:47:11 +08:00
|
|
|
|
|
|
|
|
|
// 监听 itemMessage 变化并更新 resultItems
|
|
|
|
|
watch(
|
|
|
|
|
() => props.itemMessage,
|
|
|
|
|
(newVal) => {
|
|
|
|
|
resultItems.value = [];
|
|
|
|
|
if (newVal && newVal.length > 0) {
|
|
|
|
|
newVal.forEach((msg) => {
|
|
|
|
|
// resultItems.value.push({
|
|
|
|
|
// key: resultItems.value.length + 1,
|
|
|
|
|
// role: msg.role, // 'user' or 'ai'
|
|
|
|
|
// content: msg.content,
|
|
|
|
|
// footer: msg.footer,
|
|
|
|
|
// });
|
|
|
|
|
if (msg.role === 'user') {
|
|
|
|
|
resultItems.value.push({
|
|
|
|
|
key: resultItems.value.length + 1,
|
|
|
|
|
role: msg.role, // 'user' or 'ai'
|
|
|
|
|
content: msg.content,
|
|
|
|
|
footer: msg.footer,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
const filename = ref('');
|
|
|
|
|
|
|
|
|
|
if (msg.content && isPptxURL(msg.content)) {
|
|
|
|
|
filename.value = extractPptxFilename(msg.content);
|
|
|
|
|
}
|
|
|
|
|
resultItems.value.push({
|
|
|
|
|
key: resultItems.value.length + 1,
|
|
|
|
|
role: msg.role, // 'user' or 'ai'
|
|
|
|
|
content: '文档已生成',
|
|
|
|
|
footer: h(Flex, null, [
|
|
|
|
|
h(
|
|
|
|
|
Button,
|
|
|
|
|
{
|
|
|
|
|
size: 'nomarl',
|
|
|
|
|
type: 'primary',
|
|
|
|
|
onClick: () => {
|
|
|
|
|
openPreviewDrawer('right', filename);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'文档预览',
|
|
|
|
|
),
|
|
|
|
|
h(
|
|
|
|
|
Button,
|
|
|
|
|
{
|
|
|
|
|
size: 'nomarl',
|
|
|
|
|
type: 'primary',
|
|
|
|
|
style: {
|
|
|
|
|
marginLeft: '10px',
|
|
|
|
|
},
|
|
|
|
|
onClick: () => {
|
|
|
|
|
// 创建隐藏的 <a> 标签用于触发下载
|
|
|
|
|
const link = document.createElement('a');
|
|
|
|
|
link.href = msg.content; // 设置下载链接
|
|
|
|
|
link.download = filename; // 设置下载文件名
|
|
|
|
|
document.body.append(link); // 将 <a> 标签添加到页面中
|
|
|
|
|
link.click(); // 触发点击事件开始下载
|
|
|
|
|
link.remove(); // 下载完成后移除 <a> 标签
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'文档下载',
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{ deep: true },
|
|
|
|
|
);
|
2025-05-05 23:35:12 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-05-12 19:52:53 +08:00
|
|
|
|
<div>
|
|
|
|
|
<PreviewDrawer />
|
|
|
|
|
<div style="height: calc(67vh - 120px); margin: 20px; overflow-y: auto">
|
|
|
|
|
<BubbleList
|
|
|
|
|
:roles="roles"
|
|
|
|
|
:typing="true"
|
|
|
|
|
:items="resultItems"
|
|
|
|
|
:message-render="renderMarkdown"
|
|
|
|
|
/>
|
2025-05-05 23:35:12 +08:00
|
|
|
|
</div>
|
|
|
|
|
<Card class="w-full">
|
|
|
|
|
<Sender
|
|
|
|
|
v-model:value="value"
|
|
|
|
|
:loading="isFetching"
|
2025-05-12 19:52:53 +08:00
|
|
|
|
:disabled="isFetching"
|
2025-05-05 23:35:12 +08:00
|
|
|
|
:auto-size="{ minRows: 6, maxRows: 12 }"
|
|
|
|
|
@submit="startFetching"
|
|
|
|
|
/>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|