PricingVendorIntro.jsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { useState, useEffect, useMemo } from 'react';
  16. import { Card, Tag, Avatar, AvatarGroup, Typography } from '@douyinfe/semi-ui';
  17. import { getLobeHubIcon } from '../../../../../helpers';
  18. const { Paragraph } = Typography;
  19. const PricingVendorIntro = ({
  20. filterVendor,
  21. models = [],
  22. allModels = [],
  23. t
  24. }) => {
  25. // 轮播动效状态(只对全部供应商生效)
  26. const [currentOffset, setCurrentOffset] = useState(0);
  27. // 获取所有供应商信息
  28. const vendorInfo = useMemo(() => {
  29. const vendors = new Map();
  30. let unknownCount = 0;
  31. (allModels.length > 0 ? allModels : models).forEach(model => {
  32. if (model.vendor_name) {
  33. if (!vendors.has(model.vendor_name)) {
  34. vendors.set(model.vendor_name, {
  35. name: model.vendor_name,
  36. icon: model.vendor_icon,
  37. description: model.vendor_description,
  38. count: 0
  39. });
  40. }
  41. vendors.get(model.vendor_name).count++;
  42. } else {
  43. unknownCount++;
  44. }
  45. });
  46. const vendorList = Array.from(vendors.values()).sort((a, b) => a.name.localeCompare(b.name));
  47. if (unknownCount > 0) {
  48. vendorList.push({
  49. name: 'unknown',
  50. icon: null,
  51. description: t('包含来自未知或未标明供应商的AI模型,这些模型可能来自小型供应商或开源项目。'),
  52. count: unknownCount
  53. });
  54. }
  55. return vendorList;
  56. }, [allModels, models]);
  57. // 计算当前过滤器的模型数量
  58. const currentModelCount = models.length;
  59. // 设置轮播定时器(只对全部供应商且有足够头像时生效)
  60. useEffect(() => {
  61. if (filterVendor !== 'all' || vendorInfo.length <= 3) {
  62. setCurrentOffset(0); // 重置偏移
  63. return;
  64. }
  65. const interval = setInterval(() => {
  66. setCurrentOffset(prev => (prev + 1) % vendorInfo.length);
  67. }, 2000); // 每2秒切换一次
  68. return () => clearInterval(interval);
  69. }, [filterVendor, vendorInfo.length]);
  70. // 获取供应商描述信息(从后端数据中)
  71. const getVendorDescription = (vendorKey) => {
  72. if (vendorKey === 'all') {
  73. return t('查看所有可用的AI模型供应商,包括众多知名供应商的模型。');
  74. }
  75. if (vendorKey === 'unknown') {
  76. return t('包含来自未知或未标明供应商的AI模型,这些模型可能来自小型供应商或开源项目。');
  77. }
  78. const vendor = vendorInfo.find(v => v.name === vendorKey);
  79. return vendor?.description || t('该供应商提供多种AI模型,适用于不同的应用场景。');
  80. };
  81. // 为全部供应商创建特殊的头像组合
  82. const renderAllVendorsAvatar = () => {
  83. // 重新排列数组,让当前偏移量的头像在第一位
  84. const rotatedVendors = vendorInfo.length > 3 ? [
  85. ...vendorInfo.slice(currentOffset),
  86. ...vendorInfo.slice(0, currentOffset)
  87. ] : vendorInfo;
  88. // 如果没有供应商,显示占位符
  89. if (vendorInfo.length === 0) {
  90. return (
  91. <div className="min-w-16 h-16 rounded-2xl bg-white shadow-md flex items-center justify-center px-2">
  92. <Avatar size="default" color="transparent">
  93. AI
  94. </Avatar>
  95. </div>
  96. );
  97. }
  98. return (
  99. <div className="min-w-16 h-16 rounded-2xl bg-white shadow-md flex items-center justify-center px-2">
  100. <AvatarGroup
  101. maxCount={4}
  102. size="default"
  103. overlapFrom='end'
  104. key={currentOffset}
  105. renderMore={(restNumber) => (
  106. <Avatar
  107. size="default"
  108. style={{ backgroundColor: 'transparent', color: 'var(--semi-color-text-0)' }}
  109. alt={`${restNumber} more vendors`}
  110. >
  111. {`+${restNumber}`}
  112. </Avatar>
  113. )}
  114. >
  115. {rotatedVendors.map((vendor) => (
  116. <Avatar
  117. key={vendor.name}
  118. size="default"
  119. color="transparent"
  120. alt={vendor.name === 'unknown' ? t('未知供应商') : vendor.name}
  121. >
  122. {vendor.icon ?
  123. getLobeHubIcon(vendor.icon, 20) :
  124. (vendor.name === 'unknown' ? '?' : vendor.name.charAt(0).toUpperCase())
  125. }
  126. </Avatar>
  127. ))}
  128. </AvatarGroup>
  129. </div>
  130. );
  131. };
  132. // 为具体供应商渲染单个图标
  133. const renderVendorAvatar = (vendor) => (
  134. <div className="w-16 h-16 rounded-2xl bg-white shadow-md flex items-center justify-center">
  135. {vendor.icon ?
  136. getLobeHubIcon(vendor.icon, 40) :
  137. <Avatar size="large" color="transparent">
  138. {vendor.name === 'unknown' ? '?' : vendor.name.charAt(0).toUpperCase()}
  139. </Avatar>
  140. }
  141. </div>
  142. );
  143. // 如果是全部供应商
  144. if (filterVendor === 'all') {
  145. return (
  146. <div className='mb-4'>
  147. <Card className="!rounded-2xl with-pastel-balls" bodyStyle={{ padding: '16px' }}>
  148. <div className="flex items-start space-x-3 md:space-x-4">
  149. {/* 全部供应商的头像组合 */}
  150. <div className="flex-shrink-0">
  151. {renderAllVendorsAvatar()}
  152. </div>
  153. {/* 供应商信息 */}
  154. <div className="flex-1 min-w-0">
  155. <div className="flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3 mb-2">
  156. <h2 className="text-lg sm:text-xl font-bold text-gray-900 truncate">{t('全部供应商')}</h2>
  157. <Tag color="white" shape="circle" size="small" className="self-start sm:self-center">
  158. {t('共 {{count}} 个模型', { count: currentModelCount })}
  159. </Tag>
  160. </div>
  161. <Paragraph
  162. className="text-xs sm:text-sm text-gray-600 leading-relaxed !mb-0"
  163. ellipsis={{
  164. rows: 2,
  165. expandable: true,
  166. collapsible: true,
  167. collapseText: t('收起'),
  168. expandText: t('展开')
  169. }}
  170. >
  171. {getVendorDescription('all')}
  172. </Paragraph>
  173. </div>
  174. </div>
  175. </Card>
  176. </div>
  177. );
  178. }
  179. // 具体供应商
  180. const currentVendor = vendorInfo.find(v => v.name === filterVendor);
  181. if (!currentVendor) {
  182. return null;
  183. }
  184. const vendorDisplayName = currentVendor.name === 'unknown' ? t('未知供应商') : currentVendor.name;
  185. return (
  186. <div className='mb-4'>
  187. <Card className="!rounded-2xl with-pastel-balls" bodyStyle={{ padding: '16px' }}>
  188. <div className="flex items-start space-x-3 md:space-x-4">
  189. {/* 供应商图标 */}
  190. <div className="flex-shrink-0">
  191. {renderVendorAvatar(currentVendor)}
  192. </div>
  193. {/* 供应商信息 */}
  194. <div className="flex-1 min-w-0">
  195. <div className="flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3 mb-2">
  196. <h2 className="text-lg sm:text-xl font-bold text-gray-900 truncate">{vendorDisplayName}</h2>
  197. <Tag color="white" shape="circle" size="small" className="self-start sm:self-center">
  198. {t('共 {{count}} 个模型', { count: currentModelCount })}
  199. </Tag>
  200. </div>
  201. <Paragraph
  202. className="text-xs sm:text-sm text-gray-600 leading-relaxed !mb-0"
  203. ellipsis={{
  204. rows: 2,
  205. expandable: true,
  206. collapsible: true,
  207. collapseText: t('收起'),
  208. expandText: t('展开')
  209. }}
  210. >
  211. {currentVendor.description || getVendorDescription(currentVendor.name)}
  212. </Paragraph>
  213. </div>
  214. </div>
  215. </Card>
  216. </div>
  217. );
  218. };
  219. export default PricingVendorIntro;