TabContent.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { ChatContext } from '@/app/chat-context';
  2. import { apiInterceptors, collectApp, newDialogue, unCollectApp } from '@/client/api';
  3. import BlurredCard from '@/new-components/common/blurredCard';
  4. import { IApp } from '@/types/app';
  5. import { StarFilled, StarOutlined } from '@ant-design/icons';
  6. import { Avatar, Empty, Spin } from 'antd';
  7. import Image from 'next/image';
  8. import { useRouter } from 'next/router';
  9. import React, { useContext } from 'react';
  10. import IconFont from '../common/Icon';
  11. const TabContent: React.FC<{ apps: IApp[]; loading: boolean; refresh: () => void; type: 'used' | 'recommend' }> = ({
  12. apps,
  13. refresh,
  14. loading,
  15. type,
  16. }) => {
  17. const collect = async (data: Record<string, any>) => {
  18. const [error] = await apiInterceptors(
  19. data.is_collected === 'true'
  20. ? unCollectApp({ app_code: data.app_code })
  21. : collectApp({ app_code: data.app_code }),
  22. );
  23. if (error) return;
  24. refresh();
  25. };
  26. const { setAgent: setAgentToChat, model, setCurrentDialogInfo } = useContext(ChatContext);
  27. const router = useRouter();
  28. const toChat = async (data: IApp) => {
  29. // 原生应用跳转
  30. if (data.team_mode === 'native_app') {
  31. const { chat_scene = '' } = data.team_context;
  32. const [, res] = await apiInterceptors(newDialogue({ chat_mode: chat_scene }));
  33. if (res) {
  34. setCurrentDialogInfo?.({
  35. chat_scene: res.chat_mode,
  36. app_code: data.app_code,
  37. });
  38. localStorage.setItem(
  39. 'cur_dialog_info',
  40. JSON.stringify({
  41. chat_scene: res.chat_mode,
  42. app_code: data.app_code,
  43. }),
  44. );
  45. router.push(`/chat?scene=${chat_scene}&id=${res.conv_uid}${model ? `&model=${model}` : ''}`);
  46. }
  47. } else {
  48. // 自定义应用
  49. const [, res] = await apiInterceptors(newDialogue({ chat_mode: 'chat_agent' }));
  50. if (res) {
  51. setCurrentDialogInfo?.({
  52. chat_scene: res.chat_mode,
  53. app_code: data.app_code,
  54. });
  55. localStorage.setItem(
  56. 'cur_dialog_info',
  57. JSON.stringify({
  58. chat_scene: res.chat_mode,
  59. app_code: data.app_code,
  60. }),
  61. );
  62. setAgentToChat?.(data.app_code);
  63. router.push(`/chat/?scene=chat_agent&id=${res.conv_uid}${model ? `&model=${model}` : ''}`);
  64. }
  65. }
  66. };
  67. if (loading) {
  68. return <Spin size='large' className='flex items-center justify-center h-full' spinning={loading} />;
  69. }
  70. return (
  71. <div className='flex flex-wrap mt-4 w-full overflow-y-auto '>
  72. {apps?.length > 0 ? (
  73. apps.map(item => (
  74. <BlurredCard
  75. key={item.app_code}
  76. name={item.app_name}
  77. description={item.app_describe}
  78. onClick={() => toChat(item)}
  79. RightTop={
  80. item.is_collected === 'true' ? (
  81. <StarFilled
  82. onClick={e => {
  83. e.stopPropagation();
  84. collect(item);
  85. }}
  86. style={{
  87. height: '21px',
  88. cursor: 'pointer',
  89. color: '#f9c533',
  90. }}
  91. />
  92. ) : (
  93. <StarOutlined
  94. onClick={e => {
  95. e.stopPropagation();
  96. collect(item);
  97. }}
  98. style={{
  99. height: '21px',
  100. cursor: 'pointer',
  101. }}
  102. />
  103. )
  104. }
  105. LeftBottom={
  106. <div className='flex gap-8 items-center text-gray-500 text-sm'>
  107. {item.owner_name && (
  108. <div className='flex gap-1 items-center'>
  109. <Avatar
  110. src={item?.owner_avatar_url}
  111. className='bg-gradient-to-tr from-[#31afff] to-[#1677ff] cursor-pointer'
  112. >
  113. {item.owner_name}
  114. </Avatar>
  115. <span>{item.owner_name}</span>
  116. </div>
  117. )}
  118. {/* 最近使用不展示热度值 */}
  119. {type !== 'used' && (
  120. <div className='flex items-start gap-1'>
  121. <IconFont type='icon-hot' className='text-lg' />
  122. <span className='text-[#878c93]'>{item.hot_value}</span>
  123. </div>
  124. )}
  125. </div>
  126. }
  127. scene={item?.team_context?.chat_scene || 'chat_agent'}
  128. />
  129. ))
  130. ) : (
  131. <Empty
  132. image={
  133. <Image src='/pictures/empty.png' alt='empty' width={142} height={133} className='w-[142px] h-[133px]' />
  134. }
  135. className='flex justify-center items-center w-full h-full min-h-[200px]'
  136. />
  137. )}
  138. </div>
  139. );
  140. };
  141. export default TabContent;