ApiInfoPanel.jsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 from 'react';
  16. import { Card, Avatar, Tag, Divider, Empty } from '@douyinfe/semi-ui';
  17. import { Server, Gauge, ExternalLink } from 'lucide-react';
  18. import { IllustrationConstruction, IllustrationConstructionDark } from '@douyinfe/semi-illustrations';
  19. import ScrollableContainer from '../common/ui/ScrollableContainer';
  20. const ApiInfoPanel = ({
  21. apiInfoData,
  22. handleCopyUrl,
  23. handleSpeedTest,
  24. CARD_PROPS,
  25. FLEX_CENTER_GAP2,
  26. ILLUSTRATION_SIZE,
  27. t
  28. }) => {
  29. return (
  30. <Card
  31. {...CARD_PROPS}
  32. className="bg-gray-50 border-0 !rounded-2xl"
  33. title={
  34. <div className={FLEX_CENTER_GAP2}>
  35. <Server size={16} />
  36. {t('API信息')}
  37. </div>
  38. }
  39. bodyStyle={{ padding: 0 }}
  40. >
  41. <ScrollableContainer maxHeight="24rem">
  42. {apiInfoData.length > 0 ? (
  43. apiInfoData.map((api) => (
  44. <React.Fragment key={api.id}>
  45. <div className="flex p-2 hover:bg-white rounded-lg transition-colors cursor-pointer">
  46. <div className="flex-shrink-0 mr-3">
  47. <Avatar
  48. size="extra-small"
  49. color={api.color}
  50. >
  51. {api.route.substring(0, 2)}
  52. </Avatar>
  53. </div>
  54. <div className="flex-1">
  55. <div className="flex flex-wrap items-center justify-between mb-1 w-full gap-2">
  56. <span className="text-sm font-medium text-gray-900 !font-bold break-all">
  57. {api.route}
  58. </span>
  59. <div className="flex items-center gap-1 mt-1 lg:mt-0">
  60. <Tag
  61. prefixIcon={<Gauge size={12} />}
  62. size="small"
  63. color="white"
  64. shape='circle'
  65. onClick={() => handleSpeedTest(api.url)}
  66. className="cursor-pointer hover:opacity-80 text-xs"
  67. >
  68. {t('测速')}
  69. </Tag>
  70. <Tag
  71. prefixIcon={<ExternalLink size={12} />}
  72. size="small"
  73. color="white"
  74. shape='circle'
  75. onClick={() => window.open(api.url, '_blank', 'noopener,noreferrer')}
  76. className="cursor-pointer hover:opacity-80 text-xs"
  77. >
  78. {t('跳转')}
  79. </Tag>
  80. </div>
  81. </div>
  82. <div
  83. className="!text-semi-color-primary break-all cursor-pointer hover:underline mb-1"
  84. onClick={() => handleCopyUrl(api.url)}
  85. >
  86. {api.url}
  87. </div>
  88. <div className="text-gray-500">
  89. {api.description}
  90. </div>
  91. </div>
  92. </div>
  93. <Divider />
  94. </React.Fragment>
  95. ))
  96. ) : (
  97. <div className="flex justify-center items-center py-8">
  98. <Empty
  99. image={<IllustrationConstruction style={ILLUSTRATION_SIZE} />}
  100. darkModeImage={<IllustrationConstructionDark style={ILLUSTRATION_SIZE} />}
  101. title={t('暂无API信息')}
  102. description={t('请联系管理员在系统设置中配置API信息')}
  103. />
  104. </div>
  105. )}
  106. </ScrollableContainer>
  107. </Card>
  108. );
  109. };
  110. export default ApiInfoPanel;