change-password.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!-- 修改密码(登录时) -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <view class="head-box ss-m-b-60">
  6. <view class="head-title ss-m-b-20">修改密码</view>
  7. <view class="head-subtitle">如密码丢失或未设置,请点击忘记密码重新设置</view>
  8. </view>
  9. <!-- 表单项 -->
  10. <uni-forms
  11. ref="changePasswordRef"
  12. v-model="state.model"
  13. :rules="state.rules"
  14. validateTrigger="bind"
  15. labelWidth="140"
  16. labelAlign="center"
  17. >
  18. <uni-forms-item name="code" label="验证码">
  19. <uni-easyinput
  20. placeholder="请输入验证码"
  21. v-model="state.model.code"
  22. type="number"
  23. maxlength="4"
  24. :inputBorder="false"
  25. >
  26. <template v-slot:right>
  27. <button
  28. class="ss-reset-button code-btn code-btn-start"
  29. :disabled="state.isMobileEnd"
  30. :class="{ 'code-btn-end': state.isMobileEnd }"
  31. @tap="getSmsCode('changePassword')"
  32. >
  33. {{ getSmsTimer('resetPassword') }}
  34. </button>
  35. </template>
  36. </uni-easyinput>
  37. </uni-forms-item>
  38. <uni-forms-item name="reNewPassword" label="密码">
  39. <uni-easyinput
  40. type="password"
  41. placeholder="请输入密码"
  42. v-model="state.model.password"
  43. :inputBorder="false"
  44. >
  45. <template v-slot:right>
  46. <button class="ss-reset-button login-btn-start" @tap="changePasswordSubmit">
  47. 确认
  48. </button>
  49. </template>
  50. </uni-easyinput>
  51. </uni-forms-item>
  52. </uni-forms>
  53. <button class="ss-reset-button type-btn" @tap="closeAuthModal">
  54. 取消修改
  55. </button>
  56. </view>
  57. </template>
  58. <script setup>
  59. import { ref, reactive, unref } from 'vue';
  60. import { code, password } from '@/sheep/validate/form';
  61. import { closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
  62. import UserApi from '@/sheep/api/member/user';
  63. const changePasswordRef = ref(null);
  64. // 数据
  65. const state = reactive({
  66. model: {
  67. mobile: '', // 手机号
  68. code: '', // 验证码
  69. password: '', // 密码
  70. },
  71. rules: {
  72. code,
  73. password,
  74. },
  75. });
  76. // 更改密码
  77. async function changePasswordSubmit() {
  78. // 参数校验
  79. const validate = await unref(changePasswordRef)
  80. .validate()
  81. .catch((error) => {
  82. console.log('error: ', error);
  83. });
  84. if (!validate) {
  85. return;
  86. }
  87. // 发起请求
  88. const { code } = await UserApi.updateUserPassword(state.model);
  89. if (code !== 0) {
  90. return;
  91. }
  92. // 成功后,只需要关闭弹窗
  93. closeAuthModal();
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. @import '../index.scss';
  98. </style>