refactor(@vben/web-antd): 优化 spider 和 word 组件的代码结构和类型定义

- 更新爬虫默认日期为最近三天
- 在 spider组件中添加 AppListResult 类型并更新相关引用
- 修正 word 组件中消息内容的赋值方式
- 调整 self-work-view 组件的日期范围选择
- 优化 typing 文件中的类型定义,提高代码可读性和可维护性
This commit is contained in:
Kven 2025-06-25 22:15:56 +08:00
parent 25c027f3d8
commit 2dd824324f
7 changed files with 48 additions and 70 deletions

View File

@ -68,8 +68,8 @@ const [PreviewDrawer, previewDrawerApi] = useVbenDrawer({
// placement: 'left',
});
const selectedDateRange = ref<[Dayjs, Dayjs]>([
dayjs('2025-05-05'),
dayjs('2025-05-07'),
dayjs().subtract(3, 'days'),
dayjs(),
]);
function openPreviewDrawer(

View File

@ -53,10 +53,9 @@ const [PreviewDrawer, previewDrawerApi] = useVbenDrawer({
function openPreviewDrawer(
placement: DrawerPlacement = 'right',
filename?: string,
filename: any,
) {
const fileData = filename.value;
previewDrawerApi.setState({ placement }).setData(fileData).open();
previewDrawerApi.setState({ placement }).setData(filename).open();
}
const startFetching = async () => {
@ -94,10 +93,10 @@ const startFetching = async () => {
h(
Button,
{
size: 'nomarl',
// size: 'normal',
type: 'primary',
onClick: () => {
openPreviewDrawer('right', fileUrl);
openPreviewDrawer('right', fileUrl.value);
},
},
'文档预览',
@ -105,7 +104,7 @@ const startFetching = async () => {
h(
Button,
{
size: 'normal',
// size: 'normal',
type: 'primary',
style: {
marginLeft: '10px',
@ -196,7 +195,7 @@ watch(
() => props.itemMessage,
(newVal) => {
resultItems.value = [];
if (newVal && newVal.length > 0) {
if (newVal.length > 0) {
newVal.forEach((msg) => {
// resultItems.value.push({
// key: resultItems.value.length + 1,
@ -231,7 +230,7 @@ watch(
h(
Button,
{
size: 'normal',
// size: 'normal',
type: 'primary',
style: {
marginLeft: '10px',

View File

@ -1,6 +1,11 @@
<script lang="ts" setup>
// sendWorkflow
import type { ResultItem, TempItem, WordFlowItem } from './typing';
import type {
AppListResult,
ResultItem,
TempItem,
WordFlowItem,
} from './typing';
import { onMounted, ref } from 'vue';
@ -17,15 +22,15 @@ import {
import { SelfWorkView, SpiderListView, WorkflowWorkView } from './components';
const hitsory = ref([]);
const history = ref([]);
const loading = ref(true);
const temp = ref([]);
const temp = ref<AppListResult[]>([]);
const itemMessage = ref<ResultItem[]>([]);
//
// const getLogs = async (appid: string, limit: number) => {
// loading.value = true;
// hitsory.value = await getWorkflowList({
// history.value = await getWorkflowList({
// appid,
// limit,
// });
@ -88,7 +93,7 @@ onMounted(() => {
<SpiderListView
title="选择模板"
:temp="temp"
:items="hitsory"
:items="history"
:loading="loading"
@click-mode="handleClickMode"
@click="handleClick"

View File

@ -5,6 +5,11 @@ interface TempItem {
description?: string;
}
interface AppListResult {
id: string;
name: string;
}
interface ResultItem {
key: number;
role: 'ai' | 'user';
@ -22,7 +27,8 @@ interface WordFlowItem {
interface SpiderItem {
id: string;
name: string;
url: string;
url?: string;
description?: string;
}
interface SpiderContext {
@ -47,7 +53,7 @@ interface ResultItem {
}
interface Props {
itemMessage?: ResultItem;
itemMessage?: ResultItem[];
temp?: any;
item?: SpiderItem;
title: string;
@ -62,6 +68,7 @@ interface Props {
}
export type {
AppListResult,
Props,
ResultItem,
SpiderContext,

View File

@ -49,11 +49,13 @@ const props = withDefaults(defineProps<Props>(), {
itemMessage: Array,
paramsData: Array,
runChatFlow: () => async () => ({
data: {
outputs: {
result: '',
},
},
event: '',
conversationId: '',
messageFiles: [],
messageId: '',
taskId: '',
id: '',
answer: '',
}),
projectInfo: {
projectName: '',
@ -216,7 +218,7 @@ const startFetching = async () => {
});
try {
const res = await props.runChatflow(props.item.id, {
const res = await props.runChatFlow(props.item.id, {
userId: userStore.userInfo?.userId || '',
conversationId: conversationId.value,
files: [],
@ -234,8 +236,15 @@ const startFetching = async () => {
emit('history', props.item.id);
}
conversationId.value = res.conversationId;
const { filename, url } = extractDocxInfo(res.answer);
if (res.answer) {
const docxInfo = extractDocxInfo(res.answer);
if (docxInfo === null) {
resultItems.value.push({
key: resultItems.value.length + 1,
role: 'ai',
content: res.answer,
});
} else {
const { filename, url } = docxInfo;
// const { id, url } = res.messageFiles[0];
resultItems.value.push({
key: resultItems.value.length + 1,
@ -272,48 +281,6 @@ 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,
role: 'ai',
content: res.answer,
});
}
} catch (error) {
console.error(error);

View File

@ -140,7 +140,7 @@ async function handleClick(item: string) {
itemMessage.value.push({
key: itemMessage.value.length + 1,
role: 'user', // 'user' or 'ai'
content: msg.inputs.projectName,
content: msg.query,
// footer: msg.footer,
});
}

View File

@ -33,7 +33,7 @@ interface WorkflowContext {
}
interface WorkflowResult {
conversationId: string;
answer: object;
answer: string;
messageFiles?: [
{
id: string;
@ -51,7 +51,7 @@ interface Props {
item?: null | WordTempItem;
paramsData?: string[];
runChatFlow?: (
appId: any,
appId: null | string,
context: WorkflowContext,
) => Promise<WorkflowResult>;
projectInfo: {