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">
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';
@ -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);
if (selectedItem) {
// title -> name, key -> id
@ -66,7 +72,7 @@ const onConversationClick: ConversationsProps['onActiveChange'] = (key) => {
}
};
const selectedKeys = ref([]);
const selectedKeys = ref<string[]>([]);
const openKeys = ref([]);
// transformItems itemsData
@ -81,7 +87,7 @@ watch(
watch(
() => itemsData.value,
(newVal) => {
if (newVal && newVal.length > 0) {
if (newVal.length > 0 && newVal[0]) {
selectedKeys.value = [newVal[0].key]; //
handleMenuClick(newVal[0]);
}

View File

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

View File

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