index.vue 5.8 KB

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