index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view :style="viewColor">
  3. <form report-submit='true'>
  4. <view class="ChangePassword">
  5. <view class="list">
  6. <view class="item">
  7. <input type='number' placeholder='填写手机号码' placeholder-class='placeholder' v-model="phone"></input>
  8. </view>
  9. <view class="item acea-row row-between-wrapper">
  10. <input type='number' placeholder='填写验证码' placeholder-class='placeholder' class="codeIput" v-model="captcha"></input>
  11. <button class="code" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="handleVerify">
  12. {{ text }}
  13. </button>
  14. </view>
  15. </view>
  16. <button form-type="submit" @click="editPwd" class="confirmBnt">确认绑定</button>
  17. <!-- #ifdef MP -->
  18. <button v-if="wechat_phone_switch == 1" form-type="submit" class="getPhoneBtn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"><text class="iconfont icon-weixin2"></text>使用微信绑定号码</button>
  19. <!-- #endif -->
  20. </view>
  21. </form>
  22. <Verify @success="success" :captchaType="'blockPuzzle'" :imgSize="{ width: '330px', height: '155px' }" ref="verify"></Verify>
  23. </view>
  24. </template>
  25. <script>
  26. // +----------------------------------------------------------------------
  27. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  28. // +----------------------------------------------------------------------
  29. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  30. // +----------------------------------------------------------------------
  31. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  32. // +----------------------------------------------------------------------
  33. // | Author: CRMEB Team <admin@crmeb.com>
  34. // +----------------------------------------------------------------------
  35. import sendVerifyCode from "@/mixins/SendVerifyCode";
  36. import { bindingPhone, verifyCode, appletsDecrypt} from '@/api/api.js';
  37. import { registerVerify } from '@/api/user.js'
  38. import { mapGetters } from "vuex";
  39. import { configMap } from '@/utils/index';
  40. import Verify from '@/components/verify/verify.vue';
  41. import { toLogin } from '@/libs/login.js';
  42. export default {
  43. mixins: [sendVerifyCode],
  44. components: {
  45. Verify
  46. },
  47. data() {
  48. return {
  49. phone:'',
  50. captcha:'',
  51. key: '',
  52. codeVal: ''
  53. };
  54. },
  55. computed: {
  56. ...mapGetters(['isLogin', 'viewColor']),
  57. ...configMap(['wechat_phone_switch'])
  58. },
  59. onLoad() {
  60. let that = this
  61. if (this.isLogin) {
  62. // verifyCode().then(res=>{
  63. // this.$set(this, 'key', res.data.key)
  64. // });
  65. } else {
  66. toLogin()
  67. }
  68. // #ifdef MP
  69. wx.login({
  70. success (res) {
  71. if (res.code) {
  72. that.codeVal = res.code
  73. } else {
  74. console.log('登录失败!' + res.errMsg)
  75. }
  76. }
  77. })
  78. // #endif
  79. },
  80. methods: {
  81. // #ifdef MP
  82. getPhoneNumber(e) {
  83. let that = this;
  84. appletsDecrypt({
  85. iv:e.detail.iv,
  86. encryptedData:e.detail.encryptedData,
  87. code:that.codeVal
  88. }).then(res => {
  89. that.$util.Tips({
  90. title: '绑定成功!',
  91. icon: 'success'
  92. })
  93. setTimeout(()=>{
  94. uni.switchTab({
  95. url: '/pages/user/index',
  96. });
  97. },2000)
  98. })
  99. },
  100. // #endif
  101. editPwd: function() {
  102. let that = this;
  103. if (!that.phone) return that.$util.Tips({
  104. title: '请填写手机号码!'
  105. });
  106. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  107. title: '请输入正确的手机号码!'
  108. });
  109. if (!that.captcha) return that.$util.Tips({
  110. title: '请填写验证码'
  111. });
  112. bindingPhone({
  113. phone: that.phone,
  114. sms_code: that.captcha
  115. }).then(res => {
  116. if (res.data !== undefined && res.data.is_bind) {
  117. uni.showModal({
  118. title: '是否绑定账号',
  119. content: res.message,
  120. confirmText: '绑定',
  121. success(res) {
  122. if (res.confirm) {
  123. bindingPhone({
  124. phone: that.phone,
  125. captcha: that.captcha,
  126. step: 1
  127. }).then(res => {
  128. return that.$util.Tips({
  129. title: res.message,
  130. icon: 'success'
  131. }, {
  132. tab: 5,
  133. url: '/pages/users/user_info/index'
  134. });
  135. }).catch(err => {
  136. return that.$util.Tips({
  137. title: err
  138. });
  139. })
  140. } else if (res.cancel) {
  141. return that.$util.Tips({
  142. title: '您已取消绑定!'
  143. }, {
  144. tab: 5,
  145. url: '/pages/users/user_info/index'
  146. });
  147. }
  148. }
  149. });
  150. } else
  151. return that.$util.Tips({
  152. title: '绑定成功!',
  153. icon: 'success'
  154. }, {
  155. tab: 5,
  156. url: '/pages/users/user_info/index'
  157. });
  158. }).catch(err => {
  159. return that.$util.Tips({
  160. title: err
  161. });
  162. })
  163. },
  164. /**
  165. * 发送验证码
  166. *
  167. */
  168. async code(data) {
  169. let that = this;
  170. if (!that.phone) return that.$util.Tips({
  171. title: '请填写手机号码!'
  172. });
  173. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  174. title: '请输入正确的手机号码!'
  175. });
  176. this.disabled = true
  177. await registerVerify({
  178. phone:that.phone,
  179. key:that.key,
  180. code:that.captcha,
  181. type: 'binding',
  182. captchaType: 'blockPuzzle',
  183. captchaVerification: data.captchaVerification
  184. }).then(res => {
  185. this.disabled = false
  186. that.$util.Tips({
  187. title: res.message
  188. });
  189. that.sendCode();
  190. }).catch(err => {
  191. this.disabled = false
  192. return that.$util.Tips({
  193. title: err
  194. });
  195. });
  196. },
  197. success(data) {
  198. this.$refs.verify.hide();
  199. this.code(data);
  200. },
  201. handleVerify() {
  202. this.$refs.verify.show();
  203. }
  204. }
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  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: transparent;
  240. color: var(--view-theme);
  241. }
  242. .ChangePassword .list .item .code.on {
  243. color: #b9b9bc;
  244. }
  245. .ChangePassword .confirmBnt {
  246. font-size: 32rpx;
  247. width: 580rpx;
  248. height: 90rpx;
  249. border-radius: 45rpx;
  250. color: #fff;
  251. margin: 92rpx auto 0 auto;
  252. text-align: center;
  253. line-height: 90rpx;
  254. background-color: var(--view-theme);
  255. }
  256. .getPhoneBtn{
  257. font-size: 32rpx;
  258. width: 580rpx;
  259. height: 90rpx;
  260. border-radius: 45rpx;
  261. border: 1px solid #3CB625;
  262. color: #3CB625;
  263. margin: 40rpx auto 0 auto;
  264. text-align: center;
  265. line-height: 90rpx;
  266. .iconfont{
  267. font-size: 32rpx;
  268. margin-right: 12rpx;
  269. }
  270. }
  271. </style>