加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 7.47 KB
一键复制 编辑 原始数据 按行查看 历史
屈小康 提交于 2024-10-28 16:33 . '2'
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成功!')
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化