uni-tag.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view :class="[
  3. 'uni-tag--' + type,
  4. disabled === true || disabled === 'true' ? 'uni-tag--disabled' : '',
  5. inverted === true || inverted === 'true' ? type + '-uni-tag--inverted' : '',
  6. circle === true || circle === 'true' ? 'uni-tag--circle' : '',
  7. mark === true || mark === 'true' ? 'uni-tag--mark' : '',
  8. 'uni-tag--' + size
  9. ]" @click="onClick()" class="uni-tag" v-if="text">
  10. <text :class="[type === 'default' ? 'uni-tag--default':'uni-tag-text',inverted === true || inverted === 'true' ? 'uni-tag-text--'+type : '',size === 'small' ? 'uni-tag-text--small':'' ]">{{ text }}</text>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: "UniTag",
  16. props: {
  17. type: {
  18. // 标签类型default、primary、success、warning、error、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 scoped>
  64. .uni-tag {
  65. /* #ifndef APP-NVUE */
  66. display: flex;
  67. /* #endif */
  68. padding: 0px 16px;
  69. height: 30px;
  70. line-height: 30px;
  71. justify-content: center;
  72. color: #333;
  73. border-radius: 6rpx;
  74. background-color: #f8f8f8;
  75. border-width: 1rpx;
  76. border-style: solid;
  77. border-color: #f8f8f8;
  78. }
  79. .uni-tag--circle {
  80. border-radius: 15px;
  81. }
  82. .uni-tag--mark {
  83. border-top-left-radius: 0;
  84. border-bottom-left-radius: 0;
  85. border-top-right-radius: 15px;
  86. border-bottom-right-radius: 15px;
  87. }
  88. .uni-tag--disabled {
  89. opacity: 0.5;
  90. }
  91. .uni-tag--small {
  92. height: 20px;
  93. padding: 0px 8px;
  94. line-height: 20px;
  95. font-size: 24rpx;
  96. }
  97. .uni-tag--default {
  98. color: #333;
  99. font-size: 28rpx;
  100. }
  101. .uni-tag-text--small {
  102. font-size: 24rpx !important;
  103. }
  104. .uni-tag-text {
  105. color: #fff;
  106. font-size: 28rpx;
  107. }
  108. .uni-tag--default {
  109. color: #333;
  110. font-size: 28rpx;
  111. }
  112. .uni-tag-text--primary {
  113. color: #007aff !important;
  114. }
  115. .uni-tag-text--success {
  116. color: #4cd964 !important;
  117. }
  118. .uni-tag-text--warning {
  119. color: #f0ad4e !important;
  120. }
  121. .uni-tag-text--error {
  122. color: #dd524d !important;
  123. }
  124. .uni-tag--primary {
  125. color: #fff;
  126. background-color: #007aff;
  127. border-width: 1rpx;
  128. border-style: solid;
  129. border-color: #007aff;
  130. }
  131. .primary-uni-tag--inverted {
  132. color: #007aff;
  133. background-color: #ffffff;
  134. border-width: 1rpx;
  135. border-style: solid;
  136. border-color: #007aff;
  137. }
  138. .uni-tag--success {
  139. color: #fff;
  140. background-color: #4cd964;
  141. border-width: 1rpx;
  142. border-style: solid;
  143. border-color: #4cd964;
  144. }
  145. .success-uni-tag--inverted {
  146. color: #4cd964;
  147. background-color: #ffffff;
  148. border-width: 1rpx;
  149. border-style: solid;
  150. border-color: #4cd964;
  151. }
  152. .uni-tag--warning {
  153. color: #fff;
  154. background-color: #f0ad4e;
  155. border-width: 1rpx;
  156. border-style: solid;
  157. border-color: #f0ad4e;
  158. }
  159. .warning-uni-tag--inverted {
  160. color: #f0ad4e;
  161. background-color: #ffffff;
  162. border-width: 1rpx;
  163. border-style: solid;
  164. border-color: #f0ad4e;
  165. }
  166. .uni-tag--error {
  167. color: #fff;
  168. background-color: #dd524d;
  169. border-width: 1rpx;
  170. border-style: solid;
  171. border-color: #dd524d;
  172. }
  173. .error-uni-tag--inverted {
  174. color: #dd524d;
  175. background-color: #ffffff;
  176. border-width: 1rpx;
  177. border-style: solid;
  178. border-color: #dd524d;
  179. }
  180. .uni-tag--inverted {
  181. color: #333;
  182. background-color: #ffffff;
  183. border-width: 1rpx;
  184. border-style: solid;
  185. border-color: #f8f8f8;
  186. }
  187. </style>