change_mobile.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="change-info">
  3. <h1>修改手机号</h1>
  4. <div class="line"></div>
  5. <div class="contents">
  6. <div class="mobile">新手机号</div>
  7. <el-input placeholder="请输入手机号" v-model="mobile"></el-input>
  8. <div class="code">验证码</div>
  9. <ver-code @click="sendVer" @change="changeAuthCode"></ver-code>
  10. </div>
  11. <div class="sub-container">
  12. <el-button @click="clickComplete" class="next-btn" type="primary">完成</el-button>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. import VerCode from '@/components/ver_code'
  18. export default {
  19. components: {
  20. VerCode,
  21. },
  22. data() {
  23. return {
  24. mobile: '',
  25. authCode: '',
  26. canChangeMobile: false
  27. }
  28. },
  29. mounted() {
  30. this.canChange()
  31. },
  32. methods: {
  33. canChange() {
  34. this.$axios.$post('/api/user/canChangePhone', {
  35. token: localStorage.getItem('changeToken'),
  36. }).then(res=>{
  37. if (Number(res.status) === 1) {
  38. this.canChangeMobile = true
  39. setTimeout(()=>{
  40. this.canChangeMobile = false
  41. localStorage.removeItem('changeToken')
  42. }, 60 * 5 * 1000)
  43. }
  44. })
  45. },
  46. async sendVer(run) {
  47. let mobile = this.mobile
  48. if(!mobile.match(/^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/)) {
  49. this.$message({
  50. message: '请输入正确手机号',
  51. type: 'error'
  52. })
  53. return
  54. }
  55. let res = await this.$axios.$post('/api/passport/check_registered', {
  56. mobile,
  57. })
  58. // console.log(res)
  59. if(res) {
  60. if(res.data.registered) {
  61. this.$message({
  62. message: '该手机号已注册',
  63. type: 'error'
  64. })
  65. } else {
  66. let res = await this.$axios.$post('/api/user/sendMobileAuthCode', {
  67. mobile,
  68. })
  69. if(res) {
  70. run()
  71. this.$message({
  72. message: '发送成功,请查收',
  73. type: 'success'
  74. })
  75. }
  76. }
  77. }
  78. },
  79. changeAuthCode(val) {
  80. this.authCode = val
  81. },
  82. async clickComplete() {
  83. if (!this.canChangeMobile) {
  84. this.$message.error('校验码过期,请重新验证!')
  85. history.back()
  86. return
  87. }
  88. if(!this.mobile.length) {
  89. this.$message('请输入手机号')
  90. return
  91. } else if(!this.authCode.length) {
  92. this.$message('请输入验证码')
  93. return
  94. }
  95. let res = await this.$axios.$post('/api/user/update_info', {
  96. login_mobile: this.mobile,
  97. auth_code: this.authCode,
  98. token: localStorage.getItem('changeToken')
  99. })
  100. if(Number(res.status) === 1) {
  101. this.$message({
  102. message: '更新成功',
  103. type: 'success'
  104. })
  105. localStorage.removeItem('changeToken')
  106. setTimeout(() => {
  107. location.href = '/setting/user'
  108. }, 1000)
  109. }
  110. }
  111. }
  112. }
  113. </script>
  114. <style scoped>
  115. .change-info {
  116. display: flex;
  117. flex-direction: column;
  118. align-items: center;
  119. width: 1000px;
  120. height: 588px;
  121. background: white;
  122. margin-top: 20px;
  123. }
  124. h1 {
  125. margin: 27px 0 25px;
  126. }
  127. .line {
  128. width: 960px;
  129. height: 2px;
  130. background: rgba(0, 0, 0, 0.06);
  131. }
  132. .el-input {
  133. width: 311px;
  134. height: 44px;
  135. }
  136. .mobile {
  137. margin: 102px 0 5px;
  138. }
  139. .code {
  140. margin: 20px 0 5px;
  141. }
  142. .sub-container {
  143. width: 311px;
  144. }
  145. .next-btn {
  146. width: 125px;
  147. margin: 20px 0 41px;
  148. }
  149. </style>