TagChip.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <view
  3. class="tag-chip"
  4. :class="['tag-chip--' + variant, { 'is-active': active }]"
  5. @select="onTap"
  6. >
  7. <text class="tag-chip__label">{{ label }}</text>
  8. </view>
  9. </template>
  10. <script>
  11. /**
  12. * TagChip — 单选/多选标签胶囊
  13. *
  14. * 抽取自 diet-checkin / exercise-checkin / diet-index / exercise-index 的
  15. * .tag-btn + .tag-active 重复样式(F 批 · 重复模式组件化)。
  16. *
  17. * Props:
  18. * label — 文案
  19. * active — 是否选中
  20. * variant — 'brand'(成长记录页,品牌橙选中态)| 'body'(身维度首页,身体维度色选中态)
  21. * Events:
  22. * select — 点击(用 select 而非 tap,避免与小程序原生 tap 冒泡重复触发)
  23. */
  24. export default {
  25. name: 'TagChip',
  26. props: {
  27. label: { type: String, default: '' },
  28. active: { type: Boolean, default: false },
  29. variant: { type: String, default: 'brand' }
  30. },
  31. methods: {
  32. onTap() {
  33. this.$emit('select')
  34. }
  35. }
  36. }
  37. </script>
  38. <style scoped lang="scss">
  39. .tag-chip {
  40. display: inline-flex;
  41. align-items: center;
  42. justify-content: center;
  43. padding: 12rpx 24rpx;
  44. border: 2rpx solid $facade-fill-4;
  45. border-radius: 30rpx;
  46. background: $facade-fill-ghost;
  47. transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
  48. }
  49. .tag-chip__label {
  50. font-size: 26rpx;
  51. color: $facade-text-body;
  52. }
  53. .tag-chip.is-active {
  54. border-color: $brand-primary;
  55. background: $fortune-1-tint;
  56. box-shadow: 0 4rpx 12rpx rgba(249, 115, 22, 0.15);
  57. }
  58. .tag-chip.is-active .tag-chip__label {
  59. color: $brand-primary;
  60. font-weight: 600;
  61. }
  62. /* ---- 身维度首页(饮食/运动)选中态 ---- */
  63. .tag-chip--body {
  64. border-width: 1rpx;
  65. border-color: $facade-border-soft;
  66. border-radius: 30rpx;
  67. background-color: $facade-fill-ghost;
  68. transition: none;
  69. }
  70. .tag-chip--body .tag-chip__label {
  71. font-size: 24rpx;
  72. }
  73. .tag-chip--body.is-active {
  74. border-color: $dim-body;
  75. background-color: $flat-card;
  76. box-shadow: none;
  77. }
  78. .tag-chip--body.is-active .tag-chip__label {
  79. color: $dim-body;
  80. font-weight: 400;
  81. }
  82. </style>