From c5219a512b54562182c66d4501b258fb94d38e32 Mon Sep 17 00:00:00 2001
From: HelenHuang <LinHuang@pollex.com.tw>
Date: 星期四, 31 三月 2022 10:55:53 +0800
Subject: [PATCH] Update: 預設錯誤訊息改從title取

---
 PAMapp/pages/consultantLogin/index.vue |   74 +++++++++++++++++++++++++-----------
 1 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/PAMapp/pages/consultantLogin/index.vue b/PAMapp/pages/consultantLogin/index.vue
index f4bc4df..e098605 100644
--- a/PAMapp/pages/consultantLogin/index.vue
+++ b/PAMapp/pages/consultantLogin/index.vue
@@ -31,8 +31,8 @@
       </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"
+          <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">
@@ -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
+    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,24 +121,36 @@
     }
 
     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();
-          ErrorMessageBox('撽�Ⅳ頛詨�隤�');
+          this.regenerateImgOfVerification();
+          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)
         this.storeUserName();
         this.$router.push('/myAppointmentList/appointmentList');
       }).catch((error:AxiosError)=>{
@@ -134,13 +159,16 @@
     }
     private checkHttpErrorStatus(error:any):void{
       this.clearValue();
+      this.regenerateImgOfVerification();
       switch (error.response.status) {
         case 401:
           const errorMsg = error.response.data.detail;
-          ErrorMessageBox(errorMsg);
+          messageBoxService.showErrorMessage(errorMsg);
           break;
+
         default:
-          ErrorMessageBox();
+          const defaultErrorMsg = error.response.data.title
+          messageBoxService.showErrorMessage('',defaultErrorMsg);
           break;
       }
     }

--
Gitblit v1.8.0