uni-tag.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view v-if="text" :class="[disabled ? 'uni-tag--disabled' : '',inverted ? 'uni-tag--inverted' : '',circle ? 'uni-tag--circle' : '', mark ? 'uni-tag--mark' : '', 'uni-tag--' + size, 'uni-tag--' + type]" class="uni-tag" @click="_onClick">{{ text }}</view>
  3. </template>
  4. <script>
  5. export default {
  6. name: 'UniTag',
  7. props: {
  8. type: { // 标签类型default、primary、success、warning、danger、royal
  9. type: String,
  10. default: 'default'
  11. },
  12. size: { // 标签大小 normal, small
  13. type: String,
  14. default: 'normal'
  15. },
  16. text: {
  17. type: String,
  18. default: ''
  19. }, // 标签内容
  20. disabled: { // 是否为禁用状态
  21. type: Boolean,
  22. default: false
  23. },
  24. inverted: { // 是否为空心
  25. type: Boolean,
  26. default: false
  27. },
  28. circle: { // 是否为圆角样式
  29. type: Boolean,
  30. default: false
  31. },
  32. mark: { // 是否为标记样式
  33. type: Boolean,
  34. default: false
  35. }
  36. },
  37. methods: {
  38. _onClick() {
  39. if (this.disabled) {
  40. return
  41. }
  42. this.$emit('click')
  43. }
  44. }
  45. }
  46. </script>
  47. <style>
  48. @charset "UTF-8";
  49. .uni-tag {
  50. box-sizing: border-box;
  51. padding: 0 32upx;
  52. height: 60upx;
  53. line-height: calc(60upx - 2px);
  54. font-size: 28upx;
  55. display: inline-flex;
  56. align-items: center;
  57. color: #333;
  58. border-radius: 6upx;
  59. background-color: #f8f8f8;
  60. border: 1px solid #f8f8f8
  61. }
  62. .uni-tag--circle {
  63. border-radius: 30upx
  64. }
  65. .uni-tag--mark {
  66. border-radius: 0 30upx 30upx 0
  67. }
  68. .uni-tag--disabled {
  69. opacity: .5
  70. }
  71. .uni-tag--small {
  72. height: 40upx;
  73. padding: 0 16upx;
  74. line-height: calc(40upx - 2px);
  75. font-size: 24upx
  76. }
  77. .uni-tag--primary {
  78. color: #fff;
  79. background-color: #007aff;
  80. border: 1px solid #007aff
  81. }
  82. .uni-tag--primary.uni-tag--inverted {
  83. color: #007aff;
  84. background-color: #fff;
  85. border: 1px solid #007aff
  86. }
  87. .uni-tag--success {
  88. color: #fff;
  89. background-color: #4cd964;
  90. border: 1px solid #4cd964
  91. }
  92. .uni-tag--success.uni-tag--inverted {
  93. color: #4cd964;
  94. background-color: #fff;
  95. border: 1px solid #4cd964
  96. }
  97. .uni-tag--warning {
  98. color: #fff;
  99. background-color: #f0ad4e;
  100. border: 1px solid #f0ad4e
  101. }
  102. .uni-tag--warning.uni-tag--inverted {
  103. color: #f0ad4e;
  104. background-color: #fff;
  105. border: 1px solid #f0ad4e
  106. }
  107. .uni-tag--error {
  108. color: #fff;
  109. background-color: #dd524d;
  110. border: 1px solid #dd524d
  111. }
  112. .uni-tag--error.uni-tag--inverted {
  113. color: #dd524d;
  114. background-color: #fff;
  115. border: 1px solid #dd524d
  116. }
  117. .uni-tag--inverted {
  118. color: #333;
  119. background-color: #fff;
  120. border: 1px solid #f8f8f8
  121. }
  122. </style>