index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <div class="register-layout">
  3. <div class="login-con">
  4. <h1 class="common-title">{{ $t('login.codeLogin') }}</h1>
  5. <div class="input-con" :class="{inputActive:inputActive==='phone'}">
  6. <div class="phone-select" ref="quhaoMenu">
  7. <div class="phone-select-div" @click="showSelect=!showSelect">
  8. <span>{{codeActive[1]}}</span>
  9. <!-- (<span>{{codeActive[0]}}</span>) -->
  10. <div class="sanjiao"></div>
  11. </div>
  12. <phoneSelect v-show="showSelect" @selectItem="selectItem" />
  13. </div>
  14. <input class="guding" oninput="value=value.replace(/[^\d]/g,'')" v-model="phone" @focus="inputActive='phone'" @blur="inputActive=''" type="text" :placeholder="langLogin.phone.placeholder">
  15. </div>
  16. <div class="code-con">
  17. <div class="input-con" :class="{inputActive:inputActive==='code'}">
  18. <input v-model="authCode" @focus="inputActive='code'" @blur="inputActive=''" style="padding-left:6px;" type="text" oninput="value=value.replace(/[^\d]/g,'')" maxlength='6' :placeholder="langLogin.code.placeholder">
  19. <div class="send-btn" v-if="!jishi" @click="getAuthCode">{{langLogin.code.txt}}</div>
  20. <span class="send-btn" v-else>{{language==='en'?`Resend after ${interTime}s`:`${interTime}s后重新发送`}}</span>
  21. </div>
  22. </div>
  23. <div class="forget">
  24. <router-link :to="{path:'/login'}">{{langLogin.defaultLogin}}</router-link>
  25. </div>
  26. <div class="btns" @click="submit">{{langLogin.login}}</div>
  27. <div class="to-login">
  28. <div class="lo-con">
  29. <router-link :to="{path:'/forget'}">{{ $t('login.forgetPassword') }}</router-link><router-link :to="{path:'/register'}">{{langLogin.loginsub2}}</router-link>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import phoneSelect from '@/components/common/phoneSelect'
  37. import {mapState} from 'vuex'
  38. export default {
  39. data () {
  40. return {
  41. showSelect: false,
  42. codeActive: ['中国', '+86', 'China'],
  43. nickname: '',
  44. phone: '',
  45. authCode: '',
  46. inputActive: '',
  47. interTime: 60,
  48. jishi: false,
  49. interl: null
  50. }
  51. },
  52. computed: {
  53. ...mapState({
  54. language: state => state.language.current,
  55. langToast: state => state.language.home.toast,
  56. langLogin: state => state.language.home.home.loginAside,
  57. token: state => state.user.token
  58. })
  59. },
  60. components: {
  61. phoneSelect
  62. },
  63. mounted () {
  64. document.addEventListener('click', (e) => {
  65. if (this.$refs.quhaoMenu) {
  66. if (!this.$refs.quhaoMenu.contains(e.target)) {
  67. this.showSelect = false
  68. }
  69. }
  70. })
  71. },
  72. methods: {
  73. selectItem (item) {
  74. this.showSelect = false
  75. this.codeActive = item
  76. },
  77. async getAuthCode () {
  78. // if (!reg.phone.test(this.phone)) {
  79. // return
  80. // }
  81. let res = await this.$store.dispatch('getAuthCode', {
  82. phone: this.phone,
  83. code: Number(this.codeActive[1].substr(1))
  84. })
  85. if (res) {
  86. this.interl && clearInterval(this.interl)
  87. this.interl = null
  88. this.jishi = true
  89. this.interl = setInterval(() => {
  90. this.interTime--
  91. if (this.interTime <= 0) {
  92. this.jishi = false
  93. this.interTime = 60
  94. clearInterval(this.interl)
  95. this.interl = null
  96. }
  97. }, 1000)
  98. }
  99. },
  100. async submit () {
  101. let check = value => {
  102. for (let i = 0, len = value.length; i < len; i++) {
  103. if (!value[i].val) {
  104. return this.$toast.show('warn', (this.language === 'en' ? value[i].En : value[i].name) + this.langToast['7'])
  105. }
  106. }
  107. return true
  108. }
  109. let checkStr = [
  110. {
  111. name: '手机',
  112. En: 'Phone number',
  113. val: this.phone
  114. },
  115. {
  116. name: '验证码',
  117. En: 'Verification code',
  118. val: this.authCode
  119. }
  120. ]
  121. if (!check(checkStr)) {
  122. return
  123. }
  124. // let country = Number(this.codeActive[1].substr(1))
  125. let params = {
  126. phoneNum: this.phone,
  127. msgAuthCode: this.authCode
  128. }
  129. await this.$store.dispatch('codeLogin', params)
  130. if (this.token) {
  131. this.$router.replace({path: '/information'})
  132. }
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. @import './style.scss';
  139. </style>