博客功能点:发布和显示数量

master
王岚馨 11 months ago
parent 3e554e1f7f
commit f868b0f60f

@ -8,11 +8,11 @@
<div class="web-info"> <div class="web-info">
<div class="blog-info-box"> <div class="blog-info-box">
<span>博客</span> <span>博客</span>
<span class="blog-info-num">{{ $store.getters.articleTotal }}</span> <span id="totalBlogNum" class="blog-info-num"></span>
</div> </div>
<div class="blog-info-box"> <div class="blog-info-box">
<span>分类</span> <span>分类</span>
<span class="blog-info-num">{{ sortInfo.length }}</span> <span id="labelTotalNum" class="blog-info-num"></span>
</div> </div>
<div class="blog-info-box"> <div class="blog-info-box">
<span>访问量</span> <span>访问量</span>
@ -31,7 +31,9 @@
<!-- 编辑框 --> <!-- 编辑框 -->
<div class="blog-editor" v-if="showEditor"> <div class="blog-editor" v-if="showEditor">
<textarea v-model="blogContent"></textarea> <textarea class="blog-editor-title" v-model="blogContentTitle" placeholder="请输入博客标题..."></textarea>
<textarea class="blog-editor-content" v-model="blogContent" placeholder="请输入博客正文..."></textarea>
<div class="editor-btns"> <div class="editor-btns">
<button class="cancel-btn" @click="cancelEdit"></button> <button class="cancel-btn" @click="cancelEdit"></button>
<button class="publish-btn" @click="saveBlog"></button> <button class="publish-btn" @click="saveBlog"></button>
@ -56,7 +58,10 @@ export default {
showAdmireDialog: false, showAdmireDialog: false,
articleSearch: "", articleSearch: "",
showEditor: false, showEditor: false,
blogContent: "" blogContent: "",
blogContentTitle:"",
articles: [] , //
labelTotalNum: 0
} }
}, },
computed: { computed: {
@ -70,6 +75,9 @@ export default {
created() { created() {
this.getRecommendArticles(); this.getRecommendArticles();
this.getAdmire(); this.getAdmire();
this.getUserArticles(); //
this.getUserArticleLabelTotalNum();//
console.log('getUserArticleLabelTotalNum is called');
}, },
methods: { methods: {
selectSort(sort) { selectSort(sort) {
@ -117,6 +125,38 @@ export default {
}); });
}); });
}, },
getUserArticleLabelTotalNum() {
const id = this.$store.state.currentUser.id; // ID
this.$http.get(`/admin/article/getUserArticleLabelTotalNum?id=${id}`) // GETID
.then(response => {
const labelNum = response; //
document.getElementById("labelTotalNum").innerText = labelNum;
this.labelTotalNum = labelNum;
console.log(labelNum); //
console.log("label日志");
})
.catch(error => {
console.error('请求错误:', error);
});
},
getUserArticles() {
const id = this.$store.state.currentUser.id; // ID
this.$http.get(`/admin/article/getArticleByUserId?id=${id}`) // GETID
.then(response => {
if (!this.$common.isEmpty(response.data)) {
this.articles = response.data; // articles
document.getElementById("totalBlogNum").innerText = this.articles.length
console.log(response.data)
this.getUserArticleLabelTotalNum()
}
})
.catch(error => {
this.$message({
message: error.message,
type: "error"
});
});
},
showTip() { showTip() {
this.$router.push({path: '/weiYan'}); this.$router.push({path: '/weiYan'});
}, },
@ -132,16 +172,21 @@ export default {
// this.blogContent = ""; // this.blogContent = "";
// let blog = {content:this.blogContent}; // let blog = {content:this.blogContent};
const articleVO = { const articleVO = {
user_id:"sara", userId:this.$store.state.currentUser.id,
article_content: this.blogContent ,// articleContent: this.blogContent ,//
articleTitle:this.blogContentTitle,
// ... // ...
// sort_id:1, sortId:1,
}; };
console.log(this.$store.state.currentUser)
console.log(articleVO) console.log(articleVO)
this.$http.post('/article/saveArticle', articleVO) // POST this.$http.post('/article/saveArticle', articleVO) // POST
.then(response => { .then(response => {
// //
console.log('博客保存成功!'); console.log('博客保存成功!');
this.getUserArticles()
this.showEditor = false;
this.blogContent = "";
}) })
.catch(error => { .catch(error => {
// //
@ -269,42 +314,60 @@ export default {
margin: 0 auto; margin: 0 auto;
align-self: center; align-self: center;
width: 80%; width: 80%;
height: 300px; height: 400px;
background-color: #ba94dc; background-color: #e7deef;
border-radius: 20px; border-radius: 20px;
margin-top: 20px; margin-top: 20px;
padding: 10px; padding: 10px;
border: #5a0bb9 1px solid;
box-sizing: border-box;
}
.blog-editor-title {
display: block;
margin: 0 auto;
width: 40%;
height: 60px;
background-color: #ffffff;
border-radius: 20px;
padding: 10px;
box-sizing: border-box; box-sizing: border-box;
font-weight: bolder;
font-size: 23px;
text-align: center; /* 将文本居中对齐 */
} }
.blog-editor textarea { .blog-editor-content {
display: block;
margin: 0 auto; margin: 0 auto;
width: 100%; width: 100%;
height: 100%; height: 300px;
resize: none; //resize: none;
border: none; //border: none;
outline: none; //outline: none;
border-radius: 20px; border-radius: 20px;
font-size: 16px; font-size: 30px;
font-family: "Microsoft YaHei"; font-weight: bold;
margin-top: 10px;
//font-family: "Microsoft YaHei";
} }
.editor-btns { .editor-btns {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
margin-top: 10px; margin-top: 16px;
} }
.cancel-btn, .cancel-btn,
.publish-btn { .publish-btn {
width: 100px; width: 100px;
height: 30px; height: 35px;
color: #fff; color: #fff;
border-radius: 3px; border-radius: 10px;
cursor: pointer; cursor: pointer;
transition: all .2s linear; transition: all .2s linear;
font-size: 19px; font-size: 19px;
font-weight: bold; font-weight: bold;
margin-top: 8px;
} }
.cancel-btn { .cancel-btn {

Loading…
Cancel
Save