tui-badge.vue 2.4 KB

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