index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view :style="viewColor">
  3. <form report-submit='true'>
  4. <view>
  5. <view class="ChangePassword">
  6. <view class="list">
  7. <view class="item">
  8. <text class="phone">{{userInfo.phone}}</text>
  9. </view>
  10. <view class="item acea-row row-between-wrapper codeVal">
  11. <input type='number' placeholder='验证码' placeholder-class='placeholder' class="codeIput" v-model="captcha"></input>
  12. <button class="code" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="handleVerify">
  13. {{ text }}
  14. </button>
  15. </view>
  16. <view class="border"></view>
  17. <view class="item">
  18. <input type='password' placeholder='新密码' placeholder-class='placeholder' v-model="password" autocomplete="off"></input>
  19. </view>
  20. <view class="item">
  21. <input type='password' placeholder='确认新密码' placeholder-class='placeholder' v-model="repassword" autocomplete="off"></input>
  22. </view>
  23. </view>
  24. </view>
  25. <button form-type="submit" @click="confirmSubmit" class="confirmBnt">确认</button>
  26. </view>
  27. </form>
  28. <Verify @success="success" :captchaType="'blockPuzzle'" :imgSize="{ width: '330px', height: '155px' }" ref="verify"></Verify>
  29. </view>
  30. </template>
  31. <script>
  32. // +----------------------------------------------------------------------
  33. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  34. // +----------------------------------------------------------------------
  35. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  36. // +----------------------------------------------------------------------
  37. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  38. // +----------------------------------------------------------------------
  39. // | Author: CRMEB Team <admin@crmeb.com>
  40. // +----------------------------------------------------------------------
  41. import sendVerifyCode from "@/mixins/SendVerifyCode";
  42. import { modifyPassword,verifyCode } from '@/api/api.js';
  43. import { getUserInfo } from '@/api/user.js';
  44. import { registerVerify } from '@/api/user.js'
  45. import { mapGetters } from "vuex";
  46. import { toLogin } from '@/libs/login.js';
  47. import Verify from '@/components/verify/verify.vue';
  48. export default {
  49. mixins: [sendVerifyCode],
  50. components: {
  51. Verify
  52. },
  53. data() {
  54. return {
  55. userInfo: {},
  56. phone:'',
  57. repassword: '',
  58. password: '',
  59. captcha:'',
  60. key: '',
  61. codeVal: '',
  62. disabled: false,
  63. };
  64. },
  65. computed: mapGetters(['isLogin', 'viewColor']),
  66. onLoad() {
  67. let that = this
  68. if (this.isLogin) {
  69. this.getUserInfo()
  70. } else {
  71. toLogin()
  72. }
  73. // #ifdef MP
  74. wx.login({
  75. success (res) {
  76. if (res.code) {
  77. that.codeVal = res.code
  78. } else {
  79. console.log('登录失败!' + res.errMsg)
  80. }
  81. }
  82. })
  83. // #endif
  84. },
  85. methods: {
  86. /**
  87. * 获取个人用户信息
  88. */
  89. getUserInfo: function() {
  90. let that = this;
  91. getUserInfo().then(res => {
  92. that.userInfo = res.data
  93. });
  94. },
  95. confirmSubmit: function() {
  96. let that = this;
  97. if (!that.password) return that.$util.Tips({
  98. title: '请填写密码!'
  99. });
  100. if (!that.repassword) return that.$util.Tips({
  101. title: '请确认新密码!'
  102. });
  103. if (that.password !== that.repassword) return that.$util.Tips({
  104. title: '两次密码不一致,请重新填写!'
  105. });
  106. if (!that.captcha) return that.$util.Tips({
  107. title: '请填写验证码'
  108. });
  109. modifyPassword({
  110. password: that.password,
  111. repassword: that.repassword,
  112. sms_code: that.captcha
  113. }).then(res => {
  114. return that.$util.Tips({
  115. title: '修改成功!',
  116. icon: 'success'
  117. }, {
  118. tab: 5,
  119. url: '/pages/users/user_info/index'
  120. });
  121. }).catch(err => {
  122. return that.$util.Tips({
  123. title: err
  124. });
  125. })
  126. },
  127. /**
  128. * 发送验证码
  129. *
  130. */
  131. async code(data) {
  132. let that = this;
  133. // if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.userInfo.phone))) return that.$util.Tips({
  134. // title: '请输入正确的手机号码!'
  135. // });
  136. this.disabled = true
  137. await registerVerify({
  138. phone:that.userInfo.phone,
  139. code:that.captcha,
  140. type: 'change_pwd',
  141. captchaType: 'blockPuzzle',
  142. captchaVerification: data.captchaVerification
  143. }).then(res => {
  144. this.disabled = false
  145. that.$util.Tips({
  146. title: res.message
  147. });
  148. that.sendCode();
  149. }).catch(err => {
  150. this.disabled = false
  151. return that.$util.Tips({
  152. title: err
  153. });
  154. });
  155. },
  156. success(data) {
  157. this.$refs.verify.hide();
  158. this.code(data);
  159. },
  160. handleVerify() {
  161. this.$refs.verify.show();
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .ChangePassword{
  168. background: #fff;
  169. padding-top: 53rpx;
  170. }
  171. .ChangePassword .phone {
  172. font-size: 32rpx;
  173. }
  174. .ChangePassword .list .item {
  175. width: 580rpx;
  176. margin: 0 auto;
  177. height: 110rpx;
  178. border-bottom: 2rpx solid #f0f0f0;
  179. display: flex;
  180. align-items: center;
  181. }
  182. .ChangePassword .list .item input {
  183. width: 100%;
  184. font-size: 32rpx;
  185. }
  186. .ChangePassword .list .item .placeholder {
  187. color: #b9b9bc;
  188. }
  189. .ChangePassword .list .item input.codeIput {
  190. width: 340rpx;
  191. }
  192. .ChangePassword .list .item .code {
  193. font-size: 32rpx;
  194. position: relative;
  195. padding-left: 26rpx;
  196. color: var(--view-theme);
  197. &::before{
  198. content: "";
  199. width: 1rpx;
  200. height: 30rpx;
  201. position: absolute;
  202. top: 10rpx;
  203. left: 0;
  204. background: #DDDDDD;
  205. display: inline-block;
  206. }
  207. }
  208. .ChangePassword .list .item .code.on {
  209. color: #b9b9bc !important;
  210. }
  211. .ChangePassword .list .border{
  212. width: 100%;
  213. height: 21rpx;
  214. background: #F5F5F5;
  215. }
  216. .confirmBnt {
  217. font-size: 32rpx;
  218. width: 580rpx;
  219. height: 90rpx;
  220. border-radius: 45rpx;
  221. color: #fff;
  222. margin: 70rpx auto 0 auto;
  223. text-align: center;
  224. line-height: 90rpx;
  225. background-color: var(--view-theme);
  226. }
  227. </style>