forgetPassword.vue 10.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
<template>
  <el-row class="login-box">
    <div>
      <div class="restFrom">
        <el-form
          ref="registerRef"
          :model="registerForm"
          :rules="registerRules"
          class="register-form"
        >
          <div v-if="!stringId">
            <el-form-item prop="phonenumber">
              <el-input
                v-model="registerForm.phonenumber"
                type="text"
                size="large"
                auto-complete="off"
                placeholder="请输入手机号"
              >
                <template #prefix><svg-icon icon-class="phone" class="el-input__icon input-icon" /></template>
              </el-input>
            </el-form-item>
           
            <el-form-item prop="captcha">
              <captcha ref="codeRef" v-model="registerForm.captcha" v-model:uuid="registerForm.uuid" @keyup.enter="handleRegister" />
            </el-form-item>
            <el-form-item prop="code">
              <captcha-sms v-model="registerForm.code" :verify="checkCaptchaSms" @keyup.enter="handleRegister" @error="getCode" />
            </el-form-item>
            <el-form-item style="height: 20px">
              <el-button type="primary" link @click="forgetPassword">去登录</el-button>
            </el-form-item>
            <el-form-item style="width: 100%">
              <el-button
                :loading="loading"
                size="large"
                type="success"
                style="width: 100%;border: 0;"
                @click.prevent="handleRegister"
              >
                <span v-if="!loading">修 改</span>
                <span v-else>修 改 中...</span>
              </el-button>
            </el-form-item>
          </div>
          <div v-if="stringId">
            <el-form-item prop="password">
              <el-input
                v-model="registerForm.password" 
                type="password"
                size="large"
                auto-complete="off"
                placeholder="密码(6-18个字符组成,区分大小写,需包含字母+数字)"
              >
                <template #prefix><svg-icon
                  icon-class="password"
                  class="el-input__icon input-icon"
                /></template>
              </el-input>
            </el-form-item>
            <el-form-item prop="passwords">
              <el-input
                v-model="registerForm.passwords"
                type="password"
                size="large"
                auto-complete="off"
                placeholder="确认密码"
              >
                <template #prefix><svg-icon
                  icon-class="password"
                  class="el-input__icon input-icon"
                /></template>
              </el-input>
            </el-form-item>
            <el-form-item style="height: 20px">
              <el-button type="primary" link @click="forgetPassword">去登录</el-button>
            </el-form-item>
            <el-form-item style="width: 100%">
              <el-button
                :loading="loading"
                size="large"
                type="success"
                style="width: 100%;border: 0;"
                @click.prevent="modification"
              >
                <span v-if="!loading">修 改</span>
                <span v-else>修 改 中...</span>
              </el-button>
            </el-form-item>
          </div>
          
        </el-form>
      </div>
    </div>
  </el-row>
</template>

<script setup>

import { ref } from 'vue'
import { getCurrentInstance } from '@vue/runtime-core'
import { resetPassByPhonePre, resetPassByPhoneNext } from '@/api/login'
import { ElMessage, ElMessageBox } from 'element-plus'
import Captcha from '@/views/login/components/captcha.vue'
import CaptchaSms from '@/views/login/components/captchaSms.vue'


const { proxy } = getCurrentInstance()
const emit = defineEmits(['login'])
const stringId = ref()
const registerForm = ref({
  password: '',
  code: '',
  uuid: '',
  captcha: ''
})


