LoginPhone.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <script setup lang="ts">
  2. import { useI18n } from "vue-i18n";
  3. import { ref, reactive } from "vue";
  4. import Motion from "../utils/motion";
  5. import { message } from "@/utils/message";
  6. import { phoneRules } from "../utils/rule";
  7. import type { FormInstance } from "element-plus";
  8. import { $t, transformI18n } from "@/plugins/i18n";
  9. import { useVerifyCode } from "../utils/verifyCode";
  10. import { useUserStoreHook } from "@/store/modules/user";
  11. import { useRenderIcon } from "@/components/ReIcon/src/hooks";
  12. import Iphone from "~icons/ep/iphone";
  13. import Keyhole from "~icons/ri/shield-keyhole-line";
  14. const { t } = useI18n();
  15. const loading = ref(false);
  16. const ruleForm = reactive({
  17. phone: "",
  18. verifyCode: ""
  19. });
  20. const ruleFormRef = ref<FormInstance>();
  21. const { isDisabled, text } = useVerifyCode();
  22. const onLogin = async (formEl: FormInstance | undefined) => {
  23. loading.value = true;
  24. if (!formEl) return;
  25. await formEl.validate(valid => {
  26. if (valid) {
  27. // 模拟登录请求,需根据实际开发进行修改
  28. setTimeout(() => {
  29. message(transformI18n($t("login.pureLoginSuccess")), {
  30. type: "success"
  31. });
  32. loading.value = false;
  33. }, 2000);
  34. } else {
  35. loading.value = false;
  36. }
  37. });
  38. };
  39. function onBack() {
  40. useVerifyCode().end();
  41. useUserStoreHook().SET_CURRENTPAGE(0);
  42. }
  43. </script>
  44. <template>
  45. <el-form ref="ruleFormRef" :model="ruleForm" :rules="phoneRules" size="large">
  46. <Motion>
  47. <el-form-item prop="phone">
  48. <el-input
  49. v-model="ruleForm.phone"
  50. clearable
  51. :placeholder="t('login.purePhone')"
  52. :prefix-icon="useRenderIcon(Iphone)"
  53. />
  54. </el-form-item>
  55. </Motion>
  56. <Motion :delay="100">
  57. <el-form-item prop="verifyCode">
  58. <div class="w-full flex justify-between">
  59. <el-input
  60. v-model="ruleForm.verifyCode"
  61. clearable
  62. :placeholder="t('login.pureSmsVerifyCode')"
  63. :prefix-icon="useRenderIcon(Keyhole)"
  64. />
  65. <el-button
  66. :disabled="isDisabled"
  67. class="ml-2!"
  68. @click="useVerifyCode().start(ruleFormRef, 'phone')"
  69. >
  70. {{
  71. text.length > 0
  72. ? text + t("login.pureInfo")
  73. : t("login.pureGetVerifyCode")
  74. }}
  75. </el-button>
  76. </div>
  77. </el-form-item>
  78. </Motion>
  79. <Motion :delay="150">
  80. <el-form-item>
  81. <el-button
  82. class="w-full"
  83. size="default"
  84. type="primary"
  85. :loading="loading"
  86. @click="onLogin(ruleFormRef)"
  87. >
  88. {{ t("login.pureLogin") }}
  89. </el-button>
  90. </el-form-item>
  91. </Motion>
  92. <Motion :delay="200">
  93. <el-form-item>
  94. <el-button class="w-full" size="default" @click="onBack">
  95. {{ t("login.pureBack") }}
  96. </el-button>
  97. </el-form-item>
  98. </Motion>
  99. </el-form>
  100. </template>