1.0.0 • Published 3 months ago

yyq-pagedemo v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago
const express=require('express');
const app=express();
const fs=require('fs');
app.listen(8888,()=>console.log('开启'))
app.use(express.static('public'))
app.set('view engine',"ejs")
app.get('/',(req,res)=>{
    res.render('index')
})


app.get('/detail',(req,res)=>{
    let{id}=req.query;
     let data=JSON.parse(fs.readFileSync('mock/user.json'))
    let obj=data.find(item=>+item.id===+id)
    res.render('detail',obj)
})
app.get('/api/page',(req,res)=>{
    let{index,num}=req.query;
     fs.readFile('mock/user.json',(err,data)=>{
         if(err){
             res.send({code:0})
             return;
         }
         data=JSON.parse(data);
         res.send({
             code:1,
             arr:data.slice(index*num,(+index+1)*num),
             max:Math.ceil(data.length/num)
         })
     })
})
1.0.0

3 months ago