上传了程序代码

master
赵宇翔 2 years ago
parent af7e305b80
commit 3b2466bd9e

@ -0,0 +1 @@
.intro[data-v-8efaaefc]{font-size:1.6em;font-family:;color:transparent;background-image:linear-gradient(90deg,#ff0,skyblue,purple);-webkit-background-clip:text;background-clip:text;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;font-weight:1000}

@ -0,0 +1 @@
.el-tag+.el-tag[data-v-13bf8707]{margin-left:10px}.button-new-tag[data-v-13bf8707]{margin-left:10px;height:32px;line-height:30px;padding-top:0;padding-bottom:0}.input-new-tag[data-v-13bf8707]{width:90px;margin-left:10px;vertical-align:bottom}

@ -0,0 +1 @@
.login_container{height:100%}.login_box{width:450px;height:300px;background-image:linear-gradient(0deg,#fddb92 0,#d1fdff);border-radius:3px;top:50%}.login_box,.login_box .avatar_box{position:absolute;left:50%;transform:translate(-50%,-50%)}.login_box .avatar_box{height:130px;width:130px;border:1px solid #eee;border-radius:20%;padding:10px;box-shadow:0 0 10px #ddd;background-color:#fff}.login_box .avatar_box img{width:100%;height:100%;border-radius:20%;background-color:#eee}.btns .el-form-item__content{width:100%;margin-left:0!important;display:flex;flex-direction:row;justify-content:space-between;align-items:center}.login_form{position:absolute;bottom:0;width:100%;padding:0 30px;box-sizing:border-box}

@ -0,0 +1 @@
#app,body,html{height:100%;width:100%;margin:0;padding:0}.el-card__body{padding:5px}.el-header{padding:0}.header{padding:5px 20px;display:flex;flex-direction:row;justify-content:space-between;align-items:center}.header .img-box{width:30px;border-radius:10px;overflow:hidden}.footer,.header .title{font-family:;font-weight:bolder}.footer{display:flex;justify-content:center;align-items:center;font-size:20px;padding:10px;margin:5px}.ingredient{padding:5px;height:auto}.ingredient .title{margin:10px 0}.ingredient .btn{display:flex;flex-direction:column;align-items:center;padding:3px;margin:7px}.menu{padding:5px;height:auto}.menu .title{margin:10px 0}.menu .btn{align-items:center;padding:3px;margin:7px}.menu .btn,.menu .desc{display:flex;flex-direction:column}.menu .desc{margin:15px;justify-content:flex-start}.menu .desc .desc-title{margin-bottom:10px;font-family:;font-size:20px;font-weight:bolder}.menu .desc .brief{padding:10px;font-family:;font-size:15px;font-weight:400}.user{padding:5px;height:auto}.user .title{margin:10px 0}.user .btn{display:flex;flex-direction:column;align-items:center;padding:3px;margin:7px}.authority{padding:5px;height:auto}.authority .title{margin:10px 0}.authority .btn{display:flex;flex-direction:column;align-items:center;padding:3px;margin:7px}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

@ -0,0 +1 @@
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>eatwhat-admin</title><script defer="defer" type="module" src="/js/chunk-vendors.a23dee34.js"></script><script defer="defer" type="module" src="/js/app.81cfaf7b.js"></script><link href="/css/chunk-vendors.7518329a.css" rel="stylesheet"><link href="/css/app.e4d13759.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.366d64f1.js" nomodule></script><script defer="defer" src="/js/app-legacy.2c9513bf.js" nomodule></script></head><body><noscript><strong>We're sorry but eatwhat-admin doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>

@ -0,0 +1 @@
.foot[data-v-792468b2]{display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center;font-family:;font-size:larger;font-weight:1000;line-height:1.5em}.foot span[data-v-792468b2]{margin-bottom:10px}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

@ -0,0 +1 @@
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>eatwhat</title><script defer="defer" type="module" src="/js/chunk-vendors.3cfbcd5f.js"></script><script defer="defer" type="module" src="/js/app.556f4121.js"></script><link href="/css/chunk-vendors.e9d4020f.css" rel="stylesheet"><link href="/css/app.3c62ac97.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.fc168d61.js" nomodule></script><script defer="defer" src="/js/app-legacy.725b5e36.js" nomodule></script></head><body><noscript><strong>We're sorry but eatwhat doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>

@ -0,0 +1,32 @@
const express = require("express");
// 获取启动参数
const config = require("./config");
const app = express();
var path = require("path");
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use("/static", express.static(path.join(__dirname, "static")));
app.all("*", function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By", " 3.2.1");
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
//配置路由路径
app.use("/menu", require("./routes/menu"));
app.use("/user", require("./routes/user"));
app.use("/ingredient", require("./routes/ingredient"));
app.use("/admin", require("./routes/admin"));
app.use("/record", require("./routes/record"));
app.listen(config.port, () => {
console.log(`express server listening ---> ${config.db.host}:${config.port}`);
console.log(`数据库:${config.db.database}`)
console.log("学习交流:QQ2631667689")
});

@ -0,0 +1,12 @@
module.exports = {
port: 3006, // express 服务启动端口
/* 数据库相关配置 */
db: {
connectionLimit: 100,
host: 'localhost', // 主机名
port: 3306, // MySQL 默认端口为 3306
user: 'zyx', // 使用 root 用户登入 MySQL
password: '2631667689Zyx...', // MySQL 密码,用你自己的
database: 'mydb' // 使用数据库
}
}

@ -0,0 +1,23 @@
const mysql = require("mysql");
const config = require("./config").db; // 获取数据库配置信息
var pool = mysql.createPool(config); // mysql.createPool 方法创建连接连接池
exports.query = (sql, params = []) => {
return new Promise((resolve, reject) => {
pool.getConnection((err, connection) => {
if (err) {
return reject(err);
}
connection.query(sql, params, (err, result) => {
//释放连接
connection.release();
if (err) {
return reject(err);
}
resolve(result);
});
});
});
};

@ -0,0 +1,15 @@
{
"name": "eatwhat-server",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "node src/index.js"
},
"dependencies": {
"body-parser": "^1.20.0",
"express": "^4.18.1",
"formidable": "^2.0.1",
"mysql": "^2.18.1"
}
}

@ -0,0 +1,25 @@
module.exports = {
selectSuccess: (data) => {
return {
msg: "查询成功",
code: 200,
data: data,
};
},
error() {
return {
msg: "系统异常",
code: 500,
data: null,
};
},
updateSuccess() {
return {
msg: "更新成功",
code: 200,
data: null,
};
},
};

@ -0,0 +1,139 @@
const express = require("express");
let router = express.Router();
// 获取连接实例
const connection = require("../db");
//获取返回结果封装工具
var result = require("../result");
//查询所有管理员
router.get("/", function (req, res) {
console.log("正在获取所有管理员信息,请求参数:", req.params, req.body);
const sql =
"select adminAcco, adminId, adminName, adminNumb, ingredientAuth, menuAuth, power, userAuth from admin_table where adminId != 'unique'";
connection
.query(sql)
.then((data) => {
res.json(result.selectSuccess(data));
})
.then((err) => {
res.send(err);
});
});
//查询单个管理员
router.get("/:id", function (req, res) {
console.log("正在查询管理员信息,请求参数:", req.params, req.body);
const sql =
"select adminAcco, adminId, adminName, adminNumb, ingredientAuth, menuAuth, power, userAuth from admin_table where adminId = ?";
const adminId = req.params.id;
connection
.query(sql, adminId)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//添加新管理员
router.post("/", function (req, res) {
console.log("正在添加普通管理员,请求参数:", req.params, req.body);
const params = req.body;
const sql = "insert into admin_table values(?, ?, ?, ?, ?, ?, ?, ?, ?)";
connection
.query(sql, [
params.adminId,
params.adminNumb,
params.adminName,
params.power,
params.adminPass,
params.adminAcco,
params.menuAuth,
params.ingredientAuth,
params.userAuth,
])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//删除管理员的方法
router.delete("/:id", function (req, res) {
console.log("正在删除管理员,请求参数:", req.params, req.body);
const params = req.params;
const sql = "delete from admin_table where adminId = ?";
connection
.query(sql, params.id)
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//更新管理员信息
router.put("/", function (req, res) {
console.log("正在更新管理员信息,请求参数:", req.params, req.body);
const params = req.body;
const sql =
"update admin_table set adminNumb = ?, adminName = ?, adminAcco = ?, menuAuth = ?, ingredientAuth = ?, userAuth = ? where adminId = ?";
connection
.query(sql, [
params.adminNumb,
params.adminName,
params.adminAcco,
params.menuAuth,
params.ingredientAuth,
params.userAuth,
params.adminId,
])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//重置密码的方法---管理员(密码:123456)
router.post("/password/:id", function (req, res) {
console.log("正在重置管理员密码,请求参数:", req.params, req.body);
const sql = "update admin_table set adminPass = ? where adminId = ?";
const id = req.params.id;
const password = req.body.password;
connection
.query(sql, [password, id])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//管理员登录接口
router.get("/login/:adminAcco", function (req, res) {
console.log("正在调用管理员登录接口,请求参数", req.params, req.body);
const sql = "select * from admin_table where adminAcco = ?";
const adminAcco = req.params.adminAcco;
connection
.query(sql, adminAcco)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
module.exports = router;

@ -0,0 +1,152 @@
const express = require("express");
let router = express.Router();
// 获取连接实例
const connection = require("../db");
//获取返回结果封装工具
var result = require("../result");
//绝对路径
var path = require("path");
//文件上传所需
let formidable = require("formidable");
//上传食材图片图片存放至static/imgs_ingredient目录下
router.post("/upload", function (req, res, next) {
console.log("开始上传食材图片...");
let form = new formidable.IncomingForm();
form.encoding = "utf-8"; // 编码
// 保留扩展名
form.options.keepExtensions = true;
//文件存储路径 最后要注意加 '/' 否则会被存在public下
form.uploadDir = path.join(__dirname, "../static/imgs_ingredient/");
// 解析 formData 数据
form.parse(req, (err, fields, files) => {
if (err) return next(err);
// 返回路径和文件名
let index = files.file.filepath.indexOf("static");
let localPath = files.file.filepath.substr(
index,
files.file.filepath.length
);
var serverPath = ("http://121.37.102.50:3006/" + localPath).replaceAll(
"\\",
"/"
);
console.log("图片路径: " + serverPath);
res.json({
status: 1,
data: serverPath,
msg: "食材图片上传成功",
});
return;
});
});
//添加新食材方法
router.post("/", function (req, res) {
console.log("正在添加新食材,请求参数:", req.params, req.body);
const params = req.body;
const sql = "insert into ingre_table values(?, ?, ?, ?, ?, ?)";
connection
.query(sql, [
params.ingreName,
params.ingreId,
params.ingreAdd,
params.ingreAttr,
params.ingrePut,
params.ingrePrice,
])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//删除食材方法
router.delete("/:id", function (req, res) {
console.log("正在删除食材,请求参数:", req.params, req.body);
const sql = "delete from ingre_table where ingreId = ?";
const params = req.params;
connection
.query(sql, params.id)
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//更新食材信息
router.put("/", function (req, res) {
console.log("正在更新食材信息,请求参数:", req.params, req.body);
const sql =
"update ingre_table set ingreName = ?, ingreAdd = ?, ingreAttr = ?, ingrePut = ?, ingrePrice = ? where ingreId = ?";
const params = req.body;
console.log(params.ingrePut);
connection
.query(sql, [
params.ingreName,
params.ingreAdd,
params.ingreAttr,
params.ingrePut,
params.ingrePrice,
params.ingreId,
])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//查询所有食材
router.get("/", function (req, res) {
console.log("正在查询所有食材信息,请求参数:", req.params, req.body);
const sql = "select * from ingre_table";
connection
.query(sql)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//查询单个食材
router.get("/:id", function (req, res) {
console.log("正在查询单个食材信息,请求参数:", req.params, req.body);
const sql = "select * from ingre_table where ingreId = ?";
const params = req.params;
connection
.query(sql, params.id)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//模糊查询---客户端(keyword格式条件1|条件2|条件3)
router.get("/searchlike/:keyword", function (req, res) {
console.log("正在进行模糊查询,请求参数:", req.params, req.body);
const sql = "select * from ingre_table where ingreName REGEXP ? ";
const keyword = req.params.keyword;
connection
.query(sql, keyword)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
module.exports = router;

@ -0,0 +1,179 @@
const express = require("express");
let router = express.Router();
// 获取连接实例
const connection = require("../db");
//获取返回结果封装工具
var result = require("../result");
//绝对路径
var path = require("path");
//文件上传所需
let formidable = require("formidable");
//上传菜谱图片图片存放至static/imgs_menu目录下
router.post("/upload", function (req, res, next) {
console.log("开始上传菜谱图片...");
let form = new formidable.IncomingForm();
form.encoding = "utf-8"; // 编码
// 保留扩展名
form.options.keepExtensions = true;
//文件存储路径 最后要注意加 '/' 否则会被存在public下
form.uploadDir = path.join(__dirname, "../static/imgs_menu/");
// 解析 formData 数据
form.parse(req, (err, fields, files) => {
if (err) return next(err);
// 返回路径和文件名
let index = files.file.filepath.indexOf("static");
let localPath = files.file.filepath.substr(
index,
files.file.filepath.length
);
var serverPath = ("http://121.37.102.50:3006/" + localPath).replaceAll(
"\\",
"/"
);
console.log("图片路径: " + serverPath);
res.json({
status: 1,
data: serverPath,
msg: "菜谱图片上传成功",
});
return;
});
});
//获取所有菜谱的方法
router.get("/", function (req, res) {
console.log("正在获取所有菜谱信息,请求参数", req.params, req.body);
const sql = "select * from menu_table";
connection
.query(sql)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//查询单个菜谱方法
router.get("/:id", function (req, res) {
console.log("正在获取单个菜谱信息,请求参数", req.params, req.body);
const sql = "select * from menu_table where menuId = ?";
const params = req.params;
connection
.query(sql, params.id)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//添加一个菜谱
router.post("/", function (req, res) {
console.log("正在添加新菜谱,请求参数", req.params, req.body);
const sql = "insert into menu_table values(?, ?, ?, ?, ?, ?, ?, ?, ?)";
const params = req.body;
connection
.query(sql, [
params.menuName,
params.menuId,
params.menuEle,
params.menuTaste,
params.menuCuis,
params.menuBrief,
params.menuLevel,
params.menuPut,
params.menuPrice,
])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//删除菜谱方法
router.delete("/:id", function (req, res) {
console.log("正在删除菜谱,请求参数", req.params, req.body);
const sql = "delete from menu_table where menuId = ?";
const params = req.params;
connection
.query(sql, params.id)
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//更新菜谱的方法
router.put("/", function (req, res) {
console.log("正在更新菜谱信息,请求参数", req.params, req.body);
const sql =
"update menu_table set menuName = ?, menuEle = ?, menuTaste = ?, menuCuis = ?, menuBrief = ?, menuLevel = ?, menuPut = ?, menuPrice = ? where menuId = ?";
const params = req.body;
connection
.query(sql, [
params.menuName,
params.menuEle,
params.menuTaste,
params.menuCuis,
params.menuBrief,
params.menuLevel,
params.menuPut,
params.menuPrice,
params.menuId,
])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//模糊查询---客户端(keyword格式条件1|条件2|条件3)
router.get("/searchlike/:keyword", function (req, res) {
console.log("正在进行模糊查询,请求参数", req.params, req.body);
const sql =
"select * from menu_table where concat(menuName, menuEle, menuTaste, menuCuis) REGEXP ? ";
const keyword = req.params.keyword;
connection
.query(sql, keyword)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//根据菜谱id查询多个菜谱
router.post("/user/menuinfo", function (req, res) {
console.log(
"正在根据菜谱Id查询多个菜谱信息,请求参数为:",
req.params,
req.body
);
const sql =
"select * from menu_table, record where menu_table.menuId in (?) and menu_table.menuId = record.menuId";
const ids = req.body.menuIdsArr;
connection
.query(sql, ids)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
module.exports = router;

@ -0,0 +1,97 @@
const express = require("express");
let router = express.Router();
// 获取连接实例
const connection = require("../db");
//获取返回结果封装工具
var result = require("../result");
//查询单个用户的菜谱历史记录
router.get("/:userId", function (req, res) {
console.log("正在查询单个用户菜谱历史记录,请求参数:", req.params, req.body);
const sql = "select * from record where userId = ?";
const userId = req.params.userId;
connection
.query(sql, userId)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//添加菜谱历史记录
router.post("/", function (req, res) {
console.log("正在添加菜谱历史记录", req.params, req.body);
const sql = "insert into record values(?, ?, ?, ?)";
const params = req.body;
connection
.query(sql, [
params.recordId,
params.userId,
params.menuId,
params.createTime,
])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.then((err) => {
res.send(err);
});
});
//删除单个菜谱历史记录
router.delete("/:recordId", function (req, res) {
console.log("正在删除单个菜谱历史记录,请求参数:", req.params, req.body);
const sql = "delete from record where recordId = ?";
const recordId = req.params.recordId;
connection
.query(sql, recordId)
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//删除单个用户所有菜谱历史记录
router.delete("/user/:userId", function (req, res) {
console.log(
"正在删除某个用户所有菜谱历史记录,请求参数:",
req.params,
req.body
);
const sql = "delete from record where userId = ?";
const userId = req.params.userId;
connection
.query(sql, userId)
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//更新某个菜谱历史记录
router.put("/:recordId", function (req, res) {
console.log("正在更新菜谱历史记录,请求参数:", req.params, req.body);
const sql = "update record set count = count + 1 where recordId = ?";
const recordId = req.params.recordId;
connection
.query(sql, recordId)
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
module.exports = router;

@ -0,0 +1,171 @@
const express = require("express");
let router = express.Router();
// 获取连接实例
const connection = require("../db");
//获取返回结果封装工具
var result = require("../result");
//查询所有用户方法
router.get("/", function (req, res) {
console.log("正在查询所有用户,请求参数为:", req.params, req.body);
const sql = "select * from user_table";
connection
.query(sql)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//查询单个用户的方法
router.get("/:id", function (req, res) {
console.log("正在查询单个用户信息,请求参数为:", req.params, req.body);
const params = req.params;
const sql = "select * from user_table where userId = ?";
connection
.query(sql, params.id)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//添加新用户方法
router.post("/", function (req, res) {
console.log("正在添加新用户,请求参数为:", req.params, req.body);
const params = req.body;
const sql = "insert into user_table values(?, ?, ?, ?, ?, ?, ?)";
connection
.query(sql, [
params.userId,
params.userPwd,
params.userName,
params.userNumb,
params.userLike,
params.userAdd,
params.userGend,
])
.then((data) => {
// 如果插入发生错误
if (data.affectedRows !== 1) res.json(result.error());
//否则插入数据成功
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//删除用户的方法
router.delete("/:id", function (req, res) {
console.log("正在删除用户,请求参数为:", req.params, req.body);
const params = req.params;
const sql = "delete from user_table where userId = ?";
connection
.query(sql, params.id)
.then((data) => {
// 如果删除发生错误
if (data.affectedRows !== 1) res.json(result.error());
//否则删除数据成功
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//更新用户信息
router.put("/", function (req, res) {
console.log("正在更新用户信息,请求参数为:", req.params, req.body);
const params = req.body;
const sql =
"update user_table set userPwd = ?, userName = ?, userNumb = ?, userLike = ?, userAdd = ?, userGend = ? where userId = ?";
connection
.query(sql, [
params.userPwd,
params.userName,
params.userNumb,
params.userLike,
params.userAdd,
params.userGend,
params.userId,
])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//修改密码的方法---客户端
router.post("/password/:id", function (req, res) {
console.log("正在修改用户密码,请求参数为:", req.params, req.body);
const sql = "update user_table set userPwd = ? where userId = ?";
const id = req.params.id;
const password = req.body.password;
connection
.query(sql, [password, id])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
//登录接口---客户端
router.get("/login/:userNumb", function (req, res) {
console.log("正在调用登录接口,请求参数为:", req.params, req.body);
const sql = "select * from user_table where userNumb = ?";
const userNumb = req.params.userNumb;
connection
.query(sql, userNumb)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//通过电话号码查询密码--客户端忘记密码
router.get("/login/forgetpass/:number", function (req, res) {
console.log("正在通过电话号码查询密码,请求参数为:", req.params, req.body);
const sql = "select userPwd from user_table where userNumb = ?";
const number = req.params.number;
connection
.query(sql, number)
.then((data) => {
res.json(result.selectSuccess(data));
})
.catch((err) => {
res.send(err);
});
});
//用户注册方法---客户端
router.post("/register", function (req, res) {
console.log("正在注册新用户,请求参数为:", req.params, req.body);
const params = req.body;
const sql =
"insert into user_table (userId, userPwd, userNumb) values(?, ?, ?)";
connection
.query(sql, [params.userId, params.userPwd, params.userNumb])
.then((data) => {
if (data.affectedRows !== 1) res.json(result.error());
else res.json(result.updateSuccess());
})
.catch((err) => {
res.send(err);
});
});
module.exports = router;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save