保誠-保戶業務員媒合平台
Mila
2021-12-23 9de780116757fc0025b6bd47b0957af22bf2829b
PAMapp/pages/consultantLogin/index.vue
@@ -58,9 +58,9 @@
<script lang="ts">
  import { Vue, Component , namespace } from 'nuxt-property-decorator';
  import { AxiosError } from 'axios';
  import { getImgOfVerification, logInToConsultant, getVerificationStatus } from '~/assets/ts/api/consultant';
  import { Role } from '~/assets/ts/models/enum/Role';
  import ErrorMessageBox from '~/assets/ts/errorService';
  import { Role } from '~/shared/models/enum/Role';
  import messageBoxService from '~/shared/services/message-box.service';
  import loginService from '~/shared/services/login.service'
  const roleStorage = namespace('localStorage');
  @Component({
@@ -79,25 +79,20 @@
      password: '',
    }
    get isAlreadyDone():boolean{
      return !!(this.verificationCode && this.consultantDto.username && this.consultantDto.password);
    }
    ////////////////////////////////////////////////////////////////////
    mounted() {
      this.getInitUserName();
      this.regenerateImgOfVerification();
    };
    private getInitUserName(): void {
      const username = localStorage.getItem('consultantUserName')
      if (username) {
        this.consultantDto.username = username;
        this.isRememberUserName = true;
      }
    get isAlreadyDone():boolean{
      return !!(this.verificationCode && this.consultantDto.username && this.consultantDto.password);
    }
    ////////////////////////////////////////////////////////////////////
    public regenerateImgOfVerification(): void {
      getImgOfVerification().then( imgOfBase64 =>
      loginService.getImgOfVerification().then( imgOfBase64 =>
        this.imgSrc = imgOfBase64
      );
    };
@@ -108,23 +103,33 @@
    }
    public sendInfo():void{
      this.isAlreadyDone ? this.verify() : ErrorMessageBox('請確認帳號、密碼以及驗證碼是否填寫完畢');
      this.isAlreadyDone ? this.verify() : messageBoxService.showErrorMessage('請確認帳號、密碼以及驗證碼是否填寫完畢');
    }
    ////////////////////////////////////////////////////////////////////
    private getInitUserName(): void {
      const username = localStorage.getItem('consultantUserName')
      if (username) {
        this.consultantDto.username = username;
        this.isRememberUserName = true;
      }
    }
    private verify():void{
      getVerificationStatus(this.verificationCode).then( verifySuccess => {
      loginService.getVerificationStatus(this.verificationCode).then( verifySuccess => {
        if(verifySuccess.data){
          this.loginWithConsultant()
        }else{
          this.clearValue();
          this.regenerateImgOfVerification();
          ErrorMessageBox('驗證碼輸入錯誤');
          messageBoxService.showErrorMessage('驗證碼輸入錯誤');
        }
      });
    }
    private loginWithConsultant(): void {
      logInToConsultant(this.consultantDto).then(res => {
      loginService.logInToConsultant(this.consultantDto).then(res => {
        this.storageIdToken(res.data.id_token);
        this.storageRole(Role.ADMIN);
        this.storageConsultantId(this.consultantDto.username)
@@ -140,11 +145,11 @@
      switch (error.response.status) {
        case 401:
          const errorMsg = error.response.data.detail;
          ErrorMessageBox(errorMsg);
          messageBoxService.showErrorMessage(errorMsg);
          break;
        default:
          ErrorMessageBox('',error);
          messageBoxService.showErrorMessage('',error);
          break;
      }
    }