保誠-保戶業務員媒合平台
wayne
2022-02-17 a3716f72066d25d745f4d5103ff23a553c3e102b
PAMapp/pages/consultantLogin/index.vue
@@ -58,30 +58,40 @@
<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'
import { AgentInfo } from '~/shared/models/agent-info.model';
  const loginStore  = namespace('login.store');
  const roleStorage = namespace('localStorage');
  @Component({
    layout: 'home'
  })
  export default class ConsultantLogin extends Vue {
    @roleStorage.Mutation storageIdToken!: (token: string) => void;
    @roleStorage.Mutation storageRole!: (role: string) => void;
    @roleStorage.Mutation storageConsultantId!:(id:string) => void;
    @roleStorage.Mutation
    storageIdToken!: (token: string) => void;
    @roleStorage.Mutation
    storageRole!: (role: string) => void;
    @roleStorage.Mutation
    storageConsultantId!:(id:string) => void;
    @loginStore.Action
    getLoginConsultantDetail!: (agentNo: string) => Promise<AgentInfo>;
    consultantDto = {
      password: '',
      username: '',
    };
    imgSrc = '';
    isRememberUserName = false;
    isShowPassword = false;
    imgSrc = '';
    verificationCode='';
    consultantDto = {
      username: '',
      password: '',
    }
    get isAlreadyDone():boolean{
      return !!(this.verificationCode && this.consultantDto.username && this.consultantDto.password);
    }
    ////////////////////////////////////////////////////////////////////
    mounted() {
      this.getInitUserName();
@@ -96,8 +106,11 @@
      }
    }
    ////////////////////////////////////////////////////////////////////
    public regenerateImgOfVerification(): void {
      getImgOfVerification().then( imgOfBase64 =>
      loginService.getImgOfVerification().then( imgOfBase64 =>
        this.imgSrc = imgOfBase64
      );
    };
@@ -108,23 +121,33 @@
    }
    public sendInfo():void{
      this.isAlreadyDone ? this.verify() : ErrorMessageBox('請確認帳號、密碼以及驗證碼是否填寫完畢');
      this.isAlreadyDone
        ? this.verify()
        : messageBoxService.showErrorMessage('請確認帳號、密碼以及驗證碼是否填寫完畢');
    }
    get isAlreadyDone():boolean{
      return !!(this.verificationCode && this.consultantDto.username && this.consultantDto.password);
    }
    ////////////////////////////////////////////////////////////////////
    private verify():void{
      getVerificationStatus(this.verificationCode).then( verifySuccess => {
      loginService.getVerificationStatus(this.verificationCode).then( verifySuccess => {
        if(verifySuccess.data){
          this.loginWithConsultant()
          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.getLoginConsultantDetail(this.consultantDto.username);
        this.storageIdToken(res.data.id_token);
        this.storageRole(Role.ADMIN);
        this.storageConsultantId(this.consultantDto.username)
@@ -140,11 +163,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;
      }
    }