瀏覽代碼

修改系统休眠

zhaoke 3 年之前
父節點
當前提交
cc920328dc
共有 6 個文件被更改,包括 121 次插入33 次删除
  1. 69 15
      src/App.vue
  2. 9 0
      src/api/login.js
  3. 1 0
      src/store/getters.js
  4. 9 1
      src/store/modules/app.js
  5. 32 16
      src/utils/request.js
  6. 1 1
      src/views/dashboard/index.vue

+ 69 - 15
src/App.vue

@@ -13,14 +13,20 @@
       <div class="dormancy">
         <div class="title">系统休眠,请输入密码解锁</div>
         <div class="content">
-          <el-form ref="form" :rules="rules" :model="form">
+          <el-form @submit.native.prevent ref="form" :rules="rules" :model="form">
             <el-form-item prop="pwd">
-              <el-input show-password placeholder="请输入密码" v-model="form.pwd"></el-input>
+              <el-input show-password placeholder="请输入密码" tabindex="1" v-model="form.pwd"></el-input>
             </el-form-item>
+            <div v-if="Number(errorNum) >= 2" class="flex-wrap">
+              <el-form-item class="flex1" prop="identify">
+                <el-input ref="identify" v-model.trim="form.identify" placeholder="请输入验证码" name="identify" tabindex="1" />
+              </el-form-item>
+              <Identify @changeCode="changeCode" :identifyCode="form.CheckCode" :contentHeight="48" style="margin-left: 24px;" />
+            </div>
             <el-form-item>
-              <button class="button-public-shadow onSubmit" @click="onSubmit('form')">
+              <el-button :loading="loading" style="line-height: normal;" type="primary" class="button-public-shadow onSubmit" @click="onSubmit('form')">
                 确定
-              </button>
+              </el-button>
             </el-form-item>
           </el-form>
         </div>
@@ -33,12 +39,15 @@
 
 <script>
 import Dialog from "@/layout/components/Dialog/index.vue";
+import Identify from './views/login/identify.vue';
 import { mapGetters } from "vuex";
 import { SsoLogin } from "@/api/apiHome";
