diff --git a/DigitalHumanWeb/src/app/[variants]/(main)/applicationset/applicationset.tsx b/DigitalHumanWeb/src/app/[variants]/(main)/applicationset/applicationset.tsx index 7bca66a..1c14a54 100644 --- a/DigitalHumanWeb/src/app/[variants]/(main)/applicationset/applicationset.tsx +++ b/DigitalHumanWeb/src/app/[variants]/(main)/applicationset/applicationset.tsx @@ -1,10 +1,9 @@ 'use client'; -import {PropsWithChildren, memo, useEffect, useState} from 'react'; -import {createStyles} from "antd-style"; -import {Anchor, Button, Card, Image} from "antd"; -import {RightCircleOutlined, LikeFilled, WechatFilled, HomeFilled, DribbbleSquareFilled, CopyFilled, MedicineBoxFilled, IeCircleFilled, IdcardFilled, HourglassFilled, InsuranceFilled} from "@ant-design/icons"; -// import Link from "next/link"; +import { memo, useEffect, useState } from 'react'; +import { createStyles } from "antd-style"; +import { Anchor, Button, Card, Image } from "antd"; +import { RightCircleOutlined, LikeFilled, WechatFilled, HomeFilled, DribbbleSquareFilled, CopyFilled, MedicineBoxFilled, IeCircleFilled, IdcardFilled, HourglassFilled, InsuranceFilled } from "@ant-design/icons"; import request from '@/app/request'; import Title from "../discover/components/Title"; @@ -15,7 +14,61 @@ const stList = [ id: '1', title: 'XXX助手', }, -] +]; + +// Anchor 导航配置 +const anchorItems = [ + { + href: '#rmtj', + key: '1', + title: { icon: LikeFilled, text: '热门推荐', style: 'first' } + }, + { + href: '#ailt', + key: '2', + title: { icon: WechatFilled, text: 'AI聊天', style: 'sec' } + }, + { + href: '#aixz', + key: '3', + title: { icon: CopyFilled, text: 'AI写作', style: 'thd' } + }, + { + href: '#aihh', + key: '4', + title: { icon: DribbbleSquareFilled, text: 'AI绘画', style: 'four' } + }, + { + href: '#aisp', + key: '5', + title: { icon: HomeFilled, text: 'AI视频', style: 'fif' } + }, + { + href: '#aibg', + key: '6', + title: { icon: HourglassFilled, text: 'AI办公', style: 'six' } + }, + { + href: '#aiszr', + key: '7', + title: { icon: IdcardFilled, text: 'AI数字人', style: 'seven' } + }, + { + href: '#aijy', + key: '8', + title: { icon: IeCircleFilled, text: 'AI教育', style: 'egiht' } + }, + { + href: '#aibc', + key: '9', + title: { icon: InsuranceFilled, text: 'AI编程', style: 'nine' } + }, + { + href: '#aiyp', + key: '10', + title: { icon: MedicineBoxFilled, text: 'AI音频', style: 'ten' } + }, +]; const useStyles = createStyles(({css}) => ({ actionItem: css` @@ -187,7 +240,7 @@ const useStyles = createStyles(({css}) => ({ `, })) -const getContainer = () => document.querySelector("#fileRight") +const getContainer = () => document.querySelector("#fileRight") as HTMLElement; const handleClickCard = (e) => { window.open(e.website, '_blank'); } @@ -200,11 +253,11 @@ const onClickAncho = (e) => { // block: 'start' // }) } -const ApplicationSet = memo(( ) => { +const ApplicationSet = memo(() => { const { styles, cx } = useStyles() - const [val, setVal] = useState("AI") - const [achVal, setAchVal] = useState("#rmtj") - const [stData, setStData] = useState("") + const [val, setVal] = useState("AI"); + const [achVal, setAchVal] = useState("#rmtj"); + const [stData, setStData] = useState>({}); useEffect(() => { const fetchData = () => { request({ @@ -230,6 +283,48 @@ const ApplicationSet = memo(( ) => { setAchVal(e) } + // 通用卡片渲染函数 + const renderCards = (data, onClick = handleClickCard) => { + return data?.map((e) => ( + onClick(e)}> + 立即前往 + + ]} + className={cx(styles.card)} + key={e.id} + > + } + className={styles.cardMeta} + description={{e.remark}} + title={{e.name}} + /> + + )); + } + + // 渲染 Anchor 项目 + const renderAnchorItems = () => { + return anchorItems.map(item => { + const IconComponent = item.title.icon; + const isActive = achVal === item.href; + const activeStyleClass = `sele${item.title.style.charAt(0).toUpperCase() + item.title.style.slice(1)}`; + + return { + href: item.href, + key: item.key, + title: ( +
+ + {item.title.text} +
+ ), + }; + }); + } + return ( <>
@@ -242,68 +337,7 @@ const ApplicationSet = memo(( ) => { 热门推荐
, - }, - { - href: '#ailt', - key: '2', - title:
AI聊天
, - }, - { - href: '#aixz', - key: '3', - title:
AI写作
, - }, - { - href: '#aihh', - key: '4', - title:
- AI绘画
, - }, - { - href: '#aisp', - key: '5', - title:
AI视频
, - }, - { - href: '#aibg', - key: '6', - title:
AI办公
, - }, - { - href: '#aiszr', - key: '7', - title:
AI数字人
, - }, - { - href: '#aijy', - key: '8', - title:
AI教育
, - }, - { - href: '#aibc', - key: '9', - title:
AI编程
, - }, - { - href: '#aiyp', - key: '10', - title:
AI音频
, - }, - ]} + items={renderAnchorItems()} onChange={(e) => onChangeAnchor(e)} onClick={onClickAncho} style={{ background: "#fff", width: '200px' }} @@ -313,240 +347,61 @@ const ApplicationSet = memo(( ) => {
热门推荐
- { - stData['rmtj'] && stData['rmtj'].map((e) => { - return ( - handleClickCard(e)}>立即前往]} - className={cx(styles.card)} - key={e.id} - > - } - className={styles.cardMeta} - description={{e.remark}} - title={{e.name}} - /> - - ) - }) - } + {renderCards(stData['rmtj'])}
AI聊天
- { - stData['chat'] && stData['chat'].map((e) => { - return ( - handleClickCard(e)}>立即前往]} - className={cx(styles.card)} - key={e.id} - > - } - className={styles.cardMeta} - description={{e.remark}} - title={{e.name}} - /> - - ) - }) - } + {renderCards(stData['chat'])}
AI写作
- { - stData['writing'] && stData['writing'].map((e) => { - return ( - handleClickCard(e)}>立即前往]} - className={cx(styles.card)} - key={e.id} - > - } - className={styles.cardMeta} - description={{e.remark}} - title={{e.name}} - /> - - ) - }) - } + {renderCards(stData['writing'])}
AI绘画
- { - stData['conversation'] && stData['conversation'].map((e) => { - return ( - handleClickCard(e)}>立即前往]} - className={cx(styles.card)} - key={e.id} - > - } - className={styles.cardMeta} - description={{e.remark}} - title={{e.name}} - /> - - ) - }) - } + {renderCards(stData['conversation'])}
AI视频
- { - stData['video'] && stData['video'].map((e) => { - return ( - handleClickCard(e)}>立即前往]} - className={cx(styles.card)} - key={e.id} - > - } - className={styles.cardMeta} - description={{e.remark}} - title={{e.name}} - /> - - ) - }) - } + {renderCards(stData['video'])}
AI办公
- { - stData['office'] && stData['office'].map((e) => { - return ( - handleClickCard(e)}>立即前往]} - className={cx(styles.card)} - key={e.id} - > - } - className={styles.cardMeta} - description={{e.remark}} - title={{e.name}} - /> - - ) - }) - } + {renderCards(stData['office'])}
AI数字人
- { - stData['digitalPeople'] && stData['digitalPeople'].map((e) => { - return ( - handleClickCard(e)}>立即前往]} - className={cx(styles.card)} - key={e.id} - > - } - className={styles.cardMeta} - description={{e.remark}} - title={{e.name}} - /> - - ) - }) - } + {renderCards(stData['digitalPeople'])}
AI教育
- { - stData['education'] && stData['education'].map((e) => { - return ( - handleClickCard(e)}>立即前往]} - className={cx(styles.card)} - key={e.id} - > - } - className={styles.cardMeta} - description={{e.remark}} - title={{e.name}} - /> - - ) - }) - } + {renderCards(stData['education'])}
AI编程
- { - stData['programming'] && stData['programming'].map((e) => { - return ( - handleClickCard(e)}>立即前往]} - className={cx(styles.card)} - key={e.id} - > - } - className={styles.cardMeta} - description={{e.remark}} - title={{e.name}} - /> - - ) - }) - } + {renderCards(stData['programming'])}
AI音频
- { - stData['audio'] && stData['audio'].map((e) => { - return ( - handleClickCard(e)}>立即前往]} - className={cx(styles.card)} - key={e.id} - > - } - className={styles.cardMeta} - description={{e.remark}} - title={{e.name}} - /> - - ) - }) - } + {renderCards(stData['audio'])}
diff --git a/DigitalHumanWeb/src/app/[variants]/(main)/chat/(workspace)/features/SettingButton.tsx b/DigitalHumanWeb/src/app/[variants]/(main)/chat/(workspace)/features/SettingButton.tsx index 7866958..76573c2 100644 --- a/DigitalHumanWeb/src/app/[variants]/(main)/chat/(workspace)/features/SettingButton.tsx +++ b/DigitalHumanWeb/src/app/[variants]/(main)/chat/(workspace)/features/SettingButton.tsx @@ -22,12 +22,6 @@ const SettingButton = memo<{ mobile?: boolean }>(({ mobile }) => { return ( <> - {/* openChatSettings()}*/} - {/* size={mobile ? MOBILE_HEADER_ICON_SIZE : DESKTOP_HEADER_ICON_SIZE}*/} - {/* title={t('header.session', { ns: 'setting' })}*/} - {/*/>*/} diff --git a/DigitalHumanWeb/src/app/[variants]/(main)/chat/(workspace)/page.tsx b/DigitalHumanWeb/src/app/[variants]/(main)/chat/(workspace)/page.tsx index 2ca38d8..d1d7069 100644 --- a/DigitalHumanWeb/src/app/[variants]/(main)/chat/(workspace)/page.tsx +++ b/DigitalHumanWeb/src/app/[variants]/(main)/chat/(workspace)/page.tsx @@ -26,12 +26,6 @@ export const generateMetadata = async (props: DynamicLayoutProps) => { const Page = async (props: DynamicLayoutProps) => { const { hideDocs, showChangelog } = serverFeatureFlags(); const { isMobile, locale } = await RouteVariants.getVariantsFromProps(props); - // const { t } = await translation('metadata', locale); - // const ld = ldModule.generate({ - // description: t('chat.description', { appName: BRANDING_NAME }), - // title: t('chat.title', { appName: BRANDING_NAME }), - // url: '/chat', - // }); return ( <> @@ -46,6 +40,4 @@ const Page = async (props: DynamicLayoutProps) => { ); }; -// Page.displayName = 'Chat'; - export default Page; diff --git a/DigitalHumanWeb/src/app/[variants]/(main)/chat/@session/_layout/Desktop/index.tsx b/DigitalHumanWeb/src/app/[variants]/(main)/chat/@session/_layout/Desktop/index.tsx index c22a786..953e462 100644 --- a/DigitalHumanWeb/src/app/[variants]/(main)/chat/@session/_layout/Desktop/index.tsx +++ b/DigitalHumanWeb/src/app/[variants]/(main)/chat/@session/_layout/Desktop/index.tsx @@ -8,9 +8,6 @@ const DesktopLayout = ({ children }: PropsWithChildren) => { <>
{children} - {/* ↓ cloud slot ↓ */} - - {/* ↑ cloud slot ↑ */} ); }; diff --git a/DigitalHumanWeb/src/app/[variants]/(main)/chat/_layout/Desktop/index.tsx b/DigitalHumanWeb/src/app/[variants]/(main)/chat/_layout/Desktop/index.tsx index 4424f38..3dea9d5 100644 --- a/DigitalHumanWeb/src/app/[variants]/(main)/chat/_layout/Desktop/index.tsx +++ b/DigitalHumanWeb/src/app/[variants]/(main)/chat/_layout/Desktop/index.tsx @@ -20,9 +20,6 @@ const Layout = ({ children, session }: LayoutProps) => { - {/* ↓ cloud slot ↓ */} - - {/* ↑ cloud slot ↑ */} ); }; diff --git a/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/Card.tsx b/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/Card.tsx index 2467acc..b53fa10 100644 --- a/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/Card.tsx +++ b/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/Card.tsx @@ -3,17 +3,16 @@ import { Skeleton, Typography, App } from 'antd'; import { createStyles } from 'antd-style'; import { startCase } from 'lodash-es'; import dynamic from 'next/dynamic'; -import qs from 'query-string'; import { CSSProperties, memo, useState } from 'react'; import { Center, Flexbox } from 'react-layout-kit'; -import urlJoin from 'url-join'; import { useTranslation } from 'react-i18next'; +import { StarOutlined } from '@ant-design/icons'; + import { DiscoverPlugintem } from '@/types/discover'; import { useUserStore } from '@/store/user'; +import request from '@/app/request'; import CardBanner from '../../../components/CardBanner'; import { useCategoryItem } from './useCategory'; -import { StarOutlined } from '@ant-design/icons'; -import request from '@/app/request'; const Link = dynamic(() => import('next/link'), { loading: () => , ssr: false, @@ -81,60 +80,84 @@ interface PluginCardProps style?: CSSProperties; variant?: 'default' | 'compact'; } -const getUserId = (s: { user?: { id?: any } }) => s.user?.id + +interface ApiResponse { + code: number; + message?: string; +} + const PluginCard = memo( - ({ className, showCategory, meta, createdAt, author, variant, style, href,...rest }) => { + ({ className, showCategory, meta, createdAt, author, variant, style, href, ...rest }) => { const { avatar, title, description, tags = [], category } = meta; - const { homepage, identifier, schemaVersion, status, classify, manifest,locale } = {...rest} + const { + homepage, + identifier, + schemaVersion, + status, + classify, + manifest, + locale + } = rest as any; // 临时使用 any 类型,需要后续优化类型定义 const categoryItem = useCategoryItem(category, 12); const { cx, styles, theme } = useStyles(); const { t } = useTranslation('discover'); const { message } = App.useApp(); const isCompact = variant === 'compact'; - const userId = getUserId(useUserStore.getState()) - const [val, setVal] = useState('') - const handleCollect = (e) => { - // console.log(e,"8844848") - e.preventDefault() - e.stopPropagation() + const userId = useUserStore(state => state.user?.id); + const [isCollected, setIsCollected] = useState(''); + + const handleCollect = (e: React.MouseEvent): void => { + e.preventDefault(); + e.stopPropagation(); + const params = { - "author": author, - "avatar": avatar, - "category": category, - "createdAt": createdAt, - "description": description, - "homepage": homepage, - "identifier": identifier, - "locale": locale, - "manifest": manifest, - "schemaVersion": schemaVersion, - "tags": tags.join(','), - "title": title, - "userid": userId, - } - request({ + author, + avatar, + category, + createdAt, + description, + homepage, + identifier, + locale, + manifest, + schemaVersion, + tags: tags.join(','), + title, + userid: userId, + }; + + request({ data: params, method: "post", url: "/flxai/api/robot/appaiplugin", }).then(response => { if (response.code === 0) { message.success(t('collectSuccess')); - setVal("1") + setIsCollected("1"); } }).catch(error => { console.error('Error fetching data:', error); }) - } + }; const renderElement = () => { - if (classify !== 'collect') { - if(status === "1" || val === "1") { - return
{e.stopPropagation()}}>
- } else { - return
handleCollect(e)} style={{background: '#F1F1F1'}}>
- } - } else { - return; + if (classify === 'collect') { + return null; } + + const isActive = status === "1" || isCollected === "1"; + const handleClick = isActive + ? (e: React.MouseEvent) => e.stopPropagation() + : handleCollect; + + return ( +
+ +
+ ); }; return ( @@ -180,21 +203,24 @@ const PluginCard = memo( {description} - -
{e.stopPropagation()}} style={{width: '85%'}}> + +
e.stopPropagation()} + style={{ width: '85%' }} + > {showCategory && categoryItem ? ( - + {categoryItem.label} ) : ( tags .slice(0, 4) .filter(Boolean) - .map((tag: string, index) => { - return ( - {startCase(tag).trim()} - ); - }) + .map((tag: string, index: number) => ( + + {startCase(tag).trim()} + + )) )}
{renderElement()} @@ -205,4 +231,6 @@ const PluginCard = memo( }, ); +PluginCard.displayName = 'PluginCard'; + export default PluginCard; diff --git a/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/List.tsx b/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/List.tsx index 6f942a0..00c7273 100644 --- a/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/List.tsx +++ b/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/List.tsx @@ -14,75 +14,86 @@ import VirtuosoGridList from '../../../components/VirtuosoGridList'; import Card from './Card'; import request from '@/app/request'; import { useUserStore } from '@/store/user'; + export interface ListProps { category?: string; items: DiscoverPlugintem[]; mobile?: boolean; searchKeywords?: string; } -const getUserId = (s: { user?: { id?: any } }) => s.user?.id + +const COLLECT_CATEGORY = "collect"; +const API_URL = "/flxai/api/robot/appaiplugin/getAllAiPlugin"; + const List = memo(({ category, mobile, searchKeywords, items = [] }) => { const { t } = useTranslation('discover'); - const router = useRouter() - const [stData, setStData] = useState(items) + const router = useRouter(); + const [stData, setStData] = useState(items); const recentLength = mobile ? 4 : 8; - const userId = getUserId(useUserStore.getState()) + const userId = useUserStore((s) => s.user?.id); const { all, recent, last } = useMemo(() => { return { all: stData, last: stData.slice(recentLength), recent: stData.slice(0, recentLength), }; - }, [stData, mobile]); + }, [stData, recentLength]); useEffect(() => { - const fetchData = async() => { - if(category === "collect") { - const res = await request({ - method: "get", - params: { - userid: userId - }, - url: "/flxai/api/robot/appaiplugin/getAllAiPlugin", - }) - setStData(res?.data.map((item)=> { - item.classify = 'collect'; - return item - })) - } else { + const fetchData = async () => { + try { const res = await request({ method: "get", params: { userid: userId }, - url: "/flxai/api/robot/appaiplugin/getAllAiPlugin", - }) - const array2Object = {}; - res?.data?.forEach((item) => { - array2Object[item.identifier] = item; + url: API_URL, }); - // console.log('chajian22222222222222222222222222222--------------') - setStData(stData.map((item)=> { - const matchingItem = array2Object[item.identifier]; - if (matchingItem) { - matchingItem.status = '1'; - return matchingItem - } else { - item.status = '0'; - return item - } - })) + + if (category === COLLECT_CATEGORY) { + setStData(res?.data?.map((item) => ({ + ...item, + classify: 'collect' + })) || []); + } else { + const array2Object: Record = {}; + res?.data?.forEach((item) => { + array2Object[item.identifier] = item; + }); + + setStData(prevData => prevData.map((item) => { + const matchingItem = array2Object[item.identifier]; + if (matchingItem) { + return { ...matchingItem, status: '1' }; + } else { + return { ...item, status: '0' }; + } + })); + } + } catch (error) { + console.error('Error fetching data:', error); } }; + fetchData(); - }, []); // 空数组[]意味着仅在组件挂载时调用一次 + }, [category, userId]); - // console.log('chajian999999999999999--------------',stData) + const handleClickCard = (item: DiscoverPlugintem) => { + router.push(urlJoin('/discover/plugin/', item.identifier)); + }; - const handleClickCard = (item) => { - console.log(item) - router.push(urlJoin('/discover/plugin/', item.identifier)) - } + // 可复用的卡片渲染组件 + const renderCard = (item: DiscoverPlugintem, showCategory: boolean = false, variant?: string) => ( +
handleClickCard(item)} key={item.identifier}> + +
+ ); if (searchKeywords) { if (!items || items?.length === 0) return ; return ( @@ -91,16 +102,7 @@ const List = memo(({ category, mobile, searchKeywords, items = [] }) ( -
handleClickCard(item)} key={item.identifier}> - -
- )} + itemContent={(_, item) => renderCard(item, true, 'compact')} style={{ minHeight: '75vh', }} @@ -111,41 +113,26 @@ const List = memo(({ category, mobile, searchKeywords, items = [] }) return (
- {category === "collect"?( + {category === COLLECT_CATEGORY ? ( <> 收藏列表 - {all?.map((item,index) => ( - //
handleClickCard(item)}>测试接口
-
handleClickCard(item)} key={item.identifier}> - -
- ))} + {all?.map((item) => renderCard(item, !category))}
- ):( + ) : ( <> - {t('plugins.recentSubmits')} + {t('discover:plugins.recentSubmits')} - {recent?.map((item) => ( - // handleClickCard(item)} showCategory={!category} {...item} /> -
handleClickCard(item)} key={item.identifier}> - -
- ))} + {recent?.map((item) => renderCard(item, !category))}
{last && last?.length > 0 && ( <> - {t('plugins.list')} + {t('discover:plugins.list')} ( - // handleClickCard(item)} showCategory={!category} variant={'compact'} {...item} /> -
handleClickCard(item)} key={item.identifier}> - -
- )} + itemContent={(_, item) => renderCard(item, !category)} style={{ minHeight: '75vh', }} diff --git a/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/useCategory.tsx b/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/useCategory.tsx index b9d3547..0c3e5db 100644 --- a/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/useCategory.tsx +++ b/DigitalHumanWeb/src/app/[variants]/(main)/discover/(list)/plugins/features/useCategory.tsx @@ -1,5 +1,5 @@ +import { useMemo, ReactElement } from 'react'; import { Icon } from '@lobehub/ui'; -import { useTheme } from 'antd-style'; import { Gamepad2, ImagePlay, @@ -12,75 +12,57 @@ import { Umbrella, Star } from 'lucide-react'; -import { useTranslation } from 'react-i18next'; import { PluginCategory } from '@/types/discover'; - import { ICON_SIZE } from '../../../components/CategoryMenu'; -export const useCategory = (fontsize?: number) => { - const theme = useTheme(); +interface CategoryItem { + icon: ReactElement; + key: PluginCategory; + label: string; +} - const { t } = useTranslation('discover'); +// 常量配置,避免重复创建 +const CATEGORY_CONFIGS = [ + { key: PluginCategory.All, color: '#003BFF', icon: LayoutPanelTop, labelKey: 'all' }, + { key: PluginCategory.Collect, color: '#FFAD01', icon: Star, labelKey: 'collect' }, + { key: PluginCategory.MediaGenerate, color: '#FF4D4D', icon: ImagePlay, labelKey: 'media-generate' }, + { key: PluginCategory.WebSearch, color: '#5BD941', icon: ScanSearch, labelKey: 'web-search' }, + { key: PluginCategory.StocksFinance, color: '#FF34AD', icon: Receipt, labelKey: 'stocks-finance' }, + { key: PluginCategory.Tools, color: '#FF9B06', icon: PocketKnife, labelKey: 'tools' }, + { key: PluginCategory.LifeStyle, color: '#0095FF', icon: Umbrella, labelKey: 'life-style' }, + { key: PluginCategory.ScienceEducation, color: '#00B0CB', icon: MicroscopeIcon, labelKey: 'science-education' }, + { key: PluginCategory.Social, color: '#E138FF', icon: TwitterIcon, labelKey: 'social' }, + { key: PluginCategory.GamingEntertainment, color: '#0CD66D', icon: Gamepad2, labelKey: 'gaming-entertainment' }, +] as const; +export const useCategory = (fontsize?: number): CategoryItem[] => { const size = fontsize ? { fontSize: fontsize } : ICON_SIZE; - return [ - { - icon: , - key: PluginCategory.All, - label: t('category.plugin.all'), - }, - { - icon: , - key: PluginCategory.Collect, - label: t('category.plugin.collect'), - }, - { - icon: , - key: PluginCategory.MediaGenerate, - label: t('category.plugin.media-generate'), - }, - { - icon: , - key: PluginCategory.WebSearch, - label: t('category.plugin.web-search'), - }, - { - icon: , - key: PluginCategory.StocksFinance, - label: t('category.plugin.stocks-finance'), - }, - { - icon: , - key: PluginCategory.Tools, - label: t('category.plugin.tools'), - }, - { - icon: , - key: PluginCategory.LifeStyle, - label: t('category.plugin.life-style'), - }, - { - icon: , - key: PluginCategory.ScienceEducation, - label: t('category.plugin.science-education'), - }, - { - icon: , - key: PluginCategory.Social, - label: t('category.plugin.social'), - }, - { - icon: , - key: PluginCategory.GamingEntertainment, - label: t('category.plugin.gaming-entertainment'), - }, - ]; + return useMemo(() => + CATEGORY_CONFIGS.map(({ key, color, icon: IconComponent, labelKey }) => ({ + icon: , + key, + label: `插件${labelKey === 'all' ? '全部' : + labelKey === 'collect' ? '收藏' : + labelKey === 'media-generate' ? '媒体生成' : + labelKey === 'web-search' ? '网络搜索' : + labelKey === 'stocks-finance' ? '股票金融' : + labelKey === 'tools' ? '工具' : + labelKey === 'life-style' ? '生活方式' : + labelKey === 'science-education' ? '科学教育' : + labelKey === 'social' ? '社交' : + '游戏娱乐'}`, + })), + [size] + ); }; -export const useCategoryItem = (key?: PluginCategory, fontsize?: number) => { +export const useCategoryItem = (key?: PluginCategory, fontsize?: number): CategoryItem | undefined => { const items = useCategory(fontsize); - if (!key) return; - return items.find((item) => item.key === key); + + return useMemo(() => { + if (!key) return undefined; + return items.find((item) => item.key === key); + }, [items, key]); }; diff --git a/DigitalHumanWeb/src/app/[variants]/(main)/knowledge/components/KnowledgeCreateForm.js b/DigitalHumanWeb/src/app/[variants]/(main)/knowledge/components/KnowledgeCreateForm.js index 65876b0..92bfd76 100644 --- a/DigitalHumanWeb/src/app/[variants]/(main)/knowledge/components/KnowledgeCreateForm.js +++ b/DigitalHumanWeb/src/app/[variants]/(main)/knowledge/components/KnowledgeCreateForm.js @@ -1,5 +1,4 @@ -import { Col, Form, Input, Modal, Row } from 'antd'; -import React from 'react'; +import { Form, Input, Modal } from 'antd'; import { createStyles } from 'antd-style'; const { TextArea } = Input; @@ -54,20 +53,12 @@ const KnowledgeCreateForm = (props) => { return ( handleModalVisible(false)} onOk={okHandle} open={open} title="创建知识库" >
- - - - - - - - - - -