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

This commit is contained in:
Kven 2025-06-27 00:46:29 +08:00
parent dae6d9abb8
commit 2a94aad171
3 changed files with 33 additions and 10 deletions

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ConversationsProps } from 'ant-design-x-vue'; import type { ConversationsProps } from 'ant-design-x-vue';
import type { Props } from '../typing'; import type { MenuItem, Props } from '../typing';
import { computed, ref, watch } from 'vue'; import { computed, ref, watch } from 'vue';
@ -37,9 +37,15 @@ const transformItems = computed(() => {
})); }));
}); });
const itemsData = ref([]); const itemsData = ref<MenuItem[]>([
{
title: '',
label: '',
key: '',
},
]);
const handleMenuClick = (item: { key: string }) => { const handleMenuClick = (item: any) => {
const selectedItem = itemsData.value.find((i) => i.key === item.key); const selectedItem = itemsData.value.find((i) => i.key === item.key);
if (selectedItem) { if (selectedItem) {
// title -> name, key -> id // title -> name, key -> id
@ -66,7 +72,7 @@ const onConversationClick: ConversationsProps['onActiveChange'] = (key) => {
} }
}; };
const selectedKeys = ref([]); const selectedKeys = ref<string[]>([]);
const openKeys = ref([]); const openKeys = ref([]);
// transformItems itemsData // transformItems itemsData
@ -81,7 +87,7 @@ watch(
watch( watch(
() => itemsData.value, () => itemsData.value,
(newVal) => { (newVal) => {
if (newVal && newVal.length > 0) { if (newVal.length > 0 && newVal[0]) {
selectedKeys.value = [newVal[0].key]; // selectedKeys.value = [newVal[0].key]; //
handleMenuClick(newVal[0]); handleMenuClick(newVal[0]);
} }

View File

@ -19,7 +19,7 @@ import PptPreview from './ppt-preview.vue';
defineOptions({ name: 'PptWorkView' }); defineOptions({ name: 'PptWorkView' });
const props = withDefaults(defineProps<PropsWork>(), { const props = withDefaults(defineProps<PropsWork>(), {
itemMessage: () => null, itemMessage: Array,
item: () => { item: () => {
return { return {
id: '', id: '',
@ -29,7 +29,12 @@ const props = withDefaults(defineProps<PropsWork>(), {
runWorkflow: () => async () => ({ runWorkflow: () => async () => ({
data: { data: {
outputs: { outputs: {
result: '', files: [
{
filename: '',
url: '',
},
],
}, },
}, },
}), }),

View File

@ -29,7 +29,7 @@ interface Props {
interface ResultItem { interface ResultItem {
key: number; key: number;
role: 'ai' | 'user'; role: 'ai' | 'user';
content: string; content: any;
footer?: any; footer?: any;
} }
@ -43,13 +43,18 @@ interface WorkflowContext {
interface WorkflowResult { interface WorkflowResult {
data: { data: {
outputs: { outputs: {
result: string; files: [
{
filename: string;
url: string;
},
];
}; };
}; };
} }
interface PropsWork { interface PropsWork {
itemMessage?: ResultItem; itemMessage?: ResultItem[];
item?: PPTTempItem; item?: PPTTempItem;
runWorkflow?: ( runWorkflow?: (
appId: any, appId: any,
@ -57,7 +62,14 @@ interface PropsWork {
) => Promise<WorkflowResult>; ) => Promise<WorkflowResult>;
} }
interface MenuItem {
key: string;
label: string;
title: string;
}
export type { export type {
MenuItem,
PptHistoryItem, PptHistoryItem,
PPTTempItem, PPTTempItem,
Props, Props,