feat(@vben/common-ui): 增加运行历史信息展示

This commit is contained in:
Kven 2025-05-06 20:47:11 +08:00
parent 752a7029b9
commit 80831aa367
4 changed files with 141 additions and 33 deletions

View File

@ -24,6 +24,7 @@ export namespace WorkflowApi {
page?: number;
limit?: number;
keyword?: string;
workflowRunId?: string;
}
}
@ -43,10 +44,10 @@ export function sendWorkflow(
// return requestClient.patch('/v1/workflow/stop', { data });
// };
//
// export function getWorkflowMessage(data){
// return requestClient.get('/v1/workflow/info', { data });
// };
//
export function getWorkflowLog(params: WorkflowApi.WorkflowLogParams) {
return requestClient.post(`/v1/workflow/logs/${params.appid}`, { ...params });
export function getWorkflowInfo(data: WorkflowApi.WorkflowLogParams) {
return requestClient.get(`/v1/workflow/info/${data.appid}`, { params: data });
}
export function getWorkflowList(params: WorkflowApi.WorkflowLogParams) {
return requestClient.get(`/v1/workflow/list/${params.appid}`);
}

View File

@ -5,29 +5,55 @@ import { onMounted, reactive, ref } from 'vue';
import { PptHistoryView, PptListView, PptWorkView } from '@vben/common-ui';
import { getWorkflowLog, sendWorkflow } from '#/api';
import { getWorkflowInfo, getWorkflowList, sendWorkflow } from '#/api';
let temp = reactive<PPTTempItem>({
id: 'ee3889b6-50fa-463e-b956-3b93447727fc',
name: '从可研申报书生成科技项目PPT',
});
interface ResultItem {
key: number;
role: 'ai' | 'user';
content: string;
footer?: any;
}
const hitsory = ref([]);
const loading = ref(true);
const itemMessage = ref<ResultItem[]>([]);
const getLogs = async (appid: string) => {
loading.value = true;
const res = await getWorkflowLog({
const res = await getWorkflowList({
appid,
limit: 5,
page: 1,
});
hitsory.value = res.data;
hitsory.value = res;
loading.value = false;
};
function handleClick(item: PPTTempItem) {
async function handleClick(item: PPTTempItem) {
temp = item;
const res = await getWorkflowInfo({
appid: temp.appId,
workflowRunId: item.workflowRunId,
});
itemMessage.value = [];
if (res.inputs) {
itemMessage.value.push({
key: itemMessage.value.length + 1,
role: 'user',
content: res.inputs.declarationDoc,
});
}
if (res.outputs) {
itemMessage.value.push({
key: itemMessage.value.length + 1,
role: 'ai',
content: res.outputs.result,
});
}
}
onMounted(() => {
@ -48,7 +74,11 @@ onMounted(() => {
<PptListView title="选择模板" @click="handleClick" />
</div>
<div class="w-full lg:w-3/4">
<PptWorkView :item="temp" :run-workflow="sendWorkflow" />
<PptWorkView
:item="temp"
:run-workflow="sendWorkflow"
:item-message="itemMessage"
/>
</div>
</div>
</div>

View File

@ -5,7 +5,7 @@ import type { DrawerPlacement } from '@vben/common-ui';
import type { PPTTempItem } from './typing';
import { h, ref } from 'vue';
import { h, ref, watch } from 'vue';
import { useVbenDrawer } from '@vben/common-ui';
@ -36,7 +36,15 @@ interface WorkflowResult {
};
}
interface ResultItem {
key: number;
role: 'ai' | 'user';
content: string;
footer?: any;
}
interface Props {
itemMessage?: ResultItem;
item?: PPTTempItem;
runWorkflow?: (
params: WorkflowParams,
@ -49,6 +57,7 @@ defineOptions({
});
const props = withDefaults(defineProps<Props>(), {
itemMessage: () => null,
item: () => null,
runWorkflow: () => async () => ({
data: {
@ -73,6 +82,20 @@ function openPreviewDrawer(
previewDrawerApi.setState({ placement }).setData(fileData).open();
}
// .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;
}
const startFetching = async () => {
isFetching.value = true;
fetchStatus.value = 'fetching';
@ -93,20 +116,6 @@ const startFetching = async () => {
);
const { result } = res.data.outputs;
// .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;
}
const filename = ref('');
if (result && isPptxURL(result)) {
@ -202,14 +211,78 @@ const fetchResult = ref('');
const fetchStatus = ref('');
const value = ref('');
interface ResultItem {
key: number;
role: 'ai' | 'user';
content: string;
footer?: any;
}
const resultItems = ref<ResultItem[]>([]);
// 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 },
);
</script>
<template>

View File

@ -1,6 +1,10 @@
interface PPTTempItem {
id: string;
name: string;
workflowRunId?: string;
appId?: string;
userId?: string;
taskId?: string;
}
interface PptHistoryItem {