fs-tag.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view
  3. class="fs-tag"
  4. :class="[
  5. {
  6. 'fs-tag-round': round,
  7. 'fs-tag-plain': plain,
  8. 'fs-tag-mark': mark,
  9. 'fs-tag-mark-reverse': markReverse,
  10. 'fs-tag-none': closed
  11. },
  12. 'fs-tag-' + size,
  13. 'bg-' + type
  14. ]"
  15. :style="[{ color: color, backgroundColor: bgColor }, customStyle]"
  16. >
  17. <slot></slot>
  18. <fs-icon class="fs-tag-close" size="13px" type="icon-close" v-if="closable" @click="handleClosed"></fs-icon>
  19. </view>
  20. </template>
  21. <script>
  22. /**
  23. * 标签组件
  24. * @description 标签组件
  25. * @property {String} size = [default | medium | large] 标签大小
  26. * @property {String} color 文字颜色
  27. * @property {String} bgColor 背景色
  28. * @property {Boolean} plain 是否镂空
  29. * @property {Boolean} mark 标记
  30. * @property {Boolean} markReverse 标记反转
  31. * @property {Boolean} round 圆角
  32. * @property {Boolean} closable 标签是否可移除
  33. * @property {Object} customStyle 标签自定义样式
  34. * @property {String} type = [primary | danger | warning | info | success | default] 标签颜色类型
  35. */
  36. export default {
  37. name: 'fs-tag'
  38. }
  39. </script>
  40. <script setup>
  41. import { ref } from 'vue'
  42. const props = defineProps({
  43. plain: Boolean,
  44. round: Boolean,
  45. mark: Boolean,
  46. markReverse: Boolean,
  47. closable: Boolean,
  48. type: {
  49. type: String,
  50. default: 'primary',
  51. validator(value) {
  52. return ['primary', 'success', 'info', 'warning', 'danger', 'default'].includes(value)
  53. }
  54. },
  55. color: String,
  56. bgColor: String,
  57. size: {
  58. type: String,
  59. default: 'default',
  60. validator(value) {
  61. return ['default', 'medium', 'large'].includes(value)
  62. }
  63. },
  64. customStyle: {
  65. type: Object,
  66. default() {
  67. return {}
  68. }
  69. }
  70. })
  71. const closed = ref(false)
  72. const handleClosed = () => {
  73. closed.value = true
  74. }
  75. </script>
  76. <style lang="scss" scoped>
  77. .fs-tag {
  78. display: inline-flex;
  79. height: 38rpx;
  80. line-height: 38rpx;
  81. padding: 0 10rpx;
  82. font-size: 11px;
  83. color: #fff;
  84. vertical-align: middle;
  85. border-radius: 4rpx;
  86. align-items: center;
  87. white-space: nowrap;
  88. &-plain {
  89. background-color: transparent !important;
  90. line-height: 32rpx;
  91. border: 2rpx solid currentColor;
  92. &.bg-default {
  93. color: var(--disabled);
  94. }
  95. &.bg-primary {
  96. color: var(--primary);
  97. }
  98. &.bg-success {
  99. color: var(--success);
  100. }
  101. &.bg-warning {
  102. color: var(--warning);
  103. }
  104. &.bg-info {
  105. color: var(--info);
  106. }
  107. &.bg-danger {
  108. color: var(--danger);
  109. }
  110. }
  111. &-round {
  112. border-radius: 30rpx;
  113. }
  114. &-mark {
  115. border-radius: 0 25rpx 25rpx 0;
  116. }
  117. &-mark-reverse {
  118. border-radius: 25rpx 0 0 25rpx;
  119. }
  120. &-medium {
  121. font-size: 12px;
  122. height: 48rpx;
  123. line-height: 48rpx;
  124. padding: 0 20rpx;
  125. &.plain {
  126. line-height: 48rpx;
  127. }
  128. }
  129. &-large {
  130. font-size: 13px;
  131. height: 58rpx;
  132. line-height: 58rpx;
  133. padding: 0 30rpx;
  134. &.fs-tag-plain {
  135. line-height: 58rpx;
  136. }
  137. &.fs-tag-mark-reverse {
  138. border-radius: 50rpx 0 0 50rpx;
  139. }
  140. }
  141. &-close {
  142. margin-left: 8rpx;
  143. }
  144. &-none {
  145. display: none;
  146. }
  147. }
  148. .bg-default {
  149. background-color: #cfcfcf;
  150. }
  151. </style>