register.vue 6.3 KB

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