<template>
    <div class="login-container">
      <h2>找回密码</h2>
      <form @submit.prevent="handleSubmit">
        <div class="form-group">
          <label for="email">邮箱</label>
          <input type="email" id="email" v-model="email" required />
        </div>
        <div>请输入您的邮箱。稍后，我们会将您的密码发给您</div>
        <button type="submit">发送重置链接</button>
      </form>
    </div>
  </template>
  
<script lang="ts" setup>
  import { ref } from 'vue';
  import { useRouter } from 'vue-router';
  import axios from 'axios';
  import { useToast } from 'vue-toastification' 
  const toast = useToast()
  const router = useRouter();
  const email = ref('');
  
  const handleSubmit = () => {
    // 这里可以添加找回密码逻辑，例如调用 API 发送重置链接
    console.log('邮箱:', email.value);
    // 使用 Axios 发送 POST 请求
  axios.post(`http://127.0.0.1:8080/user/findpassword/${encodeURIComponent(email.value)}`)
  .then(function (response) {
    if(response.data.code==1)
    {
          // 处理成功响应
      console.log('Response:', response.data);
      toast.success("密码已经发送到您的邮箱，请注意查收");
      router.push('/login');
    }
    else{
      toast.error("邮箱不存在，请重新输入");
    }
  })
  .catch(function (error) {
    // 处理错误
    console.error('Error:', error);
  });

  };
</script>
  
<style scoped>
  html, body {
    height: 100%;
    margin: 0;
    padding: 0;
  }
  
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #f0f0f0; /* 可以根据需要调整背景颜色 */
  }
  
  .login-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 20px;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    background-color: #f9f9f9;
  }
  
  .form-group {
    margin-bottom: 15px;
  }
  
  label {
    display: block;
    margin-bottom: 5px;
  }
  
  input[type="email"] {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
  }
  
  button {
    width: 100%;
    padding: 10px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
  }
  
  button:hover {
    background-color: #45a049;
  }
</style>