当前位置:   article > 正文

Vue+Node.js+Msyql实现一个简单的毕业设计《体检预约管理系统》_大学前端vue项目

大学前端vue项目

最近接了一个小姐姐的毕业设计,她是要我做一个纯前端《体检预约管理系统》,我一想前端咋去用node.js访问数据库呀?于是乎去面向百度了一波,终究还是找到了案例代码,然后日夜冥思苦想把这个项目做出来给交付了,废话不多说,开始正题!

话不多说咱们直接开整吧,冲啊!!!冲啊!!!冲啊!!!

开发技术及开发工具

开发工具采用vsCode【前后端代码的编写】、Navicat Premium 15【Mysql数据库的连接】

前端采用Vue、ElementUI

后端采用node.js

数据库采用Mysql

轮播图文件存储是用到了阿里云的OSS对象存储,想了解的直接去看官网的SDK就行,免费可以使用的

阿里云官网地址:

云上特卖会场

《体检预约管理系统》视频展示,视频前几十秒可能会有些许的模糊,不过也就几十秒

体检预约管理系统演示视频

项目整体架构图

前端架构图

后端架构图

Vue.js+ElementUi前端核心页面功能截图

这里就不贴代码了,内容太多了,兄弟们需要源码自行到文尾链接下载

1.首页

2.系统管理(用户管理)

3.系统管理(角色管理)

4.系统管理(菜单管理)

5.项目管理(项目详情)

6.套餐管理(套餐详情)

7.记录管理(预约记录)

8.日志管理(登录日志)

9.轮播图管理(轮播图详情)

10.个人管理(个人信息)

11.登录

 

Node.js后端核心代码(以下为部分代码,整个项目请点击文尾连接下载)

1.设置跨域请求

  1. const express = require('express')
  2. const bodyParser = require('body-parser')
  3. const router = require('./router/router.js')
  4. const app = express()
  5. // 跨域请求处理
  6. app.all('*', (req, res, next) => {
  7. res.header('Access-Control-Allow-Origin', '*')
  8. res.header('Access-Control-Allow-Headers', 'X-Requested-With')
  9. res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With, X_Requested_With')
  10. res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS')
  11. res.header('X-Powered-By', '3.2.1')
  12. if (req.method == 'OPTIONS') res.send(200)
  13. /*让options请求快速返回*/ else next()
  14. })
  15. app.use(bodyParser.urlencoded({ extended: false }))
  16. app.use(bodyParser.json())
  17. app.use(router)
  18. app.listen('3000', () => {
  19. console.log('Server is running');
  20. })

2.数据库连接信息设置

host:连接地址

user:数据库用户名

password:数据库密码

database:数据库名称

创建数据连接的js工具类(以下为部分代码,整个项目请点击文尾连接下载)

  1. var mysql = require('mysql')
  2. var mysql_config = {
  3. host: 'localhost',
  4. user: 'root',
  5. password: '123456',
  6. database: 'healthcheck'
  7. }
  8. function handleDisconnection() {
  9. var dbServer = mysql.createConnection(mysql_config)
  10. dbServer.connect(function (err) {
  11. console.log('数据库链接成功')
  12. if (err) {
  13. setTimeout(handleDisconnection, 2000)
  14. }
  15. })
  16. dbServer.on('error', function (err) {
  17. console.log('db error', err)
  18. if (err.code === 'PROTOCOL_CONNECTION_LOST') {
  19. console.log('db error执行重连:' + err.message)
  20. handleDisconnection()
  21. } else {
  22. throw err
  23. }
  24. })
  25. return dbServer //返回一个connection对象,用于调用它的其他方法
  26. exports.dbServer = dbServer
  27. }
  28. exports.handleDisconnection = handleDisconnection

3.功能接口

