修改文章状态的查询
This commit is contained in:
parent
0847b0823a
commit
07ba7c016e
2
db.sql
2
db.sql
@ -26,7 +26,7 @@ create table article(
|
|||||||
category varchar(20) not null,
|
category varchar(20) not null,
|
||||||
view_count int default 0,
|
view_count int default 0,
|
||||||
comment_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,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','测试测试','测试测试测试测试','默认');
|
INSERT INTO article(title,publish_time,description,content,category) VALUES('测试2','2022-05-10 16:52:09','测试测试','测试测试测试测试','默认');
|
||||||
|
@ -13,10 +13,10 @@ router.get("/web/list", async function (req, res) {
|
|||||||
try {
|
try {
|
||||||
const listResult = await db.query(
|
const listResult = await db.query(
|
||||||
`select id,title,category,publish_time,cover,description,view_count,comment_count
|
`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]); // 执行查询语句并等待结果出来后赋值给变量
|
[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 ?`, [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 });
|
res.send({ total: totalCount[0]['total'], list: listResult, size: size });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
@ -29,7 +29,7 @@ router.all('/web/detail',async (req,res)=>{
|
|||||||
if(!id || id <1){
|
if(!id || id <1){
|
||||||
res.send([])
|
res.send([])
|
||||||
}else{
|
}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)
|
res.send(article)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -37,12 +37,11 @@ router.all('/web/detail',async (req,res)=>{
|
|||||||
router.all('/web/update',async (req,res)=>{
|
router.all('/web/update',async (req,res)=>{
|
||||||
let id = req.query['id'];
|
let id = req.query['id'];
|
||||||
if(!id || id <1){
|
if(!id || id <1){
|
||||||
res.send("参数不对")
|
res.send({status:false,message:"参数不对"})
|
||||||
}else{
|
}else{
|
||||||
const article = await db.query('update article set view_count=view_count + 1 where id =?',[id]);
|
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
|
module.exports = router
|
@ -69,6 +69,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const id = params.id;
|
const id = params.id;
|
||||||
|
await request('./api/article/web/update', { id })
|
||||||
const articleList = await request('./api/article/web/detail', { id });
|
const articleList = await request('./api/article/web/detail', { id });
|
||||||
if (articleList.length != 1) {
|
if (articleList.length != 1) {
|
||||||
alert('文章数据有问题');
|
alert('文章数据有问题');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user