index.vue 5.4 KB

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