11<template >
22 <div class =" follow-card" >
3- <v-avatar class =" avatar" >
4- <v-img src =" https://cdn.vuetifyjs.com/images/john.jpg" ></v-img >
3+ <v-avatar class =" avatar pointer" :color =" userInfo.userPicture?'':'primary'" @click =" viewUserProfile" >
4+ <v-img :src =" qiNiuImgLink+userInfo.userPicture" v-if =" userInfo.userPicture" :alt =" userInfo.name" ></v-img >
5+ <span class =" white--text text-h4" v-else >{{userInfo.name|preNickname}}</span >
56 </v-avatar >
67 <div class =" follow-user-info" >
78 <div class =" d-flex flex-ai" >
8- <span class =" text-bold text-md" >Tom Rich </span >
9+ <span class =" text-bold text-md" >{{userInfo.name}} </span >
910 <v-spacer ></v-spacer >
10- <v-btn small color =" #333333" depressed v-if =" following" >取消关注</v-btn >
11- <v-btn small color =" primary" depressed v-else >关注</v-btn >
11+ <v-btn small color =" #3C3C3C" depressed v-if =" userInfo.myFollow" width =" 80" :loading =" unFollowLoading"
12+ @click =" unFollow" >取消关注</v-btn >
13+ <v-btn small color =" primary" depressed v-else width =" 80" :loading =" followLoading" @click =" follow" >关注</v-btn >
1214 </div >
13- <span class =" about text-describe text-sm" >这是他的个人简介...这是他的个人简介...这是他的个人简介... </span >
15+ <span class =" about text-describe text-sm" >{{userInfo.description||'ta还没想好怎么描述自己...'}} </span >
1416 <div class =" text-sm num" >
15- <span class =" instances" >实例: 123 </span >
16- <span class =" follower" >粉丝: 456 </span >
17+ <span class =" instances" >实例: {{userInfo.works|formatNumber}} </span >
18+ <span class =" follower" >粉丝: {{userInfo.fan|formatNumber}} </span >
1719 </div >
1820 </div >
1921 </div >
2022</template >
2123
2224<script >
25+ import { mapState , mapGetters } from ' vuex'
26+ import { qiNiuImgLink } from ' @utils/publicData'
2327export default {
2428 props: {
25- following: {
26- type: Boolean ,
27- default: false ,
28- },
29+ userInfo: Object ,
30+ cardIndex: Number ,
2931 },
3032 data () {
31- return {}
33+ return {
34+ qiNiuImgLink,
35+ followLoading: false ,
36+ unFollowLoading: false ,
37+ }
38+ },
39+ computed: {
40+ ... mapState ([' loginState' , ' loginInfo' ]),
41+ ... mapGetters ([' isSelfProfile' ]),
42+ },
43+ methods: {
44+ viewUserProfile () {
45+ // 查看用户主页
46+ this .$router .push (` /user/${ this .userInfo .username } ` )
47+ },
48+ async follow () {
49+ if (! this .loginState ) {
50+ this .$message .info (' 请登录后再进行相关操作!' )
51+ return void 0
52+ }
53+ this .followLoading = true
54+ try {
55+ const res = await this .$http .addFollow ({
56+ username: this .loginInfo .username ,
57+ followUsername: this .userInfo .username ,
58+ })
59+ if (res .state ) {
60+ this .$message .success (' 关注成功!' )
61+ this .$emit (' setFollow' , true , this .cardIndex )
62+ } else {
63+ this .$message .error (' 关注失败!' )
64+ }
65+ } catch (err) {
66+ console .log (err)
67+ }
68+ this .followLoading = false
69+ },
70+ async unFollow () {
71+ if (! this .loginState ) {
72+ this .$message .info (' 请登录后再进行相关操作!' )
73+ return void 0
74+ }
75+ this .unFollowLoading = true
76+ try {
77+ const res = await this .$http .delFollow ({
78+ username: this .loginInfo .username ,
79+ followUsername: this .userInfo .username ,
80+ })
81+ if (res .state ) {
82+ this .$message .success (' 取消关注成功!' )
83+ // 如果在自己的主页的关注页面取消关注,则重新查询关注列表
84+ if (this .isSelfProfile && this .$route .name === ' Following' ) {
85+ this .$emit (' search' )
86+ } else {
87+ this .$emit (' setFollow' , false , this .cardIndex )
88+ }
89+ } else {
90+ this .$message .error (' 取消关注失败!' )
91+ }
92+ } catch (err) {
93+ console .log (err)
94+ }
95+ this .unFollowLoading = false
96+ },
3297 },
33- methods: {},
3498 components: {},
3599}
36100 </script >
@@ -53,6 +117,7 @@ export default {
53117 .about {
54118 margin-top : 5px ;
55119 display : block ;
120+ height : 40px ;
56121 @include texts-ellipsis (2 );
57122 }
58123 .num {
0 commit comments