change-password.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!-- 修改密码 - changePassword -->
  2. <template>
  3. <s-layout title="修改密码" :bgStyle="{color:'#fff'}">
  4. <view class="content-block">
  5. <uni-forms ref="changePasswordRef" v-model="state.model" :rules="state.rules" validateTrigger="bind" labelWidth="140"
  6. labelAlign="left" labelPosition="top">
  7. <uni-forms-item name="mobile" label="手机号">
  8. <view class="input-line">
  9. <uni-easyinput placeholder="请输入手机号" v-model="state.model.mobile" type="number" :inputBorder="false">
  10. </uni-easyinput>
  11. </view>
  12. </uni-forms-item>
  13. <uni-forms-item name="newPassword" label="新密码">
  14. <view class="input-line">
  15. <uni-easyinput type="password" placeholder="请输入密码" v-model="state.model.newPassword" :inputBorder="false">
  16. </uni-easyinput>
  17. </view>
  18. </uni-forms-item>
  19. <uni-forms-item name="confirmPassword" label="确认密码">
  20. <view class="input-line">
  21. <uni-easyinput type="password" placeholder="请输入密码" v-model="state.model.confirmPassword" :inputBorder="false">
  22. </uni-easyinput>
  23. </view>
  24. </uni-forms-item>
  25. <uni-forms-item name="code" label="验证码">
  26. <view class="ss-flex ss-row-between">
  27. <view class="input-line w-370">
  28. <uni-easyinput placeholder="请输入验证码" v-model="state.model.verificationCode" :inputBorder="false" type="number"
  29. maxlength="6">
  30. </uni-easyinput>
  31. </view>
  32. <button class="ss-reset-button code-btn code-btn-start" :disabled="getSmsTimer('changePassword') != '获取验证码'"
  33. :class="{ 'code-btn-end': getSmsTimer('changePassword') != '获取验证码' }"
  34. @tap="getSmsCode('changePassword', state.model.mobile)">
  35. {{ getSmsTimer('changePassword') }}
  36. </button>
  37. </view>
  38. </uni-forms-item>
  39. </uni-forms>
  40. <button class="ss-reset-button toLoginBtn" @tap="changePasswordSubmit">
  41. 确认
  42. </button>
  43. </view>
  44. </s-layout>
  45. </template>
  46. <script setup>
  47. import {
  48. computed,
  49. watch,
  50. ref,
  51. reactive,
  52. unref
  53. } from 'vue';
  54. import sheep from '@/sheep';
  55. import {
  56. code,
  57. mobile,
  58. password
  59. } from '@/sheep/validate/form';
  60. import {
  61. getSmsCode,
  62. getSmsTimer
  63. } from '@/sheep/hooks/useModal';
  64. import {Base64} from 'js-base64'
  65. const changePasswordRef = ref(null);
  66. const isLogin = computed(() => sheep.$store('user').isLogin);
  67. // 数据
  68. const state = reactive({
  69. isMobileEnd: false, // 手机号输入完毕
  70. model: {
  71. mobile: '', //手机号
  72. verificationCode: '', //验证码
  73. newPassword: '', //密码
  74. confirmPassword:'',
  75. },
  76. rules: {
  77. code,
  78. mobile,
  79. newPassword:password,
  80. confirmPassword: {
  81. rules: [
  82. {
  83. required: true,
  84. errorMessage: '请确认密码',
  85. },
  86. {
  87. validateFunction: function (rule, value, data, callback) {
  88. if (value !== state.model.newPassword) {
  89. callback('两次输入的密码不一致');
  90. }
  91. return true;
  92. },
  93. },
  94. ],
  95. },
  96. },
  97. });
  98. // 6.更改密码
  99. const changePasswordSubmit = async () => {
  100. const validate = await unref(changePasswordRef)
  101. .validate()
  102. .catch((error) => {
  103. console.log('error: ', error);
  104. });
  105. if (!validate) return;
  106. state.model.uuid = sheep.$store('user').getUUID('changePassword')
  107. const data = Base64.encode(JSON.stringify(state.model))
  108. console.log(state.model)
  109. sheep.$api.user.resetPassword(data).then((res) => {
  110. if(res.code == 200) {
  111. sheep.$helper.toast('修改成功')
  112. setTimeout(()=>{
  113. uni.navigateBack()
  114. },1500)
  115. }
  116. // if (res.error === 0) {
  117. // sheep.$store('user').getInfo();
  118. // closeAuthModal();
  119. // }
  120. });
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. @import '@/sheep/components/s-auth-modal/index.scss';
  125. .content-block {
  126. padding: 0 30rpx;
  127. }
  128. .input-line {
  129. background-color: #F5F7FB;
  130. border-radius: 16rpx;
  131. padding-left: 30rpx;
  132. height: 88rpx;
  133. box-sizing: border-box;
  134. }
  135. .toLoginBtn {
  136. height: 88rpx;
  137. background: #F39801;
  138. border-radius: 16rpx;
  139. color: #fff;
  140. margin-bottom: 32rpx;
  141. margin-top: 30rpx;
  142. }
  143. .w-370 {
  144. width: 370rpx;
  145. }
  146. </style>