1.文章点赞功能2.文章赞赏功能

This commit is contained in:
ronger 2020-12-28 16:45:11 +08:00
parent 1335dd9786
commit 58ecf2232b
5 changed files with 93 additions and 8 deletions

View File

@ -13,6 +13,7 @@
"@chenfengyuan/vue-qrcode": "^1.0.2", "@chenfengyuan/vue-qrcode": "^1.0.2",
"@fortawesome/fontawesome-svg-core": "^1.2.32", "@fortawesome/fontawesome-svg-core": "^1.2.32",
"@fortawesome/free-brands-svg-icons": "^5.15.1", "@fortawesome/free-brands-svg-icons": "^5.15.1",
"@fortawesome/free-regular-svg-icons": "^5.15.1",
"@fortawesome/free-solid-svg-icons": "^5.15.1", "@fortawesome/free-solid-svg-icons": "^5.15.1",
"@fortawesome/vue-fontawesome": "^2.0.0", "@fortawesome/vue-fontawesome": "^2.0.0",
"@nuxtjs/axios": "^5.12.2", "@nuxtjs/axios": "^5.12.2",

View File

@ -51,7 +51,6 @@
<el-button size="mini" @click="handleCommand('editTag')" plain>编辑标签</el-button> <el-button size="mini" @click="handleCommand('editTag')" plain>编辑标签</el-button>
<el-button v-if="isPerfect" size="mini" @click="cancelPreference" plain>取消优选</el-button> <el-button v-if="isPerfect" size="mini" @click="cancelPreference" plain>取消优选</el-button>
<el-button v-else size="mini" @click="setPreference" plain>设为优选</el-button> <el-button v-else size="mini" @click="setPreference" plain>设为优选</el-button>
</template> </template>
<el-button size="mini" @click="handleCommand('share')" plain>分享</el-button> <el-button size="mini" @click="handleCommand('share')" plain>分享</el-button>
</el-col> </el-col>
@ -70,6 +69,46 @@
<div class="pt-7 pipe-content__reset vditor-reset" id="articleContent" v-html="article.articleContent" <div class="pt-7 pipe-content__reset vditor-reset" id="articleContent" v-html="article.articleContent"
style="overflow: hidden;"></div> style="overflow: hidden;"></div>
</div> </div>
<el-row>
<el-col v-if="article.portfolios && article.portfolios.length > 0">
<portfolios-widget :portfolios="article.portfolios"></portfolios-widget>
</el-col>
<el-col v-if="user">
<el-tooltip class="item" effect="dark" content="点赞" placement="top-start">
<el-button type="text" style="font-size: 1.2rem;" @click="thumbsUp">
<font-awesome-icon :icon="['far', 'thumbs-up']"></font-awesome-icon>
{{ article.articleThumbsUpCount }}
</el-button>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="赞赏" placement="top-start">
<el-button v-if="user.idUser === article.articleAuthorId" type="text" icon="el-icon-coffee" style="font-size: 1.2rem;">
{{ article.articleSponsorCount }}
</el-button>
<el-popconfirm
v-else
title="赞赏本文作者 20 巴旦木?"
@confirm="sponsor"
>
<el-button slot="reference" type="text" icon="el-icon-coffee" style="font-size: 1.2rem;">
{{ article.articleSponsorCount }}
</el-button>
</el-popconfirm>
</el-tooltip>
</el-col>
<el-col v-else>
<el-tooltip class="item" effect="dark" content="点赞" placement="top-start">
<el-button type="text" style="font-size: 1.2rem;">
<font-awesome-icon :icon="['far', 'thumbs-up']"></font-awesome-icon>
{{ article.articleThumbsUpCount }}
</el-button>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="赞赏" placement="top-start">
<el-button type="text" icon="el-icon-coffee" style="font-size: 1.2rem;">
{{ article.articleSponsorCount }}
</el-button>
</el-tooltip>
</el-col>
</el-row>
</div> </div>
</el-card> </el-card>
</el-col> </el-col>
@ -231,7 +270,7 @@ export default {
}, },
closeTagsDialog() { closeTagsDialog() {
this.$set(this, 'dialogVisible', false); this.$set(this, 'dialogVisible', false);
this.$store.dispatch('article/fetchDetail', this.$route.params) this.$store.dispatch('article/fetchDetail', this.$route.params);
}, },
followUser(idUser) { followUser(idUser) {
let _ts = this; let _ts = this;
@ -243,7 +282,7 @@ export default {
_ts.$set(_ts, 'isFollow', res); _ts.$set(_ts, 'isFollow', res);
}) })
} else { } else {
_ts.gotoLogin() _ts.gotoLogin();
} }
}, },
cancelFollowUser(idUser) { cancelFollowUser(idUser) {
@ -256,7 +295,7 @@ export default {
_ts.$set(_ts, 'isFollow', res); _ts.$set(_ts, 'isFollow', res);
}) })
} else { } else {
_ts.gotoLogin() _ts.gotoLogin();
} }
}, },
setPreference() { setPreference() {
@ -290,6 +329,37 @@ export default {
} }
} }
}) })
},
thumbsUp() {
let _ts = this;
_ts.$axios.$post('/api/article/thumbs-up', {
idArticle: _ts.article.idArticle
}).then(function (res) {
if (res) {
if (res.success) {
_ts.$message.success(res.message);
_ts.$store.dispatch('article/updateThumbsUpCount', {thumbsUpNumber: res.thumbsUpNumber})
} else {
_ts.$message.error(_ts.message);
}
}
})
},
sponsor() {
let _ts = this;
_ts.$axios.$post('/api/article/sponsor', {
dataType: '0',
dataId: _ts.article.idArticle
}).then(function (res) {
if (res) {
if (res.success) {
_ts.$message.success(res.message);
_ts.$store.dispatch('article/updateSponsorCount', {sponsorNumber: 1})
} else {
_ts.$message.error(_ts.message);
}
}
})
} }
}, },
mounted() { mounted() {

View File

@ -3,6 +3,7 @@ import { library, config } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { fas } from '@fortawesome/free-solid-svg-icons' import { fas } from '@fortawesome/free-solid-svg-icons'
import { fab } from '@fortawesome/free-brands-svg-icons' import { fab } from '@fortawesome/free-brands-svg-icons'
import { far } from '@fortawesome/free-regular-svg-icons'
// This is important, we are going to let Nuxt.js worry about the CSS // This is important, we are going to let Nuxt.js worry about the CSS
config.autoAddCss = false config.autoAddCss = false
@ -11,6 +12,7 @@ config.autoAddCss = false
// can add other styles or just individual icons. // can add other styles or just individual icons.
library.add(fas) library.add(fas)
library.add(fab) library.add(fab)
library.add(far)
// Register the component globally // Register the component globally
Vue.component('font-awesome-icon', FontAwesomeIcon) Vue.component('font-awesome-icon', FontAwesomeIcon)

View File

@ -53,6 +53,12 @@ export const mutations = {
'isRenderedFullContent', 'isRenderedFullContent',
action == null ? true : action action == null ? true : action
) )
},
updateArticleThumbsUpCount(state, action) {
state.detail.data.articleThumbsUpCount += action.thumbsUpNumber
},
updateArticleSponsorCount(state, action) {
state.detail.data.articleSponsorCount += action.sponsorNumber
} }
} }
@ -143,5 +149,11 @@ export const actions = {
commit('updateDetailFetching', false) commit('updateDetailFetching', false)
return Promise.reject(error) return Promise.reject(error)
}) })
},
updateThumbsUpCount({ commit }, params = {}) {
commit('updateArticleThumbsUpCount', params)
},
updateSponsorCount({ commit }, params = {}) {
commit('updateArticleSponsorCount', params)
} }
} }