123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <template>
- <!-- TagGroup.vue -->
- <div class="tag-group">
- <div
- v-for="(tag, index) in tags"
- :key="index"
- class="tag-item"
- :class="{ 'active': selectedIndex === index }"
- @click="selectTag(index)"
- >
- <span class="property">{{ tag.modelName }}</span>
- <span class="value">{{ tag.valueType }}</span>
- </div>
- </div>
- </template>
- <script setup>
- import { ref } from 'vue'
- const props = defineProps({
- tags: {
- type: Array,
- required: true,
- validator: (arr) => arr.every(item => item.label && item.value)
- },
- tagWidth: {
- type: String,
- default: '220px'
- }
- })
- const selectedIndex = ref(-1)
- const selectTag = (index) => {
- selectedIndex.value = selectedIndex.value === index ? -1 : index
- }
- </script>
- <style scoped>
- .tag-group {
- display: flex;
- flex-wrap: wrap;
- row-gap: 10px;
- column-gap: 16px;
- }
- .tag-item {
- /* 基础样式 */
- width: v-bind('props.tagWidth');
- height: 48px;
- background: #ffffff;
- border: 1px solid #dcdfe6;
- border-radius: 6px;
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
- cursor: pointer;
- transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
- /* 内容布局 */
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 0 16px;
- }
- /* 文字样式 */
- .property {
- color: #606266;
- font-size: 14px;
- font-weight: 500;
- flex-shrink: 0;
- }
- .value {
- color: #909399;
- font-size: 14px;
- max-width: 60%;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- /* 悬停效果 */
- .tag-item:hover {
- transform: scale(1.03);
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
- z-index: 1;
- }
- /* 选中状态 */
- .tag-item.active {
- background: #276cff;
- border-color: #276cff;
- }
- .tag-item.active .property,
- .tag-item.active .value {
- color: #fff !important;
- }
- /* 选中状态阴影 */
- .tag-item.active {
- box-shadow: 0 4px 16px rgba(39, 108, 255, 0.2);
- }
- /* 禁用状态 */
- .tag-item.disabled {
- opacity: 0.6;
- cursor: not-allowed;
- filter: grayscale(0.8);
- }
- </style>
|