登录倒计时

<template>
  <div class="container-box" style="display:flex;justify-content:space-between;min-height:100%;">
    <div class="image-container" style="flex:1;">
      <div class="container-background">
        <div class="logo" style="width:100px;height:100px;position:absolute;top:80px;left:80px;">
          <img src="@/assets/img/logo.png" alt="" width="100%" height="100%">
        </div>
        <div class="loginName" style="width:384px;height:150px;position:absolute;top:344px;left:80px;">
          <img src="@/assets/img/loginName.png" alt="" width="100%" height="100%">
        </div>
        <!-- <div style="position:absolute;top:80px;left:60px;font-size:40px;color:#fff;font-weight:600;">企业调查报送系统</div> -->
      </div>
    </div>
    <div class="login-container" style="background:#fff;width:695px;">
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" autocomplete="on" label-position="left">
        <div class="title-container">
          <h3 class="title">欢迎来到登录页面</h3>
        </div>

        <el-form-item prop="username">
          <span class="svg-container">
            <svg-icon icon-class="user" />
          </span>
          <el-input
            ref="username"
            v-model="loginForm.username"
            placeholder="请输入登录账号"
            name="username"
            type="text"
            tabindex="1"
            autocomplete="on"
          />
        </el-form-item>

        <el-form-item prop="code">
          <!-- <span class="svg-container">
            <svg-icon icon-class="message" />
          </span>
          <el-input
            v-model="loginForm.code"
            placeholder="请输入图形验证码"
            tabindex="1"
          />
          <div class="show-pwd" style="width:120px;height:50px;" @click="photoHandler">
            <img v-if="verifyImage" :src="verifyImage" alt="" style="width:100%;height:100%">
          </div> -->
        </el-form-item>
         <el-form-item>
              <JcRange ref="JcRange" :successFun="successFun()" :errorFun="errorFun()"></JcRange>
        </el-form-item>

        <el-form-item prop="shortMessge">
          <span class="svg-container">
            <svg-icon icon-class="password" />
          </span>
          <el-input
            v-model="loginForm.shortMessge"
            placeholder=""
            tabindex="1"
          />
          <span v-show="timeShow" class="show-pwd" style="top:7px;color:#0CA6FD" @click="getTencentSmsCode">
            获取验证码
          </span>
           <span v-show="!timeShow" class="show-pwd" :disabled="!timeShow">{{count}}s</span>
        </el-form-item>

        
        <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;height:50px;font-size:18px;" @click.native.prevent="login">登&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;录</el-button>

        <!-- <div style="position:relative">
          <div class="tips">
            <span>Username : admin</span>
            <span>Password : any</span>
          </div>
          <div class="tips">
            <span style="margin-right:18px;">Username : editor</span>
            <span>Password : any</span>
          </div>

          <el-button class="thirdparty-button" type="primary" @click="showDialog=true">
            Or connect with
          </el-button>
        </div> -->
      </el-form>

      <el-dialog title="Or connect with" :visible.sync="showDialog">
        Can not be simulated on local, so please combine you own business simulation! ! !
        <br>
        <br>
        <br>
        <social-sign />
      </el-dialog>
    </div>
  </div>
</template>

