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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
| <template>
| <div class="cl-avatar" :class="[size, shape]" :style="[style]">
| <el-image :src="src || modelValue" alt="">
| <template #error>
| <div class="image-slot">
| <i class="el-icon-user-solid" :style="{ color }"></i>
| </div>
| </template>
| </el-image>
| </div>
| </template>
|
| <script lang="ts">
| import { computed, defineComponent } from "vue";
| import { isNumber } from "/@/cool/utils";
|
| export default defineComponent({
| name: "cl-avatar",
|
| props: {
| modelValue: String,
| src: String,
| size: {
| type: [String, Number],
| default: 36
| },
| shape: {
| type: String,
| default: "circle"
| },
| backgroundColor: {
| type: String,
| default: "#f7f7f7"
| },
| color: {
| type: String,
| default: "#ccc"
| }
| },
|
| setup(props) {
| const size = isNumber(props.size) ? props.size + "px" : props.size;
|
| const style = computed(() => {
| return {
| height: size,
| width: size,
| backgroundColor: props.backgroundColor
| };
| });
|
| return {
| style
| };
| }
| });
| </script>
|
| <style lang="scss" scoped>
| .cl-avatar {
| overflow: hidden;
|
| &.large {
| height: 50px;
| width: 50px;
| }
|
| &.medium {
| height: 40px;
| width: 40px;
| }
|
| &.small {
| height: 30px;
| width: 30px;
| }
|
| &.circle {
| border-radius: 100%;
| }
|
| &.square {
| border-radius: 10%;
| }
|
| img {
| height: 100%;
| width: 100%;
| }
|
| .el-image {
| height: 100%;
| width: 100%;
|
| .image-slot {
| display: flex;
| justify-content: center;
| align-items: center;
| height: 100%;
| width: 100%;
|
| i {
| font-size: 20px;
| }
| }
| }
| }
| </style>
|
|