diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..43614be --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,30 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome", + "url": "http://localhost:8080/#/main/homepage", + "webRoot": "${workspaceFolder}\\src\\containers\\main\\index" + }, + // { + // "type": "chrome", + // "sourceMaps": true, + // "name": "login", + // "request": "launch", + // "program": "${workspaceFolder}\\src\\conjstainers\\login\\axios\\index" + // }, + { + "type": "node", + "sourceMaps": true, + "request": "launch", + "name": "first aplication", + "program": "${workspaceFolder}\\controllers\\user.js" + } + ] +} \ No newline at end of file diff --git a/app.js b/app.js index 5c5d7d0..c472d05 100644 --- a/app.js +++ b/app.js @@ -6,6 +6,8 @@ const http = require('http'); //静态资源托管irn app.use(serve(path.join(__dirname+"/dist"))); +// app.use(serve(path.join(__dirname+"/data"))); +console.log("dirname"+path.join(__dirname)) //用来解析body的中间件,比方说你通过post来传递表单,json数据,或者上传文件, //在koa中是不容易获取的,通过koa-bodyparser解析之后,在koa中this.body就能直接获取到数据。 @@ -13,7 +15,7 @@ const bodyParser = require('koa-bodyparser'); app.use(bodyParser()); //路由配置 -const routes = ['user','exam']; +const routes = ['user','exam','homepage','searche_grade','class_manager','student_manager','teacher_manager','create_question','create_examination','student_function','examination_manager']; routes.forEach((router) => { app.use(require(`./routes/${router}`).routes()); }); diff --git a/controllers/class_manager.js b/controllers/class_manager.js new file mode 100644 index 0000000..11800a4 --- /dev/null +++ b/controllers/class_manager.js @@ -0,0 +1,201 @@ + +//当前进入的是班级管理 + +var sessionIsExam = {} + +//添加班级 +const bluebird = require('bluebird');//promise化 +const connectionModel = require('../models/connection'); + +exports.add_class = async function(ctx, next){ + try { + const data = ctx.request.body; + console.log("body"+JSON.stringify(ctx.request.body)) + //console.log(ctx.request) + + const connection = connectionModel.getConnection(); + const query = bluebird.promisify(connection.query.bind(connection)); + // console.log('a'+JSON.stringify(data.params.managerId)); + // `INSERT INTO user_table (username, password) VALUES('${username}', '${password}')` + console.log("name"+data.classId) + console.log('stubjectID'+data.subjectId) + const classId = JSON.parse(data.classId); + const results = await query( + // `insert into class values('${data.name}','${data.classId}','${data.subjectId}','',null)` + `insert into class values('${data.name}','${data.classId}','${data.subjectId}',null,null,null)` + ); + console.log("result"+JSON.stringify(results)); + if(!results.length){ + let user = results[0]; + ctx.body = { + respCode: 1, + respMsg:'添加成功' + }; + }else { + ctx.body = { + respCode: -1, + respMsg : 'null' + }; + } + connection.end(); + }catch(e){ + console.log('[/user/login] error:', e.message, e.stack); + ctx.body = { + respCode: e.code || -1, + respMsg: e.message + }; + } +}; + + + + +//查询班级 +exports.query_class = async function(ctx, next){ + try { + const data = ctx.request.body; + const connection = connectionModel.getConnection(); + const query = bluebird.promisify(connection.query.bind(connection)); + // console.log('a'+JSON.stringify(data.params.managerId)); + // console.log('para'+data.managerId) + const results = await query( + `select * from class` + ); + console.log("result",JSON.stringify(results)); + if(results.length){ + ctx.body = { + respCode: 1, + results + + }; + }else { + ctx.body = { + respCode: -1, + respMsg : '暂无可操作数据' + }; + } + connection.end(); + }catch(e){ + console.log('[/user/login] error:', e.message, e.stack); + ctx.body = { + respCode: e.code || -1, + respMsg: e.message + }; + } +}; +//搜索班级 +exports.search_class = async function(ctx, next){ + try { + const data = ctx.request.body; + const connection = connectionModel.getConnection(); + const query = bluebird.promisify(connection.query.bind(connection)); + // console.log('a'+JSON.stringify(data.params.managerId)); + console.log(data.searchType) + if(data.searchType == '1'){ + console.log('班级') + results = await query( + `select * from class where + class_name like '%${data.content}%'` + ); + } + if(data.searchType == '2'){ + console.log('科目') + results = await query( + `select * from class where + exam_subject like '%${data.content}%'` + ); + } + if(data.searchType == '3'){ + console.log('状态') + results = await query( + `select * from class where + status like '%${data.content}%'` + ); + } + console.log("result",JSON.stringify(results)); + if(results.length){ + ctx.body = { + respCode: 1, + results + }; + }else { + ctx.body = { + respCode: -1, + respMsg : '无匹配数据' + }; + } + connection.end(); + }catch(e){ + console.log('[/user/login] error:', e.message, e.stack) + console.log("e"+e) + ctx.body = { + respCode: e.code || -1, + respMsg: e.message + }; + } +}; +//删除班级 + +exports.delete_class = async function(ctx, next){ + try { + const data = ctx.request.body; + const connection = connectionModel.getConnection(); + const query = bluebird.promisify(connection.query.bind(connection)); + // console.log('a'+JSON.stringify(data.params.managerId)); + console.log('content'+data.content) + const results = await query( + `delete from class where + class_id= '${data.classId}'` + ); + console.log("result",JSON.stringify(results)); + if(!results.length){ + ctx.body = { + respCode: 1, + respMsg:'成功删除' + }; + }else { + ctx.body = { + respCode:"-1", + respMsg : '删除失败' + }; + } + connection.end(); + }catch(e){ + } +}; + +//修改班级 +exports.change_class = async function(ctx, next){ + try { + const data = ctx.request.body; + const connection = connectionModel.getConnection(); + const query = bluebird.promisify(connection.query.bind(connection)); + // console.log('a'+JSON.stringify(data.params.managerId)); + console.log('content'+data.content) + const results = await query( + `update class set class_name='${data.class_Name}', exam_subject ='${data.subject_name}',exam_subject_id='${data.subjectId}' where + class_id= '${data.classId}'` + ); + console.log("result",JSON.stringify(results)); + if(!results.length){ + ctx.body = { + respCode: 1, + results, + respMsg:'跟新成功' + }; + }else { + ctx.body = { + respCode:"-1", + respMsg : '跟新失败' + }; + } + connection.end(); + }catch(e){ + } +}; + + + + + + diff --git a/controllers/create_examination.js b/controllers/create_examination.js new file mode 100644 index 0000000..3dbd0d0 --- /dev/null +++ b/controllers/create_examination.js @@ -0,0 +1,48 @@ + + +const bluebird = require('bluebird');//promise化 +const connectionModel = require('../models/connection'); +let exam_id = 1; +exports.paperInfo= async function(ctx, next){ + try { + const data = ctx.request.body; + console.log("body"+JSON.stringify(ctx)) + + const connection = connectionModel.getConnection(); + const query = bluebird.promisify(connection.query.bind(connection)); + let question = JSON.parse(data.paperInfo); + // console.log(JSON.parse(data.paperInfo).questionObjects) + for(let i =0; i1){ + for(let i = 0 ;i 0) { //修改密码 const results = await query( - `update user set password='${data.password}' - where instId = '1'` + `update user set password='${data.password}' where username = '${data.username}'` ); if(results.changedRows > 0) { console.log("这个学生要修改密码,旧密码:"+data.oldPassword+",新密码"+data.password); diff --git a/dist/index.html b/dist/index.html index 56cbc6a..25dc977 100644 --- a/dist/index.html +++ b/dist/index.html @@ -5,8 +5,8 @@ - +
- + diff --git a/package-lock.json b/package-lock.json index 56cf81f..e607293 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3299,7 +3299,8 @@ "balanced-match": { "version": "0.4.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "bcrypt-pbkdf": { "version": "1.0.1", @@ -3332,6 +3333,7 @@ "version": "1.1.7", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^0.4.1", "concat-map": "0.0.1" @@ -3373,7 +3375,8 @@ "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", @@ -3487,7 +3490,8 @@ "fs.realpath": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "fstream": { "version": "1.0.11", @@ -3549,6 +3553,7 @@ "version": "7.1.2", "bundled": true, "dev": true, + "optional": true, "requires": { "fs.realpath": "1.0.0", "inflight": "1.0.6", @@ -3601,7 +3606,8 @@ "hoek": { "version": "2.16.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "http-signature": { "version": "1.1.1", @@ -3618,6 +3624,7 @@ "version": "1.0.6", "bundled": true, "dev": true, + "optional": true, "requires": { "once": "1.4.0", "wrappy": "1.0.2" @@ -3626,7 +3633,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.4", @@ -3742,6 +3750,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "1.1.7" } @@ -3830,6 +3839,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1.0.2" } @@ -3859,7 +3869,8 @@ "path-is-absolute": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "performance-now": { "version": "0.2.0", @@ -3954,6 +3965,7 @@ "version": "2.6.1", "bundled": true, "dev": true, + "optional": true, "requires": { "glob": "7.1.2" } @@ -4147,7 +4159,8 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/package.json b/package.json index aba54ad..41ffc91 100644 --- a/package.json +++ b/package.json @@ -52,4 +52,3 @@ "webpack-dev-server": "^2.10.0" } } - diff --git a/webpack.production.config.js b/webpack.production.config.js index 5117b68..b6f1f60 100644 --- a/webpack.production.config.js +++ b/webpack.production.config.js @@ -6,6 +6,7 @@ var autoprefixer = require('autoprefixer'); var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); module.exports = { + // devtool: 'eval-source-map', entry: { app: path.resolve(__dirname, './src/index.js'), // 将 第三方依赖 单独打包