<script>
// import { validUsername } from '@/utils/validate'
import SocialSign from './components/SocialSignin'
import { getImageVerificationCode, getTencentSmsCode } from '@/api/login'
// import { jumpDwsurvey } from '@/api/dwsurvey'
import JcRange from './JcRange.vue'
// import { getToken, setToken, removeToken } from '@/utils/auth'
// import request from '@/utils/request'
// import qs from 'qs'
export default {
  name: 'Login',
  components: { SocialSign },
  data() {
    // const validateUsername = (rule, value, callback) => {
    //   if (!validUsername(value)) {
    //     callback(new Error('Please enter the correct user name'))
    //   } else {
    //     callback()
    //   }
    // }
    // const validatePassword = (rule, value, callback) => {
    //   if (value.length < 6) {
    //     callback(new Error('The password can not be less than 6 digits'))
    //   } else {
    //     callback()
    //   }
    // }
    return {
      verifyImage: '/corp-investigate/sms/getImageVerificationCode?key=' + new Date().getTime(),
      loginForm: {
        username: '13313333333',
        smsNum: '',
        password: '111111',
        code: '',
        shortMessage: ''
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur' }],
        password: [{ required: true, trigger: 'blur' }]
      },
      passwordType: 'password',
      capsTooltip: false,
      loading: false,
      showDialog: false,
      redirect: undefined,
      otherQuery: {},
      status: true,
      timeShow: true, // 初始启用按钮
      count: '', // 初始化次数
      timer: null
    }
  },
  components:{
    JcRange
  },
  watch: {
    $route: {
      handler: function(route) {
        const query = route.query
        if (query) {
          this.redirect = query.redirect
          this.otherQuery = this.getOtherQuery(query)
        }
      },
      immediate: true
    }
  },
  created() {
    // window.addEventListener('storage', this.afterQRScan)
  },
  mounted() {
    if (this.loginForm.username === '') {
      this.$refs.username.focus()
    } else if (this.loginForm.password === '') {
      this.$refs.password.focus()
    }
  },
  destroyed() {
    // window.removeEventListener('storage', this.afterQRScan)
  },
  methods: {
    getImageVerificationCode() {
      const key = new Date().getTime()
      getImageVerificationCode(key).then(res => {
      })
    },
    photoHandler() {
      this.verifyImage = ''
      this.$nextTick(() => {
        this.verifyImage = '/corp-investigate/sms/getImageVerificationCode?key=' + new Date().getTime()
      })
    },
    login() {
      // const account = this.loginForm.username
      // const smsNum = ''
      // const data = {
      //   account,
      //   smsNum
      // }
      const statusType = this.$refs.JcRange.rangeStatus
      console.log(statusType)
      if(!statusType){
         this.$message({
                type: 'error',
                message: '请重新验证'
            })
          return
      }
      this.loading = true
      this.$store.dispatch('user/login', this.loginForm)
        .then((res) => {
          console.log(res)
          window.localStorage.setItem('jwtToken', res.jwtToken)
          window.localStorage.setItem('userId', res.userId)
          window.localStorage.setItem('userData', JSON.stringify(res))
          // console.log(111)
          // console.log(window.localStorage.getItem("jwtToken"))
          // console.log(111)
          // let status = res.status;
          // let jwtToken = res.jwtToken;
          // if(status == 0){
          //   this.jumpDwsurvey(jwtToken)
          // }

          const userInfo = this.$store.getters.userInfo
          if (userInfo && Array.isArray(userInfo.functionList) && userInfo.functionList.length > 0 && userInfo.functionList.find(item => item === 'auth.manager.corp' || item === 'auth.manager.questionnaire' || item === 'auth.data.analysis' || item === 'auth.system.managerment')) {
            if (this.redirect === '/enterpriseQuestionnaire') {
              this.$router.push({ path: '/' })
            } else {
              this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
            }
          } else {
            this.$router.push({ path: '/enterpriseQuestionnaire' })
          }
          this.loading = false
        }).finally(() => {
          this.loading = false
        })
      // login(data).then(res => {
      //   setToken(res.userId)
      //   this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
      //   this.loading = false
      // }).catch(() => {
      //   this.loading = false
      // })
    },
    checkCapslock({ shiftKey, key } = {}) {
      if (key && key.length === 1) {
        if (shiftKey && (key >= 'a' && key <= 'z') || !shiftKey && (key >= 'A' && key <= 'Z')) {
          this.capsTooltip = true
        } else {
          this.capsTooltip = false
        }
      }
      if (key === 'CapsLock' && this.capsTooltip === true) {
        this.capsTooltip = false
      }
    },
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('user/login', this.loginForm)
            .then(() => {
              this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
              this.loading = false
            })
            .catch(() => {
              this.loading = false
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    getOtherQuery(query) {
      return Object.keys(query).reduce((acc, cur) => {
        if (cur !== 'redirect') {
          acc[cur] = query[cur]
        }
        return acc
      }, {})
    },
    getTencentSmsCode() {
      this.countDown()
      const phoneNumber = this.loginForm.username
      getTencentSmsCode({phoneNumber}).then(res => {
        const status = res.status
        if(status == "0"){
           this.$message({
                type: 'success',
                message: '发送成功'
            })
        }
      })
      
    },
    countDown() {
       const TIME_COUNT = 60 //更改倒计时时间
       if (!this.timer) {
            this.count = TIME_COUNT;
            this.timeShow = false;
            this.timer = setInterval(() => {
              if (this.count > 0 && this.count <= TIME_COUNT) {
                this.count--;
              } else {
                this.timeShow = true;
                clearInterval(this.timer); // 清除定时器
                this.timer = null;
              }
            }, 1000)
       }
    },
    successFun(){
    
    },
    errorFun() {
    },
    jumpDwsurvey(param) {
      // const jwtToken = param
      // jumpDwsurvey({jwtToken}).then(res => {
      //    console.log(res)
      //    let  status = res.status;
      //    if(status == "0"){
      //       const userInfo = this.$store.getters.userInfo
      //     if (userInfo && Array.isArray(userInfo.functionList) && userInfo.functionList.length > 0 && userInfo.functionList.find(item => item === 'auth.manager.corp' || item === 'auth.manager.questionnaire' || item === 'auth.data.analysis' || item === 'auth.system.managerment')) {
      //       if (this.redirect === '/enterpriseQuestionnaire') {
      //         this.$router.push({ path: '/' })
      //       } else {
      //         this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
      //       }
      //     } else {
      //       this.$router.push({ path: '/enterpriseQuestionnaire' })
      //     }

      //    }else{
      //       console.log('error!!!')
      //     return false
      //    }
      // })
    },
    // afterQRScan() {
    //   if (e.key === 'x-admin-oauth-code') {
    //     const code = getQueryObject(e.newValue)
    //     const codeMap = {
    //       wechat: 'code',
    //       tencent: 'code'
    //     }
    //     const type = codeMap[this.auth_type]
    //     const codeName = code[type]
    //     if (codeName) {
    //       this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
    //         this.$router.push({ path: this.redirect || '/' })
    //       })
    //     } else {
    //       alert('第三方登录失败')
    //     }
    //   }
    // }
  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg:#283443;
$light_gray:#000;
$cursor: #000;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px #fff inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.0);
    border-radius: 5px;
    border-bottom: 1px solid #f2f2f2;
    color: #454545;
  }
}
</style>

<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

.image-container {
  .container-background {
    background-image: url('~@/assets/img/login.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    width:100%;
    height:100%;
    position:relative;
    // #fff;
    // background-image: url("~@/assets/image/bankDetailBG.png");
    // background-size: auto 100%;
    // background-repeat: no-repeat;
    // background-position: right;
  }
}

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: #fff;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 260px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: #0CA6FD; // $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 0px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
}
</style>
posted @ 2021-04-09 16:50  威武的大萝卜  阅读(70)  评论(0编辑  收藏  举报