修改文章状态的查询

This commit is contained in:
LittleBoy 2022-05-12 11:02:47 +08:00
parent 0847b0823a
commit 07ba7c016e
3 changed files with 7 additions and 7 deletions

2
db.sql
View File

@ -26,7 +26,7 @@ create table article(
category varchar(20) not null,
view_count int default 0,
comment_count int default 0,
status tinyint(1) default 1 -- 状态 1标识草稿 2表示已发布 0表示已删除
status tinyint(1) default 1 -- 状态 1标识已发布 2表示草稿 0表示已删除
);
INSERT INTO article(title,publish_time,description,content,category,cover) VALUES('测试1','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认','https://www.liulinblog.com/wp-content/uploads/2022/05/1652233699-97014b5f43a5d59-300x200.webp');
INSERT INTO article(title,publish_time,description,content,category) VALUES('测试2','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认');

View File

@ -13,10 +13,10 @@ router.get("/web/list", async function (req, res) {
try {
const listResult = await db.query(
`select id,title,category,publish_time,cover,description,view_count,comment_count
from article where title like ? or content like ? limit ?,?`,
from article where (title like ? or content like ? ) and status = 1 limit ?,?`,
[search, search, start, size]); // 执行查询语句并等待结果出来后赋值给变量
const totalCount = await db.query(
`select count(*) as total from article where title like ? or content like ?`, [search, search]); // 执行获取总条数
`select count(*) as total from article where (title like ? or content like ?) and status = 1`, [search, search]); // 执行获取总条数
res.send({ total: totalCount[0]['total'], list: listResult, size: size });
} catch (e) {
console.log(e)
@ -29,7 +29,7 @@ router.all('/web/detail',async (req,res)=>{
if(!id || id <1){
res.send([])
}else{
const article = await db.query('select * from article where id =?',[id]);
const article = await db.query('select * from article where id =? and status = 1',[id]);
res.send(article)
}
});
@ -37,12 +37,11 @@ router.all('/web/detail',async (req,res)=>{
router.all('/web/update',async (req,res)=>{
let id = req.query['id'];
if(!id || id <1){
res.send("参数不对")
res.send({status:false,message:"参数不对"})
}else{
const article = await db.query('update article set view_count=view_count + 1 where id =?',[id]);
res.send("true")
res.send({status:true})
}
});
// 管理后台模块
module.exports = router

View File

@ -69,6 +69,7 @@
return;
}
const id = params.id;
await request('./api/article/web/update', { id })
const articleList = await request('./api/article/web/detail', { id });
if (articleList.length != 1) {
alert('文章数据有问题');