文章优选功能

This commit is contained in:
ronger 2020-12-18 14:13:03 +08:00
parent 2b3d6861e9
commit b79977863c
2 changed files with 88 additions and 30 deletions

View File

@ -4,8 +4,14 @@
<el-col v-for="article in articles.articles" :key="article.idArticle" style="padding-bottom: 1rem;"> <el-col v-for="article in articles.articles" :key="article.idArticle" style="padding-bottom: 1rem;">
<el-card> <el-card>
<div class="card-body d-flex flex-column"> <div class="card-body d-flex flex-column">
<el-link rel="nofollow" @click="onRouter('article',article.articleLink)" :underline="false" style="margin-bottom: .5rem;"> <el-link rel="nofollow" @click="onRouter('article',article.articleLink)" :underline="false"
<h4 v-html="article.articleTitle"></h4> style="margin-bottom: .5rem;">
<h4>
<span v-if="isPerfect(article.articlePerfect)" style="color: gold;" title="优选">
<font-awesome-icon :icon="['fas', 'medal']"></font-awesome-icon>
</span>
{{ article.articleTitle }}
</h4>
</el-link> </el-link>
<el-tag <el-tag
style="margin-left: 0.5rem;" style="margin-left: 0.5rem;"
@ -25,14 +31,16 @@
</el-col> </el-col>
<el-col :xs="16" :sm="16" :xl="16"> <el-col :xs="16" :sm="16" :xl="16">
<div> <div>
<el-link rel="nofollow" @click="onRouter('user', article.articleAuthorName)" :underline="false" class="text-default"> <el-link rel="nofollow" @click="onRouter('user', article.articleAuthorName)" :underline="false"
class="text-default">
{{ article.articleAuthorName }} {{ article.articleAuthorName }}
</el-link> </el-link>
<small class="d-block text-muted">{{ article.timeAgo }}</small> <small class="d-block text-muted">{{ article.timeAgo }}</small>
</div> </div>
</el-col> </el-col>
<el-col class="text-right"> <el-col class="text-right">
<el-link rel="nofollow" :underline="false" title="总浏览数"><i class="el-icon-s-data"></i><span style="color: red;">{{ article.articleViewCount }}</span> <el-link rel="nofollow" :underline="false" title="总浏览数"><i class="el-icon-s-data"></i><span
style="color: red;">{{ article.articleViewCount }}</span>
</el-link> </el-link>
</el-col> </el-col>
</el-row> </el-row>
@ -80,6 +88,9 @@
} }
) )
} }
},
isPerfect(articlePerfect) {
return articlePerfect === '1';
} }
} }
} }

View File

@ -4,7 +4,12 @@
<el-card> <el-card>
<div class="card-body d-flex flex-column article"> <div class="card-body d-flex flex-column article">
<div class="article__item"> <div class="article__item">
<h1 class="list__title" v-html="article.articleTitle"></h1> <h1 class="list__title">
<span v-if="isPerfect" style="color: gold;" title="优选">
<font-awesome-icon :icon="['fas', 'medal']"></font-awesome-icon>
</span>
{{ article.articleTitle }}
</h1>
<el-row class="pt-5"> <el-row class="pt-5">
<el-col :xs="3" :sm="1" :xl="1"> <el-col :xs="3" :sm="1" :xl="1">
<el-avatar v-if="article.articleAuthorAvatarUrl" :src="article.articleAuthorAvatarUrl"></el-avatar> <el-avatar v-if="article.articleAuthorAvatarUrl" :src="article.articleAuthorAvatarUrl"></el-avatar>
@ -42,7 +47,12 @@
<el-button size="mini" v-else @click="followUser(article.articleAuthorId)" plain>关注</el-button> <el-button size="mini" v-else @click="followUser(article.articleAuthorId)" plain>关注</el-button>
</template> </template>
<el-button size="mini" v-if="hasPermissions" @click="handleCommand('edit')" plain>编辑文章</el-button> <el-button size="mini" v-if="hasPermissions" @click="handleCommand('edit')" plain>编辑文章</el-button>
<el-button size="mini" v-if="isAdmin" @click="handleCommand('editTag')" plain>编辑标签</el-button> <template v-if="isAdmin">
<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-else size="mini" @click="setPreference" plain>设为优选</el-button>
</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>
<el-col v-else :span="12" style="text-align: right;"> <el-col v-else :span="12" style="text-align: right;">
@ -125,7 +135,7 @@ export default {
return this.$store.getters.hasPermissions('blog_admin'); return this.$store.getters.hasPermissions('blog_admin');
}, },
routeArticleId() { routeArticleId() {
return Number(this.$route.params.article_id) return Number(this.$route.params.article_id);
} }
}, },
head() { head() {
@ -173,6 +183,7 @@ export default {
isShare: false, isShare: false,
dialogVisible: false, dialogVisible: false,
isFollow: false, isFollow: false,
isPerfect: false,
shareData: {} shareData: {}
} }
}, },
@ -212,7 +223,10 @@ export default {
}, },
gotoLogin() { gotoLogin() {
this.$router.push({ this.$router.push({
name: 'login' name: 'login',
query: {
historyUrl: window.location.href
}
}) })
}, },
closeTagsDialog() { closeTagsDialog() {
@ -244,6 +258,38 @@ export default {
} else { } else {
_ts.gotoLogin() _ts.gotoLogin()
} }
},
setPreference() {
let _ts = this;
_ts.$axios.$patch("/api/article/update-perfect", {
idArticle: _ts.article.idArticle,
articlePerfect: '1',
}).then(function (res) {
if (res) {
if (res.success) {
_ts.$set(_ts, 'isPerfect', false);
_ts.$message.success("设置成功!");
} else {
_ts.$message.error(_ts.message);
}
}
})
},
cancelPreference() {
let _ts = this;
_ts.$axios.$patch("/api/article/update-perfect", {
idArticle: _ts.article.idArticle,
articlePerfect: '0',
}).then(function (res) {
if (res) {
if (res.success) {
_ts.$set(_ts, 'isPerfect', true);
_ts.$message.success("取消成功!");
} else {
_ts.$message.error(_ts.message);
}
}
})
} }
}, },
mounted() { mounted() {
@ -267,6 +313,7 @@ export default {
Vue.VditorPreview.lazyLoadImageRender(previewElement); Vue.VditorPreview.lazyLoadImageRender(previewElement);
//VditorPreview.outlineRender(previewElement, outLineElement); //VditorPreview.outlineRender(previewElement, outLineElement);
window.scrollTo(0, 0); window.scrollTo(0, 0);
_ts.$set(_ts, 'isPerfect', _ts.article.articlePerfect === '1')
}) })
if (_ts.user) { if (_ts.user) {