2026-05-27 09:17:57 +08:00
|
|
|
<template>
|
|
|
|
|
<ElSelect
|
|
|
|
|
class="enterprise-select"
|
|
|
|
|
popper-class="enterprise-select-popper"
|
|
|
|
|
:model-value="modelValue"
|
|
|
|
|
:placeholder="placeholder"
|
|
|
|
|
:disabled="disabled"
|
|
|
|
|
:clearable="clearable"
|
|
|
|
|
:filterable="filterable"
|
|
|
|
|
:size="size"
|
|
|
|
|
:teleported="teleported"
|
|
|
|
|
@change="handleChange"
|
|
|
|
|
>
|
|
|
|
|
<ElOption
|
|
|
|
|
v-for="option in normalizedOptions"
|
|
|
|
|
:key="option.key"
|
|
|
|
|
:label="option.label"
|
|
|
|
|
:value="option.value"
|
|
|
|
|
:disabled="option.disabled"
|
|
|
|
|
/>
|
|
|
|
|
</ElSelect>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import { computed } from 'vue'
|
2026-05-29 14:11:06 +08:00
|
|
|
import { ElSelect, ElOption } from 'element-plus/es/components/select/index.mjs'
|
2026-05-27 09:17:57 +08:00
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
modelValue: { type: [String, Number, Boolean], default: '' },
|
|
|
|
|
options: { type: Array, required: true },
|
|
|
|
|
placeholder: { type: String, default: '请选择' },
|
|
|
|
|
disabled: { type: Boolean, default: false },
|
|
|
|
|
clearable: { type: Boolean, default: false },
|
|
|
|
|
filterable: { type: Boolean, default: false },
|
|
|
|
|
size: { type: String, default: 'default' },
|
|
|
|
|
teleported: { type: Boolean, default: true }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['update:modelValue', 'change'])
|
|
|
|
|
|
|
|
|
|
const normalizedOptions = computed(() =>
|
|
|
|
|
props.options.map((option, index) => {
|
|
|
|
|
if (option && typeof option === 'object') {
|
|
|
|
|
const value = option.value ?? option.label ?? ''
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
key: `${value}-${index}`,
|
|
|
|
|
label: String(option.label ?? value),
|
|
|
|
|
value,
|
|
|
|
|
disabled: Boolean(option.disabled)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
key: `${option}-${index}`,
|
|
|
|
|
label: String(option),
|
|
|
|
|
value: option,
|
|
|
|
|
disabled: false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
function handleChange(value) {
|
|
|
|
|
emit('update:modelValue', value)
|
|
|
|
|
emit('change', value)
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.enterprise-select {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|