| | |
| | | <script lang="ts"> |
| | | import { namespace } from 'nuxt-property-decorator'; |
| | | import { Vue, Component, Ref } from 'vue-property-decorator'; |
| | | import { LoginRequest, LoginVerify, loginVerify, OtpInfo, register, RegisterInfo, sendOtp } from '~/assets/ts/api/consultant'; |
| | | import ErrorMessageBox from '~/assets/ts/errorService'; |
| | | import { OtpErrorCode } from '~/assets/ts/models/enum/otpErrorCode'; |
| | | import { Role } from '~/assets/ts/models/enum/Role'; |
| | | import { LoginRequest } from '~/assets/ts/models/loginRequest.model'; |
| | | import { LoginVerify } from '~/assets/ts/models/loginVerify.model'; |
| | | import { OtpInfo } from '~/assets/ts/models/otpInfo.model'; |
| | | import { RegisterInfo } from '~/assets/ts/models/registerInfo'; |
| | | import loginService from '~/assets/ts/services/login.service'; |
| | | |
| | | const roleStorage = namespace('localStorage'); |
| | | |
| | |
| | | applyAccount_onAction = false; |
| | | |
| | | previousPath = ''; |
| | | |
| | | ///////////////////////////////////////////////////// |
| | | mounted() { |
| | | const phoneOtpTime = localStorage.getItem('phoneOtpTime'); |
| | | const emailOtpTime = localStorage.getItem('emailOtpTime'); |
| | |
| | | } |
| | | } |
| | | |
| | | beforeRouteEnter (to, from, next) { |
| | | next(vm => { |
| | | console.log(from.path, 'beforeRouteEnter'); |
| | | vm.previousPath = from.path; |
| | | }) |
| | | } |
| | | |
| | | destroyed() { |
| | | this.removeOtpTime(); |
| | | clearInterval(this.otpInterval); |
| | | clearInterval(this.emailResendInterval); |
| | | clearInterval(this.autoRedirectInterval); |
| | | } |
| | | |
| | | |
| | | ////////////////////////////////////////////////////////// |
| | | detectContractReadStatus(event: any): void { |
| | | const scrollTop = Math.round(event.target.scrollTop); |
| | | const height = event.target.scrollHeight - event.target.clientHeight; |
| | |
| | | loginType: isMobile ? 'SMS' : 'EMAIL', |
| | | account: isMobile ? this.phoneNumber : this.email, |
| | | } |
| | | sendOtp(loginInfo).then(otpInfo => { |
| | | loginService.sendOtp(loginInfo).then(otpInfo => { |
| | | if (otpInfo.success) { |
| | | this.storageOtpTime(type, otpInfo); |
| | | this.startOtpSetting(type); |
| | |
| | | this.applyAccount_onAction = true; |
| | | const registerInfo = this.setRegisterInfo(); |
| | | |
| | | register(registerInfo).then(res => { |
| | | this.storageIdToken(res.data.id_token); |
| | | loginService.register(registerInfo).then(res => { |
| | | this.storageIdToken(res.id_token); |
| | | this.storageRole(Role.USER); |
| | | this.storagePhoneOrEmail(registerInfo); |
| | | this.autoRedirect(); |
| | |
| | | this.redirect(); |
| | | } |
| | | |
| | | private autoRedirect() { |
| | | this.autoRedirectInterval = setInterval(() => { |
| | | this.autoRedirectCounter -= 1; |
| | | |
| | | if (this.autoRedirectCounter === 0) { |
| | | clearInterval(this.autoRedirectInterval); |
| | | this.redirect(); |
| | | } |
| | | }, 1000) |
| | | } |
| | | |
| | | private redirect() { |
| | | const backToPrevious = ['questionnaire', 'myConsultantList']; |
| | | const find = backToPrevious.findIndex(item => this.previousPath.includes(item)); |
| | | console.log(this.previousPath, find, 'redirect'); |
| | | find > -1 ? this.$router.go(-1) : this.$router.push('/'); |
| | | } |
| | | |
| | | beforeRouteEnter (to, from, next) { |
| | | next(vm => { |
| | | console.log(from.path, 'beforeRouteEnter'); |
| | | vm.previousPath = from.path; |
| | | }) |
| | | } |
| | | |
| | | login() { |
| | | const login: LoginVerify = this.setLoginInfo(); |
| | | this.removeOtpTime(); |
| | | loginVerify(login).then(res => { |
| | | this.storageIdToken(res.data.id_token); |
| | | loginService.loginVerify(login).then(res => { |
| | | this.storageIdToken(res.id_token); |
| | | this.storageRole(Role.USER); |
| | | this.phoneSuccessConfirmVisable = true; |
| | | this.autoRedirect(); |
| | |
| | | this.checkHttpErrorStatus(error); |
| | | }); |
| | | } |
| | | |
| | | |
| | | ////////////////////////////////////////////////////////////////// |
| | | private checkHttpErrorStatus(error:any):void{ |
| | | switch (error.response.status) { |
| | | case 401: |
| | |
| | | } |
| | | } |
| | | |
| | | destroyed() { |
| | | this.removeOtpTime(); |
| | | clearInterval(this.otpInterval); |
| | | clearInterval(this.emailResendInterval); |
| | | clearInterval(this.autoRedirectInterval); |
| | | private autoRedirect() { |
| | | this.autoRedirectInterval = setInterval(() => { |
| | | this.autoRedirectCounter -= 1; |
| | | |
| | | if (this.autoRedirectCounter === 0) { |
| | | clearInterval(this.autoRedirectInterval); |
| | | this.redirect(); |
| | | } |
| | | }, 1000) |
| | | } |
| | | |
| | | private redirect() { |
| | | const backToPrevious = ['questionnaire', 'myConsultantList']; |
| | | const find = backToPrevious.findIndex(item => this.previousPath.includes(item)); |
| | | console.log(this.previousPath, find, 'redirect'); |
| | | find > -1 ? this.$router.go(-1) : this.$router.push('/'); |
| | | } |
| | | |
| | | private phoneDiffTime(parseOtpTime: any) { |