You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
2.4 KiB
122 lines
2.4 KiB
|
3 years ago
|
<template>
|
||
|
3 years ago
|
<div class="head-image" @click="showUserInfo($event)">
|
||
|
2 years ago
|
<img class="avatar-image" v-show="url" :src="url"
|
||
|
|
:style="avatarImageStyle" loading="lazy" />
|
||
|
2 years ago
|
<div class="avatar-text" v-show="!url" :style="avatarTextStyle">
|
||
|
|
{{name.substring(0,1).toUpperCase()}}</div>
|
||
|
|
<div v-show="online" class="online" title="用户当前在线"></div>
|
||
|
3 years ago
|
<slot></slot>
|
||
|
|
</div>
|
||
|
3 years ago
|
</template>
|
||
|
|
|
||
|
|
<script>
|
||
|
3 years ago
|
|
||
|
3 years ago
|
export default {
|
||
|
|
name: "headImage",
|
||
|
|
data() {
|
||
|
2 years ago
|
return {
|
||
|
|
colors:["#7dd24b","#c7515a","#db68ef","#15d29b","#85029b",
|
||
|
|
"#c9b455","#fb2609","#bda818","#af0831","#326eb6"]
|
||
|
|
|
||
|
|
}
|
||
|
3 years ago
|
},
|
||
|
|
props: {
|
||
|
3 years ago
|
id:{
|
||
|
|
type: Number
|
||
|
|
},
|
||
|
3 years ago
|
size: {
|
||
|
|
type: Number,
|
||
|
|
default: 50
|
||
|
|
},
|
||
|
2 years ago
|
width: {
|
||
|
|
type: Number
|
||
|
|
},
|
||
|
|
height: {
|
||
|
|
type: Number
|
||
|
|
},
|
||
|
|
radius:{
|
||
|
|
type: String,
|
||
|
|
default: "10%"
|
||
|
|
},
|
||
|
3 years ago
|
url: {
|
||
|
3 years ago
|
type: String
|
||
|
2 years ago
|
},
|
||
|
|
name:{
|
||
|
|
type: String,
|
||
|
2 years ago
|
default: "?"
|
||
|
2 years ago
|
},
|
||
|
|
online:{
|
||
|
|
type: Boolean,
|
||
|
|
default:false
|
||
|
3 years ago
|
}
|
||
|
3 years ago
|
},
|
||
|
|
methods:{
|
||
|
|
showUserInfo(e){
|
||
|
|
if(this.id && this.id>0){
|
||
|
|
this.$http({
|
||
|
3 years ago
|
url: `/user/find/${this.id}`,
|
||
|
3 years ago
|
method: 'get'
|
||
|
|
}).then((user) => {
|
||
|
|
this.$store.commit("setUserInfoBoxPos",e);
|
||
|
|
this.$store.commit("showUserInfoBox",user);
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
2 years ago
|
},
|
||
|
|
computed:{
|
||
|
2 years ago
|
avatarImageStyle() {
|
||
|
|
let w = this.width ? this.width : this.size;
|
||
|
|
let h = this.height ? this.height : this.size;
|
||
|
|
return `width:${w}px; height:${h}px;
|
||
|
|
border-radius: ${this.radius};`
|
||
|
2 years ago
|
},
|
||
|
2 years ago
|
avatarTextStyle() {
|
||
|
|
let w = this.width ? this.width : this.size;
|
||
|
|
let h = this.height ? this.height : this.size;
|
||
|
|
return `width: ${w}px;height:${h}px;
|
||
|
|
color:${this.textColor};font-size:${w*0.6}px;
|
||
|
|
border-radius: ${this.radius};`
|
||
|
2 years ago
|
},
|
||
|
|
textColor(){
|
||
|
|
let hash = 0;
|
||
|
|
for (var i = 0; i< this.name.length; i++) {
|
||
|
|
hash += this.name.charCodeAt(i);
|
||
|
|
}
|
||
|
|
return this.colors[hash%this.colors.length];
|
||
|
|
}
|
||
|
|
}
|
||
|
3 years ago
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<style scoped lang="scss">
|
||
|
3 years ago
|
.head-image {
|
||
|
|
position: relative;
|
||
|
2 years ago
|
cursor: pointer;
|
||
|
|
.avatar-image {
|
||
|
3 years ago
|
position: relative;
|
||
|
|
overflow: hidden;
|
||
|
2 years ago
|
display: block;
|
||
|
3 years ago
|
}
|
||
|
2 years ago
|
|
||
|
|
.avatar-text{
|
||
|
|
background-color: #f2f2f2; /* 默认背景色 */
|
||
|
2 years ago
|
border-radius: 15%; /* 圆角效果 */
|
||
|
2 years ago
|
display: flex;
|
||
|
|
align-items: center;
|
||
|
|
justify-content: center;
|
||
|
|
border: 1px solid #ccc;
|
||
|
|
}
|
||
|
|
|
||
|
|
.online{
|
||
|
|
position: absolute;
|
||
|
|
right: -5px;
|
||
|
|
bottom: 0;
|
||
|
|
width: 12px;
|
||
|
|
height: 12px;
|
||
|
|
background: limegreen;
|
||
|
|
border-radius: 50%;
|
||
|
|
border: 3px solid white;
|
||
|
3 years ago
|
}
|
||
|
3 years ago
|
}
|
||
|
|
</style>
|