index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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">
  11. <input type='number' placeholder='新手机号' placeholder-class='placeholder' v-model="phone"></input>
  12. </view>
  13. <view class="item acea-row row-between-wrapper">
  14. <input type='number' placeholder='验证码' placeholder-class='placeholder' class="codeIput" v-model="captcha"></input>
  15. <button class="code" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="handleVerify">
  16. {{ text }}
  17. </button>
  18. </view>
  19. <view v-if="isShowCode" class="item acea-row row-between-wrapper" >
  20. <input type="text" placeholder-class='placeholder' placeholder="填写验证码" class="codeIput" v-model="codeVal" />
  21. <view class="code" @click=""><image class="code-img" :src="codeUrl" /></view>
  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 { modifyPhone, verifyCode } from '@/api/api.js';
  43. import { getUserInfo, getCaptcha } 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. captcha:'',
  58. key: '',
  59. codeVal: '',
  60. codeUrl: "",
  61. disabled: false,
  62. isShowCode: 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.phone) return that.$util.Tips({
  98. title: '请填写手机号码!'
  99. });
  100. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  101. title: '请输入正确的手机号码!'
  102. });
  103. if (!that.captcha) return that.$util.Tips({
  104. title: '请填写验证码'
  105. });
  106. modifyPhone({
  107. phone: that.phone,
  108. sms_code: that.captcha
  109. }).then(res => {
  110. return that.$util.Tips({
  111. title: '修改成功!',
  112. icon: 'success'
  113. }, {
  114. tab: 5,
  115. url: '/pages/users/user_info/index'
  116. });
  117. }).catch(err => {
  118. return that.$util.Tips({
  119. title: err
  120. });
  121. })
  122. },
  123. /**
  124. * 发送验证码
  125. *
  126. */
  127. async code(data) {
  128. let that = this;
  129. if (!that.phone) return that.$util.Tips({
  130. title: '请填写手机号码!'
  131. });
  132. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  133. title: '请输入正确的手机号码!'
  134. });
  135. that.disabled = true
  136. await registerVerify({
  137. phone:that.phone,
  138. code:that.captcha,
  139. type: 'change_phone',
  140. captchaType: 'blockPuzzle',
  141. captchaVerification: data.captchaVerification
  142. }).then(res => {
  143. that.disabled = false
  144. that.$util.Tips({
  145. title: res.message
  146. });
  147. that.sendCode();
  148. }).catch(err => {
  149. that.disabled = false
  150. // that.getcaptcha();
  151. return that.$util.Tips({
  152. title: err
  153. });
  154. });
  155. },
  156. getcaptcha() {
  157. let that = this
  158. getCaptcha().then(data => {
  159. that.codeUrl = data.data.captcha;
  160. })
  161. that.isShowCode = true;
  162. },
  163. success(data) {
  164. this.$refs.verify.hide();
  165. this.code(data);
  166. },
  167. handleVerify() {
  168. this.$refs.verify.show();
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .ChangePassword{
  175. background: #ffffff;
  176. padding-top: 53rpx;
  177. }
  178. .ChangePassword .phone {
  179. font-size: 32rpx;
  180. }
  181. .ChangePassword .list {
  182. width: 580rpx;
  183. margin: 0 auto;
  184. }
  185. .ChangePassword .list .item {
  186. width: 100%;
  187. height: 110rpx;
  188. display: flex;
  189. align-items: center;
  190. border-bottom: 2rpx solid #f0f0f0;
  191. }
  192. .ChangePassword .list .item input {
  193. width: 100%;
  194. height: 100%;
  195. font-size: 32rpx;
  196. }
  197. .ChangePassword .list .item .placeholder {
  198. color: #b9b9bc;
  199. }
  200. .ChangePassword .list .item input.codeIput {
  201. width: 340rpx;
  202. }
  203. .ChangePassword .list .item .code {
  204. font-size: 32rpx;
  205. position: relative;
  206. padding-left: 26rpx;
  207. color: var(--view-theme);
  208. &::before{
  209. content: "";
  210. width: 1rpx;
  211. height: 30rpx;
  212. position: absolute;
  213. top: 10rpx;
  214. left: 0;
  215. background: #DDDDDD;
  216. display: inline-block;
  217. }
  218. }
  219. .ChangePassword .list .item .code[disabled]{
  220. background: transparent;
  221. }
  222. .ChangePassword .list .item .code.on {
  223. color: #b9b9bc !important;
  224. }
  225. .ChangePassword .list .item .code-img{
  226. width: 100rpx;
  227. height: 50rpx;
  228. }
  229. .confirmBnt {
  230. font-size: 32rpx;
  231. width: 580rpx;
  232. height: 90rpx;
  233. border-radius: 45rpx;
  234. color: #fff;
  235. margin: 70rpx auto 0 auto;
  236. text-align: center;
  237. line-height: 90rpx;
  238. background-color: var(--view-theme);
  239. }
  240. </style>