ModelsTable.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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, { useMemo } from 'react';
  16. import { Empty } from '@douyinfe/semi-ui';
  17. import CardTable from '../../common/ui/CardTable.js';
  18. import {
  19. IllustrationNoResult,
  20. IllustrationNoResultDark,
  21. } from '@douyinfe/semi-illustrations';
  22. import { getModelsColumns } from './ModelsColumnDefs.js';
  23. const ModelsTable = (modelsData) => {
  24. const {
  25. models,
  26. loading,
  27. activePage,
  28. pageSize,
  29. modelCount,
  30. compactMode,
  31. handlePageChange,
  32. handlePageSizeChange,
  33. rowSelection,
  34. handleRow,
  35. manageModel,
  36. setEditingModel,
  37. setShowEdit,
  38. refresh,
  39. vendorMap,
  40. t,
  41. } = modelsData;
  42. // Get all columns
  43. const columns = useMemo(() => {
  44. return getModelsColumns({
  45. t,
  46. manageModel,
  47. setEditingModel,
  48. setShowEdit,
  49. refresh,
  50. vendorMap,
  51. });
  52. }, [
  53. t,
  54. manageModel,
  55. setEditingModel,
  56. setShowEdit,
  57. refresh,
  58. ]);
  59. // Handle compact mode by removing fixed positioning
  60. const tableColumns = useMemo(() => {
  61. return compactMode ? columns.map(col => {
  62. if (col.dataIndex === 'operate') {
  63. const { fixed, ...rest } = col;
  64. return rest;
  65. }
  66. return col;
  67. }) : columns;
  68. }, [compactMode, columns]);
  69. return (
  70. <CardTable
  71. columns={tableColumns}
  72. dataSource={models}
  73. scroll={compactMode ? undefined : { x: 'max-content' }}
  74. pagination={{
  75. currentPage: activePage,
  76. pageSize: pageSize,
  77. total: modelCount,
  78. showSizeChanger: true,
  79. pageSizeOptions: [10, 20, 50, 100],
  80. onPageSizeChange: handlePageSizeChange,
  81. onPageChange: handlePageChange,
  82. }}
  83. hidePagination={true}
  84. loading={loading}
  85. rowSelection={rowSelection}
  86. onRow={handleRow}
  87. empty={
  88. <Empty
  89. image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
  90. darkModeImage={<IllustrationNoResultDark style={{ width: 150, height: 150 }} />}
  91. description={t('搜索无结果')}
  92. style={{ padding: 30 }}
  93. />
  94. }
  95. className="rounded-xl overflow-hidden"
  96. size="middle"
  97. />
  98. );
  99. };
  100. export default ModelsTable;