wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
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
import { defineComponent, type PropType } from 'vue';
import { UserFilled } from '@element-plus/icons-vue';
 
export default defineComponent({
    name: 'cl-avatar',
 
    props: {
        modelValue: String,
        src: String,
        icon: {
            type: null,
            default: UserFilled
        },
        size: {
            type: [String, Number] as PropType<'large' | 'default' | 'small' | number>,
            default: 40
        },
        shape: {
            type: String as PropType<'circle' | 'square'>,
            default: 'square'
        },
        fit: {
            type: String as PropType<'fill' | 'contain' | 'cover' | 'none' | 'scale-down'>,
            default: 'cover'
        }
    },
 
    setup(props) {
        return () => {
            const height = props.size + 'px';
 
            return (
                <div
                    class="cl-avatar"
                    style={{
                        height
                    }}
                >
                    <el-avatar
                        style={{
                            height,
                            width: props.size + 'px'
                        }}
                        {...{
                            ...props,
                            src: props.modelValue || props.src
                        }}
                    />
                </div>
            );
        };
    }
});