forgot.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div class="container">
  3. <template v-if="!emailSent">
  4. <n-form ref="formRef" label-placement="left" :label-width="100" :model="form" :rules="rules" size="large" require-mark-placement="left">
  5. <n-form-item :label="t('common.register.email')+':'" path="email">
  6. <n-input v-model:value="form.email" :placeholder="t('common.register.forgetPasswordPlaceholder')" />
  7. </n-form-item>
  8. </n-form>
  9. <n-button class="login-btn" attr-type="button" type="info" color="#18A058" :disabled="submitLoading" @click="handleSend">
  10. {{ submitLoading ? t('common.login.sending') : t('common.login.clickToSend') }}
  11. </n-button>
  12. </template>
  13. <template v-else>
  14. <p style="text-align: center">
  15. <n-icon size="30" color="#00C849" :component="MdCheckmarkCircle" />
  16. </p>
  17. <p class="tip">
  18. {{t('common.login.emailSendSuccess')}}
  19. </p>
  20. <n-button class="login-btn" attr-type="button" type="info" color="#18A058" @click="handleSure">
  21. {{t('common.login.confirm')}}
  22. </n-button>
  23. </template>
  24. </div>
  25. </template>
  26. <script lang="ts" setup>
  27. import { useI18n } from "#imports";
  28. import { createDiscreteApi } from "naive-ui";
  29. import { MdCheckmarkCircle } from "@vicons/ionicons4";
  30. import { ref, reactive } from "vue";
  31. const { t, locale, setLocale } = useI18n();
  32. const emit = defineEmits(["closeSginDialog"]);
  33. const message = createDiscreteApi(["message"]);
  34. const formRef = ref();
  35. const submitLoading = ref(false);
  36. const form = reactive<object>({
  37. email: "",
  38. });
  39. const rules: FormRules = {
  40. email: [
  41. {
  42. required: true,
  43. message: "请输入邮箱",
  44. trigger: ["input", "blur"],
  45. },
  46. {
  47. required: true,
  48. validator: (rule: FormItemRule, value: string): boolean => {
  49. return value && isEmail(value);
  50. },
  51. message: "请输入正确格式邮箱",
  52. trigger: ["blur"],
  53. },
  54. ],
  55. };
  56. const emailSent = ref<boolean>(false);
  57. const handleSend = () => {
  58. formRef.value?.validate(async (errors: any) => {
  59. if (!errors) {
  60. submitLoading.value = true;
  61. const { code } = await email_Api(form);
  62. if (code === 200) {
  63. message.message.success("发送成功");
  64. emailSent.value = true;
  65. }
  66. submitLoading.value = false;
  67. }
  68. });
  69. };
  70. const handleSure = () => {
  71. emit("closeSginDialog", "success");
  72. };
  73. </script>
  74. <style lang="scss" scoped>
  75. .container {
  76. width: 100%;
  77. padding: 30px 20px;
  78. .login-btn {
  79. display: block;
  80. width: 50%;
  81. height: 50px;
  82. color: #fff;
  83. font-size: 18px;
  84. border-radius: 8px;
  85. margin: 0 auto;
  86. :deep(.n-button__content) {
  87. display: block;
  88. }
  89. }
  90. .tip {
  91. font-size: 16px;
  92. line-height: 32px;
  93. }
  94. }
  95. </style>