UptimePanel.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 {
  17. Card,
  18. Button,
  19. Spin,
  20. Tabs,
  21. TabPane,
  22. Tag,
  23. Empty,
  24. } from '@douyinfe/semi-ui';
  25. import { Gauge, RefreshCw } from 'lucide-react';
  26. import {
  27. IllustrationConstruction,
  28. IllustrationConstructionDark,
  29. } from '@douyinfe/semi-illustrations';
  30. import ScrollableContainer from '../common/ui/ScrollableContainer';
  31. const UptimePanel = ({
  32. uptimeData,
  33. uptimeLoading,
  34. activeUptimeTab,
  35. setActiveUptimeTab,
  36. loadUptimeData,
  37. uptimeLegendData,
  38. renderMonitorList,
  39. CARD_PROPS,
  40. ILLUSTRATION_SIZE,
  41. t,
  42. }) => {
  43. return (
  44. <Card
  45. {...CARD_PROPS}
  46. className='shadow-sm !rounded-2xl lg:col-span-1'
  47. title={
  48. <div className='flex items-center justify-between w-full gap-2'>
  49. <div className='flex items-center gap-2'>
  50. <Gauge size={16} />
  51. {t('服务可用性')}
  52. </div>
  53. <Button
  54. icon={<RefreshCw size={14} />}
  55. onClick={loadUptimeData}
  56. loading={uptimeLoading}
  57. size='small'
  58. theme='borderless'
  59. type='tertiary'
  60. className='text-gray-500 hover:text-blue-500 hover:bg-blue-50 !rounded-full'
  61. />
  62. </div>
  63. }
  64. bodyStyle={{ padding: 0 }}
  65. >
  66. {/* 内容区域 */}
  67. <div className='relative'>
  68. <Spin spinning={uptimeLoading}>
  69. {uptimeData.length > 0 ? (
  70. uptimeData.length === 1 ? (
  71. <ScrollableContainer maxHeight='24rem'>
  72. {renderMonitorList(uptimeData[0].monitors)}
  73. </ScrollableContainer>
  74. ) : (
  75. <Tabs
  76. type='card'
  77. collapsible
  78. activeKey={activeUptimeTab}
  79. onChange={setActiveUptimeTab}
  80. size='small'
  81. >
  82. {uptimeData.map((group, groupIdx) => (
  83. <TabPane
  84. tab={
  85. <span className='flex items-center gap-2'>
  86. <Gauge size={14} />
  87. {group.categoryName}
  88. <Tag
  89. color={
  90. activeUptimeTab === group.categoryName
  91. ? 'red'
  92. : 'grey'
  93. }
  94. size='small'
  95. shape='circle'
  96. >
  97. {group.monitors ? group.monitors.length : 0}
  98. </Tag>
  99. </span>
  100. }
  101. itemKey={group.categoryName}
  102. key={groupIdx}
  103. >
  104. <ScrollableContainer maxHeight='21.5rem'>
  105. {renderMonitorList(group.monitors)}
  106. </ScrollableContainer>
  107. </TabPane>
  108. ))}
  109. </Tabs>
  110. )
  111. ) : (
  112. <div className='flex justify-center items-center py-8'>
  113. <Empty
  114. image={<IllustrationConstruction style={ILLUSTRATION_SIZE} />}
  115. darkModeImage={
  116. <IllustrationConstructionDark style={ILLUSTRATION_SIZE} />
  117. }
  118. title={t('暂无监控数据')}
  119. description={t('请联系管理员在系统设置中配置Uptime')}
  120. />
  121. </div>
  122. )}
  123. </Spin>
  124. </div>
  125. {/* 图例 */}
  126. {uptimeData.length > 0 && (
  127. <div className='p-3 bg-gray-50 rounded-b-2xl'>
  128. <div className='flex flex-wrap gap-3 text-xs justify-center'>
  129. {uptimeLegendData.map((legend, index) => (
  130. <div key={index} className='flex items-center gap-1'>
  131. <div
  132. className='w-2 h-2 rounded-full'
  133. style={{ backgroundColor: legend.color }}
  134. />
  135. <span className='text-gray-600'>{legend.label}</span>
  136. </div>
  137. ))}
  138. </div>
  139. </div>
  140. )}
  141. </Card>
  142. );
  143. };
  144. export default UptimePanel;