index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <div class="round-comp">
  3. <template v-if="list.length">
  4. <div class="round" :class="`round--${length}`">
  5. <div class="round--center">
  6. <div v-for="(img, i) in list" :key="i" class="header">
  7. <van-image width="100%" height="100%" fit="cover" :src="img" />
  8. </div>
  9. </div>
  10. </div>
  11. </template>
  12. </div>
  13. </template>
  14. <script setup>
  15. const props = defineProps({
  16. size: {
  17. type: Number,
  18. default: 48
  19. },
  20. imgUrls: Array
  21. })
  22. const length = ref(0)
  23. const list = ref([])
  24. const initStyle = () => {
  25. const root = document.documentElement
  26. const size = props.size
  27. root.style.setProperty('--round-size', size + 'px')
  28. root.style.setProperty('--round-size-header', (size * 22) / 44 + 'px')
  29. root.style.setProperty('--round-size-sm-header', (size * 15) / 44 + 'px')
  30. }
  31. const initData = () => {
  32. list.value = (props.imgUrls ?? []).slice(0, 9)
  33. length.value = list.value.length
  34. }
  35. onMounted(() => {
  36. initStyle()
  37. initData()
  38. })
  39. </script>
  40. <style scoped lang="scss">
  41. .round-comp {
  42. width: var(--round-size);
  43. height: var(--round-size);
  44. background: #f7f8fa;
  45. border-radius: 100%;
  46. }
  47. .round {
  48. margin: 0px auto;
  49. width: var(--round-size);
  50. height: var(--round-size);
  51. background: #f7f8fa;
  52. border-radius: 100%;
  53. overflow: clip;
  54. position: relative;
  55. .round--center {
  56. height: 100%;
  57. position: absolute;
  58. display: grid;
  59. gap: 1px;
  60. align-items: center;
  61. justify-items: center;
  62. align-content: center;
  63. justify-content: center;
  64. top: 50%;
  65. left: 50%;
  66. transform: translate(-50%, -50%);
  67. .header {
  68. text-align: center;
  69. font-size: 12px;
  70. }
  71. }
  72. }
  73. .round--1 {
  74. .round--center {
  75. .header {
  76. width: var(--round-size);
  77. height: var(--round-size);
  78. }
  79. }
  80. }
  81. .round--2 {
  82. .round--center {
  83. grid-template-columns: auto auto;
  84. grid-template-rows: auto;
  85. .header {
  86. width: var(--round-size-header);
  87. height: var(--round-size-header);
  88. }
  89. }
  90. }
  91. .round--3 {
  92. .round--center {
  93. grid-template-columns: auto auto;
  94. grid-template-rows: auto auto;
  95. }
  96. .header {
  97. width: var(--round-size-header);
  98. height: var(--round-size-header);
  99. &:nth-child(1) {
  100. grid-column: 1 / span 2;
  101. }
  102. }
  103. }
  104. .round--4 {
  105. .round--center {
  106. grid-template-columns: auto auto;
  107. grid-template-rows: auto auto;
  108. .header {
  109. width: var(--round-size-header);
  110. height: var(--round-size-header);
  111. }
  112. }
  113. }
  114. .round--5 {
  115. .round--center {
  116. grid-template-columns: auto auto auto auto auto auto;
  117. grid-template-rows: auto auto;
  118. .header {
  119. width: var(--round-size-sm-header);
  120. height: var(--round-size-sm-header);
  121. grid-column: span 2;
  122. &:nth-child(1) {
  123. grid-column: 2 / span 2;
  124. }
  125. &:nth-child(2) {
  126. grid-column: 4 / span 2;
  127. }
  128. }
  129. }
  130. }
  131. .round--6 {
  132. .round--center {
  133. grid-template-columns: auto auto auto;
  134. grid-template-rows: auto auto;
  135. .header {
  136. width: var(--round-size-sm-header);
  137. height: var(--round-size-sm-header);
  138. }
  139. }
  140. }
  141. .round--7 {
  142. .round--center {
  143. grid-template-columns: auto auto auto;
  144. grid-template-rows: auto auto;
  145. .header {
  146. width: var(--round-size-sm-header);
  147. height: var(--round-size-sm-header);
  148. &:nth-child(1) {
  149. grid-column: 1 / span 3;
  150. }
  151. }
  152. }
  153. }
  154. .round--8 {
  155. .round--center {
  156. grid-template-columns: auto auto auto auto auto auto;
  157. grid-template-rows: auto auto;
  158. .header {
  159. width: var(--round-size-sm-header);
  160. height: var(--round-size-sm-header);
  161. grid-column: span 2;
  162. &:nth-child(1) {
  163. grid-column: 2 / span 2;
  164. }
  165. &:nth-child(2) {
  166. grid-column: 4 / span 2;
  167. }
  168. }
  169. }
  170. }
  171. .round--9 {
  172. .round--center {
  173. grid-template-columns: auto auto auto;
  174. grid-template-rows: auto auto;
  175. .header {
  176. width: var(--round-size-sm-header);
  177. height: var(--round-size-sm-header);
  178. }
  179. }
  180. }
  181. </style>