TdDeviceLabel.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <!-- TagGroup.vue -->
  3. <div class="tag-group">
  4. <div
  5. v-for="(tag, index) in tags"
  6. :key="index"
  7. class="tag-item"
  8. :class="{ 'active': selectedIndex === index }"
  9. @click="selectTag(index)"
  10. >
  11. <span class="property">{{ tag.modelName }}</span>
  12. <span class="value">{{ tag.valueType }}</span>
  13. </div>
  14. </div>
  15. </template>
  16. <script setup>
  17. import { ref } from 'vue'
  18. const props = defineProps({
  19. tags: {
  20. type: Array,
  21. required: true,
  22. validator: (arr) => arr.every(item => item.label && item.value)
  23. },
  24. tagWidth: {
  25. type: String,
  26. default: '220px'
  27. }
  28. })
  29. const selectedIndex = ref(-1)
  30. const selectTag = (index) => {
  31. selectedIndex.value = selectedIndex.value === index ? -1 : index
  32. }
  33. </script>
  34. <style scoped>
  35. .tag-group {
  36. display: flex;
  37. flex-wrap: wrap;
  38. row-gap: 10px;
  39. column-gap: 16px;
  40. }
  41. .tag-item {
  42. /* 基础样式 */
  43. width: v-bind('props.tagWidth');
  44. height: 48px;
  45. background: #ffffff;
  46. border: 1px solid #dcdfe6;
  47. border-radius: 6px;
  48. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  49. cursor: pointer;
  50. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  51. /* 内容布局 */
  52. display: flex;
  53. justify-content: space-between;
  54. align-items: center;
  55. padding: 0 16px;
  56. }
  57. /* 文字样式 */
  58. .property {
  59. color: #606266;
  60. font-size: 14px;
  61. font-weight: 500;
  62. flex-shrink: 0;
  63. }
  64. .value {
  65. color: #909399;
  66. font-size: 14px;
  67. max-width: 60%;
  68. overflow: hidden;
  69. text-overflow: ellipsis;
  70. white-space: nowrap;
  71. }
  72. /* 悬停效果 */
  73. .tag-item:hover {
  74. transform: scale(1.03);
  75. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  76. z-index: 1;
  77. }
  78. /* 选中状态 */
  79. .tag-item.active {
  80. background: #276cff;
  81. border-color: #276cff;
  82. }
  83. .tag-item.active .property,
  84. .tag-item.active .value {
  85. color: #fff !important;
  86. }
  87. /* 选中状态阴影 */
  88. .tag-item.active {
  89. box-shadow: 0 4px 16px rgba(39, 108, 255, 0.2);
  90. }
  91. /* 禁用状态 */
  92. .tag-item.disabled {
  93. opacity: 0.6;
  94. cursor: not-allowed;
  95. filter: grayscale(0.8);
  96. }
  97. </style>