From d34a7e3417924f82262711fad4ecd3ab47bbaea2 Mon Sep 17 00:00:00 2001 From: Ricky Date: Mon, 13 Mar 2017 20:37:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=99=BB=E5=BD=95=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- musicManager/app.js | 17 +++- .../src/controller/accountController.js | 29 ++++++- .../controller/studentManagerController.js | 35 +++++++++ musicManager/src/router/accountRouter.js | 9 ++- .../src/router/studentManagerRouter.js | 14 ++++ musicManager/src/views/login.html | 78 ++++++++++--------- musicManager/src/views/parent.html | 67 ++++++++++++++++ musicManager/src/views/studentlist.html | 73 +++++++++++++++++ 8 files changed, 277 insertions(+), 45 deletions(-) create mode 100644 musicManager/src/controller/studentManagerController.js create mode 100644 musicManager/src/router/studentManagerRouter.js create mode 100644 musicManager/src/views/parent.html create mode 100644 musicManager/src/views/studentlist.html diff --git a/musicManager/app.js b/musicManager/app.js index 166ce8b..d6948b7 100644 --- a/musicManager/app.js +++ b/musicManager/app.js @@ -1,14 +1,27 @@ 'use strict' const express = require('express') - +const path = require('path') const app = express() +const bodyParser = require('body-parser') + +app.use(bodyParser.urlencoded({ + extended: false +})) + +// app.use(bodyParser.json()) app.get('/', (req, res) => { - res.end('OK') }) +const accountRouter = require(path.join(__dirname, './src/router/accountRouter')) +const studentManagerRouter = require(path.join(__dirname, './src/router/studentManagerRouter')) + +app.use(express.static(path.join(__dirname, 'src/statics'))) +app.use('/account', accountRouter) +app.use('/list', studentManagerRouter) + app.listen(5000, (error) => { if (error) console.log(error) console.log('start server success') diff --git a/musicManager/src/controller/accountController.js b/musicManager/src/controller/accountController.js index 29faded..d6a047b 100644 --- a/musicManager/src/controller/accountController.js +++ b/musicManager/src/controller/accountController.js @@ -1,12 +1,35 @@ 'use strict' const path = require('path') const fs = require('fs') -const bodyParser = require('body-parser') +const MongoClient = require('mongodb').MongoClient module.exports.getLoginPage = (req, res) => { - + console.log('LoginPage') + fs.readFile(path.join(__dirname, '../views/login.html'), (error, content) => { + if (error) console.log(error) + res.setHeader('Content-Type', 'text/html;charset=utf-8') + res.end(content) + }) } module.exports.login = (req, res) => { - + console.log(req.body) + + const url = 'mongodb://localhost:27017/musicmanager' + // 连接数据库 + MongoClient.connect(url, (error, db) => { + db.collection('account').findOne({ + username: req.body.uname, + password: req.body.pwd, + status: 0 + }, (error, doc) => { + if (error) console.log(error) + console.log(doc) + if (doc !== null) { + res.end('login success') + } else { + res.end('') + } + }) + }) } \ No newline at end of file diff --git a/musicManager/src/controller/studentManagerController.js b/musicManager/src/controller/studentManagerController.js new file mode 100644 index 0000000..5c3cf9c --- /dev/null +++ b/musicManager/src/controller/studentManagerController.js @@ -0,0 +1,35 @@ +'use strict' +const path = require('path') +const fs = require('fs') +const MongoClient = require('mongodb').MongoClient + +module.exports.getStudentList = (req, res) => { + console.log('studentList') + fs.readFile(path.join(__dirname, '../views/login.html'), (error, content) => { + if (error) console.log(error) + res.setHeader('Content-Type', 'text/html;charset=utf-8') + res.end(content) + }) +} + +module.exports.login = (req, res) => { + console.log(req.body) + + const url = 'mongodb://localhost:27017/musicmanager' + // 连接数据库 + MongoClient.connect(url, (error, db) => { + db.collection('account').findOne({ + username: req.body.uname, + password: req.body.pwd, + status: 0 + }, (error, doc) => { + if (error) console.log(error) + console.log(doc) + if (doc !== null) { + res.end('login success') + } else { + res.end('') + } + }) + }) +} \ No newline at end of file diff --git a/musicManager/src/router/accountRouter.js b/musicManager/src/router/accountRouter.js index cc160b2..4dbb44f 100644 --- a/musicManager/src/router/accountRouter.js +++ b/musicManager/src/router/accountRouter.js @@ -2,8 +2,13 @@ const express = require('express') const path = require('path') +// 创建路由 const accountRouter = express.Router() -router.get('/login', accountCtrl.getLoginPage) +const accountCtrl = require(path.join(__dirname, '../controller/accountController')) -router.post('/login', accountCtrl.login) \ No newline at end of file +accountRouter.get('/login', accountCtrl.getLoginPage) + +accountRouter.post('/login', accountCtrl.login) + +module.exports = accountRouter \ No newline at end of file diff --git a/musicManager/src/router/studentManagerRouter.js b/musicManager/src/router/studentManagerRouter.js new file mode 100644 index 0000000..2b95f46 --- /dev/null +++ b/musicManager/src/router/studentManagerRouter.js @@ -0,0 +1,14 @@ +'use strict' +const express = require('express') +const path = require('path') + +// 创建路由 +const studentManagerRouter = express.Router() + +const studentManagerCtrl = require(path.join(__dirname, '../controller/studentManagerController')) + +studentManagerRouter.get('/login', studentManagerCtrl.getStudentList) + +// studentManagerRouter.post('/login', studentManagerCtrl.login) + +module.exports = studentManagerRouter \ No newline at end of file diff --git a/musicManager/src/views/login.html b/musicManager/src/views/login.html index ee4141f..3aabf12 100644 --- a/musicManager/src/views/login.html +++ b/musicManager/src/views/login.html @@ -1,45 +1,47 @@ + - 欢迎登录 - + 欢迎登录 + + -
+
-
-
-
登录学生管理系统
-
-
-
- -
- -
-
-
- -
- -
-
-
-
- -    - -
-
-
-
-
-
-
- +
+
+
登录音乐管理系统
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+    + +
+
+
+
+
+
+
+ - + + \ No newline at end of file diff --git a/musicManager/src/views/parent.html b/musicManager/src/views/parent.html new file mode 100644 index 0000000..eb81ee0 --- /dev/null +++ b/musicManager/src/views/parent.html @@ -0,0 +1,67 @@ + + + + + + + + + + + + + > + + + + +
+
+
+ +
+
+
+ +
+ + {{{block ("body")}}} + +
+
+
+ + + + diff --git a/musicManager/src/views/studentlist.html b/musicManager/src/views/studentlist.html new file mode 100644 index 0000000..287089a --- /dev/null +++ b/musicManager/src/views/studentlist.html @@ -0,0 +1,73 @@ +{{extend ("./parent.html")}} + +{{#block ("body")}} +
+
+ +
+
+
+ 学生姓名 + + + +
+
+
+ + + + + + + + + + + + {{#each(studentlist)}} + + + + + + + + {{/each}} + +
姓名年龄性别手机号码操作
{{this.name}}{{this.age}}{{this.sex}}{{this.phone}} + 编辑 | + + +
+
+
+ +{{/block}}