tui-badge.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view :class="[dot ? 'tui-badge-dot' : 'tui-badge', 'tui-' + type, !dot ? 'tui-badge-scale' : '']" :style="{ top: top, right: right, position: absolute ? 'absolute' : 'static', transform: getStyle, margin: margin }"
  3. @tap="handleClick">
  4. <slot></slot>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'tuiBadge',
  10. props: {
  11. //primary,warning,green,danger,white,black,gray,white_red
  12. type: {
  13. type: String,
  14. default: 'primary'
  15. },
  16. //是否是圆点
  17. dot: {
  18. type: Boolean,
  19. default: false
  20. },
  21. margin: {
  22. type: String,
  23. default: '0'
  24. },
  25. //是否绝对定位
  26. absolute: {
  27. type: Boolean,
  28. default: false
  29. },
  30. top: {
  31. type: String,
  32. default: '-8rpx'
  33. },
  34. right: {
  35. type: String,
  36. default: '0'
  37. },
  38. //缩放比例
  39. scaleRatio: {
  40. type: Number,
  41. default: 1
  42. },
  43. //水平方向移动距离
  44. translateX: {
  45. type: String,
  46. default: '0'
  47. }
  48. },
  49. computed: {
  50. getStyle() {
  51. return `scale(${this.scaleRatio}) translateX(${this.translateX})`;
  52. }
  53. },
  54. methods: {
  55. handleClick() {
  56. this.$emit('click', {});
  57. }
  58. }
  59. };
  60. </script>
  61. <style scoped>
  62. /* color start*/
  63. .tui-primary {
  64. background-color: #5677fc;
  65. color: #fff;
  66. }
  67. .tui-danger {
  68. background-color: #ed3f14;
  69. color: #fff;
  70. }
  71. .tui-red {
  72. background-color: #F74D54;
  73. color: #fff;
  74. }
  75. .tui-warning {
  76. background-color: #ff7900;
  77. color: #fff;
  78. }
  79. .tui-green {
  80. background-color: #19be6b;
  81. color: #fff;
  82. }
  83. .tui-white {
  84. background-color: #fff;
  85. color: #333;
  86. }
  87. .tui-white_red {
  88. background-color: #fff;
  89. color: #F74D54;
  90. }
  91. .tui-white_primary {
  92. background-color: #fff;
  93. color: #5677fc;
  94. }
  95. .tui-white_green {
  96. background-color: #fff;
  97. color: #19be6b;
  98. }
  99. .tui-white_warning {
  100. background-color: #fff;
  101. color: #ff7900;
  102. }
  103. .tui-black {
  104. background-color: #000;
  105. color: #fff;
  106. }
  107. .tui-gray {
  108. background-color: #ededed;
  109. color: #999;
  110. }
  111. /* color end*/
  112. /* badge start*/
  113. .tui-badge-dot {
  114. height: 8px;
  115. width: 8px;
  116. border-radius: 50%;
  117. }
  118. .tui-badge {
  119. font-size: 24rpx;
  120. line-height: 24rpx;
  121. height: 36rpx;
  122. min-width: 36rpx;
  123. padding: 0 10rpx;
  124. box-sizing: border-box;
  125. border-radius: 100rpx;
  126. display: flex;
  127. align-items: center;
  128. justify-content: center;
  129. z-index: 10;
  130. }
  131. .tui-badge-scale {
  132. transform-origin: center center;
  133. }
  134. /* badge end*/
  135. </style>