yyq-zsgc
v1.0.0
Published
```js const express=require('express'); const app=express(); const fs=require('fs'); app.listen(8080,()=>console.log('开启')) app.use(express.static('public',{index:"index.html"})) app.use(express.json()) //登录 app.post('/api/login',(req,res)=>{
Downloads
2
Readme
const express=require('express');
const app=express();
const fs=require('fs');
app.listen(8080,()=>console.log('开启'))
app.use(express.static('public',{index:"index.html"}))
app.use(express.json())
//登录
app.post('/api/login',(req,res)=>{
let {user,pass}=req.body;
let data=JSON.parse(fs.readFileSync('mock/user.json'));
let flay=data.some(item=>item.user===user&&item.pass===pass);
if(flay){
res.send({
code:1
})
}else{
res.send({
code:0
})
}
})
//注册
app.post('/api/list',(req,res)=>{
let {user,pass}=req.body;
let data=JSON.parse(fs.readFileSync('mock/user.json'));
let flay=data.some(item=>item.user===user);
if(flay){
res.send({
code:0
})
}else{
data.push(req.body)
fs.writeFileSync('mock/user.json',JSON.stringify(data))
res.send({
code:1
})
}
})
//渲染数据
app.post('/api/re',(req,res)=>{
let data=JSON.parse(fs.readFileSync('mock/list.json'))
res.send(data)
})
//模糊搜索
app.post('/api/sou',(req,res)=>{
let{val}=req.body;
let data=JSON.parse(fs.readFileSync('mock/list.json'));
let arr=data.filter(item=>item.id.includes(val)||item.name.includes(val)||item.age.toString().includes(val))
res.send(arr)
})
//删除
app.post('/api/shan',(req,res)=>{
let {id}=req.body
let data=JSON.parse(fs.readFileSync('mock/list.json'))
data=data.filter(item=>item.id!==id)
let flay= fs.writeFileSync('mock/list.json',JSON.stringify(data))
if(flay){
res.send({
code:0
})
}else{
res.send({
code:1
})
}
})
//提交
app.post('/api/ti',(req,res)=>{
let data=JSON.parse(fs.readFileSync('mock/list.json'))
data.push(req.body)
fs.writeFileSync('mock/list.json',JSON.stringify(data))
res.send({code:1})
})