66 </router-link >
77 </div >
88 <div class =" instance-name flex-sh pointer d-flex flex-ai" >
9- <div class =" d-flex flex-clo " >
9+ <div class =" d-flex flex-end " >
1010 <span class =" text-small" >{{isNewWork?'新建实例':curInstanceDetail.title}}</span >
11- <span class =" text-xs author" @click =" goToUserProfile" v-if =" !isNewWork" >{{curInstanceDetail.username }}</span >
11+ <span class =" text-xs author" @click =" goToUserProfile" v-if =" !isNewWork" >By {{curInstanceDetail.nickname }}</span >
1212 </div >
13- <v-btn icon small @click =" setVisibleDialogName('instanceConfig')" v-if =" !isNewWork&&isSelfProfile " >
13+ <v-btn icon small @click =" setVisibleDialogName('instanceConfig')" v-if =" !isNewWork&&isSelfInstance " >
1414 <v-icon >mdi-pencil-outline</v-icon >
1515 </v-btn >
16- <v-btn icon small v-if =" !isNewWork&& !isSelfProfile" >
17- <v-icon >mdi-label-multiple-outline</v-icon >
18- </v-btn >
16+ <v-menu :close-on-content-click =" false" offset-y open-delay =" 200" close-delay =" 200" bottom >
17+ <template v-slot :activator =" { on , attrs } " >
18+ <v-btn icon small v-bind =" attrs" v-on =" on" v-if =" !isNewWork&& !isSelfInstance" :disabled =" tags.length===0" >
19+ <v-icon >mdi-label-multiple-outline</v-icon >
20+ </v-btn >
21+ </template >
22+ <v-card color =" info" style =" padding : 10px " >
23+ <v-chip v-for =" (item,index) in tags" :key =" index" small style =" margin : 0 5px " >{{item}}</v-chip >
24+ </v-card >
25+ </v-menu >
1926 </div >
2027 <v-spacer ></v-spacer >
2128 <div class =" d-flex flex-ai" >
2229 <div class =" btn-opts" >
2330 <v-btn color =" #2a53cd" :disabled =" disableSave" class =" radius-2" small depressed @click =" saveInstance"
24- :loading =" saveInstanceLoading" v-if =" isSelfProfile || isNewWork" >
31+ :loading =" saveInstanceLoading" v-if =" isSelfInstance || isNewWork" >
2532 <v-icon left dark >mdi-cloud-upload</v-icon >保存
2633 </v-btn >
27- <v-btn small color =" info" class =" radius-2" depressed @click =" like" :loading =" likeLoading"
28- :disabled =" !loginState" v-if =" !hideLike" >
29- <v-icon left small color =" red" >mdi-heart</v-icon >喜爱
30- </v-btn >
34+ <div v-if =" !hideLike" >
35+ <v-btn small color =" info" class =" radius-2" depressed @click =" like" :loading =" likeLoading"
36+ :disabled =" !loginState" v-show =" curInstanceDetail.liked" >
37+ <v-icon left small color =" red" >mdi-heart</v-icon >取消喜爱
38+ </v-btn >
39+ <v-btn small color =" info" class =" radius-2" depressed @click =" like" :loading =" likeLoading"
40+ :disabled =" !loginState" v-show =" !curInstanceDetail.liked" >
41+ <v-icon left small color =" gray" >mdi-heart</v-icon >喜爱
42+ </v-btn >
43+ </div >
3144 </div >
3245 <header-account dense ></header-account >
3346 </div >
@@ -41,21 +54,27 @@ import { mapMutations, mapState, mapGetters } from 'vuex'
4154import HeaderAccount from ' @components/headerAccount.vue'
4255import InstanceConfig from ' @components/dialog/instanceConfig.vue'
4356export default {
57+ inject: [' changeRouterKey' ],
4458 data () {
4559 return {
4660 saveInstanceLoading: false ,
4761 likeLoading: false ,
62+ tags: [],
4863 }
4964 },
65+ created () {
66+ const tags = this .curInstanceDetail .tags
67+ this .tags = tags ? tags .split (' ,' ) : []
68+ },
5069 computed: {
5170 ... mapState ([' loginState' , ' loginInfo' , ' curInstanceDetail' ]),
52- ... mapGetters ([' instanceContent' , ' isSelfProfile ' ]),
71+ ... mapGetters ([' instanceContent' , ' isSelfInstance ' ]),
5372 isNewWork () {
5473 return this .$route .name === ' NewWork'
5574 },
5675 hideLike () {
5776 const isNewWork = this .isNewWork
58- return isNewWork || this .isSelfProfile
77+ return isNewWork || this .isSelfInstance
5978 },
6079 disableSave () {
6180 return ! this .loginState || this .curInstanceDetail .saved
@@ -81,7 +100,6 @@ export default {
81100 headTags,
82101 })
83102 const reqData = {
84- username: loginInfo .username ,
85103 exampleName: isNewWork ? ' 新建实例' : instance .title ,
86104 ispublic: instance .ispublic ,
87105 label: instance .tags ,
@@ -103,8 +121,9 @@ export default {
103121 if (isNewWork) {
104122 this .$router
105123 .replace (` /work/${ loginInfo .username } /${ res .data } ` )
106- .catch ((err ) => {})
107- this .$emit (' initInstanceData' )
124+ .then (() => {
125+ this .changeRouterKey ()
126+ })
108127 }
109128 } else {
110129 this .$message .error (' 实例保存失败!' )
@@ -119,8 +138,22 @@ export default {
119138 const username = this .curInstanceDetail .username
120139 this .$router .push (` /user/${ username} ` )
121140 },
122- like () {
141+ async like () {
142+ const { liked: myFavorites , id: exampleId } = this .curInstanceDetail
123143 this .likeLoading = true
144+ try {
145+ // 根据当前是否已喜欢来判定调用喜欢还是取消喜欢接口
146+ const api = this .$http
147+ const req = myFavorites ? api .delLikeWork : api .addLikeWork
148+ const res = await req ({ username: this .loginInfo .username , exampleId })
149+ if (res .state ) {
150+ this .setCurInstanceDetail ({ liked: ! myFavorites })
151+ this .$message .success (myFavorites ? ' 已取消喜爱!' : ' 已喜爱!' )
152+ }
153+ } catch (err) {
154+ console .log (err)
155+ }
156+ this .likeLoading = false
124157 },
125158 },
126159 components: {
@@ -149,7 +182,8 @@ export default {
149182 color : $light-5 ;
150183 margin-left : 20px ;
151184 .author {
152- margin-top : -2px ;
185+ margin-left : 5px ;
186+ margin-right : 10px ;
153187 color : $light-7 ;
154188 & :hover {
155189 color : $light-2 ;
0 commit comments