11<template >
22 <v-card class =" instance-card" >
3- <v-img :src =" `http://firstbird.asia/ ${info.img}`" class =" instance-card-img" >
3+ <v-img :src =" `${qiNiuImgLink} ${info.img}`" class =" instance-card-img" >
44 <div class =" img-screen pointer d-flex flex-ai flex-jcc" @click =" viewInstance" >
55 <v-icon >mdi-eye</v-icon >
66 </div >
99 <v-menu transition =" none" :close-on-content-click =" false" offset-y open-delay =" 500" close-delay =" 200"
1010 :open-on-hover =" true" top >
1111 <template v-slot :activator =" { on , attrs } " >
12- <v-avatar size =" 40" class =" pointer" v-bind =" attrs" v-on =" on" color =" primary" @click.native =" viewUserProfile" >
13- <v-img :src =" qiNiuImgLink+info.userPicture" v-if =" info.userPicture" ></v-img >
12+ <v-avatar size =" 40" class =" pointer" v-bind =" attrs" v-on =" on" :color =" info.userPicture?'':'primary'"
13+ @click.native =" viewUserProfile" >
14+ <v-img :src =" qiNiuImgLink+info.userPicture" v-if =" info.userPicture" :alt =" info.name" ></v-img >
1415 <span class =" white--text text-h7" v-else >{{info.name|preNickname}}</span >
1516 </v-avatar >
1617 </template >
1718 <user-card :avatar =" info.userPicture" :myFollow =" info.myFollow" :username =" info.username" :nickname =" info.name"
18- :about =" info.description" ></user-card >
19+ :about =" info.description" @setFollow = " setFollow " ></user-card >
1920 </v-menu >
2021 <div class =" instance-info d-flex flex-clo pointer" >
2122 <span class =" text-sm" :title =" info.exampleName" >{{info.exampleName}}</span >
2223 <span class =" text-xs author" @click =" viewUserProfile" >{{info.name}}</span >
2324 </div >
2425 <v-spacer ></v-spacer >
25- <v-btn icon :class =" info.myFavorites?'icon-like-active':'icon-like'" :loading =" likeLoading"
26- @click =" like" >
26+ <v-btn icon :class =" info.myFavorites?'icon-like-active':'icon-like'" :loading =" likeLoading" @click =" like" >
2727 <v-icon >mdi-heart</v-icon >
2828 </v-btn >
2929 <span class =" liked-num text-xs" >{{info.favorites|formatNumber}}</span >
3535</template >
3636
3737<script >
38- import { mapState } from ' vuex'
38+ import { mapState , mapGetters } from ' vuex'
3939import UserCard from ' @components/userCard'
4040import { copyToClip } from ' @utils/tools'
4141import { qiNiuImgLink } from ' @utils/publicData'
4242import env from ' @service/env'
4343export default {
4444 props: {
4545 info: Object ,
46+ cardIndex: Number ,
4647 },
4748 data () {
4849 return {
@@ -52,6 +53,7 @@ export default {
5253 },
5354 computed: {
5455 ... mapState ([' loginState' , ' loginInfo' ]),
56+ ... mapGetters ([' isSelfProfile' ]),
5557 isSelfWork () {
5658 return this .info .username === this .loginInfo .username
5759 },
@@ -64,33 +66,49 @@ export default {
6466 },
6567 viewInstance () {
6668 const { username , exampleId } = this .info
67- this .$router .push ({
68- path: ` /work/${ username} /${ exampleId} ` ,
69- })
69+ this .$router .push (` /work/${ username} /${ exampleId} ` )
7070 },
7171 viewUserProfile () {
72- // 查看用户主页
73- this .$router .push ({
74- path: ` /user/${ this .info .username } ` ,
75- })
72+ this .$router .push (` /user/${ this .info .username } ` )
7673 },
7774 async like () {
75+ if (! this .loginState ) {
76+ this .$message .info (' 请登录后再进行相关操作!' )
77+ return void 0
78+ } else if (this .isSelfWork ) {
79+ this .$message .info (' 不能对自己的实例点喜欢哦' )
80+ return void 0
81+ }
7882 const { myFavorites , exampleId } = this .info
7983 this .likeLoading = true
8084 try {
8185 // 根据当前是否已喜欢来判定调用喜欢还是取消喜欢接口
8286 const api = this .$http
8387 const req = myFavorites ? api .delLikeWork : api .addLikeWork
84- const res = req ({ username: this .loginInfo .username , exampleId })
88+ const res = await req ({ username: this .loginInfo .username , exampleId })
8589 if (res .state ) {
90+ if (
91+ this .isSelfProfile &&
92+ myFavorites &&
93+ this .$route .name === ' Liked'
94+ ) {
95+ this .$emit (' search' )
96+ } else {
97+ this .setFav (! myFavorites)
98+ }
8699 this .$message .success (myFavorites ? ' 已取消喜爱!' : ' 已喜爱!' )
87- this .info .myFavorites = ! myFavorites
88100 }
89101 } catch (err) {
90102 console .log (err)
91103 }
92104 this .likeLoading = false
93105 },
106+ setFollow (isFollow ) {
107+ this .$emit (' setFollow' , isFollow, this .cardIndex )
108+ },
109+ setFav (isFav ) {
110+ this .$emit (' setFav' , isFav, this .cardIndex )
111+ },
94112 },
95113 components: {
96114 UserCard,
0 commit comments