2025-05-05 16:33:06 +08:00
|
|
|
|
<script setup lang="ts">
|
2025-05-16 17:44:56 +08:00
|
|
|
|
import type { BubbleListProps } from 'ant-design-x-vue';
|
|
|
|
|
|
|
|
|
|
import type { DrawerPlacement } from '@vben-core/popup-ui';
|
|
|
|
|
|
2025-05-05 16:33:06 +08:00
|
|
|
|
import type { SpiderItem } from './typing';
|
|
|
|
|
|
2025-05-16 17:44:56 +08:00
|
|
|
|
import { h, ref, watch } from 'vue';
|
2025-05-05 16:33:06 +08:00
|
|
|
|
|
2025-05-16 17:44:56 +08:00
|
|
|
|
import { useVbenDrawer } from '@vben-core/popup-ui';
|
2025-05-05 16:33:06 +08:00
|
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Card,
|
|
|
|
|
CardContent,
|
|
|
|
|
CardFooter,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
|
|
|
|
} from '@vben-core/shadcn-ui';
|
|
|
|
|
|
2025-05-16 17:44:56 +08:00
|
|
|
|
import { UserOutlined } from '@ant-design/icons-vue';
|
|
|
|
|
import { Flex, message, RangePicker } from 'ant-design-vue';
|
|
|
|
|
import { Attachments, Bubble } from 'ant-design-x-vue';
|
2025-05-14 19:48:01 +08:00
|
|
|
|
import dayjs, { Dayjs } from 'dayjs';
|
2025-05-16 17:44:56 +08:00
|
|
|
|
|
|
|
|
|
import SpiderPreview from './spider-preview.vue';
|
2025-05-12 19:52:53 +08:00
|
|
|
|
|
2025-05-05 16:33:06 +08:00
|
|
|
|
interface SpiderParams {
|
|
|
|
|
appid: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface SpiderContext {
|
|
|
|
|
userId: string;
|
|
|
|
|
conversationId: string;
|
|
|
|
|
files: unknown[];
|
|
|
|
|
inputs: Record<string, unknown>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface SpiderResult {
|
|
|
|
|
data: {
|
|
|
|
|
outputs: {
|
|
|
|
|
result: string;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-16 17:44:56 +08:00
|
|
|
|
interface ResultItem {
|
|
|
|
|
key: number;
|
|
|
|
|
role: 'ai' | 'user';
|
|
|
|
|
content: string;
|
|
|
|
|
footer?: any;
|
|
|
|
|
}
|
2025-05-14 19:48:01 +08:00
|
|
|
|
|
2025-05-05 16:33:06 +08:00
|
|
|
|
interface Props {
|
2025-05-16 17:44:56 +08:00
|
|
|
|
itemMessage?: ResultItem;
|
2025-05-05 16:33:06 +08:00
|
|
|
|
item?: SpiderItem;
|
|
|
|
|
title: string;
|
|
|
|
|
runSpider?: (
|
|
|
|
|
params: SpiderParams,
|
|
|
|
|
context: SpiderContext,
|
|
|
|
|
) => Promise<SpiderResult>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineOptions({
|
|
|
|
|
name: 'SpiderWorkView',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
2025-05-16 17:44:56 +08:00
|
|
|
|
itemMessage: () => null,
|
2025-05-05 16:33:06 +08:00
|
|
|
|
item: () => {
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
runSpider: () => async () => ({
|
|
|
|
|
data: {
|
|
|
|
|
outputs: {
|
|
|
|
|
result: '',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-16 17:44:56 +08:00
|
|
|
|
// const styles = computed(() => {
|
|
|
|
|
// return {
|
|
|
|
|
// 'placeholder': {
|
|
|
|
|
// 'padding-top': '32px',
|
|
|
|
|
// 'text-align': 'left',
|
|
|
|
|
// 'flex': 1,
|
|
|
|
|
// },
|
|
|
|
|
// } as const
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
// const placeholderNode = computed(() => h(
|
|
|
|
|
// Space,
|
|
|
|
|
// { direction: "vertical", size: 16, style: styles.value.placeholder },
|
|
|
|
|
// [
|
|
|
|
|
// h(
|
|
|
|
|
// Welcome,
|
|
|
|
|
// {
|
|
|
|
|
// variant: "borderless",
|
|
|
|
|
// icon: "https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*s5sNRo5LjfQAAAAAAAAAAAAADgCCAQ/fmt.webp",
|
|
|
|
|
// title: "Hello, I'm Ant Design X",
|
|
|
|
|
// description: "Base on Ant Design, AGI product interface solution, create a better intelligent vision~",
|
|
|
|
|
// extra: h(Space, {}, [h(Button, { icon: h(ShareAltOutlined) }), h(Button, { icon: h(EllipsisOutlined) })]),
|
|
|
|
|
// }
|
|
|
|
|
// ),
|
|
|
|
|
// ]
|
|
|
|
|
// ))
|
|
|
|
|
|
|
|
|
|
const resultItems = ref<ResultItem[]>([]);
|
|
|
|
|
// const items = computed<BubbleListProps['items']>(() => {
|
|
|
|
|
// if (resultItems.value.length === 0) {
|
|
|
|
|
// return [{ content: placeholderNode, variant: 'borderless' }]
|
|
|
|
|
// }
|
|
|
|
|
// return resultItems
|
|
|
|
|
// })
|
2025-05-14 19:48:01 +08:00
|
|
|
|
|
2025-05-16 17:44:56 +08:00
|
|
|
|
const [PreviewDrawer, previewDrawerApi] = useVbenDrawer({
|
|
|
|
|
// 连接抽离的组件
|
|
|
|
|
connectedComponent: SpiderPreview,
|
|
|
|
|
// placement: 'left',
|
|
|
|
|
});
|
2025-05-14 19:48:01 +08:00
|
|
|
|
|
2025-05-16 17:44:56 +08:00
|
|
|
|
function openPreviewDrawer(
|
|
|
|
|
placement: DrawerPlacement = 'right',
|
|
|
|
|
filename?: string,
|
|
|
|
|
) {
|
|
|
|
|
const fileData = filename.value;
|
|
|
|
|
previewDrawerApi.setState({ placement }).setData(fileData).open();
|
|
|
|
|
}
|
2025-05-14 19:48:01 +08:00
|
|
|
|
|
|
|
|
|
const selectedDateRange = ref<[Dayjs, Dayjs]>([
|
|
|
|
|
dayjs('2025-05-05'),
|
|
|
|
|
dayjs('2025-05-07'),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// 判断是否是以 .docx 结尾的 URL
|
2025-05-16 17:44:56 +08:00
|
|
|
|
function isDocxURL(str: string): boolean {
|
|
|
|
|
return str.endsWith('.docx');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用正则提取 /static/ 后面的文件名部分
|
|
|
|
|
function extractDocxFilename(url: string): null | string {
|
|
|
|
|
const match = url.match(/\/static\/([a-f0-9-]+\.docx)$/i);
|
|
|
|
|
if (match) {
|
|
|
|
|
return match[1]; // 返回类似:9e1c421e-991c-411f-8176-6350a97e70f3.docx
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2025-05-12 19:52:53 +08:00
|
|
|
|
|
2025-05-05 16:33:06 +08:00
|
|
|
|
const startFetching = async () => {
|
|
|
|
|
// 更新状态为“抓取中”
|
|
|
|
|
isFetching.value = true;
|
|
|
|
|
fetchStatus.value = 'fetching';
|
|
|
|
|
|
2025-05-13 16:51:40 +08:00
|
|
|
|
let publish_start_time = ''; // 默认值
|
|
|
|
|
let publish_end_time = ''; // 默认值
|
2025-05-12 19:52:53 +08:00
|
|
|
|
|
|
|
|
|
if (selectedDateRange.value && selectedDateRange.value.length === 2) {
|
2025-05-13 16:51:40 +08:00
|
|
|
|
publish_start_time =
|
|
|
|
|
dayjs(selectedDateRange.value[0]).format('YYYYMMDDhhmmss') || '';
|
|
|
|
|
publish_end_time =
|
|
|
|
|
dayjs(selectedDateRange.value[1]).format('YYYYMMDDhhmmss') || '';
|
2025-05-12 19:52:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 16:33:06 +08:00
|
|
|
|
try {
|
|
|
|
|
const res = await props.runSpider(
|
|
|
|
|
{
|
2025-05-05 23:35:12 +08:00
|
|
|
|
appid: props.item.id,
|
2025-05-05 16:33:06 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
userId: '1562',
|
|
|
|
|
conversationId: '',
|
|
|
|
|
files: [],
|
2025-05-12 19:52:53 +08:00
|
|
|
|
inputs: {
|
2025-05-13 16:51:40 +08:00
|
|
|
|
publish_start_time,
|
|
|
|
|
publish_end_time,
|
2025-05-12 19:52:53 +08:00
|
|
|
|
},
|
2025-05-05 16:33:06 +08:00
|
|
|
|
},
|
|
|
|
|
);
|
2025-05-13 16:51:40 +08:00
|
|
|
|
if (res.data.outputs.result) {
|
|
|
|
|
// 保存抓取结果
|
|
|
|
|
fetchResult.value = res.data.outputs.result;
|
|
|
|
|
message.success('抓取成功');
|
2025-05-16 17:44:56 +08:00
|
|
|
|
const { result } = res.data.outputs;
|
|
|
|
|
|
|
|
|
|
const filename = ref('');
|
|
|
|
|
|
|
|
|
|
if (result && isDocxURL(result)) {
|
|
|
|
|
filename.value = extractDocxFilename(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存抓取结果 url http://47.112.173.8:6802/static/66f3cfd95e364a239d8036390db658ae.docx
|
|
|
|
|
fetchResult.value = `/static/${filename.value}`;
|
|
|
|
|
resultItems.value.push({
|
|
|
|
|
key: resultItems.value.length + 1,
|
|
|
|
|
role: '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 = result; // 设置下载链接
|
|
|
|
|
link.download = filename; // 设置下载文件名
|
|
|
|
|
document.body.append(link); // 将 <a> 标签添加到页面中
|
|
|
|
|
link.click(); // 触发点击事件开始下载
|
|
|
|
|
link.remove(); // 下载完成后移除 <a> 标签
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'文档下载',
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
});
|
|
|
|
|
fetchStatus.value = 'completed';
|
2025-05-13 16:51:40 +08:00
|
|
|
|
} else {
|
|
|
|
|
fetchResult.value = '';
|
|
|
|
|
message.error('抓取无结果');
|
|
|
|
|
}
|
2025-05-05 16:33:06 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 模拟抓取完成
|
|
|
|
|
isFetching.value = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 下载文件逻辑
|
|
|
|
|
const downloadFile = () => {
|
2025-05-13 17:24:20 +08:00
|
|
|
|
if (!fetchResult.value || !fetchResult.value.startsWith('http')) {
|
|
|
|
|
message.error('无效的文件链接');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-05 16:33:06 +08:00
|
|
|
|
|
2025-05-13 17:24:20 +08:00
|
|
|
|
const fileUrl = fetchResult.value;
|
|
|
|
|
const fileName = decodeURIComponent(
|
|
|
|
|
fileUrl.slice(Math.max(0, fileUrl.lastIndexOf('/') + 1)),
|
|
|
|
|
);
|
2025-05-05 16:33:06 +08:00
|
|
|
|
|
|
|
|
|
const link = document.createElement('a');
|
2025-05-13 17:24:20 +08:00
|
|
|
|
link.href = fileUrl;
|
2025-05-05 16:33:06 +08:00
|
|
|
|
link.download = fileName;
|
|
|
|
|
link.click();
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-14 19:48:01 +08:00
|
|
|
|
// 列表角色
|
2025-05-16 17:44:56 +08:00
|
|
|
|
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' } },
|
|
|
|
|
},
|
|
|
|
|
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 }),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
};
|
2025-05-14 19:48:01 +08:00
|
|
|
|
|
2025-05-05 16:33:06 +08:00
|
|
|
|
const isFetching = ref(false);
|
|
|
|
|
const fetchResult = ref('');
|
|
|
|
|
const fetchStatus = ref('');
|
2025-05-16 17:44:56 +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 && isDocxURL(msg.content)) {
|
|
|
|
|
filename.value = extractDocxFilename(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 16:33:06 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-05-14 19:48:01 +08:00
|
|
|
|
<!-- style="flex-direction: column"-->
|
2025-05-16 17:44:56 +08:00
|
|
|
|
<div class="flex h-full" style="width: 70%">
|
|
|
|
|
<PreviewDrawer />
|
2025-05-14 19:48:01 +08:00
|
|
|
|
<!-- <PreviewDrawer />-->
|
2025-05-16 17:44:56 +08:00
|
|
|
|
<Bubble.List
|
|
|
|
|
variant="shadow"
|
|
|
|
|
:typing="true"
|
|
|
|
|
:items="resultItems"
|
|
|
|
|
:roles="roles"
|
|
|
|
|
style="flex: 1"
|
|
|
|
|
/>
|
|
|
|
|
|
2025-05-05 16:33:06 +08:00
|
|
|
|
<Card class="w-full self-end" v-loading="isFetching">
|
|
|
|
|
<CardHeader class="py-4">
|
|
|
|
|
<CardTitle class="text-lg">{{ title }}</CardTitle>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent class="flex flex-wrap pt-0">
|
|
|
|
|
{{ item ? item.name : '请选择右侧爬虫' }}
|
|
|
|
|
</CardContent>
|
|
|
|
|
<CardFooter class="flex justify-end">
|
2025-05-12 19:52:53 +08:00
|
|
|
|
<RangePicker
|
|
|
|
|
class="mx-2"
|
|
|
|
|
v-model:value="selectedDateRange"
|
2025-05-13 16:51:40 +08:00
|
|
|
|
format="YYYY/MM/DD"
|
2025-05-12 19:52:53 +08:00
|
|
|
|
/>
|
2025-05-13 17:24:20 +08:00
|
|
|
|
<Button
|
|
|
|
|
:disabled="!item || selectedDateRange.length < 2"
|
|
|
|
|
@click="startFetching"
|
|
|
|
|
>
|
2025-05-05 16:33:06 +08:00
|
|
|
|
{{ isFetching ? '抓取中...' : '开始抓取' }}
|
|
|
|
|
</Button>
|
2025-05-08 19:00:31 +08:00
|
|
|
|
<Button
|
|
|
|
|
class="mx-2"
|
|
|
|
|
:disabled="fetchStatus !== 'completed'"
|
|
|
|
|
@click="downloadFile"
|
|
|
|
|
>
|
2025-05-05 16:33:06 +08:00
|
|
|
|
下载文件
|
|
|
|
|
</Button>
|
|
|
|
|
</CardFooter>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|