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 {
|
|
|
|
|
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';
|
2025-05-16 23:02:11 +08:00
|
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Flex,
|
|
|
|
|
message,
|
|
|
|
|
notification,
|
|
|
|
|
RangePicker,
|
|
|
|
|
Space,
|
|
|
|
|
} from 'ant-design-vue';
|
|
|
|
|
import { Attachments, Bubble, Welcome } 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;
|
2025-05-17 22:07:52 +08:00
|
|
|
|
files: [];
|
2025-05-05 16:33:06 +08:00
|
|
|
|
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;
|
2025-05-17 22:07:52 +08:00
|
|
|
|
runSpider?: (context: any) => Promise<SpiderResult>;
|
|
|
|
|
getSpiderStatus?: () => Promise<{
|
|
|
|
|
status: string;
|
|
|
|
|
}>;
|
|
|
|
|
stopSpider?: () => Promise<{
|
|
|
|
|
status: string;
|
|
|
|
|
}>;
|
|
|
|
|
sendWorkflow?: (params: SpiderParams, data: SpiderContext) => Promise<any>;
|
2025-05-05 16:33:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 () => ({
|
2025-05-17 22:07:52 +08:00
|
|
|
|
msg: '',
|
|
|
|
|
code: '',
|
|
|
|
|
}),
|
|
|
|
|
getSpiderStatus: () => async () => ({
|
|
|
|
|
msg: '',
|
|
|
|
|
code: '',
|
|
|
|
|
}),
|
|
|
|
|
stopSpider: () => async () => ({
|
|
|
|
|
msg: '',
|
|
|
|
|
code: '',
|
|
|
|
|
}),
|
|
|
|
|
sendWorkflow: () => async () => ({
|
|
|
|
|
outputs: {
|
|
|
|
|
result: '',
|
|
|
|
|
files: [],
|
2025-05-05 16:33:06 +08:00
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-16 17:44:56 +08:00
|
|
|
|
const resultItems = ref<ResultItem[]>([]);
|
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 {
|
2025-05-17 22:07:52 +08:00
|
|
|
|
const match = url.match(/\/static\/([^/]+\.docx)$/i); // 匹配 /static/ 后任意非斜杠字符加 .docx
|
|
|
|
|
return match ? match[1] : null;
|
2025-05-16 17:44:56 +08:00
|
|
|
|
}
|
2025-05-18 01:17:03 +08:00
|
|
|
|
const startChecking = () => {
|
|
|
|
|
statusPollingInterval = window.setInterval(startPolling, 1000);
|
|
|
|
|
};
|
|
|
|
|
let statusPollingInterval: null | number;
|
|
|
|
|
let pollingCount = 0;
|
|
|
|
|
const maxPollingAttempts = 300; // 最多轮询300秒
|
|
|
|
|
|
|
|
|
|
const startPolling = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await props.getSpiderStatus();
|
|
|
|
|
|
|
|
|
|
if (!response.data.is_running) {
|
|
|
|
|
clearInterval(statusPollingInterval!);
|
|
|
|
|
statusPollingInterval = null;
|
|
|
|
|
|
|
|
|
|
if (response.data.download_url) {
|
|
|
|
|
const download_url = response.data.download_url;
|
|
|
|
|
fetchResult.value = download_url;
|
|
|
|
|
notification.success({ message: '获取成功', duration: 3 });
|
|
|
|
|
|
|
|
|
|
let filename = '';
|
|
|
|
|
if (isDocxURL(download_url)) {
|
|
|
|
|
filename = extractDocxFilename(download_url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fetchResult.value = `/spider/${filename}`;
|
|
|
|
|
resultItems.value.push({
|
|
|
|
|
key: resultItems.value.length + 1,
|
|
|
|
|
role: 'ai',
|
|
|
|
|
content: '文档已生成',
|
|
|
|
|
footer: h(Flex, null, [
|
|
|
|
|
h(
|
|
|
|
|
Button,
|
|
|
|
|
{
|
|
|
|
|
size: 'normal',
|
|
|
|
|
type: 'primary',
|
|
|
|
|
onClick: () => {
|
|
|
|
|
openPreviewDrawer('right', fetchResult);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'文档预览',
|
|
|
|
|
),
|
|
|
|
|
h(
|
|
|
|
|
Button,
|
|
|
|
|
{
|
|
|
|
|
size: 'normal',
|
|
|
|
|
type: 'primary',
|
|
|
|
|
style: { marginLeft: '10px' },
|
|
|
|
|
onClick: () => {
|
|
|
|
|
const link = document.createElement('a');
|
|
|
|
|
link.href = download_url;
|
|
|
|
|
link.download = fetchResult.value;
|
|
|
|
|
document.body.append(link);
|
|
|
|
|
link.click();
|
|
|
|
|
link.remove();
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'文档下载',
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
isFetching.value = false;
|
|
|
|
|
fetchStatus.value = 'completed';
|
|
|
|
|
} else {
|
|
|
|
|
isFetching.value = false;
|
|
|
|
|
fetchResult.value = '';
|
|
|
|
|
message.error('抓取无结果');
|
|
|
|
|
}
|
|
|
|
|
} else if (++pollingCount >= maxPollingAttempts) {
|
|
|
|
|
clearInterval(statusPollingInterval!);
|
|
|
|
|
statusPollingInterval = null;
|
|
|
|
|
props.stopSpider();
|
|
|
|
|
message.warn('轮询超时,请稍后再试');
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
clearInterval(statusPollingInterval!);
|
|
|
|
|
statusPollingInterval = null;
|
|
|
|
|
message.error(`状态查询失败:${error}`);
|
|
|
|
|
}
|
|
|
|
|
};
|
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-17 22:07:52 +08:00
|
|
|
|
if (props.item.id === '77c068fd-d5b6-4c33-97d8-db5511a09b26') {
|
|
|
|
|
try {
|
|
|
|
|
notification.info({
|
|
|
|
|
message: '正在获取中...',
|
2025-05-18 01:17:03 +08:00
|
|
|
|
duration: 5,
|
2025-05-17 22:07:52 +08:00
|
|
|
|
});
|
2025-05-12 19:52:53 +08:00
|
|
|
|
|
2025-05-17 22:07:52 +08:00
|
|
|
|
const res = await props.runSpider({
|
2025-05-16 23:02:11 +08:00
|
|
|
|
publish_start_time,
|
|
|
|
|
publish_end_time,
|
2025-05-17 22:07:52 +08:00
|
|
|
|
llm_api_key: props.item.id,
|
2025-05-16 23:02:11 +08:00
|
|
|
|
});
|
2025-05-16 17:44:56 +08:00
|
|
|
|
|
2025-05-18 01:17:03 +08:00
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
notification.info({
|
|
|
|
|
message: res.msg,
|
|
|
|
|
duration: 5,
|
|
|
|
|
});
|
|
|
|
|
startChecking();
|
|
|
|
|
} else {
|
2025-05-17 22:07:52 +08:00
|
|
|
|
isFetching.value = false;
|
|
|
|
|
fetchResult.value = '';
|
|
|
|
|
message.error('抓取无结果');
|
|
|
|
|
return;
|
2025-05-16 17:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-17 22:07:52 +08:00
|
|
|
|
// 组件卸载时清理定时器(需配合 onUnmounted 生命周期)
|
|
|
|
|
// 示例:
|
|
|
|
|
// onUnmounted(() => {
|
|
|
|
|
// if (statusPollingInterval) {
|
|
|
|
|
// clearInterval(statusPollingInterval);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
isFetching.value = false;
|
2025-05-13 16:51:40 +08:00
|
|
|
|
fetchResult.value = '';
|
2025-05-17 22:07:52 +08:00
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (props.item.id === 'c736edd0-925d-4877-9223-56aab7342311') {
|
|
|
|
|
try {
|
|
|
|
|
notification.info({
|
|
|
|
|
message: '正在获取中...',
|
|
|
|
|
duration: 3,
|
|
|
|
|
});
|
|
|
|
|
const res = await props.sendWorkflow(
|
|
|
|
|
{
|
|
|
|
|
appid: props.item.id,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
userId: '1562',
|
|
|
|
|
conversationId: '',
|
|
|
|
|
files: [],
|
|
|
|
|
inputs: {
|
|
|
|
|
publish_start_time,
|
|
|
|
|
publish_end_time,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
if (res.data.outputs.files) {
|
|
|
|
|
// 保存抓取结果
|
|
|
|
|
fetchResult.value = res.data.outputs.files[0].url;
|
|
|
|
|
notification.success({
|
|
|
|
|
message: '获取成功',
|
|
|
|
|
duration: 3,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const fileUrl = ref('');
|
2025-05-18 01:17:03 +08:00
|
|
|
|
fileUrl.value = `/guangzhou${fetchResult.value}`;
|
2025-05-17 22:07:52 +08:00
|
|
|
|
|
|
|
|
|
resultItems.value.push({
|
|
|
|
|
key: resultItems.value.length + 1,
|
|
|
|
|
role: 'ai',
|
2025-05-18 01:17:03 +08:00
|
|
|
|
content: '文档已生成,有效时间5分钟,请及时查看或下载',
|
2025-05-17 22:07:52 +08:00
|
|
|
|
footer: h(Flex, null, [
|
2025-05-18 01:17:03 +08:00
|
|
|
|
h(
|
|
|
|
|
Button,
|
|
|
|
|
{
|
|
|
|
|
size: 'nomarl',
|
|
|
|
|
type: 'primary',
|
|
|
|
|
onClick: () => {
|
|
|
|
|
openPreviewDrawer('right', fileUrl);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'文档预览',
|
|
|
|
|
),
|
2025-05-17 22:07:52 +08:00
|
|
|
|
h(
|
|
|
|
|
Button,
|
|
|
|
|
{
|
|
|
|
|
size: 'normal',
|
|
|
|
|
type: 'primary',
|
|
|
|
|
style: {
|
|
|
|
|
marginLeft: '10px',
|
|
|
|
|
},
|
|
|
|
|
onClick: () => {
|
|
|
|
|
// 创建隐藏的 <a> 标签用于触发下载
|
|
|
|
|
const link = document.createElement('a');
|
2025-05-18 01:17:03 +08:00
|
|
|
|
link.href = fileUrl.value; // 设置下载链接
|
2025-05-17 22:07:52 +08:00
|
|
|
|
link.download = '广州公共资源交易中心数据获取'; // 设置下载文件名
|
|
|
|
|
document.body.append(link); // 将 <a> 标签添加到页面中
|
|
|
|
|
link.click(); // 触发点击事件开始下载
|
|
|
|
|
link.remove(); // 下载完成后移除 <a> 标签
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'文档下载',
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
});
|
|
|
|
|
fetchStatus.value = 'completed';
|
|
|
|
|
} else {
|
|
|
|
|
fetchResult.value = '';
|
|
|
|
|
message.error('抓取无结果');
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
message.error(`${error}`);
|
2025-05-13 16:51:40 +08:00
|
|
|
|
}
|
2025-05-17 22:07:52 +08:00
|
|
|
|
isFetching.value = false;
|
2025-05-05 16:33:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-17 22:07:52 +08:00
|
|
|
|
// try {
|
|
|
|
|
// notification.info({
|
|
|
|
|
// message: '正在获取中...',
|
|
|
|
|
// duration: 3,
|
|
|
|
|
// });
|
|
|
|
|
// const res = await props.runSpider(
|
|
|
|
|
// {
|
|
|
|
|
// publish_start_time,
|
|
|
|
|
// publish_end_time,
|
|
|
|
|
// llm_api_key: '77c068fd-d5b6-4c33-97d8-db5511a09b26',
|
|
|
|
|
// },
|
|
|
|
|
// );
|
|
|
|
|
// if (res.data.outputs.result) {
|
|
|
|
|
// // 保存抓取结果
|
|
|
|
|
// fetchResult.value = res.data.outputs.result;
|
|
|
|
|
// notification.success({
|
|
|
|
|
// message: '获取成功',
|
|
|
|
|
// duration: 3,
|
|
|
|
|
// });
|
|
|
|
|
// 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: 'normal',
|
|
|
|
|
// 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> 标签
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// '文档下载',
|
|
|
|
|
// ),
|
|
|
|
|
// ]),
|
|
|
|
|
// });
|
|
|
|
|
// fetchStatus.value = 'completed';
|
|
|
|
|
// } else {
|
|
|
|
|
// fetchResult.value = '';
|
|
|
|
|
// message.error('抓取无结果');
|
|
|
|
|
// }
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// message.error(`${error}`);
|
|
|
|
|
// }
|
2025-05-05 16:33:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
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 {
|
|
|
|
|
resultItems.value.push({
|
|
|
|
|
key: resultItems.value.length + 1,
|
|
|
|
|
role: msg.role, // 'user' or 'ai'
|
|
|
|
|
content: '文档已生成',
|
|
|
|
|
footer: h(Flex, null, [
|
2025-05-17 22:07:52 +08:00
|
|
|
|
// h(
|
|
|
|
|
// Button,
|
|
|
|
|
// {
|
|
|
|
|
// size: 'normal',
|
|
|
|
|
// type: 'primary',
|
|
|
|
|
// onClick: () => {
|
|
|
|
|
// openPreviewDrawer('right', filename);
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// '文档预览',
|
|
|
|
|
// ),
|
2025-05-16 17:44:56 +08:00
|
|
|
|
h(
|
|
|
|
|
Button,
|
|
|
|
|
{
|
2025-05-16 23:02:11 +08:00
|
|
|
|
size: 'normal',
|
2025-05-16 17:44:56 +08:00
|
|
|
|
type: 'primary',
|
|
|
|
|
style: {
|
|
|
|
|
marginLeft: '10px',
|
|
|
|
|
},
|
|
|
|
|
onClick: () => {
|
|
|
|
|
// 创建隐藏的 <a> 标签用于触发下载
|
|
|
|
|
const link = document.createElement('a');
|
|
|
|
|
link.href = msg.content; // 设置下载链接
|
2025-05-17 22:07:52 +08:00
|
|
|
|
link.download = '广州公共资源交易中心数据获取'; // 设置下载文件名
|
2025-05-16 17:44:56 +08:00
|
|
|
|
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 23:02:11 +08:00
|
|
|
|
<div
|
|
|
|
|
class="flex h-full"
|
|
|
|
|
style="flex-direction: column; width: 70%; padding-top: 20px"
|
|
|
|
|
>
|
2025-05-16 17:44:56 +08:00
|
|
|
|
<PreviewDrawer />
|
2025-05-14 19:48:01 +08:00
|
|
|
|
<!-- <PreviewDrawer />-->
|
2025-05-16 23:02:11 +08:00
|
|
|
|
<Space
|
|
|
|
|
v-if="resultItems.length === 0"
|
|
|
|
|
direction="vertical"
|
|
|
|
|
size:16
|
|
|
|
|
style="flex: 1"
|
|
|
|
|
>
|
|
|
|
|
<Welcome
|
|
|
|
|
variant="borderless"
|
|
|
|
|
icon="https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*s5sNRo5LjfQAAAAAAAAAAAAADgCCAQ/fmt.webp"
|
|
|
|
|
title="欢迎使用AI平台信息获取"
|
|
|
|
|
description="请选择数据信息列表中需要获取信息的链接,选取时间后开始爬取获取信息。"
|
|
|
|
|
/>
|
|
|
|
|
</Space>
|
2025-05-16 17:44:56 +08:00
|
|
|
|
<Bubble.List
|
2025-05-16 23:02:11 +08:00
|
|
|
|
v-else
|
2025-05-16 17:44:56 +08:00
|
|
|
|
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">
|
2025-05-17 17:34:27 +08:00
|
|
|
|
{{ item ? item.url : '请选择左侧列表' }}
|
2025-05-05 16:33:06 +08:00
|
|
|
|
</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"
|
2025-05-17 17:34:27 +08:00
|
|
|
|
type="primary"
|
2025-05-13 17:24:20 +08:00
|
|
|
|
@click="startFetching"
|
|
|
|
|
>
|
2025-05-05 16:33:06 +08:00
|
|
|
|
{{ isFetching ? '抓取中...' : '开始抓取' }}
|
|
|
|
|
</Button>
|
|
|
|
|
</CardFooter>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|