index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view>
  3. <view class="ChangePassword">
  4. <form @submit="editPwd" report-submit='true'>
  5. <view class="phone">当前手机号:{{phone}}</view>
  6. <view class="list">
  7. <view class="item">
  8. <input type='password' placeholder='设置新密码' placeholder-class='placeholder' name="password" :value="password"></input>
  9. </view>
  10. <view class="item">
  11. <input type='password' placeholder='确认新密码' placeholder-class='placeholder' name="qr_password" :value="qr_password"></input>
  12. </view>
  13. <view class="item acea-row row-between-wrapper">
  14. <input type='number' placeholder='填写验证码' placeholder-class='placeholder' class="codeIput" name="captcha" :value="captcha"></input>
  15. <button class="code font-color" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="code">
  16. {{ text }}
  17. </button>
  18. </view>
  19. </view>
  20. <button form-type="submit" class="confirmBnt bg-color">确认修改</button>
  21. </form>
  22. </view>
  23. <!-- #ifdef MP -->
  24. <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
  25. <!-- #endif -->
  26. </view>
  27. </template>
  28. <script>
  29. import sendVerifyCode from "@/mixins/SendVerifyCode";
  30. import {
  31. phoneRegisterReset,
  32. registerVerify
  33. } from '@/api/api.js';
  34. import {
  35. getUserInfo
  36. } from '@/api/user.js';
  37. import {
  38. toLogin
  39. } from '@/libs/login.js';
  40. import {
  41. mapGetters
  42. } from "vuex";
  43. // #ifdef MP
  44. import authorize from '@/components/Authorize';
  45. // #endif
  46. export default {
  47. mixins: [sendVerifyCode],
  48. components: {
  49. // #ifdef MP
  50. authorize
  51. // #endif
  52. },
  53. data() {
  54. return {
  55. userInfo: {},
  56. phone: '',
  57. password: '',
  58. captcha: '',
  59. qr_password: '',
  60. isAuto: false, //没有授权的不会自动授权
  61. isShowAuth: false //是否隐藏授权
  62. };
  63. },
  64. computed: mapGetters(['isLogin']),
  65. onLoad() {
  66. if (this.isLogin) {
  67. this.getUserInfo();
  68. } else {
  69. // #ifdef H5 || APP-PLUS
  70. toLogin();
  71. // #endif
  72. // #ifdef MP
  73. this.isAuto = true;
  74. this.$set(this, 'isShowAuth', true)
  75. // #endif
  76. }
  77. },
  78. methods: {
  79. /**
  80. * 授权回调
  81. */
  82. onLoadFun: function(e) {
  83. this.isShowAuth = false;
  84. this.getUserInfo();
  85. },
  86. // 授权关闭
  87. authColse: function(e) {
  88. this.isShowAuth = e
  89. },
  90. /**
  91. * 获取个人用户信息
  92. */
  93. getUserInfo: function() {
  94. let that = this;
  95. getUserInfo().then(res => {
  96. let tel = res.data.phone;
  97. let phone = tel.substr(0, 3) + "****" + tel.substr(7);
  98. that.$set(that, 'userInfo', res.data);
  99. that.phone = phone;
  100. });
  101. },
  102. /**
  103. * 发送验证码
  104. *
  105. */
  106. async code() {
  107. let that = this;
  108. if (!that.userInfo.phone) return that.$util.Tips({
  109. title: '手机号码不存在,无法发送验证码!'
  110. });
  111. await registerVerify(that.userInfo.phone).then(res => {
  112. that.$util.Tips({
  113. title: res.msg
  114. });
  115. that.sendCode();
  116. }).catch(err => {
  117. return that.$util.Tips({
  118. title: err
  119. });
  120. });
  121. },
  122. /**
  123. * H5登录 修改密码
  124. *
  125. */
  126. editPwd: function(e) {
  127. let that = this,
  128. password = e.detail.value.password,
  129. qr_password = e.detail.value.qr_password,
  130. captcha = e.detail.value.captcha;
  131. if (!password) return that.$util.Tips({
  132. title: '请输入新密码'
  133. });
  134. if (qr_password != password) return that.$util.Tips({
  135. title: '两次输入的密码不一致!'
  136. });
  137. if (!captcha) return that.$util.Tips({
  138. title: '请输入验证码'
  139. });
  140. phoneRegisterReset({
  141. account: that.userInfo.phone,
  142. captcha: captcha,
  143. password: password
  144. }).then(res => {
  145. return that.$util.Tips({
  146. title: res.msg
  147. }, {
  148. tab: 3,
  149. url: 1
  150. });
  151. }).catch(err => {
  152. return that.$util.Tips({
  153. title: err
  154. });
  155. });
  156. }
  157. }
  158. }
  159. </script>
  160. <style lang="scss">
  161. page {
  162. background-color: #fff !important;
  163. }
  164. .ChangePassword .phone {
  165. font-size: 32rpx;
  166. font-weight: bold;
  167. text-align: center;
  168. margin-top: 55rpx;
  169. }
  170. .ChangePassword .list {
  171. width: 580rpx;
  172. margin: 53rpx auto 0 auto;
  173. }
  174. .ChangePassword .list .item {
  175. width: 100%;
  176. height: 110rpx;
  177. border-bottom: 2rpx solid #f0f0f0;
  178. }
  179. .ChangePassword .list .item input {
  180. width: 100%;
  181. height: 100%;
  182. font-size: 32rpx;
  183. }
  184. .ChangePassword .list .item .placeholder {
  185. color: #b9b9bc;
  186. }
  187. .ChangePassword .list .item input.codeIput {
  188. width: 340rpx;
  189. }
  190. .ChangePassword .list .item .code {
  191. font-size: 32rpx;
  192. background-color: #fff;
  193. }
  194. .ChangePassword .list .item .code.on {
  195. color: #b9b9bc !important;
  196. }
  197. .ChangePassword .confirmBnt {
  198. font-size: 32rpx;
  199. width: 580rpx;
  200. height: 90rpx;
  201. border-radius: 45rpx;
  202. color: #fff;
  203. margin: 92rpx auto 0 auto;
  204. text-align: center;
  205. line-height: 90rpx;
  206. }
  207. </style>