From abfd26bb700d93a92da6a04703b0187d4acaaeb5 Mon Sep 17 00:00:00 2001 From: Tomas <tomasysh@gmail.com> Date: 星期三, 22 十二月 2021 10:13:02 +0800 Subject: [PATCH] refactor: move ts folder to shared folder --- PAMapp/pages/consultantLogin/index.vue | 156 +++++++++++++++++++++++++++++++-------------------- 1 files changed, 95 insertions(+), 61 deletions(-) diff --git a/PAMapp/pages/consultantLogin/index.vue b/PAMapp/pages/consultantLogin/index.vue index e702a19..3a90f3f 100644 --- a/PAMapp/pages/consultantLogin/index.vue +++ b/PAMapp/pages/consultantLogin/index.vue @@ -10,24 +10,16 @@ class="pam-consultant-login__input" placeholder="頛詨eService撣唾��"> <div class="pam-consultant-login__inputIcon text--primary cursor--pointer fix-chrome-click--issue" - @click="isRemember = !isRemember"> - <i :class="[isRemember ? 'icon-checkbox-1' : 'icon-checkbox','pr-5']"></i> + @click="isRememberChange"> + <i :class="[isRememberUserName ? 'icon-checkbox-1' : 'icon-checkbox','pr-5']"></i> 閮�� </div> </div> </div> <div class="pam-paragraph"> - <div class="pam-consultant-login__title "> - <div>撖Ⅳ</div> - <a class="pam-consultant-login__forgot-password cursor--pointer fix-chrome-click--issue" - :href="forgotPasswordLink" - target="_blank" - rel="靽�犖憯�"> - 敹��Ⅳ嚗� - </a> - </div> + <div class="pam-consultant-login__title ">撖Ⅳ</div> <div class="position-r mt-10"> - <input :type="[isShowPassword ? 'text' : 'password']" + <input :type="[ isShowPassword ? 'text' : 'password']" v-model="consultantDto.password" class="pam-consultant-login__input" placeholder="頛詨eService撖Ⅳ"> @@ -39,35 +31,36 @@ </div> <div class="pam-paragraph"> <div class="pam-consultant-login__title"> - <div>撽�Ⅳ</div> - <div class="text--dark-blue fs-16 cursor--pointer fix-chrome-click--issue" - @click="regenerateCode">������</div> + <div>撽�Ⅳ <span class="text--dark-blue fs-16">(����之撠神)</span></div> + <div class="text--primary fs-16 cursor--pointer fix-chrome-click--issue" + @click="regenerateImgOfVerification">������</div> </div> <div class="pam-consultant-login__verifyBlock mt-10"> <div class="w-55"> <input type="text" - v-model="consultantDto.verificationCode" + v-model="verificationCode" + maxlength="4" class="pam-consultant-login__input"> </div> <div class="pam-consultant-login__verifyImg"> - <img src="~/assets/images/logo.png" - alt="撽�Ⅳ"> + <img :src="imgSrc" alt="撽�Ⅳ"> </div> </div> </div> <div class="pam-consultant-login__confirmBlock pam-paragraph"> <button class="pam-consultant-login__confirm cursor--pointer fix-chrome-click--issue" - @click="loginWithConsultant">�</button> + @click="sendInfo">�</button> </div> </div> </div> </template> <script lang="ts"> - import { namespace } from 'nuxt-property-decorator'; - import { Role } from '~/assets/ts/models/enum/Role'; - import { Vue, Component } from 'vue-property-decorator'; - import { getForgotPasswordLink, getVerificationCodeImg, logInToConsultant } from '~/assets/ts/api/consultant'; + import { Vue, Component , namespace } from 'nuxt-property-decorator'; + import { AxiosError } from 'axios'; + import { Role } from '~/shared/models/enum/role'; + import ErrorMessageBox from '~/shared/errorService'; + import loginService from '~/shared/services/login.service' const roleStorage = namespace('localStorage'); @Component({ @@ -76,64 +69,105 @@ export default class ConsultantLogin extends Vue { @roleStorage.Mutation storageIdToken!: (token: string) => void; @roleStorage.Mutation storageRole!: (role: string) => void; - - isRemember = false; + @roleStorage.Mutation storageConsultantId!:(id:string) => void; + isRememberUserName = false; isShowPassword = false; - forgotPasswordLink = ''; // 撠 - imgOfVerificationCode = ''; // 撠 + imgSrc = ''; + verificationCode=''; consultantDto = { username: '', password: '', - verificationCode: '', } + //////////////////////////////////////////////////////////////////// mounted() { - this.getRememberUserName(); - this.regenerateCode(); - this.getLinkOfForgotPassword(); + this.getInitUserName(); + this.regenerateImgOfVerification(); }; - private getRememberUserName(): void { + get isAlreadyDone():boolean{ + return !!(this.verificationCode && this.consultantDto.username && this.consultantDto.password); + } + + + //////////////////////////////////////////////////////////////////// + public regenerateImgOfVerification(): void { + loginService.getImgOfVerification().then( imgOfBase64 => + this.imgSrc = imgOfBase64 + ); + }; + + public isRememberChange():void{ + this.isRememberUserName = !this.isRememberUserName; + this.storeUserName(); + } + + public sendInfo():void{ + this.isAlreadyDone ? this.verify() : ErrorMessageBox('隢Ⅱ隤董����Ⅳ隞亙���Ⅳ��憛怠神摰'); + } + + + //////////////////////////////////////////////////////////////////// + private getInitUserName(): void { const username = localStorage.getItem('consultantUserName') if (username) { this.consultantDto.username = username; - this.isRemember = true; + this.isRememberUserName = true; } } - private getLinkOfForgotPassword(): void { - getForgotPasswordLink().then(link => { - this.forgotPasswordLink = link; - }); - }; - public regenerateCode(): void { - getVerificationCodeImg().then(imgOfbase64 => { - this.imgOfVerificationCode = imgOfbase64; - }); - }; - - public loginWithConsultant(): void { - this.recordAccount(); - - logInToConsultant(this.consultantDto).then(res => { - this.storageIdToken(res.data.id_token); - this.storageRole(Role.ADMIN); - this.$router.push('/myAppointmentList/appointmentList'); - }, (error) => { - this.consultantDto.password = ''; - this.consultantDto.verificationCode = ''; + private verify():void{ + loginService.getVerificationStatus(this.verificationCode).then( verifySuccess => { + if(verifySuccess.data){ + this.loginWithConsultant() + }else{ + this.clearValue(); + this.regenerateImgOfVerification(); + ErrorMessageBox('撽�Ⅳ頛詨�隤�'); + } }); } - private recordAccount(): void { - localStorage.setItem('consultantUserName', this.isRemember ? this.consultantDto.username : ''); + private loginWithConsultant(): void { + loginService.logInToConsultant(this.consultantDto).then(res => { + this.storageIdToken(res.data.id_token); + this.storageRole(Role.ADMIN); + this.storageConsultantId(this.consultantDto.username) + this.storeUserName(); + this.$router.push('/myAppointmentList/appointmentList'); + }).catch((error:AxiosError)=>{ + this.checkHttpErrorStatus(error); + }); + } + private checkHttpErrorStatus(error:any):void{ + this.clearValue(); + this.regenerateImgOfVerification(); + switch (error.response.status) { + case 401: + const errorMsg = error.response.data.detail; + ErrorMessageBox(errorMsg); + break; + + default: + ErrorMessageBox('',error); + break; + } + } + + private storeUserName(): void { + localStorage.setItem('consultantUserName', this.isRememberUserName ? this.consultantDto.username : ''); }; + + private clearValue():void{ + if (!this.isRememberUserName) this.consultantDto.username=''; + this.consultantDto.password = ''; + this.verificationCode = ''; + } }; </script> -<style lang="scss" - scoped> +<style lang="scss" scoped> .mt-20 { margin-top: 20px; } @@ -193,9 +227,9 @@ } &__forgot-password { - color: $PRIMARY_RED; + color: $PRIMARY_RED; text-decoration: none; - font-size: 16px; + font-size: 16px; } &__verifyBlock { @@ -205,8 +239,8 @@ &__verifyImg { width: 126px; - border: 1px black solid; height: 50px; + border:1px #cccccc solid; img { width: 100%; height: 100%; -- Gitblit v1.8.0