index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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='以字母开头,长度在6~18之间,只能包含字符、数字和下划线' 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. watch:{
  66. isLogin:{
  67. handler:function(newV,oldV){
  68. if(newV){
  69. this.getUserInfo();
  70. }
  71. },
  72. deep:true
  73. }
  74. },
  75. onLoad() {
  76. if (this.isLogin) {
  77. this.getUserInfo();
  78. } else {
  79. toLogin();
  80. }
  81. },
  82. methods: {
  83. /**
  84. * 授权回调
  85. */
  86. onLoadFun: function(e) {
  87. this.getUserInfo();
  88. },
  89. // 授权关闭
  90. authColse: function(e) {
  91. this.isShowAuth = e
  92. },
  93. /**
  94. * 获取个人用户信息
  95. */
  96. getUserInfo: function() {
  97. let that = this;
  98. getUserInfo().then(res => {
  99. let tel = res.data.phone;
  100. let phone = tel.substr(0, 3) + "****" + tel.substr(7);
  101. that.$set(that, 'userInfo', res.data);
  102. that.phone = phone;
  103. });
  104. },
  105. /**
  106. * 发送验证码
  107. *
  108. */
  109. async code() {
  110. let that = this;
  111. if (!that.userInfo.phone) return that.$util.Tips({
  112. title: '手机号码不存在,无法发送验证码!'
  113. });
  114. await registerVerify(that.userInfo.phone).then(res => {
  115. that.$util.Tips({
  116. title: res.message
  117. });
  118. that.sendCode();
  119. }).catch(err => {
  120. return that.$util.Tips({
  121. title: err
  122. });
  123. });
  124. },
  125. /**
  126. * H5登录 修改密码
  127. *
  128. */
  129. editPwd: function(e) {
  130. let that = this,
  131. password = e.detail.value.password,
  132. qr_password = e.detail.value.qr_password,
  133. captcha = e.detail.value.captcha;
  134. if (!password) return that.$util.Tips({
  135. title: '请输入新密码'
  136. });
  137. if (!/^[a-zA-Z]\w{5,17}$/i.test(password)) return that.$util.Tips({
  138. title: '以字母开头,长度在6~18之间,只能包含字符、数字和下划线'
  139. });
  140. if (qr_password != password) return that.$util.Tips({
  141. title: '两次输入的密码不一致!'
  142. });
  143. if (!captcha) return that.$util.Tips({
  144. title: '请输入验证码'
  145. });
  146. phoneRegisterReset({
  147. account: that.userInfo.phone,
  148. captcha: captcha,
  149. password: password
  150. }).then(res => {
  151. return that.$util.Tips({
  152. title: res.message
  153. }, {
  154. tab: 3,
  155. url: 1
  156. });
  157. }).catch(err => {
  158. return that.$util.Tips({
  159. title: err
  160. });
  161. });
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss">
  167. page {
  168. background-color: #fff !important;
  169. }
  170. .ChangePassword .phone {
  171. font-size: 32rpx;
  172. font-weight: bold;
  173. text-align: center;
  174. margin-top: 55rpx;
  175. }
  176. .ChangePassword .list {
  177. width: 580rpx;
  178. margin: 53rpx auto 0 auto;
  179. }
  180. .ChangePassword .list .item {
  181. width: 100%;
  182. height: 110rpx;
  183. border-bottom: 2rpx solid #f0f0f0;
  184. }
  185. .ChangePassword .list .item input {
  186. width: 100%;
  187. height: 100%;
  188. font-size: 32rpx;
  189. }
  190. .ChangePassword .list .item .placeholder {
  191. color: #b9b9bc;
  192. }
  193. .ChangePassword .list .item input.codeIput {
  194. width: 340rpx;
  195. }
  196. .ChangePassword .list .item .code {
  197. font-size: 32rpx;
  198. background-color: #fff;
  199. }
  200. .ChangePassword .list .item .code.on {
  201. color: #b9b9bc !important;
  202. }
  203. .ChangePassword .confirmBnt {
  204. font-size: 32rpx;
  205. width: 580rpx;
  206. height: 90rpx;
  207. border-radius: 45rpx;
  208. color: #fff;
  209. margin: 92rpx auto 0 auto;
  210. text-align: center;
  211. line-height: 90rpx;
  212. }
  213. </style>