123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <template>
- <div>
- <div class="login-con">
- <div class="input-con" :class="{inputActive:inputActive==='phone'}">
- <div class="phone-select" ref="quhaoMenu">
- <div class="phone-select-div" @click="showSelect=!showSelect">
- <span>{{codeActive[1]}}</span>
- <!-- (<span>{{codeActive[0]}}</span>) -->
- <div class="sanjiao"></div>
- </div>
- <phoneSelect v-show="showSelect" @selectItem="selectItem" />
- </div>
- <input
- class="guding"
- v-model="phone"
- oninput="value=value.replace(/[^\d]/g,'')"
- maxlength="11"
- @focus="inputActive='phone'"
- @blur="inputActive=''"
- type="text"
- :placeholder="langLogin.phone.placeholder"
- />
- </div>
- <div class="code-con">
- <div class="input-con" :class="{inputActive:inputActive==='code'}">
- <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"
- />
- <div class="send-btn" v-if="!jishi" @click="getAuthCode">{{langLogin.code.txt}}</div>
- <span
- class="send-btn"
- v-else
- >{{language==='en'?`Resend after ${interTime}s`:`${interTime}s后重新发送`}}</span>
- </div>
- </div>
- <div class="input-con" :class="{inputActive:inputActive==='password'}">
- <input
- v-model="password"
- @focus="inputActive='password'"
- @blur="inputActive=''"
- maxlength="16"
- type="password"
- :placeholder="langLogin.newpass.placeholder"
- />
- </div>
- <div class="input-con" :class="{inputActive:inputActive==='confirm'}">
- <input
- v-model="confirmpass"
- @focus="inputActive='confirm'"
- @blur="inputActive=''"
- maxlength="16"
- type="password"
- :placeholder="langLogin.comfirmpass.placeholder"
- />
- </div>
- <div class="btns" @click="submit">{{langLogin.submit}}</div>
- <div class="to-login">
- <div class="lo-con">
- {{langLogin.resigter1}}
- <router-link :to="{path:'/login'}">{{langLogin.resigter2}}</router-link>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import {mapState} from 'vuex'
- import phoneSelect from '@/components/common/phoneSelect'
- import { encodeStr } from '@/util'
- import { Base64 } from 'js-base64'
- export default {
- computed: {
- ...mapState({
- language: state => state.language.current,
- langToast: state => state.language.home.toast,
- langLogin: state => state.language.home.home.loginAside,
- token: state => state.user.token
- })
- },
- data () {
- return {
- showSelect: false,
- codeActive: ['中国', '+86', 'China'],
- phone: '',
- authCode: '',
- interTime: 60,
- jishi: false,
- password: '',
- confirmpass: '',
- inputActive: ''
- }
- },
- components: {
- phoneSelect
- },
- mounted () {
- document.addEventListener('click', (e) => {
- if (this.$refs.quhaoMenu) {
- if (!this.$refs.quhaoMenu.contains(e.target)) {
- this.showSelect = false
- }
- }
- })
- },
- methods: {
- selectItem (item) {
- this.showSelect = false
- this.codeActive = item
- },
- async getAuthCode () {
- let check = value => {
- for (let i = 0, len = value.length; i < len; i++) {
- if (!value[i].val) {
- return this.$toast.show('warn', (this.language === 'en' ? value[i].En : value[i].name) + this.langToast['7'])
- }
- }
- return true
- }
- let checkStr = [
- {
- name: '手机号码',
- En: 'Phone number',
- val: this.phone
- }
- ]
- if (!check(checkStr)) {
- return
- }
- let res = await this.$store.dispatch('getAuthCode', {
- phone: this.phone,
- code: Number(this.codeActive[1].substr(1))
- })
- if (res) {
- this.interl && clearInterval(this.interl)
- this.interl = null
- this.jishi = true
- this.interl = setInterval(() => {
- this.interTime--
- if (this.interTime <= 0) {
- this.jishi = false
- this.interTime = 60
- clearInterval(this.interl)
- this.interl = null
- }
- }, 1000)
- }
- },
- async submit () {
- let check = value => {
- for (let i = 0, len = value.length; i < len; i++) {
- if (!value[i].val) {
- return this.$toast.show('warn', (this.language === 'en' ? value[i].En : value[i].name) + this.langToast['7'])
- }
- }
- return true
- }
- let checkStr = [
- {
- name: '手机号码',
- En: 'Phone number',
- val: this.phone
- },
- {
- name: '验证码',
- En: 'Verification code',
- val: this.authCode
- },
- {
- name: '密码',
- En: 'Password',
- val: this.password
- },
- {
- name: '确认密码',
- En: 'Password',
- val: this.confirmpass
- }
- ]
- if (!check(checkStr)) {
- return
- }
- if (this.password.length < 8 || this.confirmpass.length < 8) {
- return this.$toast.show('warn', this.langToast['31'])
- }
- let temp = encodeStr(Base64.encode(this.password), Base64.encode(this.confirmpass))
- let params = {
- password: temp[0],
- phoneNum: this.phone,
- confirmPwd: temp[1],
- msgAuthCode: this.authCode
- }
- let res = await this.$http({
- method: 'post',
- headers: {
- token: this.token
- },
- data: params,
- url: 'sso/user/changePassword'
- })
- let response = res.data
- if (response.code !== 0) {
- return this.$toast.show('warn', this.langToast[response.code])
- }
- this.$toast.show('success', this.langToast['32'], () => {
- this.$router.push({path: '/login'})
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import './style.scss';
- </style>
|