SkeletonWrapper.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 { Skeleton } from '@douyinfe/semi-ui';
  17. const SkeletonWrapper = ({
  18. loading = false,
  19. type = 'text',
  20. count = 1,
  21. width = 60,
  22. height = 16,
  23. isMobile = false,
  24. className = '',
  25. children,
  26. ...props
  27. }) => {
  28. if (!loading) {
  29. return children;
  30. }
  31. // 导航链接骨架屏
  32. const renderNavigationSkeleton = () => {
  33. const skeletonLinkClasses = isMobile
  34. ? 'flex items-center gap-1 p-1 w-full rounded-md'
  35. : 'flex items-center gap-1 p-2 rounded-md';
  36. return Array(count)
  37. .fill(null)
  38. .map((_, index) => (
  39. <div key={index} className={skeletonLinkClasses}>
  40. <Skeleton
  41. loading={true}
  42. active
  43. placeholder={
  44. <Skeleton.Title
  45. active
  46. style={{ width: isMobile ? 40 : width, height }}
  47. />
  48. }
  49. />
  50. </div>
  51. ));
  52. };
  53. // 用户区域骨架屏 (头像 + 文本)
  54. const renderUserAreaSkeleton = () => {
  55. return (
  56. <div
  57. className={`flex items-center p-1 rounded-full bg-semi-color-fill-0 dark:bg-semi-color-fill-1 ${className}`}
  58. >
  59. <Skeleton
  60. loading={true}
  61. active
  62. placeholder={
  63. <Skeleton.Avatar active size='extra-small' className='shadow-sm' />
  64. }
  65. />
  66. <div className='ml-1.5 mr-1'>
  67. <Skeleton
  68. loading={true}
  69. active
  70. placeholder={
  71. <Skeleton.Title
  72. active
  73. style={{ width: isMobile ? 15 : width, height: 12 }}
  74. />
  75. }
  76. />
  77. </div>
  78. </div>
  79. );
  80. };
  81. // Logo图片骨架屏
  82. const renderImageSkeleton = () => {
  83. return (
  84. <Skeleton
  85. loading={true}
  86. active
  87. placeholder={
  88. <Skeleton.Image
  89. active
  90. className={`absolute inset-0 !rounded-full ${className}`}
  91. style={{ width: '100%', height: '100%' }}
  92. />
  93. }
  94. />
  95. );
  96. };
  97. // 系统名称骨架屏
  98. const renderTitleSkeleton = () => {
  99. return (
  100. <Skeleton
  101. loading={true}
  102. active
  103. placeholder={<Skeleton.Title active style={{ width, height: 24 }} />}
  104. />
  105. );
  106. };
  107. // 通用文本骨架屏
  108. const renderTextSkeleton = () => {
  109. return (
  110. <div className={className}>
  111. <Skeleton
  112. loading={true}
  113. active
  114. placeholder={<Skeleton.Title active style={{ width, height }} />}
  115. />
  116. </div>
  117. );
  118. };
  119. // 根据类型渲染不同的骨架屏
  120. switch (type) {
  121. case 'navigation':
  122. return renderNavigationSkeleton();
  123. case 'userArea':
  124. return renderUserAreaSkeleton();
  125. case 'image':
  126. return renderImageSkeleton();
  127. case 'title':
  128. return renderTitleSkeleton();
  129. case 'text':
  130. default:
  131. return renderTextSkeleton();
  132. }
  133. };
  134. export default SkeletonWrapper;