TagBar.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <!-- 单选标签选择按钮条,可显示一行标签,然后高亮选中项 -->
  3. <div class="d-flex flex-row flex-wrap">
  4. <div
  5. :class="[
  6. 'tag-button',
  7. { 'active': tag.id === selectedTag },
  8. ]"
  9. v-for="tag in tags"
  10. :key="tag.id"
  11. @click="emit('update:selectedTag', tag.id ?? tag)"
  12. >
  13. {{ tag.name?? tag }}
  14. </div>
  15. </div>
  16. </template>
  17. <script setup lang="ts">
  18. import type { PropType } from 'vue';
  19. defineProps({
  20. /**
  21. * 标签列表
  22. */
  23. tags: {
  24. type: Object as PropType<Array<{
  25. id: number|string,
  26. name: string,
  27. }>>,
  28. required: true,
  29. },
  30. /**
  31. * 选中的标签,可双向绑定
  32. */
  33. selectedTag: {
  34. type: [Number,String],
  35. default: null,
  36. }
  37. })
  38. const emit = defineEmits([
  39. "update:selectedTag"
  40. ])
  41. </script>
  42. <style lang="scss">
  43. @use '@/assets/scss/colors.scss' as *;
  44. .tag-button {
  45. display: flex;
  46. flex-direction: row;
  47. align-items: center;
  48. background-color: $box-inset-color;
  49. color: $text-color;
  50. padding: 10px 15px;
  51. margin-right: 8px;
  52. cursor: pointer;
  53. user-select: none;
  54. &:hover {
  55. background-color: $box-hover-color;
  56. }
  57. &:active, &.active {
  58. color: $text-color-light;
  59. background-color: $primary-color;
  60. }
  61. }
  62. </style>