From 2ef57d2cdc4af55c25f3b94d0670864ed3af081c Mon Sep 17 00:00:00 2001 From: callmeyan Date: Thu, 26 May 2022 09:49:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=96=87=E7=AB=A0=E7=9A=84?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/article.js | 14 ++++++++++++-- modules/comment.js | 4 +++- public/assets/manage.js | 39 ++++++++++++++++++++++++++++++--------- public/detail.html | 1 + public/manage.html | 6 +++++- 5 files changed, 51 insertions(+), 13 deletions(-) diff --git a/modules/article.js b/modules/article.js index 9b76a45..271549c 100644 --- a/modules/article.js +++ b/modules/article.js @@ -66,11 +66,11 @@ router.get("/admin/list", async function (req, res) { const search = "%" + (req.query["search"] || "") + "%"; // 搜索关键字 try { const listResult = await db.query( - `select * from article where (title like ? or content like ? ) and status = 1 limit ?,?`, + `select * from article where (title like ? or content like ? ) and status > 0 limit ?,?`, [search, search, start, size] ); // 执行查询语句并等待结果出来后赋值给变量 const totalCount = await db.query( - `select count(*) as total from article where (title like ? or content like ?) and status = 1`, + `select count(*) as total from article where (title like ? or content like ?) and status > 0`, [search, search] ); // 执行获取总条数 res.send({ @@ -116,4 +116,14 @@ router.post("/admin/save", async function (req, res) { res.send({ status: true }); }); +// 更新状态 +router.all("/admin/update", async function (req, res) { + // 从请求参数中获取要更新的数据 + const {id,status} = req.query; + await db.query( + `update article set status=? where id =?`, + [status,id] + ); + res.send({ status: true }); +}); module.exports = router; diff --git a/modules/comment.js b/modules/comment.js index b1d6482..c91df20 100644 --- a/modules/comment.js +++ b/modules/comment.js @@ -31,6 +31,8 @@ router.post('/web/add', async (req, res) => { commentData.ip = getIp(req.ip); console.log(commentData) await db.query('insert into comment set ?', commentData); + db.query('update article set comment_count=comment_count + 1 where id=?', + [commentData.article_id]) res.send({ status: true }) } catch (e) { console.log(e) @@ -53,7 +55,7 @@ function getIpAddress(ip) { return '内部网络'; } if (!result.province) return result.country; - return (result.country != '中国' ? result.country : '') + "-" + result.province + "-" + result.city; + return (result.country != '中国' ? result.country + "-" : '') + result.province + "-" + result.city; } diff --git a/public/assets/manage.js b/public/assets/manage.js index 24a9c6b..c131a7b 100644 --- a/public/assets/manage.js +++ b/public/assets/manage.js @@ -33,8 +33,8 @@ export default { this.list = ret.list; }, showEdit(a) { - // 不能直接赋值一个对象 - this.form = {...a}; + // 不能直接赋值一个对象 + this.form = { ...a }; this.showDialog = true; if (editor == null) { @@ -53,15 +53,36 @@ export default { }, saveArticle() { this.form.content = editor.html(); // 获取编辑器的内容 - request("./api/article/admin/save", this.form, "POST").then((ret) =>{ - if(ret.status){ - this.$message('更新成功') - this.showDialog = false // 隐藏对话框 - this.loadArticleList() - }else{ - this.$message('更新出错了') + request("./api/article/admin/save", this.form, "POST").then( + (ret) => { + if (ret.status) { + this.$message("更新成功"); + this.showDialog = false; // 隐藏对话框 + this.loadArticleList(); + } else { + this.$message("更新出错了"); + } } + ); + }, + async deleteArticlebyId(id) { + // status为0表示文章被删除 + const ret = await request("/api/article/admin/update", { + id, + status: 0, }); + this.loadArticleList(); // 重新加载文章列表 + }, + deleteArticle(art) { + // 原生的confirm + // if(confirm('此操作将永久删除该文章数据,是否继续?')){ + // this.deleteArticlebyId(art.id) + // } + // this.$confirm("此操作将永久删除该文件, 是否继续?", "提示") + // .then(() => { // 点击了确定按钮 + // this.deleteArticlebyId(art.id) + // }) + // .catch(() => {}); }, }, }; diff --git a/public/detail.html b/public/detail.html index 42d4089..0b707c7 100644 --- a/public/detail.html +++ b/public/detail.html @@ -132,6 +132,7 @@ if(ret.status){ this.$message.success('发表评论成功') + this.a.comment_count ++; // 直接对评论数+1 this.loadCommentList() // this.commentContent = '' // 将评论内容清空 }else{ diff --git a/public/manage.html b/public/manage.html index 59f5f3f..1d06294 100644 --- a/public/manage.html +++ b/public/manage.html @@ -73,7 +73,11 @@ 修改 - 删除 + + 删除 +