index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view style="padding: 30rpx;">
  3. <uni-forms ref="formRef" :modelValue="formData" :rules="formRules" validateTrigger="bind" label-width="80px" label-align="right" label-position="left">
  4. <uni-forms-item name="email" label="企业邮箱" required>
  5. <uni-easyinput v-model="formData.email" placeholder="请输入企业邮箱"></uni-easyinput>
  6. </uni-forms-item>
  7. <uni-forms-item name="code" label="验证码" required>
  8. <uni-easyinput v-model="formData.code" :inputBorder="false" placeholder="请输入邮箱验证码">
  9. <template v-slot:right>
  10. <button class="login-code" @tap.stop="handleCode">
  11. {{ getSmsTimer('resetPassword') }}
  12. </button>
  13. </template>
  14. </uni-easyinput>
  15. </uni-forms-item>
  16. <uni-forms-item name="password" label="新密码" required>
  17. <uni-easyinput v-model="formData.password" type="password" placeholder="请输入新密码"></uni-easyinput>
  18. </uni-forms-item>
  19. <uni-forms-item name="passwordConfirm" label="二次确认" required>
  20. <uni-easyinput v-model="formData.passwordConfirm" type="password" placeholder="请再次输入新密码"></uni-easyinput>
  21. </uni-forms-item>
  22. </uni-forms>
  23. <button class="send-button" @tap="handleSubmit">提 交</button>
  24. </view>
  25. </template>
  26. <script setup>
  27. import { ref, unref } from 'vue'
  28. import { password, emailRequired } from '@/utils/validate'
  29. import { resetPassword } from '@/api/enterprise'
  30. import { getEmailCode, getSmsTimer } from '@/utils/code'
  31. const formRef = ref(null)
  32. const formData = ref({
  33. email: null,
  34. code: null,
  35. password: null,
  36. passwordConfirm: null
  37. })
  38. const formRules = {
  39. email: emailRequired,
  40. code: {
  41. rules: [
  42. { required: true, errorMessage: '请输入邮箱验证码' },
  43. ]
  44. },
  45. password,
  46. passwordConfirm: {
  47. rules: [
  48. { required: true, errorMessage: '请再次输入密码' },
  49. {
  50. validateFunction: function(rule, value, data, callback) {
  51. if (value !== data.password) callback('两次输入的密码不一致')
  52. return true
  53. }
  54. }
  55. ]
  56. }
  57. }
  58. // 获取邮箱验证码
  59. const handleCode = async () => {
  60. if (!formData.value.email) {
  61. uni.showToast({
  62. title: '请输入您的企业邮箱',
  63. icon: 'none',
  64. duration: 2000
  65. })
  66. return
  67. }
  68. getEmailCode('resetPassword', formData.value.email)
  69. }
  70. // 提交
  71. const handleSubmit = async () => {
  72. const valid = await unref(formRef).validate()
  73. if (!valid) return
  74. uni.showLoading({ title: '提交中' })
  75. try {
  76. await resetPassword(formData.value)
  77. uni.hideLoading()
  78. uni.showToast({
  79. title: '操作成功',
  80. icon: 'success'
  81. })
  82. setTimeout(() => {
  83. uni.navigateBack({ delta: 1 })
  84. }, 1000)
  85. } catch {
  86. uni.hideLoading()
  87. }
  88. }
  89. </script>
  90. <style scoped lang="scss">
  91. .login-code {
  92. width: 73px;
  93. min-width: 73px;
  94. color: #00B760;
  95. text-align: center;
  96. font-size: 12px;
  97. cursor: pointer;
  98. padding: 0;
  99. }
  100. </style>