代码拉取完成,页面将自动刷新
import express from 'express';
import bodyParser from 'body-parser'
import fs from 'fs'
const app = express();
app.use(bodyParser.json());
const router = express.Router();
app.use(router);
app.use(bodyParser.urlencoded({ extended: false }))
import jwt from 'jsonwebtoken';
const secretKey = 'your_secret_key';
function authenticateToken(req, res, next) {
const authHeader = req.headers.authorization;
const token = authHeader;
console.log(token)
if (token == null) return res.sendStatus(401);
jwt.verify(token, secretKey, (err, user) => {
if (err) return res.sendStatus(403);
req.user = user;
next();
});
}
router.post('/list', (req, res) => {
res.json({ message: 'This is a protected route. User: ' + req.user.username });
})
router.post('/login', (req, res) => {
const { name, password, phone } = req.body;
const user = req.body;
const token = jwt.sign(user, secretKey, { expiresIn: '1h' });
if ((name == '1' && password == '1') || (phone === '1' && password == '1')) {
res.send({
status: '200',
data: true,
token: token
})
} else {
res.send({
status: '400',
data: false,
message: '账号或密码错误!'
})
}
})
router.get('/register', (req, res) => {
const { name, password, phone, verifyCode, InvitationCode } = req.body;
const user = req.body;
const token = jwt.sign(user, secretKey, { expiresIn: '1h' });
if (password != '' && phone != '' && verifyCode != '' && InvitationCode != '') {
res.send({
status: '200',
data: true,
id: '1'
})
} else {
res.send({
status: '400',
data: false,
message: '请填写完整信息!'
})
}
})
router.get('/uniList', (req, res) => {
res.send({
status: '200',
data: true,
})
})
router.get('/getTitle', authenticateToken, (req, res) => {
res.send({
status: '200',
data: 'Title',
})
})
router.get('/icon', (req, res) => {
res.send({
status: '200',
data: 'https://fastly.jsdelivr.net/npm/@vant/assets/logo.png',
})
})
router.get('/background', (req, res) => {
res.send({
status: '200',
data: '../../static/login.jpg',
})
})
router.get('/getProductTitle', (req, res) => {
let data = [
{
id: '1',
title: 'product'
},
{
id: '2',
title: 'vip'
},
{
id: '3',
title: 'gift'
},
{
id: '4',
title: 'salary'
},
{
id: '5',
title: 'balance'
},
]
res.send({
status: '200',
data: data,
})
})
router.get('/homeNote', (req, res) => {
res.send({
status: '200',
data: {
icon: 'https://fastly.jsdelivr.net/npm/@vant/assets/logo.png',
title: '我是第一个',
note: '我是第二个',
text: 'button'
}
})
})
router.get('/revenue', (req, res) => {
res.send({
status: '200',
data: {
title: "Total Revenue",
revenue_sum: "421$",
revenue_list: [
{
name: "XXXX",
increase: 100,
reduce: "product",
remaining: "remaining",
description: "description",
time: "2022-01-01"
}, {
name: "XXXX",
increase: 100,
reduce: "product",
remaining: "remaining",
description: "description",
time: "2022-01-01"
}, {
name: "XXXX",
increase: 100,
reduce: "product",
remaining: "remaining",
description: "description",
time: "2022-01-01"
}, {
name: "XXXX",
increase: 100,
reduce: "product",
remaining: "remaining",
description: "description",
time: "2022-01-01"
}, {
name: "XXXX",
increase: 100,
reduce: "product",
remaining: "remaining",
description: "description",
time: "2022-01-01"
}, {
name: "XXXX",
increase: 100,
reduce: "product",
remaining: "remaining",
description: "description",
time: "2022-01-02"
},
]
}
})
})
router.get('/getProduction', (req, res) => {
const { page, size, categories, needVipLevel } = req.query;
fs.readFile('./productList.json', 'utf8', (err, data) => {
const jsonData = JSON.parse(data);
const dataList = jsonData.dataList.filter(item => {
return item.page == page && item.size == size && item.categories == categories && item.need_vip_level == needVipLevel
})
res.send({
status: '200',
data: dataList,
})
});
})
// 我的页面
router.get('/getUserInfo', authenticateToken, (req, res) => {
res.send({
status: '200',
data: {
userName: '肥胖年糕',
icon: 'https://fastly.jsdelivr.net/npm/@vant/assets/logo.png',
backgroundImage: '../../static/login.jpg',
newLevel: 'Vip5',
nextLevel: 'Vip8',
progress: '10',
countProgress: '100',
myList: [
{
id: 1,
text: 'text1'
},
{
id: 2,
text: 'text2'
},
{
id: 3,
text: 'text3'
},
{
id: 4,
text: 'text4'
},
]
}
})
})
router.get('/sendSms', (req, res) => {
res.send({
status: '200',
data: "4455"
})
})
router.get('/team', (req, res) => {
res.send({
status: '200',
data: {
team: {
team_size: 3,
totle_revenue: '1',
purchasing_commission: '2',
invitation_income: "4",
wealth_income: "4",
task_income: "5"
},
team_level: [
{
team_level: "L1",
team_size: 3,
number_of_investors: 0,
team_charging: "2",
investment_rate: "2",
},
{
team_level: "L2",
team_size: 33,
number_of_investors: 0,
team_charging: "2",
investment_rate: "2",
},
{
team_level: "L3",
team_size: 32,
number_of_investors: 0,
team_charging: "2",
investment_rate: "2",
},
]
}
})
})
app.listen(8080, () => {
console.log('监听端口8080成功!')
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。