change-password.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 ref="changePasswordRef" v-model="state.model" :rules="state.rules" validateTrigger="bind"
  11. labelWidth="140" labelAlign="center">
  12. <uni-forms-item name="code" label="验证码">
  13. <uni-easyinput placeholder="请输入验证码" v-model="state.model.code" type="number" maxlength="4"
  14. :inputBorder="false">
  15. <template v-slot:right>
  16. <button class="ss-reset-button code-btn code-btn-start" :disabled="state.isMobileEnd"
  17. :class="{ 'code-btn-end': state.isMobileEnd }" @tap="getSmsCode('changePassword')">
  18. {{ getSmsTimer('changePassword') }}
  19. </button>
  20. </template>
  21. </uni-easyinput>
  22. </uni-forms-item>
  23. <uni-forms-item name="reNewPassword" label="密码">
  24. <uni-easyinput type="password" placeholder="请输入密码" v-model="state.model.password" :inputBorder="false">
  25. <template v-slot:right>
  26. <button class="ss-reset-button login-btn-start" @tap="changePasswordSubmit">
  27. 确认
  28. </button>
  29. </template>
  30. </uni-easyinput>
  31. </uni-forms-item>
  32. </uni-forms>
  33. <button class="ss-reset-button type-btn" @tap="closeAuthModal">
  34. 取消修改
  35. </button>
  36. </view>
  37. </template>
  38. <script setup>
  39. import sheep from '@/sheep';
  40. import {
  41. ref,
  42. reactive,
  43. unref
  44. } from 'vue';
  45. import {
  46. code,
  47. password
  48. } from '@/sheep/validate/form';
  49. import {
  50. closeAuthModal,
  51. getSmsCode,
  52. getSmsTimer
  53. } from '@/sheep/hooks/useModal';
  54. import UserApi from '@/sheep/api/member/user';
  55. const changePasswordRef = ref(null);
  56. // 数据
  57. const state = reactive({
  58. isMobileEnd: false, // 手机号输入完毕
  59. model: {
  60. mobile: '', // 手机号
  61. code: '', // 验证码
  62. password: '', // 密码
  63. },
  64. rules: {
  65. code,
  66. password,
  67. },
  68. });
  69. // 更改密码
  70. async function changePasswordSubmit() {
  71. if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+\S{5,12}$/.test(state.model.password)) {
  72. console.log(123)
  73. uni.showToast({
  74. icon: 'error',
  75. title: "需包含字母和数字,长度在6-12之间",
  76. });
  77. }
  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 {
  89. code
  90. } = await UserApi.updateUserPassword(state.model);
  91. if (code !== 0) {
  92. return;
  93. }
  94. uni.showToast({
  95. icon: 'success',
  96. title: "修改成功",
  97. });
  98. // 成功后,只需要1秒后推出登录关闭弹窗
  99. setTimeout(function(){
  100. closeAuthModal();
  101. },1000)
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. @import '../index.scss';
  106. </style>