forget.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div class="iforget-layout">
  3. <div class="input phone-select" ref="quhaoMenu" >
  4. <div @click="showSelect=!showSelect">
  5. <span>{{codeActive[1]}}</span>
  6. <img :src="`${$cdn}images/quhao-jiantou.png`" >
  7. </div>
  8. <ul v-show="showSelect" >
  9. <li @click="selectItem(item)" v-for="(item,i) in selectCall" :key="i">
  10. {{language==='en'?item[2]:item[0]}}{{item[1]}}
  11. </li>
  12. </ul>
  13. <input autocomplete="off" :placeholder="languagelAside.phone.placeholder" oninput="value=value.replace(/[^\d]/g,'')" maxlength='11' v-model="phone" type="text">
  14. </div>
  15. <div class="verification input">
  16. <input autocomplete="off" :placeholder="languagelAside.code.placeholder" v-model="authCode" oninput="value=value.replace(/[^\d]/g,'')" maxlength='6'>
  17. <span v-if="!jishi" @click="getAuthCode">{{languagelAside.code.txt}}</span>
  18. <span v-else>{{language==='en'?`Resend after ${interTime}s`:`${interTime}s后重新发送`}}</span>
  19. </div>
  20. <div class="input"><input :style="{color:password&&password.length<8?'#ff0000':'#fff'}" readonly onfocus="this.removeAttribute('readonly')" maxlength='16' autocomplete="off" v-model="password" :placeholder="languagelAside.newpass.placeholder" type="password"></div>
  21. <div class="input"><input :style="{color:confirmpass&&confirmpass.length<8?'#ff0000':'#fff'}" readonly onfocus="this.removeAttribute('readonly')" maxlength='16' autocomplete="off" v-model="confirmpass" :placeholder="languagelAside.comfirmpass.placeholder" type="password"></div>
  22. <div class="login-dec">{{languagelAside.resigter1}}<span @click="$bus.$emit('changName', {
  23. name: '用户登录',
  24. enName: 'User login',
  25. id: 'ilogin'
  26. })">{{languagelAside.resigter2}}</span>
  27. </div>
  28. <div class="temp-btn submit" @click="submit">{{languagelAside.submit}}</div>
  29. </div>
  30. </template>
  31. <script>
  32. import {mapState} from 'vuex'
  33. import selectCall from '@/util/country.js'
  34. import { reg, encodeStr } from '@/util'
  35. import { Base64 } from 'js-base64'
  36. export default {
  37. computed: {
  38. ...mapState({
  39. languagelAside: state => state.language.home.home.loginAside,
  40. langToast: state => state.language.home.toast,
  41. language: state => state.language.current,
  42. token: state => state.user.token
  43. })
  44. },
  45. data () {
  46. return {
  47. showSelect: false,
  48. selectCall,
  49. codeActive: ['中国', '+86', 'China'],
  50. phone: '',
  51. authCode: '',
  52. interTime: 60,
  53. jishi: false,
  54. password: '',
  55. confirmpass: ''
  56. }
  57. },
  58. mounted () {
  59. document.addEventListener('click', (e) => {
  60. if (this.$refs.quhaoMenu) {
  61. if (!this.$refs.quhaoMenu.contains(e.target)) {
  62. this.showSelect = false
  63. }
  64. }
  65. })
  66. },
  67. methods: {
  68. async getAuthCode () {
  69. if (!reg.phone.test(this.phone)) {
  70. return
  71. }
  72. let res = await this.$store.dispatch('getAuthCode', {
  73. phone: this.phone,
  74. code: this.codeActive[1].substr(1)
  75. })
  76. if (res) {
  77. this.interl && clearInterval(this.interl)
  78. this.interl = null
  79. this.jishi = true
  80. this.interl = setInterval(() => {
  81. this.interTime--
  82. if (this.interTime <= 0) {
  83. this.jishi = false
  84. this.interTime = 60
  85. clearInterval(this.interl)
  86. this.interl = null
  87. }
  88. }, 1000)
  89. }
  90. },
  91. selectItem (item) {
  92. this.showSelect = false
  93. this.codeActive = item
  94. },
  95. async submit () {
  96. let check = value => {
  97. for (let i = 0, len = value.length; i < len; i++) {
  98. if (!value[i].val) {
  99. return this.$toast.show('warn', (this.language === 'en' ? value[i].En : value[i].name) + this.langToast['7'])
  100. }
  101. }
  102. return true
  103. }
  104. let checkStr = [
  105. {
  106. name: '手机',
  107. En: 'Phone number',
  108. val: this.phone
  109. },
  110. {
  111. name: '验证码',
  112. En: 'Verification code',
  113. val: this.authCode
  114. },
  115. {
  116. name: '密码',
  117. En: 'Password',
  118. val: this.password
  119. },
  120. {
  121. name: '确认密码',
  122. En: 'Password',
  123. val: this.confirmpass
  124. }
  125. ]
  126. if (!check(checkStr)) {
  127. return
  128. }
  129. if (this.password.length < 8 || this.confirmpass.length < 8) {
  130. return this.$toast.show('warn', this.langToast['31'])
  131. }
  132. let temp = encodeStr(Base64.encode(this.password), Base64.encode(this.confirmpass))
  133. let params = {
  134. password: temp[0],
  135. phoneNum: this.phone,
  136. confirmPwd: temp[1],
  137. msgAuthCode: this.authCode
  138. }
  139. let res = await this.$http({
  140. method: 'post',
  141. headers: {
  142. token: this.token
  143. },
  144. data: params,
  145. url: 'sso/user/changePassword'
  146. })
  147. let response = res.data
  148. if (response.code !== 0) {
  149. return this.$toast.show('warn', this.langToast[response.code])
  150. }
  151. this.$toast.show('warn', this.langToast['32'], () => {
  152. this.$bus.$emit('currentActive', 'ilogin')
  153. })
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. @import './style.scss';
  160. </style>