+import { GetSSOCheckCode } from '@/api/login';
 export default {
   name: "App",
   components: {
     Dialog,
+    Identify
   },
   data () {
     return {
@@ -50,15 +59,19 @@ export default {
       form: {
         //表单数据
         pwd: "",
+        identify: "",
+        CheckCode: ""
       },
       rules: {
         //表单验证
         pwd: [{ required: true, message: "请输入密码", trigger: "blur" }],
       },
+      flag: false,
+      loading: false
     };
   },
   computed: {
-    ...mapGetters(["dialog", "token", "name", "systemSet", "roles"]),
+    ...mapGetters(["dialog", "token", "name", "systemSet", "roles", "errorNum"]),
   },
   watch: {
     "$store.state.user.token": {
@@ -82,6 +95,11 @@ export default {
     },
   },
   mounted () {
+    const num = Number(this.errorNum);
+    if (this.dialog && num >= 2) {
+      // this.flag = true;
+      this.getCheckCode();
+    }
     this.beforeUnload();
   },
   beforeDestroy () {
@@ -146,6 +164,7 @@ export default {
             if (result[result.length - 2] === result[result.length - 1]) {
               // 相同时 结束倒计时
               this.$store.dispatch("app/toggleDialog", true);
+              this.getCheckCode();
               this.clearAll();
             } else {
               this.time = this.desc;
@@ -202,17 +221,52 @@ export default {
     },
     //锁屏验证
     async ssoLogin () {
-      const res = await SsoLogin({
-        LoginName: this.name,
-        LoginPwd: this.form.pwd,
-      });
+      try {
+        this.loading = true;
+        const obj = {
+          LoginName: this.name,
+          LoginPwd: this.form.pwd,
+        }
+        if (Number(this.errorNum) >= 2) {
+          obj.CheckCode = this.form.identify;
+        }
+        const res = await SsoLogin(obj);
+        if (res.code === 0) {
+          this.$store.dispatch("app/toggleDialog", false);
+          this.$store.dispatch("app/getErrorNum", 0);
+          this.arr = [];
+          this.arrLen = [];
+          this.time = this.desc;
+          this.form.pwd = "";
+          this.handleTimer();
+          this.loading = false;
+        } else {
+          const num = Number(res.returnData);
+          this.$store.dispatch("app/getErrorNum", num);
+          if (num >= 2) {
+            this.getCheckCode();
+          }
+          if (num >= 5) {
+            await this.$store.dispatch('user/logout')
+            this.$router.push(`/login?redirect=${this.$route.fullPath}`)
+          }
+          this.$message.error(res.message);
+          this.loading = false;
+        }
+      } catch (error) {
+        console.log(error);
+        this.loading = false;
+      }
+    },
+    //验证码重新获取
+    changeCode () {
+      this.getCheckCode()
+    },
+    //获取动态验证码
+    async getCheckCode () {
+      const res = await GetSSOCheckCode();
       if (res.code === 0) {
-        this.$store.dispatch("app/toggleDialog", false);
-        this.arr = [];
-        this.arrLen = [];
-        this.time = this.desc;
-        this.form.pwd = "";
-        this.handleTimer();
+        this.form.CheckCode = res.returnData;
       } else {
         this.$message.error(res.message);
       }

+ 9 - 0
src/api/login.js

@@ -10,6 +10,15 @@ export function GetCheckCode (params) {
     })
 }
 
+//获取动态验证码
+export function GetSSOCheckCode () {
+    return request({
+        url: '/api/fs4a/GetSSOCheckCode/v1',
+        method: 'post'
+        // data: params
+    })
+}
+
 //登录
 export function login (params) {
     return request({

+ 1 - 0
src/store/getters.js

@@ -23,6 +23,7 @@ const getters = {
   visitedViews: state => state.tagsView.visitedViews,
   cachedViews: state => state.tagsView.cachedViews,
   systemSet: state => state.app.systemSet,
+  errorNum: state => state.app.errorNum,
   authArrs: state => state.auth.authArrs,
   authList: state => state.auth.authList,
   authId: state => state.auth.authId,

+ 9 - 1
src/store/modules/app.js

@@ -19,6 +19,7 @@ const state = {
   outflag: false,
   outcheck: false,
   systemSet: Cookies.get('systemSet') != null ? Cookies.get('systemSet') : null,
+  errorNum: Cookies.get('errorNum') ? Cookies.get('errorNum') : 0,
 }
 const mutations = {
   TOGGLE_SIDEBAR: state => {
@@ -54,6 +55,10 @@ const mutations = {
   SYSTEM_SET: (state, systemSet) => {
     state.systemSet = systemSet
     Cookies.set('systemSet', systemSet)
+  },
+  ERROR_NUM: (state, systemSet) => {
+    state.errorNum = systemSet
+    Cookies.set('errorNum', systemSet)
   }
 }
 
@@ -79,8 +84,11 @@ const actions = {
   toggleOutcheck ({ commit }, outcheck) {
     commit('TOGGLE_OUTCHECK', outcheck)
   },
-  getSystemSet({ commit }, systemSet) {
+  getSystemSet ({ commit }, systemSet) {
     commit('SYSTEM_SET', systemSet)
+  },
+  getErrorNum ({ commit }, systemSet) {
+    commit('ERROR_NUM', systemSet)
   }
 }
 

+ 32 - 16
src/utils/request.js

@@ -64,18 +64,10 @@ service.interceptors.response.use(
    */
   response => {
     const res = response.data
-
-    // if the custom code is not 20000, it is judged as an error.
-    if (res.code != 0) {
-      Message({
-        message: res.message || 'Error',
-        type: 'error',
-        duration: 5 * 1000
-      })
-
-      // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
+    if (res.code == 0 || res.code == -1) {
+      return res
+    } else {
       if (res.code == 500) {
-        // to re-login
         Message({
           message: '身份令牌过期或失效,即将重新登录',
           type: 'error',
@@ -88,12 +80,36 @@ service.interceptors.response.use(
           }
         })
       }
-      // loadingInstance.close()
-      return Promise.reject(new Error(res.message || 'Error'))
-    } else {
-      // loadingInstance.close()
-      return res
     }
+    // if the custom code is not 20000, it is judged as an error.
+    // if (res.code != 0 || res.code == -1) {
+    //   Message({
+    //     message: res.message || 'Error',
+    //     type: 'error',
+    //     duration: 5 * 1000
+    //   })
+
+    //   // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
+    //   if (res.code == 500) {
+    //     // to re-login
+    //     Message({
+    //       message: '身份令牌过期或失效,即将重新登录',
+    //       type: 'error',
+    //       duration: 5 * 1000,
+    //       onClose: () => {
+    //         store.dispatch('tagsView/delAllViews').then(() => { })
+    //         store.dispatch('user/resetToken').then(() => {
+    //           location.reload()
+    //         })
+    //       }
+    //     })
+    //   }
+    //   // loadingInstance.close()
+    //   return Promise.reject(new Error(res.message || 'Error'))
+    // } else {
+    //   // loadingInstance.close()
+    //   return res
+    // }
   },
   error => {
     // console.log('err', error) // for debug

+ 1 - 1
src/views/dashboard/index.vue

@@ -35,7 +35,7 @@
           <el-select :style="inputFlag ? 'width:150px;':'width:200px;'" @change="handleChange" v-model="select" placeholder="功能菜单">
             <el-option v-for="(item,index) in routes" :key="index" :label="item.meta.title" :value="item.path"></el-option>
           </el-select>
-          <el-input v-show="inputFlag" :style="inputFlag ? 'width:330px;':'width:280px;'" placeholder="如需搜索,请输入" v-model.trim="input" class="input-with-select">
+          <el-input v-show="inputFlag" :style="inputFlag ? 'width:330px;':'width:280px;'" @keyup.enter.native="searchByLink" placeholder="如需搜索,请输入" v-model.trim="input" class="input-with-select">
           </el-input>
           <!-- <el-select v-model="select" slot="prepend" placeholder="功能菜单">
             <el-option v-for="(item,index) in selectArr" :key="index" :label="item.name" :value="item.value"></el-option>