uni-badge.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <text v-if="text" :class="inverted ? 'uni-badge--' + type + ' uni-badge--' + size + ' uni-badge--' + type + '-inverted' : 'uni-badge--' + type + ' uni-badge--' + size"
  3. class="uni-badge" :style="width" @click="onClick()">{{ text }}</text>
  4. </template>
  5. <script>
  6. export default {
  7. name: 'UniBadge',
  8. props: {
  9. type: {
  10. type: String,
  11. default: 'default'
  12. },
  13. inverted: {
  14. type: Boolean,
  15. default: false
  16. },
  17. text: {
  18. type: [String,Number],
  19. default: ''
  20. },
  21. size: {
  22. // small.normal
  23. type: String,
  24. default: 'normal'
  25. }
  26. },
  27. data() {
  28. return {
  29. width: `display: inline-block;width: ${String(this.text).length * 15 + 25}rpx`
  30. };
  31. },
  32. methods: {
  33. onClick() {
  34. this.$emit('click');
  35. }
  36. }
  37. };
  38. </script>
  39. <style lang="scss" scoped>
  40. $bage-size: 12px;
  41. $bage-small: scale(0.8);
  42. $bage-height: 40rpx;
  43. .uni-badge {
  44. /* #ifndef APP-PLUS */
  45. display: flex;
  46. /* #endif */
  47. flex-direction: row;
  48. height: $bage-height;
  49. line-height: $bage-height;
  50. color: $uni-text-color;
  51. border-radius: 100px;
  52. background-color: $uni-bg-color-hover;
  53. background-color: transparent;
  54. text-align: center;
  55. font-family: 'Helvetica Neue', Helvetica, sans-serif;
  56. font-size: $bage-size;
  57. padding: 0;
  58. }
  59. .uni-badge--inverted {
  60. padding: 0 5px 0 0;
  61. color: $uni-bg-color-hover;
  62. }
  63. .uni-badge--default {
  64. color: $uni-text-color;
  65. background-color: $uni-bg-color-hover;
  66. }
  67. .uni-badge--default-inverted {
  68. color: $uni-text-color-grey;
  69. background-color: transparent;
  70. }
  71. .uni-badge--primary {
  72. color: $uni-text-color-inverse;
  73. background-color: $uni-color-primary;
  74. }
  75. .uni-badge--primary-inverted {
  76. color: $uni-color-primary;
  77. background-color: transparent;
  78. }
  79. .uni-badge--success {
  80. color: $uni-text-color-inverse;
  81. background-color: $uni-color-success;
  82. }
  83. .uni-badge--success-inverted {
  84. color: $uni-color-success;
  85. background-color: transparent;
  86. }
  87. .uni-badge--warning {
  88. color: $uni-text-color-inverse;
  89. background-color: $uni-color-warning;
  90. }
  91. .uni-badge--warning-inverted {
  92. color: $uni-color-warning;
  93. background-color: transparent;
  94. }
  95. .uni-badge--error {
  96. color: $uni-text-color-inverse;
  97. background-color: $uni-color-error;
  98. }
  99. .uni-badge--error-inverted {
  100. color: $uni-color-error;
  101. background-color: transparent;
  102. }
  103. .uni-badge--small {
  104. transform: $bage-small;
  105. transform-origin: center center;
  106. }
  107. </style>