FindPwd.vue 6.8 KB
<template>
  <div class="login_pwd">
    <!-- 找回密码 -->
    <el-dialog
      :visible="pwdVisible"
      @update:visible="$emit('update:pwdVisible',false)"
      width="636px"
      :before-close="handleClose"
      :close-on-click-modal="false"
      center
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="手机号" prop="name">
          <el-input v-model="ruleForm.name" maxlength="11" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="code" class="ver_code">
          <el-input v-model="ruleForm.code" maxlength="4" placeholder="请输入验证码"></el-input>
          <!-- 获取验证码 -->
          <div class="code_btn" v-show="isShow" @click="getCode">获取验证码</div>
          <div class="code_btn sended"  v-show="!isShow">{{auth_time}}秒后重发</div>
        </el-form-item>
        <el-form-item label="新密码" prop="newPwd">
          <el-input type="password" minlength="6" v-model="ruleForm.newPwd" placeholder="请输入新密码"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="oldPwd">
          <el-input type="password" v-model="ruleForm.oldPwd" placeholder="确认密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">找回密码</el-button>
        </el-form-item>
        <!-- 联系管理员 -->
        <div class="contact">
          <p @click="contact">联系管理员</p>
        </div>
      </el-form>

      <!-- 联系管理员 -->
      <ContactAdmin :contactVisible.sync="contactVisible" v-if="contactVisible"></ContactAdmin>
    </el-dialog>
  </div>
</template>
<script>
// 联系管理员
import ContactAdmin from "./ContactAdmin";
import { get, post } from "@/api/http";
import { Notification } from "element-ui";
export default {
  props: ["pwdVisible", "pwdType"],
  data() {
    // 电话号码验证
    var phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/;
    var validatePhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("请输入11位手机号码"));
      }
      setTimeout(() => {
        if (!phoneReg.test(value)) {
          callback(new Error("号码不存在,请输入正确的手机号"));
        } else {
          callback();
        }
      }, 100);
    };
    // 验证码

    // 密码验证
    var regex = new RegExp("");
    var validatePwd = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("密码不能为空,请输入密码"));
      }
      setTimeout(() => {
        console.log(value)
        if (!/((?=.*[a-z])(?=.*\d)|(?=[a-z])(?=.*[#@!~%^&*])|(?=.*\d)(?=.*[#@!~%^&*]))[a-z\d#@!~%^&*]{6,16}/i.test(value)) {
          callback(new Error("密码不能为纯数字、纯字符或纯字母"));
        } else {
          callback();
        }
      }, 100);
    };
    
    return {
      isShow: true,
      sending: false,
      auth_time: 0,
      contactVisible: false,
      ruleForm: {
        name: "",
        code: "",
        newPwd: "",
        oldPwd: ""
      },
      rules: {
        name: [
          {
            required: true,
            validator: validatePhone,
            trigger: "blur"
          }
        ],
        code: [
          { required: true, message: "验证码为空,请重新验证码", trigger: "blur" }
        ],
        newPwd: [
          {
            required: true,
            validator:validatePwd,
            trigger: "blur"
          }
        ],
        oldPwd: [
          {
            required: true,
            message: "密码不能为空,请输入密码",
            trigger: "blur"
          }
        ]
      },
      groupId: "",
      schoolId:""
    };
  },
  methods: {
    handleClose: function() {
      this.$emit("update:pwdVisible", false);
    },
    // 获取验证码
    getCode() {
      
      // 找回密码
      let tel = /^1(3|4|5|6|7|8|9)\d{9}$/;
      let that = this;
      if (!tel.test(that.ruleForm.name)) {
        Notification.info({
          title: "提示",
          message: "请输入手机号",
          duration: 1500
        });
        return "";
      }
      
      let url = "/api/sms/send";
      let params = {
        mobile: this.ruleForm.name,
        event: "resetpwd",
        type: this.pwdType
      };
      let  auth_timetimer;
      get(url, params).then(res => {
        that.isShow = !that.isShow;
        that.auth_time = 60;
        auth_timetimer = setInterval(function() {
          that.auth_time--;
          if (that.auth_time <= 0) {
            that.isShow = true;
            clearInterval(auth_timetimer);
          }
        }, 1000);
        // that.sending = true;
      });
      if (!this.sending) {
        
      }
    },
    // 找回密码
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          if (this.ruleForm.newPwd == this.ruleForm.oldPwd) {
            let url = "/api/common/resetpwd";
            let params = {
              mobile: this.ruleForm.name,
              captcha: this.ruleForm.code,
              newpassword: this.ruleForm.newPwd,
              confirmpassword: this.ruleForm.oldPwd,
              type: this.pwdType,
              schoolId:this.schoolId
            };
            get(url, params).then(res => {
              this.$emit("update:pwdVisible", false);
              Notification.info({
                title: "提示",
                message: "找回密码成功",
                duration: 1500
              });
            });
          } else {
            Notification.info({
              title: "提示",
              message: "密码不一致,请重新输入",
              duration: 1500
            });
          }
        }
      });
    },
    // 联系管理员
    contact: function() {
      this.contactVisible = true;
    }
  },
  components: {
    ContactAdmin
  },
  mounted() {
    this.schoolId = this.$route.params.test;
    console.log(this.schoolId,111)
  },
  watch:{
    '$route'(to,from){
      console.log(to,from)
      this.schoolId = this.$route.params.test;
      localStorage.setItem("schoolSymbol",this.schoolId)
    }
  },
};
</script>
<style scoped>
/* 获取验证码按钮 */
.ver_code {
  position: relative;
}
.code_btn {
  position: absolute;
  top: 7px;
  right: 25px;
  width: 110px;
  height: 36px;
  background: #409eff;
  border-radius: 18px;
  font-size: 18px;
  font-family: Source Han Sans SC;
  font-weight: 400;
  line-height: 36px;
  text-align: center;
  color: rgba(255, 255, 255, 1);
  opacity: 1;
}
.sended{
  background: #f3f3f3;
  color: #8C9198;
}
.contact {
  color: #bdc4ce;
  font-size: 14px;
  text-align: right;
  margin-right: 24px;
  margin-top: -17px;
  line-height: 1;
}
</style>