uni-tag.vue 2.8 KB

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