|  |  |  | @ -3,18 +3,17 @@ | 
		
	
		
			
				|  |  |  |  | import { Grid } from '@lobehub/ui'; | 
		
	
		
			
				|  |  |  |  | import { Empty } from 'antd'; | 
		
	
		
			
				|  |  |  |  | import Link from 'next/link'; | 
		
	
		
			
				|  |  |  |  | import { memo, useMemo, useEffect,useState } from 'react'; | 
		
	
		
			
				|  |  |  |  | import { memo, useMemo } from 'react'; | 
		
	
		
			
				|  |  |  |  | import { useTranslation } from 'react-i18next'; | 
		
	
		
			
				|  |  |  |  | import urlJoin from 'url-join'; | 
		
	
		
			
				|  |  |  |  | import { useRouter } from 'next/navigation'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | import { DiscoverPlugintem } from '@/types/discover'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | import SearchResultCount from '../../../components/SearchResultCount'; | 
		
	
		
			
				|  |  |  |  | import Title from '../../../components/Title'; | 
		
	
		
			
				|  |  |  |  | import VirtuosoGridList from '../../../components/VirtuosoGridList'; | 
		
	
		
			
				|  |  |  |  | import Card from './Card'; | 
		
	
		
			
				|  |  |  |  | import request from '@/app/api/request'; | 
		
	
		
			
				|  |  |  |  | import { useUserStore } from '@/store/user'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | export interface ListProps { | 
		
	
		
			
				|  |  |  |  |   category?: string; | 
		
	
		
			
				|  |  |  |  |   items: DiscoverPlugintem[]; | 
		
	
	
		
			
				
					|  |  |  | @ -24,68 +23,14 @@ export interface ListProps { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | const List = memo<ListProps>(({ category, mobile, searchKeywords, items = [] }) => { | 
		
	
		
			
				|  |  |  |  |   const { t } = useTranslation('discover'); | 
		
	
		
			
				|  |  |  |  |   const router = useRouter() | 
		
	
		
			
				|  |  |  |  |   const [stData, setStData] = useState(items) | 
		
	
		
			
				|  |  |  |  |   const recentLength = mobile ? 4 : 8; | 
		
	
		
			
				|  |  |  |  |   const getUserId = (s: UserStore) => s.user?.id | 
		
	
		
			
				|  |  |  |  |   const userId = getUserId(useUserStore.getState()) | 
		
	
		
			
				|  |  |  |  |   console.log(userId,'chajian---3837373266262266') | 
		
	
		
			
				|  |  |  |  |   console.log('chajian33333333--------------',items) | 
		
	
		
			
				|  |  |  |  |   const { all, recent, last } = useMemo(() => { | 
		
	
		
			
				|  |  |  |  |     return { | 
		
	
		
			
				|  |  |  |  |       all: stData, | 
		
	
		
			
				|  |  |  |  |       last: stData.slice(recentLength), | 
		
	
		
			
				|  |  |  |  |       recent: stData.slice(0, recentLength), | 
		
	
		
			
				|  |  |  |  |       all: items, | 
		
	
		
			
				|  |  |  |  |       last: items.slice(recentLength), | 
		
	
		
			
				|  |  |  |  |       recent: items.slice(0, recentLength), | 
		
	
		
			
				|  |  |  |  |     }; | 
		
	
		
			
				|  |  |  |  |   }, [stData, mobile]); | 
		
	
		
			
				|  |  |  |  |   useEffect(() => { | 
		
	
		
			
				|  |  |  |  |     const fetchData = async() => { | 
		
	
		
			
				|  |  |  |  |       if(category == "collect") { | 
		
	
		
			
				|  |  |  |  |         const res = await request({ | 
		
	
		
			
				|  |  |  |  |             url: "/flxai/api/robot/appaiplugin/getAllAiPlugin", | 
		
	
		
			
				|  |  |  |  |             method: "get", | 
		
	
		
			
				|  |  |  |  |             params: { | 
		
	
		
			
				|  |  |  |  |               userid: userId | 
		
	
		
			
				|  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  |         }) | 
		
	
		
			
				|  |  |  |  |         setStData(res?.data.map((item,index)=> { | 
		
	
		
			
				|  |  |  |  |             item.classify = 'collect'; | 
		
	
		
			
				|  |  |  |  |             return item | 
		
	
		
			
				|  |  |  |  |         })) | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         const res = await request({ | 
		
	
		
			
				|  |  |  |  |             url: "/flxai/api/robot/appaiplugin/getAllAiPlugin", | 
		
	
		
			
				|  |  |  |  |             method: "get", | 
		
	
		
			
				|  |  |  |  |             params: { | 
		
	
		
			
				|  |  |  |  |               userid: userId | 
		
	
		
			
				|  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  |         }) | 
		
	
		
			
				|  |  |  |  |         const array2Object = {}; | 
		
	
		
			
				|  |  |  |  |         res?.data?.forEach((item) => { | 
		
	
		
			
				|  |  |  |  |           array2Object[item.identifier] = item; | 
		
	
		
			
				|  |  |  |  |         }); | 
		
	
		
			
				|  |  |  |  |         console.log('chajian22222222222222222222222222222--------------') | 
		
	
		
			
				|  |  |  |  |         setStData(stData.map((item,index)=> { | 
		
	
		
			
				|  |  |  |  |             const matchingItem = array2Object[item.identifier]; | 
		
	
		
			
				|  |  |  |  |             if (matchingItem) { | 
		
	
		
			
				|  |  |  |  |               matchingItem.status = '1'; | 
		
	
		
			
				|  |  |  |  |               return matchingItem | 
		
	
		
			
				|  |  |  |  |             } else { | 
		
	
		
			
				|  |  |  |  |               item.status = '0'; | 
		
	
		
			
				|  |  |  |  |               return item | 
		
	
		
			
				|  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  |         })) | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     }; | 
		
	
		
			
				|  |  |  |  |     fetchData(); | 
		
	
		
			
				|  |  |  |  |   }, []); // 空数组[]意味着仅在组件挂载时调用一次
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   console.log('chajian999999999999999--------------',stData) | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   const handleClickCard = (item) => { | 
		
	
		
			
				|  |  |  |  |     console.log(item) | 
		
	
		
			
				|  |  |  |  |     router.push(urlJoin('/discover/plugin/', item.identifier)) | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  |   }, [items, mobile]); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   if (searchKeywords) { | 
		
	
		
			
				|  |  |  |  |     if (!items || items?.length === 0) return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />; | 
		
	
	
		
			
				
					|  |  |  | @ -96,7 +41,9 @@ const List = memo<ListProps>(({ category, mobile, searchKeywords, items = [] }) | 
		
	
		
			
				|  |  |  |  |           data={all} | 
		
	
		
			
				|  |  |  |  |           initialItemCount={24} | 
		
	
		
			
				|  |  |  |  |           itemContent={(_, item) => ( | 
		
	
		
			
				|  |  |  |  |               <Card onClick={() => handleClickCard(item)} showCategory variant={'compact'} {...item} /> | 
		
	
		
			
				|  |  |  |  |             <Link href={urlJoin('/discover/plugin/', item.identifier)} key={item.identifier}> | 
		
	
		
			
				|  |  |  |  |               <Card showCategory variant={'compact'} {...item} /> | 
		
	
		
			
				|  |  |  |  |             </Link> | 
		
	
		
			
				|  |  |  |  |           )} | 
		
	
		
			
				|  |  |  |  |           style={{ | 
		
	
		
			
				|  |  |  |  |             minHeight: '75vh', | 
		
	
	
		
			
				
					|  |  |  | @ -107,24 +54,13 @@ const List = memo<ListProps>(({ category, mobile, searchKeywords, items = [] }) | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   return ( | 
		
	
		
			
				|  |  |  |  |     <> | 
		
	
		
			
				|  |  |  |  |       {category == "collect"?( | 
		
	
		
			
				|  |  |  |  |         <> | 
		
	
		
			
				|  |  |  |  |           <Title tag={all.length}>收藏列表</Title> | 
		
	
		
			
				|  |  |  |  |           <Grid maxItemWidth={280} rows={4}> | 
		
	
		
			
				|  |  |  |  |             {all?.map((item) => ( | 
		
	
		
			
				|  |  |  |  |               // <Link href={urlJoin('/discover/assistant/', item.identifier)} key={item.identifier}>
 | 
		
	
		
			
				|  |  |  |  |                 <Card onClick={() => handleClickCard(item)} showCategory={!category} {...item} /> | 
		
	
		
			
				|  |  |  |  |               // </Link>
 | 
		
	
		
			
				|  |  |  |  |             ))} | 
		
	
		
			
				|  |  |  |  |           </Grid> | 
		
	
		
			
				|  |  |  |  |         </> | 
		
	
		
			
				|  |  |  |  |       ):( | 
		
	
		
			
				|  |  |  |  |     <> | 
		
	
		
			
				|  |  |  |  |       <Title>{t('plugins.recentSubmits')}</Title> | 
		
	
		
			
				|  |  |  |  |       <Grid maxItemWidth={280} rows={4}> | 
		
	
		
			
				|  |  |  |  |             {recent?.map((item) => ( | 
		
	
		
			
				|  |  |  |  |                 <Card onClick={() => handleClickCard(item)} showCategory={!category} {...item} /> | 
		
	
		
			
				|  |  |  |  |         {recent.map((item) => ( | 
		
	
		
			
				|  |  |  |  |           <Link href={urlJoin('/discover/plugin/', item.identifier)} key={item.identifier}> | 
		
	
		
			
				|  |  |  |  |             <Card showCategory={!category} {...item} /> | 
		
	
		
			
				|  |  |  |  |           </Link> | 
		
	
		
			
				|  |  |  |  |         ))} | 
		
	
		
			
				|  |  |  |  |       </Grid> | 
		
	
		
			
				|  |  |  |  |       {last && last?.length > 0 && ( | 
		
	
	
		
			
				
					|  |  |  | @ -134,7 +70,9 @@ const List = memo<ListProps>(({ category, mobile, searchKeywords, items = [] }) | 
		
	
		
			
				|  |  |  |  |             data={last} | 
		
	
		
			
				|  |  |  |  |             initialItemCount={12} | 
		
	
		
			
				|  |  |  |  |             itemContent={(_, item) => ( | 
		
	
		
			
				|  |  |  |  |                     <Card onClick={() => handleClickCard(item)} showCategory={!category} variant={'compact'} {...item} /> | 
		
	
		
			
				|  |  |  |  |               <Link href={urlJoin('/discover/plugin/', item.identifier)} key={item.identifier}> | 
		
	
		
			
				|  |  |  |  |                 <Card showCategory={!category} variant={'compact'} {...item} /> | 
		
	
		
			
				|  |  |  |  |               </Link> | 
		
	
		
			
				|  |  |  |  |             )} | 
		
	
		
			
				|  |  |  |  |             style={{ | 
		
	
		
			
				|  |  |  |  |               minHeight: '75vh', | 
		
	
	
		
			
				
					|  |  |  | @ -143,8 +81,6 @@ const List = memo<ListProps>(({ category, mobile, searchKeywords, items = [] }) | 
		
	
		
			
				|  |  |  |  |         </> | 
		
	
		
			
				|  |  |  |  |       )} | 
		
	
		
			
				|  |  |  |  |     </> | 
		
	
		
			
				|  |  |  |  |       )} | 
		
	
		
			
				|  |  |  |  |     </> | 
		
	
		
			
				|  |  |  |  |   ); | 
		
	
		
			
				|  |  |  |  | }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | 
 |