diff --git a/client/web/src/components/Card/FileCard.tsx b/client/web/src/components/Card/FileCard.tsx index 6b827def..be80cb7f 100644 --- a/client/web/src/components/Card/FileCard.tsx +++ b/client/web/src/components/Card/FileCard.tsx @@ -4,12 +4,11 @@ import { Icon } from 'tailchat-design'; import { useMemoizedFn, t } from 'tailchat-shared'; import { IconBtn } from '../IconBtn'; import { CardWrapper } from './Wrapper'; - -export interface FileCardPayload { +import type { BaseCardPayload } from '@/components/Card/index'; +interface FileCardPayload extends BaseCardPayload { label: string; url: string; } - export const FileCard: React.FC<{ payload: FileCardPayload; }> = React.memo((props) => { diff --git a/client/web/src/components/Card/index.tsx b/client/web/src/components/Card/index.tsx index cebabf49..5501ace4 100644 --- a/client/web/src/components/Card/index.tsx +++ b/client/web/src/components/Card/index.tsx @@ -1,15 +1,25 @@ import React from 'react'; import { t } from 'tailchat-shared'; -import { FileCard, FileCardPayload } from './FileCard'; +import { FileCard } from './FileCard'; import { CardWrapper } from './Wrapper'; +import { pluginCardItemMap } from '@/plugin/common'; interface Props { - type: 'file'; - payload: FileCardPayload; + type: string; + payload: BaseCardPayload; +} +export interface BaseCardPayload { + [key: string]: any; } export const Card: React.FC = React.memo((props) => { + if (pluginCardItemMap[props.type]) { + const info = pluginCardItemMap[props.type]; + const Component = info.render; + return ; + } + if (props.type === 'file') { - return ; + return ; } return {t('未知的卡片类型')}; diff --git a/client/web/src/plugin/common/reg.ts b/client/web/src/plugin/common/reg.ts index 052104cf..53339996 100644 --- a/client/web/src/plugin/common/reg.ts +++ b/client/web/src/plugin/common/reg.ts @@ -14,7 +14,8 @@ import { import type { MetaFormFieldMeta } from 'tailchat-design'; import type { FullModalFactoryConfig } from '@/components/FullModal/Factory'; import type { ReactElement } from 'react'; - +import type { BaseCardPayload } from '@/components/Card'; +export type { BaseCardPayload }; /** * 注册自定义面板 */ @@ -304,6 +305,16 @@ interface PluginInboxItem { export const [pluginInboxItemMap, regPluginInboxItemMap] = buildRegMap(); +interface PluginCardItem { + render: React.ComponentType<{ payload: BaseCardPayload }>; +} + +/** + * 注册卡片类型 + */ +export const [pluginCardItemMap, regPluginCardItem] = + buildRegMap(); + export const [pluginGroupConfigItems, regPluginGroupConfigItem] = buildRegList<{ name: string; title: string;