user-profile.vue
3.22 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<template>
<div class="profile-user">
<avatar :title=userProfile.userID :src="userProfile.avatar"/>
<div class="nick-name text-ellipsis">
<span v-if="userProfile.nick" :title=userProfile.nick>
{{ userProfile.nick }}
</span>
<span v-else class="anonymous" title="该用户未设置昵称">
[Anonymous]
</span>
</div>
<div class="gender" v-if="genderClass">
<span :title="gender" class="iconfont" :class="genderClass"></span>
</div>
<div>
<span>{{ userProfile.selfSignature }}</span>
</div>
<!-- <el-button-->
<!-- title="将该用户加入黑名单"-->
<!-- type="text"-->
<!-- @click="addToBlackList"-->
<!-- v-if="!isInBlacklist && userProfile.userID !== myUserID"-->
<!-- class="btn-add-blacklist"-->
<!-- >加入黑名单</el-button-->
<!-- >-->
<!-- <el-button title="将该用户移出黑名单" type="text" @click="removeFromBlacklist" v-else-if="isInBlacklist">移出黑名单</el-button>-->
<!-- 拉黑 和 反拉黑 -->
</div>
</template>
<script>
import {mapState} from 'vuex'
export default {
props: {
userProfile: {
type: Object,
required: true
}
},
computed: {
...mapState({
blacklist: state => state.blacklist.blacklist,
myUserID: state => state.user.currentUserProfile.userID
}),
isInBlacklist() {
return this.blacklist.findIndex(item => item.userID === this.userProfile.userID) >= 0
},
gender() {
switch (this.userProfile.gender) {
case this.TIM.TYPES.GENDER_MALE:
return '男'
case this.TIM.TYPES.GENDER_FEMALE:
return '女'
default:
return '未设置'
}
},
genderClass() {
switch (this.userProfile.gender) {
case this.TIM.TYPES.GENDER_MALE:
return 'icon-male'
case this.TIM.TYPES.GENDER_FEMALE:
return 'icon-female'
default:
return ''
}
}
},
methods: {
addToBlackList() {
this.tim
.addToBlacklist({userIDList: [this.userProfile.userID]})
.then(() => {
this.$store.dispatch('getBlacklist')
})
.catch(imError => {
this.$store.commit('showMessage', {
message: imError.message,
type: 'error'
})
})
},
removeFromBlacklist() {
this.tim.removeFromBlacklist({userIDList: [this.userProfile.userID]}).then(() => {
this.$store.commit('removeFromBlacklist', this.userProfile.userID)
})
.catch(error => {
this.$store.commit('showMessage', {
type: 'error',
message: error.message
})
})
}
}
}
</script>
<style lang="stylus" scoped>
.profile-user
width 100%
text-align center
padding 0 20px
.avatar
width 160px
height 160px
border-radius 50%
margin 30px auto
.nick-name
width 100%
color $base
font-size 20px
font-weight bold
text-shadow $font-dark 0 0 0.1em
.anonymous
color $first
text-shadow none
.gender
padding 5px 0 10px 0
border-bottom 1px solid $border-base
.btn-add-blacklist
color $danger
</style>