reset.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <cwg-page-wrapper>
  3. <view class="reset-container">
  4. <view class="reset-form">
  5. <cwg-input v-model:value="email" type="text" fkey="email" label="邮箱" :clearable="true"
  6. placeholder="请输入邮箱" :rules="[
  7. { required: true, message: '请输入邮箱' },
  8. { pattern: config.Pattern.Email, message: '请输入正确的邮箱格式' },
  9. ]" @change="handleChange">
  10. <template #left-icon1>
  11. <cwg-icon name="email-outline" :size="20" color="#000" />
  12. </template>
  13. </cwg-input>
  14. <view class="reset-button cwg-button">
  15. <u-button type="primary" block :loading="loading" @click="handleReset">{{ t('forget.forget')
  16. }}</u-button>
  17. </view>
  18. <view class="login-link">
  19. {{ t('signin.forget') }}<text @click="handleLogin">{{ t('newSignin.item7') }}</text>
  20. </view>
  21. </view>
  22. </view>
  23. </cwg-page-wrapper>
  24. </template>
  25. <script setup lang="ts">
  26. import { ref } from 'vue'
  27. import { useI18n } from 'vue-i18n'
  28. import useRouter from '@/hooks/useRouter'
  29. import { userApi } from '@/api/user'
  30. import config from '@/config'
  31. const { t } = useI18n()
  32. const router = useRouter()
  33. const loading = ref(false)
  34. const email = ref('')
  35. async function handleReset() {
  36. if (!email.value) {
  37. uni.showToast({ title: t('vaildate.email.empty'), icon: 'none' })
  38. return
  39. }
  40. if (!config.Pattern.Email.test(email.value)) {
  41. uni.showToast({ title: t('vaildate.email.format'), icon: 'none' })
  42. return
  43. }
  44. loading.value = true
  45. try {
  46. const res = await userApi.updatePassword({ email: email.value })
  47. uni.showToast({ title: res.msg || '成功', icon: 'none' })
  48. router.push('/pages/login/index')
  49. }
  50. catch (error: any) {
  51. uni.showToast({ title: error.message || '重置失败', icon: 'none' })
  52. }
  53. finally {
  54. loading.value = false
  55. }
  56. }
  57. function handleChange(value: any) {
  58. if (value.key == 'email') {
  59. email.value = value.value
  60. }
  61. }
  62. function handleLogin() {
  63. router.push('/pages/login/index')
  64. }
  65. </script>
  66. <style scoped lang="scss">
  67. @import "@/uni.scss";
  68. .reset-container {
  69. padding: px2rpx(40) 0;
  70. }
  71. .reset-button {
  72. margin-bottom: px2rpx(20);
  73. u-button {
  74. height: px2rpx(44);
  75. border-radius: px2rpx(12);
  76. background: var(--main-yellow);
  77. border: none;
  78. color: var(--black);
  79. font-size: var(--font-size-16);
  80. font-weight: bold;
  81. }
  82. :deep(u-button--loading) {
  83. opacity: 0.8;
  84. }
  85. }
  86. .login-link {
  87. text-align: center;
  88. font-size: var(--font-size-14);
  89. color: var(--gray);
  90. text {
  91. color: var(--main-yellow);
  92. margin-left: px2rpx(4);
  93. }
  94. }
  95. </style>