refactor(@vben/web-antd): 优化 spider 和 word 组件的代码结构和类型定义
- 更新爬虫默认日期为最近三天 - 在 spider组件中添加 AppListResult 类型并更新相关引用 - 修正 word 组件中消息内容的赋值方式 - 调整 self-work-view 组件的日期范围选择 - 优化 typing 文件中的类型定义,提高代码可读性和可维护性
This commit is contained in:
parent
25c027f3d8
commit
2dd824324f
@ -68,8 +68,8 @@ const [PreviewDrawer, previewDrawerApi] = useVbenDrawer({
|
|||||||
// placement: 'left',
|
// placement: 'left',
|
||||||
});
|
});
|
||||||
const selectedDateRange = ref<[Dayjs, Dayjs]>([
|
const selectedDateRange = ref<[Dayjs, Dayjs]>([
|
||||||
dayjs('2025-05-05'),
|
dayjs().subtract(3, 'days'),
|
||||||
dayjs('2025-05-07'),
|
dayjs(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function openPreviewDrawer(
|
function openPreviewDrawer(
|
||||||
|
@ -53,10 +53,9 @@ const [PreviewDrawer, previewDrawerApi] = useVbenDrawer({
|
|||||||
|
|
||||||
function openPreviewDrawer(
|
function openPreviewDrawer(
|
||||||
placement: DrawerPlacement = 'right',
|
placement: DrawerPlacement = 'right',
|
||||||
filename?: string,
|
filename: any,
|
||||||
) {
|
) {
|
||||||
const fileData = filename.value;
|
previewDrawerApi.setState({ placement }).setData(filename).open();
|
||||||
previewDrawerApi.setState({ placement }).setData(fileData).open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const startFetching = async () => {
|
const startFetching = async () => {
|
||||||
@ -94,10 +93,10 @@ const startFetching = async () => {
|
|||||||
h(
|
h(
|
||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
size: 'nomarl',
|
// size: 'normal',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
openPreviewDrawer('right', fileUrl);
|
openPreviewDrawer('right', fileUrl.value);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'文档预览',
|
'文档预览',
|
||||||
@ -105,7 +104,7 @@ const startFetching = async () => {
|
|||||||
h(
|
h(
|
||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
size: 'normal',
|
// size: 'normal',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
style: {
|
style: {
|
||||||
marginLeft: '10px',
|
marginLeft: '10px',
|
||||||
@ -196,7 +195,7 @@ watch(
|
|||||||
() => props.itemMessage,
|
() => props.itemMessage,
|
||||||
(newVal) => {
|
(newVal) => {
|
||||||
resultItems.value = [];
|
resultItems.value = [];
|
||||||
if (newVal && newVal.length > 0) {
|
if (newVal.length > 0) {
|
||||||
newVal.forEach((msg) => {
|
newVal.forEach((msg) => {
|
||||||
// resultItems.value.push({
|
// resultItems.value.push({
|
||||||
// key: resultItems.value.length + 1,
|
// key: resultItems.value.length + 1,
|
||||||
@ -231,7 +230,7 @@ watch(
|
|||||||
h(
|
h(
|
||||||
Button,
|
Button,
|
||||||
{
|
{
|
||||||
size: 'normal',
|
// size: 'normal',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
style: {
|
style: {
|
||||||
marginLeft: '10px',
|
marginLeft: '10px',
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// sendWorkflow
|
// sendWorkflow
|
||||||
import type { ResultItem, TempItem, WordFlowItem } from './typing';
|
import type {
|
||||||
|
AppListResult,
|
||||||
|
ResultItem,
|
||||||
|
TempItem,
|
||||||
|
WordFlowItem,
|
||||||
|
} from './typing';
|
||||||
|
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
|
|
||||||
@ -17,15 +22,15 @@ import {
|
|||||||
|
|
||||||
import { SelfWorkView, SpiderListView, WorkflowWorkView } from './components';
|
import { SelfWorkView, SpiderListView, WorkflowWorkView } from './components';
|
||||||
|
|
||||||
const hitsory = ref([]);
|
const history = ref([]);
|
||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const temp = ref([]);
|
const temp = ref<AppListResult[]>([]);
|
||||||
const itemMessage = ref<ResultItem[]>([]);
|
const itemMessage = ref<ResultItem[]>([]);
|
||||||
|
|
||||||
// 获取日志
|
// 获取日志
|
||||||
// const getLogs = async (appid: string, limit: number) => {
|
// const getLogs = async (appid: string, limit: number) => {
|
||||||
// loading.value = true;
|
// loading.value = true;
|
||||||
// hitsory.value = await getWorkflowList({
|
// history.value = await getWorkflowList({
|
||||||
// appid,
|
// appid,
|
||||||
// limit,
|
// limit,
|
||||||
// });
|
// });
|
||||||
@ -88,7 +93,7 @@ onMounted(() => {
|
|||||||
<SpiderListView
|
<SpiderListView
|
||||||
title="选择模板"
|
title="选择模板"
|
||||||
:temp="temp"
|
:temp="temp"
|
||||||
:items="hitsory"
|
:items="history"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
@click-mode="handleClickMode"
|
@click-mode="handleClickMode"
|
||||||
@click="handleClick"
|
@click="handleClick"
|
||||||
|
@ -5,6 +5,11 @@ interface TempItem {
|
|||||||
description?: string;
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface AppListResult {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface ResultItem {
|
interface ResultItem {
|
||||||
key: number;
|
key: number;
|
||||||
role: 'ai' | 'user';
|
role: 'ai' | 'user';
|
||||||
@ -22,7 +27,8 @@ interface WordFlowItem {
|
|||||||
interface SpiderItem {
|
interface SpiderItem {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url?: string;
|
||||||
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SpiderContext {
|
interface SpiderContext {
|
||||||
@ -47,7 +53,7 @@ interface ResultItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
itemMessage?: ResultItem;
|
itemMessage?: ResultItem[];
|
||||||
temp?: any;
|
temp?: any;
|
||||||
item?: SpiderItem;
|
item?: SpiderItem;
|
||||||
title: string;
|
title: string;
|
||||||
@ -62,6 +68,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
|
AppListResult,
|
||||||
Props,
|
Props,
|
||||||
ResultItem,
|
ResultItem,
|
||||||
SpiderContext,
|
SpiderContext,
|
||||||
|
@ -49,11 +49,13 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
itemMessage: Array,
|
itemMessage: Array,
|
||||||
paramsData: Array,
|
paramsData: Array,
|
||||||
runChatFlow: () => async () => ({
|
runChatFlow: () => async () => ({
|
||||||
data: {
|
event: '',
|
||||||
outputs: {
|
conversationId: '',
|
||||||
result: '',
|
messageFiles: [],
|
||||||
},
|
messageId: '',
|
||||||
},
|
taskId: '',
|
||||||
|
id: '',
|
||||||
|
answer: '',
|
||||||
}),
|
}),
|
||||||
projectInfo: {
|
projectInfo: {
|
||||||
projectName: '',
|
projectName: '',
|
||||||
@ -216,7 +218,7 @@ const startFetching = async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await props.runChatflow(props.item.id, {
|
const res = await props.runChatFlow(props.item.id, {
|
||||||
userId: userStore.userInfo?.userId || '',
|
userId: userStore.userInfo?.userId || '',
|
||||||
conversationId: conversationId.value,
|
conversationId: conversationId.value,
|
||||||
files: [],
|
files: [],
|
||||||
@ -234,8 +236,15 @@ const startFetching = async () => {
|
|||||||
emit('history', props.item.id);
|
emit('history', props.item.id);
|
||||||
}
|
}
|
||||||
conversationId.value = res.conversationId;
|
conversationId.value = res.conversationId;
|
||||||
const { filename, url } = extractDocxInfo(res.answer);
|
const docxInfo = extractDocxInfo(res.answer);
|
||||||
if (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];
|
// const { id, url } = res.messageFiles[0];
|
||||||
resultItems.value.push({
|
resultItems.value.push({
|
||||||
key: resultItems.value.length + 1,
|
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) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -140,7 +140,7 @@ async function handleClick(item: string) {
|
|||||||
itemMessage.value.push({
|
itemMessage.value.push({
|
||||||
key: itemMessage.value.length + 1,
|
key: itemMessage.value.length + 1,
|
||||||
role: 'user', // 'user' or 'ai'
|
role: 'user', // 'user' or 'ai'
|
||||||
content: msg.inputs.projectName,
|
content: msg.query,
|
||||||
// footer: msg.footer,
|
// footer: msg.footer,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ interface WorkflowContext {
|
|||||||
}
|
}
|
||||||
interface WorkflowResult {
|
interface WorkflowResult {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
answer: object;
|
answer: string;
|
||||||
messageFiles?: [
|
messageFiles?: [
|
||||||
{
|
{
|
||||||
id: string;
|
id: string;
|
||||||
@ -51,7 +51,7 @@ interface Props {
|
|||||||
item?: null | WordTempItem;
|
item?: null | WordTempItem;
|
||||||
paramsData?: string[];
|
paramsData?: string[];
|
||||||
runChatFlow?: (
|
runChatFlow?: (
|
||||||
appId: any,
|
appId: null | string,
|
||||||
context: WorkflowContext,
|
context: WorkflowContext,
|
||||||
) => Promise<WorkflowResult>;
|
) => Promise<WorkflowResult>;
|
||||||
projectInfo: {
|
projectInfo: {
|
||||||
|
Loading…
Reference in New Issue
Block a user