index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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="code">
  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. <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
  29. </view>
  30. </template>
  31. <script>
  32. // +----------------------------------------------------------------------
  33. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  34. // +----------------------------------------------------------------------
  35. // | Copyright (c) 2016~2021 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, appletsDecrypt } from '@/api/api.js';
  43. import { getUserInfo, getCaptcha } from '@/api/user.js';
  44. import { registerVerify } from '@/api/user.js'
  45. import {
  46. mapGetters
  47. } from "vuex";
  48. import authorize from '@/components/Authorize';
  49. export default {
  50. mixins: [sendVerifyCode],
  51. components: {
  52. authorize
  53. },
  54. data() {
  55. return {
  56. userInfo: {},
  57. phone:'',
  58. captcha:'',
  59. isAuto: false, //没有授权的不会自动授权
  60. isShowAuth: false, //是否隐藏授权
  61. key: '',
  62. codeVal: '',
  63. codeUrl: "",
  64. disabled: false,
  65. isShowCode: false
  66. };
  67. },
  68. computed: mapGetters(['isLogin', 'viewColor']),
  69. onLoad() {
  70. let that = this
  71. if (this.isLogin) {
  72. this.getUserInfo()
  73. } else {
  74. this.isAuto = true;
  75. this.isShowAuth = true
  76. }
  77. // #ifdef MP
  78. wx.login({
  79. success (res) {
  80. if (res.code) {
  81. that.codeVal = res.code
  82. } else {
  83. console.log('登录失败!' + res.errMsg)
  84. }
  85. }
  86. })
  87. // #endif
  88. },
  89. methods: {
  90. onLoadFun:function(){
  91. this.isShowAuth = false;
  92. },
  93. // 授权关闭
  94. authColse: function(e) {
  95. this.isShowAuth = e
  96. },
  97. /**
  98. * 获取个人用户信息
  99. */
  100. getUserInfo: function() {
  101. let that = this;
  102. getUserInfo().then(res => {
  103. that.userInfo = res.data
  104. });
  105. },
  106. confirmSubmit: function() {
  107. let that = this;
  108. if (!that.phone) return that.$util.Tips({
  109. title: '请填写手机号码!'
  110. });
  111. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  112. title: '请输入正确的手机号码!'
  113. });
  114. if (!that.captcha) return that.$util.Tips({
  115. title: '请填写验证码'
  116. });
  117. modifyPhone({
  118. phone: that.phone,
  119. sms_code: that.captcha
  120. }).then(res => {
  121. return that.$util.Tips({
  122. title: '修改成功!',
  123. icon: 'success'
  124. }, {
  125. tab: 5,
  126. url: '/pages/users/user_info/index'
  127. });
  128. }).catch(err => {
  129. return that.$util.Tips({
  130. title: err
  131. });
  132. })
  133. },
  134. /**
  135. * 发送验证码
  136. *
  137. */
  138. async code() {
  139. let that = this;
  140. if (!that.phone) return that.$util.Tips({
  141. title: '请填写手机号码!'
  142. });
  143. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  144. title: '请输入正确的手机号码!'
  145. });
  146. that.disabled = true
  147. await registerVerify({
  148. phone:that.phone,
  149. code:that.captcha,
  150. type: 'change_phone'
  151. }).then(res => {
  152. that.disabled = false
  153. that.$util.Tips({
  154. title: res.msg
  155. });
  156. that.sendCode();
  157. }).catch(err => {
  158. that.disabled = false
  159. that.getcaptcha();
  160. return that.$util.Tips({
  161. title: err
  162. });
  163. });
  164. },
  165. getcaptcha() {
  166. let that = this
  167. getCaptcha().then(data => {
  168. that.codeUrl = data.data.captcha;
  169. })
  170. that.isShowCode = true;
  171. },
  172. }
  173. }
  174. </script>
  175. <style lang="scss">
  176. .ChangePassword{
  177. background: #ffffff;
  178. padding-top: 53rpx;
  179. }
  180. .ChangePassword .phone {
  181. font-size: 32rpx;
  182. }
  183. .ChangePassword .list {
  184. width: 580rpx;
  185. margin: 0 auto;
  186. }
  187. .ChangePassword .list .item {
  188. width: 100%;
  189. height: 110rpx;
  190. display: flex;
  191. align-items: center;
  192. border-bottom: 2rpx solid #f0f0f0;
  193. }
  194. .ChangePassword .list .item input {
  195. width: 100%;
  196. height: 100%;
  197. font-size: 32rpx;
  198. }
  199. .ChangePassword .list .item .placeholder {
  200. color: #b9b9bc;
  201. }
  202. .ChangePassword .list .item input.codeIput {
  203. width: 340rpx;
  204. }
  205. .ChangePassword .list .item .code {
  206. font-size: 32rpx;
  207. position: relative;
  208. padding-left: 26rpx;
  209. color: var(--view-theme);
  210. &::before{
  211. content: "";
  212. width: 1rpx;
  213. height: 30rpx;
  214. position: absolute;
  215. top: 10rpx;
  216. left: 0;
  217. background: #DDDDDD;
  218. display: inline-block;
  219. }
  220. }
  221. .ChangePassword .list .item .code.on {
  222. color: #b9b9bc !important;
  223. }
  224. .ChangePassword .list .item .code-img{
  225. width: 100rpx;
  226. height: 50rpx;
  227. }
  228. .confirmBnt {
  229. font-size: 32rpx;
  230. width: 580rpx;
  231. height: 90rpx;
  232. border-radius: 45rpx;
  233. color: #fff;
  234. margin: 70rpx auto 0 auto;
  235. text-align: center;
  236. line-height: 90rpx;
  237. background-color: var(--view-theme);
  238. }
  239. .getPhoneBtn{
  240. font-size: 32rpx;
  241. width: 580rpx;
  242. height: 90rpx;
  243. border-radius: 45rpx;
  244. border: 1rpx solid var(--view-theme);
  245. color: var(--view-theme);
  246. margin: 40rpx auto 0 auto;
  247. text-align: center;
  248. line-height: 90rpx;
  249. .iconfont{
  250. font-size: 32rpx;
  251. margin-right: 12rpx;
  252. }
  253. }
  254. </style>