index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view>
  3. <view class="ChangePassword">
  4. <form @submit="editPwd" report-submit='true'>
  5. <view class="phone">当前手机号:{{ userInfo.mobile }}</view>
  6. <view class="list">
  7. <view class="item">
  8. <input type='password' placeholder='以字母开头,长度在6~18之间,只能包含字符、数字和下划线'
  9. placeholder-class='placeholder' name="password" :value="password" />
  10. </view>
  11. <view class="item">
  12. <input type='password' placeholder='确认新密码' placeholder-class='placeholder'
  13. name="qr_password" :value="qr_password" />
  14. </view>
  15. <view class="item acea-row row-between-wrapper">
  16. <input type='number' placeholder='填写验证码' placeholder-class='placeholder' class="codeIput" name="captcha" :value="captcha" />
  17. <button class="code font-color" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="code">
  18. {{ text }}
  19. </button>
  20. </view>
  21. </view>
  22. <button form-type="submit" class="confirmBnt bg-color">确认修改</button>
  23. </form>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import { mapGetters } from "vuex";
  29. import sendVerifyCode from "@/mixins/SendVerifyCode";
  30. import * as AuthUtil from '@/api/member/auth.js';
  31. import * as UserApi from '@/api/member/user.js';
  32. export default {
  33. data() {
  34. return {
  35. password: '',
  36. qr_password: '',
  37. captcha: '',
  38. };
  39. },
  40. mixins: [sendVerifyCode],
  41. computed: mapGetters(['isLogin', 'userInfo']),
  42. methods: {
  43. /**
  44. * 发送验证码
  45. */
  46. async code() {
  47. if (!this.userInfo.mobile) {
  48. return this.$util.Tips({
  49. title: '手机号码不存在,无法发送验证码!'
  50. });
  51. }
  52. await AuthUtil.sendSmsCode(this.userInfo.mobile, 3).then(res => {
  53. this.$util.Tips({
  54. title: '验证码已发送'
  55. });
  56. this.sendCode();
  57. }).catch(err => {
  58. return this.$util.Tips({
  59. title: err
  60. });
  61. });
  62. },
  63. /**
  64. * H5登录 修改密码
  65. */
  66. editPwd: function(e) {
  67. const password = e.detail.value.password;
  68. const qr_password = e.detail.value.qr_password;
  69. const captcha = e.detail.value.captcha;
  70. if (!password) {
  71. return this.$util.Tips({
  72. title: '请输入新密码'
  73. });
  74. }
  75. if (!/^[a-zA-Z]\w{5,17}$/i.test(password)) {
  76. return this.$util.Tips({
  77. title: '以字母开头,长度在6~18之间,只能包含字符、数字和下划线'
  78. });
  79. }
  80. if (qr_password !== password) {
  81. return this.$util.Tips({
  82. title: '两次输入的密码不一致!'
  83. });
  84. }
  85. if (!captcha) {
  86. return this.$util.Tips({
  87. title: '请输入验证码'
  88. });
  89. }
  90. UserApi.updateUserPassword({
  91. code: captcha,
  92. password: password
  93. }).then(res => {
  94. return this.$util.Tips({
  95. title: '修改成功'
  96. }, {
  97. tab: 3,
  98. url: 1
  99. });
  100. }).catch(err => {
  101. return this.$util.Tips({
  102. title: err
  103. });
  104. });
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss">
  110. page {
  111. background-color: #fff !important;
  112. }
  113. .ChangePassword .phone {
  114. font-size: 32rpx;
  115. font-weight: bold;
  116. text-align: center;
  117. margin-top: 55rpx;
  118. }
  119. .ChangePassword .list {
  120. width: 580rpx;
  121. margin: 53rpx auto 0 auto;
  122. }
  123. .ChangePassword .list .item {
  124. width: 100%;
  125. height: 110rpx;
  126. border-bottom: 2rpx solid #f0f0f0;
  127. }
  128. .ChangePassword .list .item input {
  129. width: 100%;
  130. height: 100%;
  131. font-size: 32rpx;
  132. }
  133. .ChangePassword .list .item .placeholder {
  134. color: #b9b9bc;
  135. }
  136. .ChangePassword .list .item input.codeIput {
  137. width: 340rpx;
  138. }
  139. .ChangePassword .list .item .code {
  140. font-size: 32rpx;
  141. background-color: #fff;
  142. }
  143. .ChangePassword .list .item .code.on {
  144. color: #b9b9bc !important;
  145. }
  146. .ChangePassword .confirmBnt {
  147. font-size: 32rpx;
  148. width: 580rpx;
  149. height: 90rpx;
  150. border-radius: 45rpx;
  151. color: #fff;
  152. margin: 92rpx auto 0 auto;
  153. text-align: center;
  154. line-height: 90rpx;
  155. }
  156. </style>