| }" |
| 9 | :disabled="disabled" |
| 10 | @click="handleClick" |
| 11 | > |
| 12 | <span class="item-content"> |
| 13 | <slot /> |
| 14 | </span> |
| 15 | <el-icon v-if="isSelected" class="check-icon"> |
| 16 | <Check /> |
| 17 | </el-icon> |
| 18 | </button> |
| 19 | </template> |
| 20 |
| 21 | <script setup lang="ts"> |
| 22 | import { computed, inject } from 'vue' |
| 23 | import { Check } from '@element-plus/icons-vue' |
| 24 |
| 25 | interface Props { |
| 26 | danger?: boolean |
| 27 | disabled?: boolean |
| 28 | value?: string | number |
| 29 | } |
| 30 |
| 31 | const props = withDefaults(defineProps<Props>(), { |
| 32 | danger: false, |
| 33 | disabled: false, |
| 34 | value: undefined, |
| 35 | }) |
| 36 |
| 37 | const emit = defineEmits<{ |
| 38 | (e: 'click'): void |
| 39 | }>() |
| 40 |
| 41 | const popoverMenu = inject<{ |
| 42 | close: () => void |
| 43 | select: (value: string | number) => void |
| 44 | selectable: boolean |
| 45 | modelValue: () => string | number | null |
| 46 | }>('popoverMenu') |
| 47 |
| 48 | const isSelected = computed(() => { |
| 49 | if (!popoverMenu?.selectable || props.value === undefined) return false |
| 50 | return popoverMenu.modelValue() === props.value |
| 51 | }) |
| 52 |
| 53 | const handleClick = () => { |
| 54 | if (props.disabled) return |
| 55 |
| 56 | if (popoverMenu?.selectable && props.value !== undefined) { |
| 57 | popoverMenu.select(props.value) |
| 58 | } else { |
| 59 | emit('click') |
| 60 | popoverMenu?.close() |
| 61 | } |
| 62 | } |
| 63 | </script> |
| 64 |
| 65 | <style scoped lang="scss"> |
| 66 | .popover-menu-item { |
| 67 | display: flex; |
| 68 | align-items: center; |
| 69 | justify-content: space-between; |
| 70 | width: 100%; |
| 71 | padding: 8px 12px; |
| 72 | border: none; |
| 73 | border-radius: 6px; |
| 74 | background: transparent; |
| 75 | color: $color-text-secondary; |
| 76 | font-size: 14px; |
| 77 | cursor: pointer; |
| 78 | transition: background 0.15s ease; |
| 79 | text-align: left; |
| 80 | white-space: nowrap; |
| 81 |
| 82 | &:hover:not(.is-disabled) { |
| 83 | background: $color-bg-hover; |
| 84 | } |
| 85 |
| 86 | &.is-disabled { |
| 87 | opacity: 0.5; |
| 88 | cursor: not-allowed; |
| 89 | } |
| 90 |
| 91 | &.is-danger { |
| 92 | color: $color-danger; |
| 93 |
| 94 | .item-content :deep(.el-icon) { |
| 95 | color: $color-danger; |
| 96 | } |
| 97 |
| 98 | &:hover:not(.is-disabled) { |
| 99 | background: $color-danger-light; |
| 100 | } |
| 101 | } |
| 102 |
| 103 | &.is-selected { |
| 104 | background: $color-bg-hover; |
| 105 | } |
| 106 |
| 107 | .item-content { |
| 108 | display: flex; |
| 109 | align-items: center; |
| 110 | gap: 10px; |
| 111 | color: inherit; |
| 112 |
| 113 | :deep(.el-icon) { |
| 114 | font-size: 16px; |
| 115 | color: $color-text-light; |
| 116 | } |
| 117 | } |
| 118 |
| 119 | .check-icon { |
| 120 | font-size: 16px; |
| 121 | color: $color-primary; |
| 122 | flex-shrink: 0; |
| 123 | } |
| 124 | } |
| 125 | </style> |