Browse Source

学生验证码登录

guhongwei 5 years ago
parent
commit
2064d5e668
5 changed files with 57 additions and 8 deletions
  1. 2 1
      src/plugins/var.js
  2. 20 0
      src/store.js
  3. 29 5
      src/views/login/login.vue
  4. 1 1
      src/views/want/resume/index.vue
  5. 5 1
      vue.config.js

+ 2 - 1
src/plugins/var.js

@@ -5,7 +5,8 @@ const getSiteId = () => {
   let arr = host.split('.');
   if (arr.length > 0) {
     schId = arr[0];
-    sessionStorage.setItem('schId', schId);
+    `${schId}`.includes('localhost') || `${schId}`.includes('127.0.0.1') ? (schId = 99991) : '';
+    sessionStorage.setItem('schId', `${schId}`.includes('localhost') || `${schId}`.includes('127.0.0.1') ? 99991 : schId);
   }
   return schId;
 };

+ 20 - 0
src/store.js

@@ -26,6 +26,9 @@ const api = {
   studLogin: '/api/stud/login', //query:type:0=>用户名+密码 account(学号@学校id)+passwd;1-微信(wxtoken)
   dictionary: '/api/code/{type}/items', //type === xzqh:query:level(1/2);parent(无/code)
   findOne: '/api/code/xzqh/findOne', //query:name
+  //验证码
+  verify: '/adminapi/verify/verify',
+  checkVerify: '/adminapi/verify/check_verify',
 };
 export default new Vuex.Store({
   state: {
@@ -207,6 +210,23 @@ export default new Vuex.Store({
       let result = this.$axios.$post(api.studLogin, data, {}, { type: type });
       return result;
     },
+    //验证码
+    async verifyOperation({ state }, { type, data }) {
+      let result;
+      if (type === 'verify') {
+        result = await this.$axios.$get(api.verify, {}, data);
+      }
+      if (type === 'checkVerify') {
+        result = await this.$axios.$post(api.checkVerify, data);
+      }
+      if (type === 'message') {
+        result = await this.$axios.$get(api.message, {}, data);
+      }
+      if (type === 'checkMessage') {
+        result = await this.$axios.$post(api.checkMessage, data);
+      }
+      return result;
+    },
   },
 });
 

+ 29 - 5
src/views/login/login.vue

@@ -46,11 +46,20 @@
                           </el-input>
                         </el-col>
                       </el-form-item>
+                      <el-form-item prop="mobile" class="firmRightName">
+                        <el-col :span="16">
+                          <el-input placeholder="验证码" prefix-icon="el-icon-lock" v-model="verifyForm.code" @keyup.enter="toSubmit"></el-input>
+                        </el-col>
+                        <el-col :span="8" class="firmRightImg">
+                          <!-- <img :src="pic3" /> -->
+                          <verify v-model="verifyForm.code_id" ref="verifyPic"></verify>
+                        </el-col>
+                      </el-form-item>
                     </el-form>
                   </el-col>
-                  <el-col class="inp_sty">
+                  <el-col class="inp_sty" :span="24">
                     <!-- <el-col :span="19" style="padding: 8px 0;"><el-checkbox v-model="checked">记住登陆账号</el-checkbox></el-col> -->
-                    <el-col :span="5"><el-button type="success" class="login" @click="toSubmit">登录</el-button></el-col>
+                    <el-col :span="24"><el-button type="success" class="login" @click="toSubmit">登录</el-button></el-col>
                   </el-col>
                   <el-col><el-link type="primary" class="login_tips" :underline="false">忘记登陆密码?</el-link></el-col>
                 </el-row>
@@ -75,6 +84,7 @@
 
 <script>
 import qrcode from '@/components/qrcode.vue';
+import verify from '@publics/src/components/verify.vue';
 import { mapActions, mapState } from 'vuex';
 const jwt = require('jsonwebtoken');
 export default {
@@ -82,6 +92,7 @@ export default {
   props: {},
   components: {
     qrcode,
+    verify,
   },
   data: () => ({
     img: {
@@ -97,21 +108,32 @@ export default {
       account: [{ required: true, message: '请输入学号', trigger: 'blur' }],
       passwd: [{ required: true, message: '请输入密码', trigger: 'blur' }],
     },
+    verifyForm: {},
   }),
   created() {
     this.initQrcode();
   },
   computed: {},
   methods: {
-    ...mapActions(['studLogin', 'createConnection', 'getWxtoken']),
+    ...mapActions(['studLogin', 'createConnection', 'getWxtoken', 'verifyOperation']),
     toSubmit() {
       this.$refs.form.validate(valid => {
         if (valid) {
-          this.submit();
+          // this.submit();
+          this.checkVerify();
         }
         return false;
       });
     },
+    async checkVerify() {
+      let result = await this.verifyOperation({ type: 'checkVerify', data: this.verifyForm });
+      if (`${result.errcode}` === '0') {
+        this.submit();
+      } else {
+        this.$message.error('验证码错误');
+        this.$refs.verifyPic.toCreated();
+      }
+    },
     async submit(wxtoken) {
       let data = JSON.parse(JSON.stringify(this.form));
       if (this.loginType === 0) {
@@ -129,6 +151,8 @@ export default {
         let info = jwt.decode(result.data);
         sessionStorage.setItem('user', JSON.stringify(info));
         this.$router.push({ path: '/' });
+      } else {
+        this.$refs.verifyPic.toCreated();
       }
     },
     async initQrcode() {
@@ -158,7 +182,6 @@ export default {
   padding: 15% 0;
 }
 .mainRight {
-  height: 310px;
   background: #fff;
   border-radius: 10px;
   padding: 32px 40px;
@@ -184,6 +207,7 @@ export default {
 }
 .inp_sty {
   padding: 5px 0;
+  text-align: center;
 }
 .tit_right {
   font-size: 18px !important;

+ 1 - 1
src/views/want/resume/index.vue

@@ -331,7 +331,7 @@
 </template>
 
 <script>
-import resumes from '@resume/src/views/resume.vue';
+import resumes from '@publics/src/views/resume.vue';
 import uploadFile from '@/components/upload-file.vue';
 import upload from '@/components/upload.vue';
 import tagAllSelect from '@/components/tag-all-select.vue';

+ 5 - 1
vue.config.js

@@ -10,7 +10,7 @@ module.exports = {
           '@': path.resolve(__dirname, './src'),
           '@c': path.resolve(__dirname, './src/components'),
           '@a': path.resolve(__dirname, './src/assets'),
-          '@resume': resumeSrc,
+          '@publics': resumeSrc,
         },
       },
     });
@@ -63,6 +63,10 @@ module.exports = {
         changeOrigin: true,
         ws: true,
       },
+      '/adminapi': {
+        target: 'http://10.16.5.15:8105',
+        ws: true,
+      },
     },
   },
 };