index.vue 5.8 KB

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