wujingjing
2024-08-29 19b778d2d04bed31ce2e1f167c6ff2fda9906421
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<template>
    <el-select v-model="selectValue">
        <el-option v-for="item in options" :key="item[defaultProps.key]" :value="item[defaultProps.value]" :label="item[defaultProps.label]">
            <div class="image-option">
                <el-image class="image-option__img" :src="item[defaultProps.url]"></el-image>
                <span class="image-option__label">{{ item[defaultProps.label] }}</span>
            </div>
        </el-option>
    </el-select>
</template>
 
<script setup lang="ts">
import { PropType, computed, toRefs } from 'vue';
import { ImgProps } from './imageSelect';
 
const props = defineProps({
    modelValue: {
        type: [String, Number, Boolean],
    },
    options: {
        type: Array as PropType<Array<any>>,
    },
    defaultProps: {
        type: Object as PropType<ImgProps>,
        default: {
            key: 'ID',
            label: 'Name',
            value: 'ID',
            url: 'Url',
        },
    },
});
 
const emits = defineEmits<{
    (event: 'update:modelValue', value): void;
}>();
 
const { modelValue, options, defaultProps } = toRefs(props);
 
const selectValue = computed({
    get: () => {
        return modelValue?.value;
    },
    set: (value) => {
        emits('update:modelValue', value);
    },
});
</script>
<style scoped lang="scss">
.image-option {
    display: flex;
    align-items: center;
    &__img {
        width: 70px;
        height: 35px;
        margin-right: 7px;
    }
}
</style>