感觉跟java的jdbc差不多也是创建连接对象然后再去执行sql语句,最后再获取返回结果(以下为部分代码,整个项目请点击文尾连接下载)

  1. const express = require('express')
  2. const con = require('../modul/db.js')
  3. const router = express.Router()
  4. let db= con.handleDisconnection()
  5. //====================================================================
  6. //====================================================================
  7. //首页当天查询
  8. router.get('/getToay', (req, res) => {
  9. let sql = "select (select count(*) from record as r where r.cid = c.cid and date(r.time) = curdate()) as count,c.* from combo as c ";
  10. db.query({
  11. sql: sql
  12. }, (err, results, fields) => {
  13. res.send(results)
  14. })
  15. })
  16. //近7天查询
  17. router.get('/getWeek', (req, res) => {
  18. let sql = "select (select count(*) from record as r where r.cid = c.cid and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(r.time)) as count,c.* from combo as c ";
  19. db.query({
  20. sql: sql
  21. }, (err, results, fields) => {
  22. res.send(results)
  23. })
  24. })
  25. //近30天查询
  26. router.get('/getMonth', (req, res) => {
  27. let sql = "select (select count(*) from record as r where r.cid = c.cid and DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(r.time)) as count,c.* from combo as c ";
  28. db.query({
  29. sql: sql
  30. }, (err, results, fields) => {
  31. res.send(results)
  32. })
  33. })
  34. //今年查询
  35. router.get('/getYear', (req, res) => {
  36. let sql = "select (select count(*) from record as r where r.cid = c.cid and YEAR(r.time)=YEAR(NOW())) as count,c.* from combo as c ";
  37. db.query({
  38. sql: sql
  39. }, (err, results, fields) => {
  40. res.send(results)
  41. })
  42. })
  43. //====================================================================
  44. //====================================================================
  45. //登录
  46. router.get('/login', (req, res) => {
  47. let account = req.query.account //账号
  48. let password = req.query.password //密码
  49. let sql = "select * from `user` where account = '"+account+"' and `password` = '"+password+"';";
  50. db.query({
  51. sql: sql
  52. }, (err, results, fields) => {
  53. res.send(results)
  54. })
  55. })
  56. //注册用户
  57. router.post('/register', (req, res) => {
  58. // let dat = new Date
  59. let sql = "INSERT INTO `user`(account,`password`,`time`,`status`) "+
  60. "VALUES ('"+req.body.account+"', '"+req.body.password+"', '"+req.body.time+"','1')";
  61. db.query(sql, (err, result) => {
  62. if (err) {
  63. console.log("错误信息",err)
  64. } else {
  65. //获取用户编号
  66. var uid = result.insertId;
  67. //新增用户角色表
  68. let sql = "INSERT INTO `userrole`(rid,uid) VALUES ('3', '"+uid+"')";
  69. db.query(sql, (err, result) => {
  70. if (err) {
  71. console.log("错误信息",err)
  72. } else {
  73. res.json({
  74. code: 200
  75. })
  76. }
  77. })
  78. }
  79. })
  80. })
  81. //====================================================================
  82. //====================================================================
  83. //根据用户编号查询root节点
  84. router.get('/rootMeun', (req, res) => {
  85. let uid = req.query.uid //用户编号
  86. let sql = "select * from `user` as u "+
  87. "inner join userrole as ur on ur.uid = u.uid "+
  88. "inner join role as r on ur.rid=r.rid "+
  89. "inner join menurole as mr on mr.rid=r.rid "+
  90. "inner join menu as m on mr.mid=m.mid "+
  91. "where u.uid = '"+uid+"' and m.pid = '0'";
  92. db.query({
  93. sql: sql,
  94. nestTables:'_'
  95. },function(err,result){
  96. res.send(result)
  97. })
  98. })
  99. //根据root节点查询子节点
  100. router.get('/childrenMeun', (req, res) => {
  101. let mid = req.query.mid //root菜单编号
  102. let sql = "select * from `menu` where pid = '"+mid+"';";
  103. db.query({
  104. sql: sql
  105. }, (err, results, fields) => {
  106. res.send(results)
  107. })
  108. })
  109. //====================================================================
  110. //====================================================================
  111. //新增用户
  112. router.post('/addUser', (req, res) => {
  113. let sql = "INSERT INTO `user`(account,`password`,`name`,`number`,`gender`,`phone`,`address`,`age`,`time`,`status`) "+
  114. "VALUES ('"+req.body.account+"', '"+req.body.password+"','"+req.body.name+"','"+req.body.number+"','"+req.body.gender+"','"+req.body.phone+"','"+req.body.address+"','"+req.body.age+"', '"+req.body.time+"','"+req.body.status+"')";
  115. db.query(sql, (err, result) => {
  116. if (err) {
  117. console.log("错误信息",err)
  118. } else {
  119. //获取用户编号
  120. var uid = result.insertId;
  121. //获取角色编号
  122. var rid = req.body.backup;
  123. //新增用户角色表
  124. let sql = "INSERT INTO `userrole`(rid,uid) VALUES ('"+rid+"', '"+uid+"')";
  125. db.query(sql, (err, result) => {
  126. if (err) {
  127. console.log("错误信息",err)
  128. } else {
  129. res.json({
  130. code: 200
  131. })
  132. }
  133. })
  134. }
  135. })
  136. })
  137. // 删除用户
  138. router.get('/delUser', (req, res) => {
  139. let uid = req.query.uid;
  140. let sql = "DELETE FROM `user` WHERE uid = '"+uid+"'";
  141. db.query(sql, (err, result) => {
  142. if (err) {
  143. console.log(err)
  144. } else {
  145. res.json({
  146. code: 200
  147. })
  148. }
  149. })
  150. })
  151. //修改用户
  152. router.post('/updateUser', (req, res) => {
  153. //获取用户编号
  154. let uid = req.body.uid;
  155. //获取角色编号
  156. let rid = req.body.rid;
  157. let sql = "UPDATE `user` SET "+
  158. "account = '"+req.body.account+"',"+
  159. "password = '"+req.body.password+"',"+
  160. "name = '"+req.body.name+"',"+
  161. "number = '"+req.body.number+"',"+
  162. "gender = '"+req.body.gender+"',"+
  163. "phone = '"+req.body.phone+"',"+
  164. "address = '"+req.body.address+"',"+
  165. "age = '"+req.body.age+"',"+
  166. "status = '"+req.body.status+"'"+
  167. "WHERE uid = '"+uid+"'";
  168. db.query(sql, (err, result) => {
  169. if (err) {
  170. console.log("错误信息1",err)
  171. } else {
  172. if(''!=rid){
  173. //修改用户角色表
  174. let sql = "UPDATE `userrole` SET "+
  175. "rid = '"+rid+"'"+
  176. "WHERE uid = '"+uid+"'";
  177. db.query(sql, (err, result) => {
  178. if (err) {
  179. console.log("错误信息2",err)
  180. } else {
  181. res.json({
  182. code: 200
  183. })
  184. }
  185. })
  186. }else{
  187. res.json({
  188. code: 200
  189. })
  190. }
  191. }
  192. })
  193. })
  194. //查询所有用户
  195. router.get('/queryUser', (req, res) => {
  196. let sql = "select r.rname as rname,u.* from `user` as u "+
  197. "inner join userrole as ur on ur.uid = u.uid "+
  198. "inner join role as r on ur.rid=r.rid;"
  199. db.query({
  200. sql: sql
  201. }, (err, results, fields) => {
  202. res.send(results)
  203. })
  204. })
  205. //分页查询所有用户
  206. router.get('/queryUserPage', (req, res) => {
  207. //模糊查询用户名称
  208. let input = req.query.input;
  209. //模糊查询用户地址
  210. let address = req.query.address;
  211. //模糊查询用户角色
  212. let option = req.query.option;
  213. //模糊查询用户状态
  214. let status = req.query.status;
  215. //默认页码
  216. let currentPage = 1;
  217. //默认显示数据条数
  218. let pageSize = 8;
  219. if(req.query.currentPage){
  220. currentPage = req.query.currentPage;
  221. }
  222. if(req.query.pageSize){
  223. pageSize = req.query.pageSize;
  224. }
  225. //最后一页页码
  226. let last_page = currentPage-1;
  227. if(currentPage<=1){
  228. last_page = 1;
  229. }
  230. console.log("当前页",currentPage);
  231. let total = 0;
  232. //查询总条数
  233. let sql = "select r.rname as rname,u.* from `user` as u "+
  234. "inner join userrole as ur on ur.uid = u.uid "+
  235. "inner join role as r on ur.rid=r.rid where 1=1 "
  236. if(input!='' && input!=undefined){
  237. sql += "and u.name like '%"+input+"%' ";
  238. }
  239. if(address!='' && address!=undefined){
  240. sql += "and u.address like '%"+address+"%' ";
  241. }
  242. if(option!='' && option!=undefined){
  243. sql += "and r.rid = '"+option+"' ";
  244. }
  245. if(status!='' && status!=undefined){
  246. sql += "and u.status = '"+status+"' ";
  247. }
  248. console.log(sql);
  249. db.query({
  250. sql: sql
  251. }, (err, results, fields) => {
  252. console.log(results.length)
  253. total = results.length;
  254. currentPage = (currentPage - 1 ) * pageSize;
  255. let sql2 = sql+"limit "+currentPage+","+pageSize+"";
  256. db.query({
  257. sql: sql2
  258. }, (err, results, fields) => {
  259. console.log(results)
  260. if(results!=''){
  261. results[0].backup3 = total;
  262. }
  263. res.send(results)
  264. })
  265. })
  266. })
  267. //根据ID查询用户
  268. router.get('/queryUserById', (req, res) => {
  269. let uid = req.query.uid;
  270. let sql = "select r.rname as rname,r.rid as rid,u.* from `user` as u "+
  271. "inner join userrole as ur on ur.uid = u.uid "+
  272. "inner join role as r on ur.rid=r.rid where u.uid = '"+uid+"'";
  273. db.query({
  274. sql: sql
  275. }, (err, results, fields) => {
  276. console.log(results);
  277. res.send(results)
  278. })
  279. })
  280. //====================================================================
  281. //====================================================================
  282. //新增角色
  283. router.post('/addRole', (req, res) => {
  284. let backup = req.body.pid;
  285. let sql = "INSERT INTO `role`(rname,`desc`) "+
  286. "VALUES ('"+req.body.rname+"', '"+req.body.desc+"')";
  287. db.query(sql, (err, result) => {
  288. if (err) {
  289. console.log("错误信息",err)
  290. } else {
  291. //判断新增是不是父节点
  292. res.json({
  293. code: 200
  294. })
  295. }
  296. })
  297. })
  298. //查询所有角色
  299. router.get('/queryRole', (req, res) => {
  300. let sql = "select * from `role`;";
  301. db.query({
  302. sql: sql
  303. }, (err, results, fields) => {
  304. res.send(results)
  305. })
  306. })
  307. //分页查询所有角色
  308. router.get('/queryRolePage', (req, res) => {
  309. //默认页码
  310. let currentPage = 1;
  311. //默认显示数据条数
  312. let pageSize = 9;
  313. if(req.query.currentPage){
  314. currentPage = req.query.currentPage;
  315. }
  316. if(req.query.pageSize){
  317. pageSize = req.query.pageSize;
  318. }
  319. //最后一页页码
  320. let last_page = currentPage-1;
  321. if(currentPage<=1){
  322. last_page = 1;
  323. }
  324. console.log("当前页",currentPage);
  325. let total = 0;
  326. //查询总条数
  327. let sql = "select * from role";
  328. console.log(sql);
  329. db.query({
  330. sql: sql
  331. }, (err, results, fields) => {
  332. console.log(results.length)
  333. total = results.length;
  334. currentPage = (currentPage - 1 ) * pageSize;
  335. let sql2 = "select * from role "+
  336. "limit "+currentPage+","+pageSize+" ";
  337. db.query({
  338. sql: sql2
  339. }, (err, results, fields) => {
  340. console.log(err);
  341. console.log("这是sql2",sql2)
  342. if(results!=''){
  343. results[0].backup3 = total;
  344. }
  345. res.send(results)
  346. })
  347. })
  348. })
  349. // 删除角色
  350. router.get('/delRole', (req, res) => {
  351. let rid = req.query.rid;
  352. let sql = "DELETE FROM `role` WHERE rid = '"+rid+"'";
  353. db.query(sql, (err, result) => {
  354. if (err) {
  355. console.log(err)
  356. } else {
  357. res.json({
  358. code: 200
  359. })
  360. }
  361. })
  362. })
  363. //修改角色
  364. router.post('/updateRole', (req, res) => {
  365. //获取角色编号
  366. let rid = req.body.rid;
  367. let sql = "UPDATE `role` SET "+
  368. "rname = '"+req.body.rname+"',"+
  369. "`desc` = '"+req.body.desc+"' "+
  370. "WHERE rid = '"+rid+"'";
  371. db.query(sql, (err, result) => {
  372. if (err) {
  373. console.log("错误信息1",err)
  374. } else {
  375. res.json({
  376. code: 200
  377. })
  378. }
  379. })
  380. })
  381. //根据ID查询角色
  382. router.get('/queryRoleById', (req, res) => {
  383. let rid = req.query.rid;
  384. let sql = "select * from role "+
  385. "where rid = '"+rid+"'";
  386. db.query({
  387. sql: sql
  388. }, (err, results, fields) => {
  389. console.log(results);
  390. res.send(results)
  391. })
  392. })
  393. //根据角色编号查询出他所有的父菜单
  394. router.get('/queryMenuByRid', (req, res) => {
  395. let rid = req.query.rid;
  396. let sql = "select m.mid as mid from menu as m "+
  397. "inner join menurole as mr on m.mid=mr.mid "+
  398. "where mr.rid = '"+rid+"' and m.pid = '0' ";
  399. db.query({
  400. sql: sql
  401. }, (err, results, fields) => {
  402. console.log(results);
  403. res.send(results)
  404. })
  405. })
  406. //新增角色对应菜单
  407. router.get('/addRoleMenu', (req, res) => {
  408. let sql = "INSERT INTO `menurole`(rid,mid) "+
  409. "VALUES ('"+req.query.rid+"', '"+req.query.mid+"' )";
  410. db.query(sql, (err, result) => {
  411. if (err) {
  412. console.log("错误信息",err)
  413. } else {
  414. res.json({
  415. code: 200
  416. })
  417. }
  418. })
  419. })
  420. // 删除角色对应菜单
  421. router.get('/delRoleMenu', (req, res) => {
  422. let rid = req.query.rid;
  423. let sql = "DELETE FROM `menurole` WHERE rid = '"+rid+"'";
  424. db.query(sql, (err, result) => {
  425. if (err) {
  426. console.log(err)
  427. } else {
  428. res.json({
  429. code: 200
  430. })
  431. }
  432. })
  433. })
  434. //====================================================================
  435. //====================================================================
  436. //新增菜单
  437. router.post('/addMenu', (req, res) => {
  438. let backup = req.body.pid;
  439. let sql = "INSERT INTO `menu`(mname,pid,url) "+
  440. "VALUES ('"+req.body.mname+"', '"+req.body.pid+"','"+req.body.url+"' )";
  441. db.query(sql, (err, result) => {
  442. if (err) {
  443. console.log("错误信息",err)
  444. } else {
  445. //判断新增是不是父节点
  446. res.json({
  447. code: 200
  448. })
  449. }
  450. })
  451. })
  452. // 删除菜单
  453. router.get('/delMenu', (req, res) => {
  454. let mid = req.query.mid;
  455. let sql = "DELETE FROM `menu` WHERE mid = '"+mid+"'";
  456. db.query(sql, (err, result) => {
  457. if (err) {
  458. console.log(err)
  459. } else {
  460. res.json({
  461. code: 200
  462. })
  463. }
  464. })
  465. })
  466. //修改菜单
  467. router.post('/updateMenu', (req, res) => {
  468. //获取菜单编号
  469. let mid = req.body.mid;
  470. let sql = "UPDATE `menu` SET "+
  471. "mname = '"+req.body.mname+"',"+
  472. "url = '"+req.body.url+"' "+
  473. "WHERE mid = '"+mid+"'";
  474. db.query(sql, (err, result) => {
  475. if (err) {
  476. console.log("错误信息1",err)
  477. } else {
  478. res.json({
  479. code: 200
  480. })
  481. }
  482. })
  483. })
  484. //查询所有父级菜单
  485. router.get('/queryMenu', (req, res) => {
  486. let sql = "select * from `menu` where pid ='0'";
  487. db.query({
  488. sql: sql
  489. }, (err, results, fields) => {
  490. res.send(results)
  491. })
  492. })
  493. //根据ID查询菜单
  494. router.get('/queryMenuById', (req, res) => {
  495. let mid = req.query.mid;
  496. let sql = "select * from menu "+
  497. "where mid = '"+mid+"'";
  498. db.query({
  499. sql: sql
  500. }, (err, results, fields) => {
  501. console.log(results);
  502. res.send(results)
  503. })
  504. })
  505. //分页查询所有菜单
  506. router.get('/queryMenuPage', (req, res) => {
  507. //默认页码
  508. let currentPage = 1;
  509. //默认显示数据条数
  510. let pageSize = 9;
  511. if(req.query.currentPage){
  512. currentPage = req.query.currentPage;
  513. }
  514. if(req.query.pageSize){
  515. pageSize = req.query.pageSize;
  516. }
  517. //最后一页页码
  518. let last_page = currentPage-1;
  519. if(currentPage<=1){
  520. last_page = 1;
  521. }
  522. console.log("当前页",currentPage);
  523. let total = 0;
  524. //查询总条数
  525. let sql = "select * from menu";
  526. console.log(sql);
  527. db.query({
  528. sql: sql
  529. }, (err, results, fields) => {
  530. console.log(results.length)
  531. total = results.length;
  532. currentPage = (currentPage - 1 ) * pageSize;
  533. let sql2 = "select * from menu "+
  534. "limit "+currentPage+","+pageSize+" ";
  535. db.query({
  536. sql: sql2
  537. }, (err, results, fields) => {
  538. console.log(err);
  539. console.log("这是sql2",sql2)
  540. if(results!=''){
  541. results[0].backup3 = total;
  542. }
  543. res.send(results)
  544. })
  545. })
  546. })
  547. //====================================================================
  548. //====================================================================
  549. //新增项目
  550. router.post('/addProject', (req, res) => {
  551. let sql = "INSERT INTO `project`(pname,`sage`,`sgender`,`type`,`department`) "+
  552. "VALUES ('"+req.body.pname+"', '"+req.body.sage+"','"+req.body.sgender+"','"+req.body.type+"','"+req.body.department+"')";
  553. db.query(sql, (err, result) => {
  554. if (err) {
  555. console.log("错误信息",err)
  556. } else {
  557. res.json({
  558. code: 200
  559. })
  560. }
  561. })
  562. })
  563. // 删除项目
  564. router.get('/delProject', (req, res) => {
  565. let pid = req.query.pid;
  566. let sql = "DELETE FROM `project` WHERE pid = '"+pid+"'";
  567. db.query(sql, (err, result) => {
  568. if (err) {
  569. console.log(err)
  570. } else {
  571. res.json({
  572. code: 200
  573. })
  574. }
  575. })
  576. })
  577. //修改项目
  578. router.post('/updateProject', (req, res) => {
  579. //获取项目编号
  580. let pid = req.body.pid;
  581. let sql = "UPDATE `project` SET "+
  582. "pname = '"+req.body.pname+"',"+
  583. "sage = '"+req.body.sage+"',"+
  584. "type = '"+req.body.type+"',"+
  585. "department = '"+req.body.department+"',"+
  586. "sgender = '"+req.body.sgender+"' "+
  587. "WHERE pid = '"+pid+"'";
  588. db.query(sql, (err, result) => {
  589. if (err) {
  590. console.log("错误信息1",err)
  591. } else {
  592. res.json({
  593. code: 200
  594. })
  595. }
  596. })
  597. })
  598. //查询所有项目
  599. router.get('/queryProject', (req, res) => {
  600. let sql = "select * from project";
  601. db.query({
  602. sql: sql
  603. }, (err, results, fields) => {
  604. res.send(results)
  605. })
  606. })
  607. //根据ID查询项目
  608. router.get('/queryProjectById', (req, res) => {
  609. let pid = req.query.pid;
  610. let sql = "select * from project "+
  611. "where pid = '"+pid+"'";
  612. db.query({
  613. sql: sql
  614. }, (err, results, fields) => {
  615. console.log(results);
  616. res.send(results)
  617. })
  618. })
  619. //分页查询所有项目
  620. router.get('/queryProjectPage', (req, res) => {
  621. //模糊查询项目名称
  622. let pname = req.query.pname;
  623. //默认页码
  624. let currentPage = 1;
  625. //默认显示数据条数
  626. let pageSize = 9;
  627. if(req.query.currentPage){
  628. currentPage = req.query.currentPage;
  629. }
  630. if(req.query.pageSize){
  631. pageSize = req.query.pageSize;
  632. }
  633. //最后一页页码
  634. let last_page = currentPage-1;
  635. if(currentPage<=1){
  636. last_page = 1;
  637. }
  638. console.log("当前页",currentPage);
  639. let total = 0;
  640. //查询总条数
  641. let sql = "select * from project where 1=1 ";
  642. if(pname!="" && pname!=undefined){
  643. sql += "and pname like '%"+pname+"%' ";
  644. }
  645. console.log(sql);
  646. db.query({
  647. sql: sql
  648. }, (err, results, fields) => {
  649. console.log(results.length)
  650. total = results.length;
  651. currentPage = (currentPage - 1 ) * pageSize;
  652. let sql2 = "select * from project where 1=1 ";
  653. if(pname!="" || pname!=undefined || pname!="undefined"){
  654. sql2 += "and pname like '%"+pname+"%'";
  655. }
  656. sql2 += "limit "+currentPage+","+pageSize+" ";
  657. db.query({
  658. sql: sql2
  659. }, (err, results, fields) => {
  660. console.log(err);
  661. console.log("这是sql2",sql2)
  662. if(results!=''){
  663. results[0].backup3 = total;
  664. }
  665. res.send(results)
  666. })
  667. })
  668. })
  669. //====================================================================
  670. //====================================================================
  671. //新增套餐
  672. router.post('/addCombo', (req, res) => {
  673. let sql = "INSERT INTO `combo`(`cname`,`sage`,`sgender`,`meaning`,`start`,`stop`) "+
  674. "VALUES ('"+req.body.cname+"', '"+req.body.sage+"', '"+req.body.sgender+"', '"+req.body.meaning+"', '"+req.body.start+"', '"+req.body.stop+"')";
  675. db.query(sql, (err, result) => {
  676. if (err) {
  677. console.log("错误信息",err)
  678. } else {
  679. res.json({
  680. code: 200
  681. })
  682. }
  683. })
  684. })
  685. //查询所有套餐
  686. router.get('/queryCombo', (req, res) => {
  687. let sql = "select * from `combo`;";
  688. db.query({
  689. sql: sql
  690. }, (err, results, fields) => {
  691. res.send(results)
  692. })
  693. })
  694. //分页查询所有套餐
  695. router.get('/queryComboPage', (req, res) => {
  696. //模糊查询套餐名称
  697. let input = req.query.input;
  698. //模糊查询起始结束时间
  699. let start = req.query.start;
  700. let stops = req.query.stop;
  701. //默认页码
  702. let currentPage = 1;
  703. //默认显示数据条数
  704. let pageSize = 9;
  705. if(req.query.currentPage){
  706. currentPage = req.query.currentPage;
  707. }
  708. if(req.query.pageSize){
  709. pageSize = req.query.pageSize;
  710. }
  711. //最后一页页码
  712. let last_page = currentPage-1;
  713. if(currentPage<=1){
  714. last_page = 1;
  715. }
  716. console.log("当前页",currentPage);
  717. let total = 0;
  718. //查询总条数
  719. let sql = "select * from combo where 1=1 ";
  720. if(input!='' && input!=undefined){
  721. sql += "and cname like '%"+input+"%' ";
  722. }
  723. if(start!='' && start!=undefined || stops!='' && stops!=undefined){
  724. sql += "and `start` Between '"+start+"' AND '"+stops+"' and `stop` Between '"+start+"' AND '"+stops+"' ";
  725. }
  726. console.log(sql);
  727. db.query({
  728. sql: sql
  729. }, (err, results, fields) => {
  730. console.log(results.length)
  731. total = results.length;
  732. currentPage = (currentPage - 1 ) * pageSize;
  733. let sql2 = sql+"limit "+currentPage+","+pageSize+" ";
  734. db.query({
  735. sql: sql2
  736. }, (err, results, fields) => {
  737. console.log(err);
  738. console.log("这是sql2",sql2)
  739. if(results!=''){
  740. results[0].backup3 = total;
  741. }
  742. // res.send(results)
  743. var haha = results;
  744. for(var i =0;i<results.length;i++){
  745. var a =0;
  746. //根据套餐ID查询对应的项目
  747. var sqlp = "select * from project as p inner join cp on p.pid=cp.pid "+
  748. "where cp.cid = '"+results[i].cid+"'";
  749. db.query({
  750. sql: sqlp
  751. }, (err, resul, fields) => {
  752. // haha[i].backup = resul;
  753. for(var j =0;j<resul.length;j++){
  754. results[a].backup = resul;
  755. }
  756. a++;
  757. })
  758. }
  759. console.log(results);
  760. res.send(results)
  761. })
  762. })
  763. })
  764. // 删除套餐
  765. router.get('/delCombo', (req, res) => {
  766. let cid = req.query.cid;
  767. let sql = "DELETE FROM `combo` WHERE cid = '"+cid+"'";
  768. db.query(sql, (err, result) => {
  769. if (err) {
  770. console.log(err)
  771. } else {
  772. res.json({
  773. code: 200
  774. })
  775. }
  776. })
  777. })
  778. //修改套餐
  779. router.post('/updateCombo', (req, res) => {
  780. //获取套餐编号
  781. let cid = req.body.cid;
  782. let sql = "UPDATE `combo` SET "+
  783. "cname = '"+req.body.cname+"',"+
  784. "sage = '"+req.body.sage+"',"+
  785. "sgender = '"+req.body.sgender+"',"+
  786. "meaning = '"+req.body.meaning+"',"+
  787. "start = '"+req.body.start+"',"+
  788. "`stop` = '"+req.body.stop+"' "+
  789. "WHERE cid = '"+cid+"'";
  790. db.query(sql, (err, result) => {
  791. if (err) {
  792. console.log("错误信息1",err)
  793. } else {
  794. res.json({
  795. code: 200
  796. })
  797. }
  798. })
  799. })
  800. //根据ID查询套餐
  801. router.get('/queryComboById', (req, res) => {
  802. let cid = req.query.cid;
  803. let sql = "select * from combo "+
  804. "where cid = '"+cid+"'";
  805. db.query({
  806. sql: sql
  807. }, (err, results, fields) => {
  808. console.log(results);
  809. res.send(results)
  810. })
  811. })
  812. //根据套餐编号查询出他所有的项目
  813. router.get('/queryProjectByCid', (req, res) => {
  814. let cid = req.query.cid;
  815. let sql = "select p.pid as pid,p.pname as pname from project as p "+
  816. "inner join cp on cp.pid=p.pid "+
  817. "where cp.cid = '"+cid+"' ";
  818. console.log(sql);
  819. db.query({
  820. sql: sql
  821. }, (err, results, fields) => {
  822. console.log(results);
  823. res.send(results)
  824. })
  825. })
  826. //新增套餐对应项目
  827. router.get('/addcp', (req, res) => {
  828. let sql = "INSERT INTO `cp`(cid,pid) "+
  829. "VALUES ('"+req.query.cid+"', '"+req.query.pid+"' )";
  830. db.query(sql, (err, result) => {
  831. if (err) {
  832. console.log("错误信息",err)
  833. } else {
  834. res.json({
  835. code: 200
  836. })
  837. }
  838. })
  839. })
  840. // 删除套餐对应项目
  841. router.get('/delcp', (req, res) => {
  842. let cid = req.query.cid;
  843. let sql = "DELETE FROM `cp` WHERE cid = '"+cid+"'";
  844. db.query(sql, (err, result) => {
  845. if (err) {
  846. console.log(err)
  847. } else {
  848. res.json({
  849. code: 200
  850. })
  851. }
  852. })
  853. })
  854. //====================================================================
  855. //====================================================================
  856. //分页查询所有记录
  857. router.get('/queryRecordPage', (req, res) => {
  858. //查询记录状态
  859. let status = req.query.status;
  860. //模糊查询起始结束时间
  861. let start = req.query.start;
  862. let stops = req.query.stop;
  863. //默认页码
  864. let currentPage = 1;
  865. //默认显示数据条数
  866. let pageSize = 10;
  867. if(req.query.currentPage){
  868. currentPage = req.query.currentPage;
  869. }
  870. if(req.query.pageSize){
  871. pageSize = req.query.pageSize;
  872. }
  873. //最后一页页码
  874. let last_page = currentPage-1;
  875. if(currentPage<=1){
  876. last_page = 1;
  877. }
  878. console.log("当前页",currentPage);
  879. let total = 0;
  880. //查询总条数
  881. let sql = "select r.reid as reid,u.uid as uid,u.`name` as uname,u.phone as phone,u.gender as gender,c.cname as cname,c.`start`,c.`stop`,r.`status` as `status`,r.time as time from record as r "+
  882. "inner join `user` as u on r.uid=u.uid "+
  883. "inner join combo as c on r.cid=c.cid where 1=1 ";
  884. if(status!='' && status!=undefined){
  885. sql += "and r.status = '"+status+"' ";
  886. }
  887. if(start!='' && start!=undefined || stops!='' && stops!=undefined){
  888. sql += "and r.time Between '"+start+"' AND '"+stops+"' ";
  889. }
  890. console.log(sql);
  891. db.query({
  892. sql: sql
  893. }, (err, results, fields) => {
  894. console.log(results.length)
  895. total = results.length;
  896. currentPage = (currentPage - 1 ) * pageSize;
  897. let sql2 = sql +="limit "+currentPage+","+pageSize+" ";
  898. db.query({
  899. sql: sql2
  900. }, (err, results, fields) => {
  901. console.log(err);
  902. console.log("这是sql2",sql2)
  903. if(results!=''){
  904. results[0].backup3 = total;
  905. }
  906. res.send(results)
  907. })
  908. })
  909. })
  910. //根据ID查询记录
  911. router.get('/queryRecordById', (req, res) => {
  912. let reid = req.query.reid;
  913. let sql = "select r.reid as reid,u.uid as uid,u.`name` as uname,u.phone as phone,u.gender as gender,c.cname as cname,c.`start`,c.`stop`,r.`status` as `status`,r.time as time from record as r "+
  914. "inner join `user` as u on r.uid=u.uid "+
  915. "inner join combo as c on r.cid=c.cid "+
  916. "where r.reid = '"+reid+"'";
  917. db.query({
  918. sql: sql
  919. }, (err, results, fields) => {
  920. console.log(results);
  921. res.send(results)
  922. })
  923. })
  924. //根据用户ID查询记录
  925. router.get('/queryRecordById', (req, res) => {
  926. let uid = req.query.uid;
  927. let sql = "select r.reid as reid,u.uid as uid,u.`name` as uname,u.phone as phone,u.gender as gender,c.cname as cname,c.`start`,c.`stop`,r.`status` as `status`,r.time as time from record as r "+
  928. "inner join `user` as u on r.uid=u.uid "+
  929. "inner join combo as c on r.cid=c.cid "+
  930. "where u.uid = '"+uid+"'";
  931. db.query({
  932. sql: sql
  933. }, (err, results, fields) => {
  934. console.log(results);
  935. res.send(results)
  936. })
  937. })
  938. //修改记录
  939. router.post('/updateRecord', (req, res) => {
  940. //获取记录编号
  941. let reid = req.body.reid;
  942. let sql = "UPDATE `record` SET "+
  943. "time = '"+req.body.time+"',"+
  944. "status = '"+req.body.status+"' "+
  945. "WHERE reid = '"+reid+"'";
  946. db.query(sql, (err, result) => {
  947. if (err) {
  948. console.log("错误信息1",err)
  949. } else {
  950. res.json({
  951. code: 200
  952. })
  953. }
  954. })
  955. })
  956. //新增预约记录
  957. router.post('/addRecords', (req, res) => {
  958. //获取用户编号
  959. let uid = req.body.uid;
  960. console.log(uid);
  961. let usql = "select * from `user` where uid = '"+uid+"' and `name` <> '' and `number` <> '' and `gender` <> '' and `phone` <> '' and `address` <> '' and `age` <> ''";
  962. let sql = "INSERT INTO `rotation`(`roname`,`rourl`,`describe`,`status`) "+
  963. "VALUES ('"+req.body.roname+"', '"+req.body.rourl+"','"+req.body.describe+"','"+req.body.status+"' )";
  964. db.query({
  965. usql: usql
  966. }, (err, results, fields) => {
  967. console.log(results);
  968. res.send(results)
  969. })
  970. // db.query(sql, (err, result) => {
  971. // if (err) {
  972. // console.log("错误信息",err)
  973. // } else {
  974. // res.json({
  975. // code: 200
  976. // })
  977. // }
  978. // })
  979. })
  980. //新增预约记录
  981. router.get('/addRecord', (req, res) => {
  982. //获取用户编号
  983. let uid = req.body.uid;
  984. //获取套餐编号
  985. let cid = req.body.cid;
  986. //获取时间
  987. let time = req.body.time;
  988. let sql = "select * from `user` where uid = '"+uid+"' and `name` <> '' and `number` <> '' and `gender` <> '' and `phone` <> '' and `address` <> '' and `age` <> ''";
  989. db.query({
  990. sql: sql
  991. }, (err, results, fields) => {
  992. console.log(results);
  993. if(results.length<=0){
  994. res.send("请先去完善个人信息")
  995. }else{
  996. let sqls = "INSERT INTO `record`(`uid`,`cid`,`status`,`time`) "+
  997. "VALUES ('"+uid+"', '"+cid+"', '2', '"+time+"' )";
  998. db.query(sqls, (err, result) => {
  999. if (err) {
  1000. console.log("错误信息",err)
  1001. } else {
  1002. res.json({
  1003. code: 200
  1004. })
  1005. }
  1006. })
  1007. }
  1008. })
  1009. })
  1010. // 删除记录
  1011. router.get('/delRecord', (req, res) => {
  1012. let reid = req.query.reid;
  1013. let sql = "DELETE FROM `record` WHERE reid = '"+reid+"'";
  1014. db.query(sql, (err, result) => {
  1015. if (err) {
  1016. console.log(err)
  1017. } else {
  1018. res.json({
  1019. code: 200
  1020. })
  1021. }
  1022. })
  1023. })
  1024. //====================================================================
  1025. //====================================================================
  1026. //分页查询所有日志
  1027. router.get('/queryLoginLogsPage', (req, res) => {
  1028. //默认页码
  1029. let currentPage = 1;
  1030. //默认显示数据条数
  1031. let pageSize = 13;
  1032. if(req.query.currentPage){
  1033. currentPage = req.query.currentPage;
  1034. }
  1035. if(req.query.pageSize){
  1036. pageSize = req.query.pageSize;
  1037. }
  1038. //最后一页页码
  1039. let last_page = currentPage-1;
  1040. if(currentPage<=1){
  1041. last_page = 1;
  1042. }
  1043. console.log("当前页",currentPage);
  1044. let total = 0;
  1045. //查询总条数
  1046. let sql = "select u.uid as uid,u.account as account,l.* from `logs` as l "+
  1047. "inner join `user` as u on l.uid=u.uid"
  1048. console.log(sql);
  1049. db.query({
  1050. sql: sql
  1051. }, (err, results, fields) => {
  1052. console.log(results.length)
  1053. total = results.length;
  1054. currentPage = (currentPage - 1 ) * pageSize;
  1055. let sql2 = "select u.uid as uid,u.account as account,l.* from `logs` as l "+
  1056. "inner join `user` as u on l.uid=u.uid "+
  1057. "order by l.time desc "+
  1058. "limit "+currentPage+","+pageSize+" ";
  1059. db.query({
  1060. sql: sql2
  1061. }, (err, results, fields) => {
  1062. console.log(err);
  1063. console.log("这是sql2",sql2)
  1064. if(results!=''){
  1065. results[0].backup3 = total;
  1066. }
  1067. res.send(results)
  1068. })
  1069. })
  1070. })
  1071. //新增登入登出登录日志
  1072. router.post('/addLoginLogs', (req, res) => {
  1073. //获取操作详情(0:登入,1:登出)
  1074. let details = req.body.details;
  1075. console.log("草拟吗",details)
  1076. if(details=="0"){
  1077. details='登入了系统';
  1078. }else if(details=="1"){
  1079. details='登出了系统';
  1080. }
  1081. let sql = "INSERT INTO `logs`(`uid`,`ip`,`details`,`time`) "+
  1082. "VALUES ('"+req.body.uid+"', '"+req.body.ip+"','"+details+"','"+req.body.time+"')";
  1083. db.query(sql, (err, result) => {
  1084. if (err) {
  1085. console.log("错误信息",err)
  1086. } else {
  1087. res.json({
  1088. code: 200
  1089. })
  1090. }
  1091. })
  1092. })
  1093. //====================================================================
  1094. //====================================================================
  1095. //新增轮播图
  1096. router.post('/addRotation', (req, res) => {
  1097. let sql = "INSERT INTO `rotation`(`roname`,`rourl`,`describe`,`status`) "+
  1098. "VALUES ('"+req.body.roname+"', '"+req.body.rourl+"','"+req.body.describe+"','"+req.body.status+"' )";
  1099. db.query(sql, (err, result) => {
  1100. if (err) {
  1101. console.log("错误信息",err)
  1102. } else {
  1103. res.json({
  1104. code: 200
  1105. })
  1106. }
  1107. })
  1108. })
  1109. // 删除轮播图
  1110. router.get('/delRotation', (req, res) => {
  1111. let roid = req.query.roid;
  1112. let sql = "DELETE FROM `rotation` WHERE roid = '"+roid+"'";
  1113. db.query(sql, (err, result) => {
  1114. if (err) {
  1115. console.log(err)
  1116. } else {
  1117. res.json({
  1118. code: 200
  1119. })
  1120. }
  1121. })
  1122. })
  1123. //修改轮播图
  1124. router.post('/updateRotation', (req, res) => {
  1125. //获取轮播图编号
  1126. let roid = req.body.roid;
  1127. let sql = "UPDATE `rotation` SET "+
  1128. "roname = '"+req.body.roname+"',"+
  1129. "rourl = '"+req.body.rourl+"',"+
  1130. "`describe` = '"+req.body.describe+"',"+
  1131. "status = '"+req.body.status+"' "+
  1132. "WHERE roid = "+roid+" ";
  1133. db.query(sql, (err, result) => {
  1134. if (err) {
  1135. console.log("错误信息1",err)
  1136. } else {
  1137. res.json({
  1138. code: 200
  1139. })
  1140. }
  1141. })
  1142. })
  1143. //根据ID查询轮播图
  1144. router.get('/queryRotationById', (req, res) => {
  1145. let roid = req.query.roid;
  1146. let sql = "select * from rotation "+
  1147. "where roid = '"+roid+"'";
  1148. db.query({
  1149. sql: sql
  1150. }, (err, results, fields) => {
  1151. console.log(results);
  1152. res.send(results)
  1153. })
  1154. })
  1155. //查询所有轮播图
  1156. router.get('/queryRotation', (req, res) => {
  1157. let sql = "select * from `rotation`;";
  1158. db.query({
  1159. sql: sql
  1160. }, (err, results, fields) => {
  1161. res.send(results)
  1162. })
  1163. })
  1164. //分页查询所有轮播图
  1165. router.get('/queryRotationPage', (req, res) => {
  1166. //默认页码
  1167. let currentPage = 1;
  1168. //默认显示数据条数
  1169. let pageSize = 9;
  1170. if(req.query.currentPage){
  1171. currentPage = req.query.currentPage;
  1172. }
  1173. if(req.query.pageSize){
  1174. pageSize = req.query.pageSize;
  1175. }
  1176. //最后一页页码
  1177. let last_page = currentPage-1;
  1178. if(currentPage<=1){
  1179. last_page = 1;
  1180. }
  1181. console.log("当前页",currentPage);
  1182. let total = 0;
  1183. //查询总条数
  1184. let sql = "select * from menu";
  1185. console.log(sql);
  1186. db.query({
  1187. sql: sql
  1188. }, (err, results, fields) => {
  1189. console.log(results.length)
  1190. total = results.length;
  1191. currentPage = (currentPage - 1 ) * pageSize;
  1192. let sql2 = "select * from menu "+
  1193. "limit "+currentPage+","+pageSize+" ";
  1194. db.query({
  1195. sql: sql2
  1196. }, (err, results, fields) => {
  1197. console.log(err);
  1198. console.log("这是sql2",sql2)
  1199. if(results!=''){
  1200. results[0].backup3 = total;
  1201. }
  1202. res.send(results)
  1203. })
  1204. })
  1205. })
  1206. //====================================================================
  1207. module.exports = router

  数据库表详解

combo:套餐表
cp:套餐项目中间表
logs:日志表
project:项目表
menu:菜单表
menurole:菜单角色中间表
role:角色表
record:预约记录表
rotation:轮播图表
user:用户表
userrole:用户角色表

源码+项目部署

数据库还有源码一起都打包再下边的地址里了,下载开箱即用,跟springboot一样,嘻嘻嘻!

 源码地址:

链接:https://pan.baidu.com/s/16_taBlWe-xpsx1GvPqEcRA 
提取码:7sn7

嗯嗯嗯......终于到了激动人心的时候了,我来帮你搞定一切,帝王般的服务你值得拥有,免费的哟,记得备注下:曹家的小仙女 / 小哥哥,微信:BitPlanet

最后附上

一寸光阴一寸金,寸金难买寸光阴。请珍惜现在美好的青春,咱们一起努力奋斗,创造美好未来

拜托拜托!!!拜托拜托!!!拜托拜托!!!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/166573
推荐阅读
相关标签
  

闽ICP备14008679号