完成文章的删除
This commit is contained in:
parent
4667279624
commit
2ef57d2cdc
@ -66,11 +66,11 @@ router.get("/admin/list", async function (req, res) {
|
|||||||
const search = "%" + (req.query["search"] || "") + "%"; // 搜索关键字
|
const search = "%" + (req.query["search"] || "") + "%"; // 搜索关键字
|
||||||
try {
|
try {
|
||||||
const listResult = await db.query(
|
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]
|
[search, search, start, size]
|
||||||
); // 执行查询语句并等待结果出来后赋值给变量
|
); // 执行查询语句并等待结果出来后赋值给变量
|
||||||
const totalCount = await db.query(
|
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]
|
[search, search]
|
||||||
); // 执行获取总条数
|
); // 执行获取总条数
|
||||||
res.send({
|
res.send({
|
||||||
@ -116,4 +116,14 @@ router.post("/admin/save", async function (req, res) {
|
|||||||
res.send({ status: true });
|
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;
|
module.exports = router;
|
||||||
|
@ -31,6 +31,8 @@ router.post('/web/add', async (req, res) => {
|
|||||||
commentData.ip = getIp(req.ip);
|
commentData.ip = getIp(req.ip);
|
||||||
console.log(commentData)
|
console.log(commentData)
|
||||||
await db.query('insert into comment set ?', 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 })
|
res.send({ status: true })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
@ -53,7 +55,7 @@ function getIpAddress(ip) {
|
|||||||
return '内部网络';
|
return '内部网络';
|
||||||
}
|
}
|
||||||
if (!result.province) return result.country;
|
if (!result.province) return result.country;
|
||||||
return (result.country != '中国' ? result.country : '') + "-" + result.province + "-" + result.city;
|
return (result.country != '中国' ? result.country + "-" : '') + result.province + "-" + result.city;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ export default {
|
|||||||
},
|
},
|
||||||
showEdit(a) {
|
showEdit(a) {
|
||||||
// 不能直接赋值一个对象
|
// 不能直接赋值一个对象
|
||||||
this.form = {...a};
|
this.form = { ...a };
|
||||||
this.showDialog = true;
|
this.showDialog = true;
|
||||||
|
|
||||||
if (editor == null) {
|
if (editor == null) {
|
||||||
@ -53,15 +53,36 @@ export default {
|
|||||||
},
|
},
|
||||||
saveArticle() {
|
saveArticle() {
|
||||||
this.form.content = editor.html(); // 获取编辑器的内容
|
this.form.content = editor.html(); // 获取编辑器的内容
|
||||||
request("./api/article/admin/save", this.form, "POST").then((ret) =>{
|
request("./api/article/admin/save", this.form, "POST").then(
|
||||||
if(ret.status){
|
(ret) => {
|
||||||
this.$message('更新成功')
|
if (ret.status) {
|
||||||
this.showDialog = false // 隐藏对话框
|
this.$message("更新成功");
|
||||||
this.loadArticleList()
|
this.showDialog = false; // 隐藏对话框
|
||||||
}else{
|
this.loadArticleList();
|
||||||
this.$message('更新出错了')
|
} 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(() => {});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -132,6 +132,7 @@
|
|||||||
|
|
||||||
if(ret.status){
|
if(ret.status){
|
||||||
this.$message.success('发表评论成功')
|
this.$message.success('发表评论成功')
|
||||||
|
this.a.comment_count ++; // 直接对评论数+1
|
||||||
this.loadCommentList()
|
this.loadCommentList()
|
||||||
// this.commentContent = '' // 将评论内容清空
|
// this.commentContent = '' // 将评论内容清空
|
||||||
}else{
|
}else{
|
||||||
|
@ -73,7 +73,11 @@
|
|||||||
<td>
|
<td>
|
||||||
<!-- 不需要传参则可以不写方法后的小括号 -->
|
<!-- 不需要传参则可以不写方法后的小括号 -->
|
||||||
<el-link @click="showEdit(art)">修改</el-link>
|
<el-link @click="showEdit(art)">修改</el-link>
|
||||||
<el-link>删除</el-link>
|
<el-popconfirm
|
||||||
|
title="此操作将永久删除该文章数据,是否继续?"
|
||||||
|
@confirm="deleteArticlebyId(art.id)">
|
||||||
|
<el-link slot="reference">删除</el-link>
|
||||||
|
</el-popconfirm>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user