uni-tag.vue 5.2 KB

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