refactor(@vben/web-antd): 优化 PPT 组件代码结构和类型定义
This commit is contained in:
parent
dae6d9abb8
commit
2a94aad171
@ -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]);
|
||||
}
|
||||
|
@ -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: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user