Selaa lähdekoodia

set up teacher part

Starink 6 vuotta sitten
vanhempi
commit
b77f692115

+ 28 - 5
pages/person/identification.vue

@@ -11,12 +11,13 @@
         <div class="main-card__tab__item">
           当前状态:
           <el-tag v-if="state === 'unidentified'" type="info">未认证</el-tag>
+          <el-tag v-if="state === 'rejected'" type="danger">未通过</el-tag>
           <el-tag v-if="state === 'identifying'">审核中</el-tag>
           <el-tag v-if="state === 'identified'" type="success">已认证</el-tag>
         </div>
         <div class="main-card__tab__item">
           真实姓名:
-          <el-input v-model="realName" class="main-card__tab__input" maxlength="20" oninput="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g,'')"></el-input>
+          <el-input v-model="realName" class="main-card__tab__input" maxlength="20" :disabled="disabled" oninput="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g,'')"></el-input>
         </div>
         <div class="main-card__tab__item">
           所属单位:
@@ -25,15 +26,17 @@
               v-for="item in organizations"
               :key="item"
               :label="item"
-              :value="item">
+              :value="item"
+              :disabled="disabled"
+            >
             </el-option>
           </el-select>
         </div>
         <div class="main-card__tab__item" >
           教师工号:
-          <el-input v-model="jobNumber" class="main-card__tab__input" maxlength="20" oninput="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')"></el-input>
+          <el-input v-model="jobNumber" class="main-card__tab__input" maxlength="20" :disabled="disabled" oninput="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')"></el-input>
         </div>
-        <div class="main-card__tab__item">
+        <div class="main-card__tab__item" v-if="!disabled">
           <el-button type="primary" class="main-card__tab__button" :loading="loading" @click="apply">提交审核</el-button>
         </div>
       </el-tab-pane>
@@ -44,6 +47,8 @@
 </template>
 
 <script>
+  import { state } from "../../store";
+
   export default {
     name: "identification",
     layout: 'person',
@@ -59,10 +64,28 @@
         organization: '',
         pageLoading: true,
         jobNumber: '',
-        loading: false
+        loading: true,
+        disabled: state === 'identifying' || state === 'identified'
       }
     },
     mounted(){
+      this.$api.get('/teacher/getInfo', {
+        realName: this.realName,
+        jobNumber: this.jobNumber,
+        organization: this.organization
+      }).then((res) => {
+        if(res.data.code === 0){
+          let data = res.data.data;
+          this.realName = data.realName;
+          this.jobNumber = data.jobNumber;
+          this.organization = data.organization;
+          this.state = data.state;
+          this.disabled = (this.state === 'identifying' || this.state === 'identified');
+        }
+      }
+      ).catch((e)=>{
+        console.log(e);
+      });
       this.pageLoading = false;
     },
     methods:{

+ 32 - 0
server/controller/teacher.js

@@ -0,0 +1,32 @@
+const teacherModel = require('../model/teacher');
+const Response = require('../util/response');
+const getTokenUser = require('../util/tokenProcessor');
+
+
+class TeacherController {
+  static async getInfo(ctx){
+    let theUser = await getTokenUser(ctx);
+    let teacher = await teacherModel.findByUid(theUser.id);
+    if(teacher){
+     ctx.body = Response.success({realName: teacher.realName, certificate: teacher.certificate, organization: teacher.organization, jobNumber: teacher.jobNumber, state: teacher.state});
+     console.log(ctx.body);
+    }else{
+      ctx.body = Response.failed("此教师不存在");
+    }
+  }
+
+  static async apply(ctx){
+    let theUser = await getTokenUser(ctx);
+    let data = ctx.request.body;
+    console.log("...user, ...data", {...theUser, ...data});
+    let result = await teacherModel.create({...data, ...theUser});
+    if(result){
+      ctx.body = Response.success({});
+    }else{
+      ctx.body = Response.failed("参数错误");
+    }
+  }
+}
+
+
+module.exports = TeacherController;

+ 35 - 0
server/model/teacher.js

@@ -0,0 +1,35 @@
+const db = require('../config/db');
+const getNowFormatTime = require('../util/time-processer');
+const Teacher = db.import('../schema/teacher.js');
+
+Teacher.sync();
+
+class TeacherModel {
+
+  static async findByUid(uid){
+    return Teacher.findOne({
+      where: {uid: uid}
+    });
+  }
+
+  static async create({realName, organization, jobNumber, certificate = '', id, phone, email} ){
+    try{
+      let teacher = await Teacher.create({realName: realName, organization: organization, jobNumber: jobNumber,
+        phone: phone, email: email, certificate: certificate,
+        uid: id, createdTime: getNowFormatTime()});
+      return true;
+    }catch (e) {
+      console.log(e);
+      return false;
+    }
+  }
+
+  static async updateState(id, state){
+    await Teacher.update({state: state}, {where: {id: id}});
+    return true;
+  }
+
+
+}
+
+module.exports = TeacherModel;

+ 4 - 0
server/routes/index.js

@@ -3,6 +3,7 @@ const UserController = require('../controller/user');
 const CourseController = require('../controller/course');
 const OIDCController = require('../controller/oidc');
 const AuthController = require('../controller/auth');
+const TeacherController = require('../controller/teacher');
 const router = new Router({prefix: '/api'});
 
 module.exports = () => {
@@ -14,6 +15,9 @@ module.exports = () => {
   router.post('/user/saveEmail', UserController.saveEmail);
   router.post('/user/saveSignature', UserController.saveSignature);
 
+  router.get('/teacher/getInfo', TeacherController.getInfo);
+  router.post('/teacher/apply', TeacherController.apply);
+
     router.get('/course/getMyCourses',  CourseController.getMyCourses);
     router.get('/course/getHotCourses',  CourseController.getHotCourses);
 

+ 60 - 0
server/schema/teacher.js

@@ -0,0 +1,60 @@
+
+const moment = require('moment');
+
+module.exports = (sequelize, DataTypes) =>
+  sequelize.define('user', {
+    id: {
+      type: DataTypes.INTEGER,
+      allowNull: false,
+      primaryKey: true,
+      autoIncrement: true
+    },
+    realName: {
+      type: DataTypes.STRING(64),
+      allowNull: false
+    },
+    organization: {
+      type: DataTypes.STRING(64),
+      allowNull: false,
+      defaultValue: '南京大学'
+    },
+    jobNumber: {
+      type: DataTypes.STRING(64),
+      allowNull: false
+    },
+    certificate: {
+      type: DataTypes.STRING(512),
+      allowNull: false,
+      defaultValue: ""
+    },
+    phone: {
+      type: DataTypes.STRING(64),
+      allowNull: false,
+      unique: 'column'
+    },
+    email: {
+      type: DataTypes.STRING(512),
+      allowNull: false,
+      defaultValue: "xxxxx@xxx.com"
+    },
+    uid: {
+      type: DataTypes.INTEGER,
+      allowNull: false,
+      unique: 'column'
+    },
+    createdTime: {
+      type: DataTypes.DATE,
+      allowNull: false,
+      get() {
+        return moment(this.getDataValue('createdTime')).format('YYYY-MM-DD HH:mm:ss');
+      }
+    },
+    state: {
+      type:   DataTypes.ENUM,
+      values: ['identifying', 'identified', 'rejected'],
+      allowNull: false,
+      defaultValue: 'identifying'
+    },
+  }, {
+    tableName: 'teacher'
+  });