AppCard.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { ChatContext } from '@/app/chat-context';
  2. import { apiInterceptors, newDialogue } from '@/client/api';
  3. import { IApp } from '@/types/app';
  4. import { Card, Tag, Tooltip, Typography } from 'antd';
  5. import Image from 'next/image';
  6. import { useRouter } from 'next/router';
  7. import React, { useContext } from 'react';
  8. const languageMap = {
  9. en: '英文',
  10. zh: '中文',
  11. };
  12. const AppCard: React.FC<{ data: IApp }> = ({ data }) => {
  13. const { setAgent: setAgentToChat, model } = useContext(ChatContext);
  14. const router = useRouter();
  15. return (
  16. <Card
  17. className='flex h-full flex-col bg-white rounded-lg dark:bg-[#232734] dark:text-white'
  18. hoverable
  19. bordered={false}
  20. onClick={async () => {
  21. const [, res] = await apiInterceptors(newDialogue({ chat_mode: 'chat_agent' }));
  22. if (res) {
  23. // 原生应用跳转
  24. if (data.team_mode === 'native_app') {
  25. const { chat_scene = '' } = data.team_context;
  26. router.push(`/chat?scene=${chat_scene}&id=${res.conv_uid}${model ? `&model=${model}` : ''}`);
  27. } else {
  28. setAgentToChat?.(data.app_code);
  29. router.push(`/chat/?scene=chat_agent&id=${res.conv_uid}${model ? `&model=${model}` : ''}`);
  30. }
  31. }
  32. }}
  33. >
  34. {/* title & functions */}
  35. <div className='flex items-center justify-between'>
  36. <div className='flex items-center '>
  37. <Image
  38. src={'/icons/node/vis.png'}
  39. width={44}
  40. height={44}
  41. alt={data.app_name}
  42. className='w-11 h-11 rounded-full mr-4 object-contain bg-white'
  43. />
  44. <div className='flex flex-col'>
  45. <Tooltip title={data?.app_name}>
  46. <span className='font-medium text-[16px] mb-1 line-clamp-1'>{data?.app_name}</span>
  47. </Tooltip>
  48. <div>
  49. <Tag color='default' className='text-xs'>
  50. {languageMap[data?.language]}
  51. </Tag>
  52. <Tag color='default' className='text-xs'>
  53. {data?.team_mode}
  54. </Tag>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. {/* content */}
  60. <Typography.Paragraph
  61. ellipsis={{
  62. rows: 2,
  63. tooltip: true,
  64. }}
  65. className='mt-4 text-sm text-gray-500 font-normal h-10'
  66. >
  67. {data?.app_describe}
  68. </Typography.Paragraph>
  69. </Card>
  70. );
  71. };
  72. export default AppCard;