const registerRules = {
  phonenumber: [
    { required: true, trigger: 'blur', message: '请输入手机号' },
    {
      pattern: /^1[3456789]\d{9}$/,
      message: '手机号码格式不正确',
      trigger: 'blur'
    }
  ],
  password: [
    { required: true, trigger: 'blur', message: '请输入您的密码' },
    {
      min: 6,
      max: 18,
      message: '用户密码长度必须介于 6 和 18 之间',
      trigger: 'blur'
    },
    {
      pattern: /^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)(?=.*?[!#@*&.])[a-zA-Z\d!#@*&.]{8,}$/,
      message: '8位以上大小写字母、数字、特殊符号组合',
      trigger: 'blur'
    }
  ],
  passwords: [
    { required: true, trigger: 'blur', message: '请确认密码' },
    { validator: validatePassword, trigger: 'blur' }

  ],
  captcha: [{ required: true, trigger: 'blur', message: '请输入图形验证码' }],
  code: [{ required: true, trigger: 'blur', message: '请输入短信验证码' }]
}

const loading = ref(false)

function handleRegister() {
  proxy.$refs['registerRef'].validate((valid) => {
    if (valid) {
      loading.value = true
      resetPassByPhonePre(registerForm.value)
        .then((res) => {
          // emit('login')
          stringId.value = res.data
          console.log(res)
          loading.value = false
        })
        .catch(() => {
          loading.value = false
          getCode()
        })
    }
  })
}

function modification(params) {
  proxy.$refs['registerRef'].validate((valid) => {
    if (valid) {
      loading.value = true
      resetPassByPhoneNext({ passwd: registerForm.value.password, uuid: stringId.value })
        .then((res) => {
          ElMessageBox.alert(
            "<font color='red'>修改成功,请登录!</font>",
            {
              dangerouslyUseHTMLString: true,
              type: 'success'
            }
          ).then(() => {
            loading.value = false
            // router.push('/login')
            emit('login')
          })
        })
        .catch(() => {
          loading.value = false
          getCode()
        })
    }
  })
}

// 确认密码
function validatePassword(rule, value, callback) {
  if (registerForm.value.password === value) {
    return callback() // callback() is a function on the Vue prototype. It can be called like the regular callback. (See https://vuejs.org
  } else {
    return callback(new Error('两次密码不一致,请重新输入'))
  }
}

// 发送短信验证码
function checkCaptchaSms() {
  // 判断手机号正确
  if (!registerForm.value.phonenumber) {
    ElMessage({
      showClose: true,
      message: '请输入手机号',
      type: 'error'
    })
    return Promise.reject()
  }
  // 判断验证码填了没
  if (!registerForm.value.captcha) {
    ElMessage({
      showClose: true,
      message: '请输入图形验证码',
      type: 'error'
    })
    return Promise.reject()
  }

  const strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/
  if (!strTemp.test(registerForm.value.phonenumber)) {
    ElMessage({
      showClose: true,
      message: '请输入正确的手机号',
      type: 'error'
    })
    return Promise.reject()
  }

  return Promise.resolve({
    uuid: registerForm.value.uuid,
    telNo: registerForm.value.phonenumber,
    captcha: registerForm.value.captcha
  })
}

function getCode() {
  proxy.$refs['codeRef'].getCode()
}

function forgetPassword() {
  emit('login')
}
</script>

<style lang="scss" scoped>
:deep(.el-input-group__append) {
  color: #fff;
  background-color: #44dcb5;
}
.restFrom {
  display: flex;
  justify-content: center;
  align-items: center;
  // height: 80%;
  min-height:  430px;
}
.login-box {
  display: flex;
  justify-content: center;
  align-items: center;
}
.title {
  padding: 0px 200px;
  height: 100px;
  background-color: #fff;
}
.title-right {
  display: flex;
  justify-content: space-between;
}
.title-left {
  color: #043793;
  font-weight: 900;
  font-size: 30px;
  margin-left: 100px;
  padding-top: 25px;
}

.tilt-btn {
  // background-color: #043793;
  color: #043793;
  font-weight: 700;
  background-color: none;
  font-size: 20px;
  margin-right: 20px;
  padding-top: 15px;
  padding-left: 20px;
  padding-right: 20px;
  cursor: pointer;
}
.btn {
  color: #fff;
  background-color: #043793;
  border-radius: 10px;
}
.title-text {
  color: #043793;
  font-weight: 500;
  font-size: 20px;
}
.text-center {
  color: #fff;
  font-size: 40px;
  font-weight: 700;
  margin-right: 40px;
}
.register {
  // display: flex;
  // justify-content: center;
  // align-items: center;
  height: 100%;
  background-image: url("@/assets/images/login-background.jpg");
  background-size: cover;
}

.register-form {
  width: 580px;
  // height: 460px;
  background: #FFFFFF;
  box-shadow: 0px 0px 38px 0px rgba(30,98,151,0.73);
  border-radius: 15px;
  padding: 40px 65px;
  :deep(.el-input) {
    height: 40px;
    input {
      height: 40px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 0px;
  }
}
.register-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.register-code {
  width: 33%;
  height: 40px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-register-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.register-code-img {
  height: 40px;
  padding-left: 12px;
}

.text{
  text-align: center;
  position: absolute;
  top: 120px;
  font-size: 36px;
  font-family: Source Han Sans CN;
  font-weight: bold;
  color: #FFFFFF;
}

.con{
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #7B7F83;
}
.imgs{
  width: 268px;
  height:249px ;
}
.imgbox{
  width: 350px;
  // margin: 25px;
  text-align: center;
}

.card{
  margin: 25px;
  border: 4px solid #DCDCDC;
  border-radius: 15px;
  position: relative;
}

.imgSon{
  position: absolute;
  top: -1px;
  left: -1px;
  width: 90px;
  height: 90px;
  border: 0  !important;
}

.active{
  border: 4px solid #014A9F !important;

}

.btn{
  width: 440px;
  height: 60px;
  background: #014A9F;
  border-radius: 4px;
}

:deep(.btn span){
  font-size: 20px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #FFFFFF;
}
h1{text-align: center;    color: #fff;}
</style>