StampBadge.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div
  3. class="first-ring"
  4. v-bind="getBindValue"
  5. :class="getStampBadgeClass"
  6. :style="{ transform: `rotate(${rotate}deg)` }"
  7. >
  8. <div class="second-ring" :class="getStampBadgeClass">
  9. <div class="third-ring" :class="getStampBadgeClass">
  10. <div class="forth-ring" :class="getStampBadgeClass">
  11. <div class="content-rectangle ellipsis" :class="getStampBadgeClass">
  12. <span class="">{{ content }}</span>
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'StampBadge',
  22. // inheritAttrs: false,
  23. props: {
  24. color: {
  25. type: String,
  26. default: 'primary',
  27. validator: (v) =>
  28. ['primary', 'error', 'warning', 'success', 'info'].includes(v)
  29. },
  30. /**
  31. * stamp badge size.
  32. * @default: middle
  33. */
  34. size: {
  35. type: String,
  36. default: 'middle',
  37. validator: (v) => ['large', 'middle', 'small'].includes(v)
  38. },
  39. /**
  40. * stamp badge rotate deg.
  41. * @default: 0
  42. */
  43. rotate: { type: Number, default: 0 },
  44. content: { type: String, default: 'Unknown' }
  45. },
  46. computed: {
  47. getStampBadgeClass() {
  48. const { color, size } = this.$props
  49. return [
  50. {
  51. [`stamp-badge-${color}`]: !!color,
  52. [`stamp-badge-${size}`]: !!size
  53. }
  54. ]
  55. },
  56. getBindValue() {
  57. return { ...this.$attrs, ...this.$props }
  58. }
  59. },
  60. methods: {}
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .first-ring {
  65. border-radius: 100px;
  66. display: flex;
  67. justify-content: center;
  68. align-items: center;
  69. }
  70. .second-ring {
  71. background: #fff;
  72. border-radius: 100px;
  73. display: flex;
  74. justify-content: center;
  75. align-items: center;
  76. }
  77. .third-ring {
  78. border-radius: 100px;
  79. display: flex;
  80. justify-content: center;
  81. align-items: center;
  82. }
  83. .forth-ring {
  84. background: #fff;
  85. border-radius: 100px;
  86. display: flex;
  87. justify-content: center;
  88. align-items: center;
  89. position: relative;
  90. }
  91. .content-rectangle {
  92. background: #fff;
  93. font-weight: bold;
  94. text-align: center;
  95. position: absolute;
  96. }
  97. .ellipsis {
  98. overflow: hidden;
  99. white-space: nowrap;
  100. text-overflow: ellipsis;
  101. }
  102. // primary
  103. .stamp-badge-primary.first-ring {
  104. background: #1890ff;
  105. }
  106. .stamp-badge-primary.third-ring {
  107. background: #1890ff;
  108. }
  109. .stamp-badge-primary.content-rectangle {
  110. border: 1px solid #1890ff;
  111. color: #1890ff;
  112. }
  113. // success
  114. .stamp-badge-success.first-ring {
  115. background: #52c41a;
  116. }
  117. .stamp-badge-success.third-ring {
  118. background: #52c41a;
  119. }
  120. .stamp-badge-success.content-rectangle {
  121. border: 1px solid #52c41a;
  122. color: #52c41a;
  123. }
  124. // error
  125. .stamp-badge-error.first-ring {
  126. background: #ff4d4f;
  127. }
  128. .stamp-badge-error.third-ring {
  129. background: #ff4d4f;
  130. }
  131. .stamp-badge-error.content-rectangle {
  132. border: 1px solid #ff4d4f;
  133. color: #ff4d4f;
  134. }
  135. // warning
  136. .stamp-badge-warning.first-ring {
  137. background: #faad14;
  138. }
  139. .stamp-badge-warning.third-ring {
  140. background: #faad14;
  141. }
  142. .stamp-badge-warning.content-rectangle {
  143. border: 1px solid #faad14;
  144. color: #faad14;
  145. }
  146. // info
  147. .stamp-badge-info.first-ring {
  148. background: #ccc;
  149. }
  150. .stamp-badge-info.third-ring {
  151. background: #ccc;
  152. }
  153. .stamp-badge-info.content-rectangle {
  154. border: 1px solid #ccc;
  155. color: #ccc;
  156. }
  157. // large
  158. .stamp-badge-large.first-ring {
  159. width: 84px;
  160. height: 84px;
  161. }
  162. .stamp-badge-large.second-ring {
  163. width: 80px;
  164. height: 80px;
  165. }
  166. .stamp-badge-large.third-ring {
  167. width: 74px;
  168. height: 74px;
  169. }
  170. .stamp-badge-large.forth-ring {
  171. width: 64px;
  172. height: 64px;
  173. }
  174. .stamp-badge-large.content-rectangle {
  175. width: 90px;
  176. font-size: 1.2rem;
  177. }
  178. // middle
  179. .stamp-badge-middle.first-ring {
  180. width: 64px;
  181. height: 64px;
  182. }
  183. .stamp-badge-middle.second-ring {
  184. width: 60px;
  185. height: 60px;
  186. }
  187. .stamp-badge-middle.third-ring {
  188. width: 56px;
  189. height: 56px;
  190. }
  191. .stamp-badge-middle.forth-ring {
  192. width: 48px;
  193. height: 48px;
  194. }
  195. .stamp-badge-middle.content-rectangle {
  196. width: 70px;
  197. font-size: 1rem;
  198. }
  199. // small
  200. .stamp-badge-small.first-ring {
  201. width: 54px;
  202. height: 54px;
  203. }
  204. .stamp-badge-small.second-ring {
  205. width: 50px;
  206. height: 50px;
  207. }
  208. .stamp-badge-small.third-ring {
  209. width: 46px;
  210. height: 46px;
  211. }
  212. .stamp-badge-small.forth-ring {
  213. width: 38px;
  214. height: 38px;
  215. }
  216. .stamp-badge-small.content-rectangle {
  217. width: 60px;
  218. font-size: 0.8rem;
  219. }
  220. </style>