<template>
  <div class="email-registration">
    <!-- 账号信息 -->
    <div class="form" v-if="active === 0">
      <div class="title">重设密码</div>
      <div class="Password">
        <el-input
          type="Password"
          size="large"
          class="input-item"
          v-model="Password"
          show-password
          placeholder="请输入新密码"
        />
        <text class="password-tip">您的密码必须包含大小字母和数字，长度在6-16位之间</text>
      </div>
      <div class="ConfirmPassword">
        <el-input
          type="Password"
          size="large"
          class="input-item"
          v-model="ConfirmPassword"
          show-password
          placeholder="请再次输入新密码"
        />
      </div>
      <div class="btn">
        <div class="nextStep" @click="nextStep">确认</div>
      </div>
    </div>
    <!-- 完成注册 -->
    <div class="forms" v-if="active === 1">
        <div class="title">重设密码成功</div>
    </div>
  </div>
</template>

<script setup>
import { useRoute } from "vue-router";
import { ref, watch, onMounted, onUpdated, onUnmounted } from "vue";
import { resetPassword } from "@/api/account";
const active = ref(0);// 当前步骤
const route = useRoute();
const token = ref("");
const Password = ref("");// 密码
const ConfirmPassword = ref("");// 确认密码
import { ElMessage } from "element-plus";

//确认
function nextStep() {
  // 密码验证
  const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{6,16}$/;
  if (!passwordRegex.test(Password.value)) {
    ElMessage.error('密码必须包含大小写字母和数字，长度6-16位');
    return;
  }
  // 确认密码验证
  if (Password.value !== ConfirmPassword.value) {
    ElMessage.error('两次输入的密码不一致');
    return;
  }
  resetPassword({
    token: token.value,
    password: Password.value,
    confirmPassword: ConfirmPassword.value
  }).then(() => {
    active.value = active.value + 1;
  })
}

onMounted(() => {
  token.value = route.params.token;
});

onUpdated(() => {
  // 组件更新后执行
});

onUnmounted(() => {
  // 组件销毁前执行
});
</script>


<style scoped>
.email-registration {
  padding: 0;
  margin: 0;
  width: 100vw;
  height: 100vh;
  background-image: url(../assets/bg.png);
  background-size: 100% 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
.stepBar {
  width: 80%;
}
.form {
  margin-top: 30px;
  width: 80%;
  height: 80%;
  background-image: linear-gradient(180deg, #dbf0f1, #ffffff);
  border-radius: 10px;
  border: 1px solid #4fcacd;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.forms{
    margin-top: 30px;
  width: 900px;
  height: 600px;
  background-image: linear-gradient(180deg, #dbf0f1, #ffffff);
  border-radius: 10px;
  border: 1px solid #4fcacd;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.title{
  font-size: 70px;
  color: #4fcacd;
  margin-top: 70px;
  text-align: center;
  font-weight: bold;
}
.Hint{
  width: 900px;
  height: 400px;
  color:#4fcacd;
  font-size: 20px;
  text-align: center;
  line-height: 500px;
  margin-top: -50px;
}
.ResendEmail{
  width: 200px;
  height: 40px;
  background-image: linear-gradient(0deg, #4fcacd, #5fdbde);
  border-radius: 10px;
  color: #ffffff;
  font-size: 16px;
  text-align: center;
  line-height: 40px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 50px;
}
.ResendEmail:hover{
  box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3);
    transform: scale(1.08);
    opacity: 0.8;
}
.Email{
  margin-top: 30px;
  width: 90%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.Password{
  margin-top: 30px;
  width: 90%;
  height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.ConfirmPassword{
  margin-top: 50px;
  width: 90%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.password-tip{
  font-size: 40px;
  color: #8c939d;
  margin-top: 10px;
}
.btn{
  width: 70%;
  margin-top: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.Return{
  width: 200px;
  height: 40px;
  background-image: linear-gradient(0deg, #4fcacd, #5fdbde);
  border-radius: 10px;
  color: #ffffff;
  font-size: 16px;
  text-align: center;
  line-height: 40px;
  cursor: pointer;
  transition: all 0.3s ease;
}
.Return:hover{
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3);
    transform: scale(1.08);
    opacity: 0.8;
}
.nextStep{
  width: 100%;
  height: 100px;
  background-image: linear-gradient(0deg, #4fcacd, #5fdbde);
  border-radius: 10px;
  color: #ffffff;
  font-size: 50px;
  text-align: center;
  line-height: 100px;
  cursor: pointer;
  transition: all 0.3s ease;
}
.nextStep:hover{
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3);
    transform: scale(1.08);
    opacity: 0.8;
}
.avatar {
  width: 90%;
  margin-top: 30px;
  height: 178px;
}
.input {
  width: 90%;
  margin-top: 100px;
  height: 200px;
}
.input-item {
  border: none;
  width: 80%;
  height: 100px;
  background-color: #ffffff00;
  border-bottom: 1px solid #4fcacd;
  font-size: 40px;
}
:deep(.el-input__wrapper) {
    height: 50px;
  box-shadow: none !important;
  background-color: transparent !important;
}
:deep(.el-input__icon) {
    width: 50px;
    height: 50px;
}
:deep(.el-input__wrapper.is-focus) {
  box-shadow: none !important;
}
.avatar-uploader {
  width: 178px;
  height: 178px;
  border: 3px solid #4fcacd;
  border-radius: 10px;
}
.avatar-uploader .avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
}
.avatar-tip {
  width: 178px;
  text-align: center;
  font-size: 12px;
  color: #8c939d;
}
</style>

