index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. captcha:'',
  64. };
  65. },
  66. computed: mapGetters(['isLogin']),
  67. watch:{
  68. isLogin:{
  69. handler:function(newV,oldV){
  70. if(newV){
  71. this.getUserInfo();
  72. this.getVerifyCode();
  73. }
  74. },
  75. deep:true
  76. }
  77. },
  78. onLoad() {
  79. if (this.isLogin) {
  80. this.getUserInfo();
  81. this.getVerifyCode();
  82. } else {
  83. toLogin();
  84. }
  85. },
  86. onShow() {
  87. uni.removeStorageSync('form_type_cart');
  88. },
  89. methods: {
  90. /**
  91. * 授权回调
  92. */
  93. onLoadFun: function(e) {
  94. this.getUserInfo();
  95. this.getVerifyCode();
  96. this.isShowAuth = false;
  97. },
  98. // 授权关闭
  99. authColse: function(e) {
  100. this.isShowAuth = e
  101. },
  102. getVerifyCode(){
  103. verifyCode().then(res=>{
  104. this.$set(this, 'key', res.data.key)
  105. });
  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. success(data) {
  120. console.log(data,'data');
  121. this.$refs.verify.hide()
  122. getCodeApi()
  123. .then(res => {
  124. this.keyCode = res.data.key;
  125. this.getCode(data);
  126. })
  127. .catch(res => {
  128. this.$util.Tips({
  129. title: res
  130. });
  131. });
  132. },
  133. /**
  134. * 发送验证码
  135. *
  136. */
  137. code(data) {
  138. let that = this;
  139. if (!that.userInfo.phone) return that.$util.Tips({
  140. title: '手机号码不存在,无法发送验证码!'
  141. });
  142. this.$refs.verify.show()
  143. },
  144. async getCode(data){
  145. console.log('data-------',data);
  146. let that = this;
  147. await registerVerify({
  148. phone: that.userInfo.phone,
  149. type: 'reset',
  150. key: that.key,
  151. captchaType: 'blockPuzzle',
  152. captchaVerification: data.captchaVerification,
  153. })
  154. .then(res => {
  155. that.$util.Tips({
  156. title: res.msg
  157. });
  158. that.sendCode();
  159. })
  160. .catch(res => {
  161. that.$util.Tips({
  162. title: res
  163. });
  164. });
  165. },
  166. /**
  167. * H5登录 修改密码
  168. *
  169. */
  170. editPwd: function(e) {
  171. let that = this,
  172. password = e.detail.value.password,
  173. qr_password = e.detail.value.qr_password,
  174. captcha = e.detail.value.captcha;
  175. if (!password) return that.$util.Tips({
  176. title: '请输入新密码'
  177. });
  178. if (qr_password != password) return that.$util.Tips({
  179. title: '两次输入的密码不一致!'
  180. });
  181. if (!captcha) return that.$util.Tips({
  182. title: '请输入验证码'
  183. });
  184. phoneRegisterReset({
  185. account: that.userInfo.phone,
  186. captcha: captcha,
  187. password: password
  188. }).then(res => {
  189. uni.reLaunch({
  190. url: '/pages/users/login/index'
  191. })
  192. // return that.$util.Tips({
  193. // title: res.msg
  194. // }, {
  195. // tab: 4,
  196. // url: '/pages/users/login/index'
  197. // });
  198. }).catch(err => {
  199. return that.$util.Tips({
  200. title: err
  201. });
  202. });
  203. }
  204. }
  205. }
  206. </script>
  207. <style lang="scss">
  208. page {
  209. background-color: #fff !important;
  210. }
  211. .ChangePassword .phone {
  212. font-size: 32rpx;
  213. font-weight: bold;
  214. text-align: center;
  215. margin-top: 55rpx;
  216. }
  217. .ChangePassword .list {
  218. width: 580rpx;
  219. margin: 53rpx auto 0 auto;
  220. }
  221. .ChangePassword .list .item {
  222. width: 100%;
  223. height: 110rpx;
  224. border-bottom: 2rpx solid #f0f0f0;
  225. }
  226. .ChangePassword .list .item input {
  227. width: 100%;
  228. height: 100%;
  229. font-size: 32rpx;
  230. }
  231. .ChangePassword .list .item .placeholder {
  232. color: #b9b9bc;
  233. }
  234. .ChangePassword .list .item input.codeIput {
  235. width: 340rpx;
  236. }
  237. .ChangePassword .list .item .code {
  238. font-size: 32rpx;
  239. background-color: #fff;
  240. }
  241. .ChangePassword .list .item .code.on {
  242. color: #b9b9bc !important;
  243. }
  244. .ChangePassword .confirmBnt {
  245. font-size: 32rpx;
  246. width: 580rpx;
  247. height: 90rpx;
  248. border-radius: 45rpx;
  249. color: #fff;
  250. margin: 92rpx auto 0 auto;
  251. text-align: center;
  252. line-height: 90rpx;
  253. }
  254. </style>