uni-tag.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. /**
  15. * Tag 标签
  16. * @description 用于展示1个或多个文字标签,可点击切换选中、不选中的状态
  17. * @tutorial https://ext.dcloud.net.cn/plugin?id=35
  18. * @property {String} text 标签内容
  19. * @property {String} size = [normal|small] 大小尺寸
  20. * @value normal 正常
  21. * @value small 小尺寸
  22. * @property {String} type = [default|primary|success|warning|error|royal] 颜色类型
  23. * @value default 灰色
  24. * @value primary 蓝色
  25. * @value success 绿色
  26. * @value warning 黄色
  27. * @value error 红色
  28. * @value royal 紫色
  29. * @property {Boolean} disabled = [true|false] 是否为禁用状态
  30. * @property {Boolean} inverted = [true|false] 是否无需背景颜色(空心标签)
  31. * @property {Boolean} circle = [true|false] 是否为圆角
  32. * @event {Function} click 点击 Tag 触发事件
  33. */
  34. export default {
  35. name: "UniTag",
  36. props: {
  37. type: {
  38. // 标签类型default、primary、success、warning、error、royal
  39. type: String,
  40. default: "default"
  41. },
  42. size: {
  43. // 标签大小 normal, small
  44. type: String,
  45. default: "normal"
  46. },
  47. // 标签内容
  48. text: {
  49. type: String,
  50. default: ""
  51. },
  52. disabled: {
  53. // 是否为禁用状态
  54. type: [Boolean, String],
  55. default: false
  56. },
  57. inverted: {
  58. // 是否为空心
  59. type: [Boolean, String],
  60. default: false
  61. },
  62. circle: {
  63. // 是否为圆角样式
  64. type: [Boolean, String],
  65. default: false
  66. },
  67. mark: {
  68. // 是否为标记样式
  69. type: [Boolean, String],
  70. default: false
  71. }
  72. },
  73. methods: {
  74. onClick() {
  75. if (this.disabled === true || this.disabled === "true") {
  76. return;
  77. }
  78. this.$emit("click");
  79. }
  80. }
  81. };
  82. </script>
  83. <style scoped>
  84. .uni-tag {
  85. /* #ifndef APP-NVUE */
  86. display: flex;
  87. /* #endif */
  88. padding: 0px 16px;
  89. height: 30px;
  90. line-height: 30px;
  91. justify-content: center;
  92. color: #333;
  93. border-radius: 3px;
  94. background-color: #f8f8f8;
  95. border-width: 1rpx;
  96. border-style: solid;
  97. border-color: #f8f8f8;
  98. }
  99. .uni-tag--circle {
  100. border-radius: 15px;
  101. }
  102. .uni-tag--mark {
  103. border-top-left-radius: 0;
  104. border-bottom-left-radius: 0;
  105. border-top-right-radius: 15px;
  106. border-bottom-right-radius: 15px;
  107. }
  108. .uni-tag--disabled {
  109. opacity: 0.5;
  110. }
  111. .uni-tag--small {
  112. height: 20px;
  113. padding: 0px 8px;
  114. line-height: 20px;
  115. font-size: 12px;
  116. }
  117. .uni-tag--default {
  118. color: #333;
  119. font-size: 14px;
  120. }
  121. .uni-tag-text--small {
  122. font-size: 12px !important;
  123. }
  124. .uni-tag-text {
  125. color: #fff;
  126. font-size: 14px;
  127. }
  128. .uni-tag-text--primary {
  129. color: #007aff !important;
  130. }
  131. .uni-tag-text--success {
  132. color: #4cd964 !important;
  133. }
  134. .uni-tag-text--warning {
  135. color: #f0ad4e !important;
  136. }
  137. .uni-tag-text--error {
  138. color: #dd524d !important;
  139. }
  140. .uni-tag--primary {
  141. color: #fff;
  142. background-color: #007aff;
  143. border-width: 1rpx;
  144. border-style: solid;
  145. border-color: #007aff;
  146. }
  147. .primary-uni-tag--inverted {
  148. color: #007aff;
  149. background-color: #ffffff;
  150. border-width: 1rpx;
  151. border-style: solid;
  152. border-color: #007aff;
  153. }
  154. .uni-tag--success {
  155. color: #fff;
  156. background-color: #4cd964;
  157. border-width: 1rpx;
  158. border-style: solid;
  159. border-color: #4cd964;
  160. }
  161. .success-uni-tag--inverted {
  162. color: #4cd964;
  163. background-color: #ffffff;
  164. border-width: 1rpx;
  165. border-style: solid;
  166. border-color: #4cd964;
  167. }
  168. .uni-tag--warning {
  169. color: #fff;
  170. background-color: #f0ad4e;
  171. border-width: 1rpx;
  172. border-style: solid;
  173. border-color: #f0ad4e;
  174. }
  175. .warning-uni-tag--inverted {
  176. color: #f0ad4e;
  177. background-color: #ffffff;
  178. border-width: 1rpx;
  179. border-style: solid;
  180. border-color: #f0ad4e;
  181. }
  182. .uni-tag--error {
  183. color: #fff;
  184. background-color: #dd524d;
  185. border-width: 1rpx;
  186. border-style: solid;
  187. border-color: #dd524d;
  188. }
  189. .error-uni-tag--inverted {
  190. color: #dd524d;
  191. background-color: #ffffff;
  192. border-width: 1rpx;
  193. border-style: solid;
  194. border-color: #dd524d;
  195. }
  196. .uni-tag--inverted {
  197. color: #333;
  198. background-color: #ffffff;
  199. border-width: 1rpx;
  200. border-style: solid;
  201. border-color: #f8f8f8;
  202. }
  203. </style>