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 |  257 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 182 insertions(+), 75 deletions(-)

diff --git a/PAMapp/pages/consultantLogin/index.vue b/PAMapp/pages/consultantLogin/index.vue
index c131841..3a90f3f 100644
--- a/PAMapp/pages/consultantLogin/index.vue
+++ b/PAMapp/pages/consultantLogin/index.vue
@@ -1,118 +1,210 @@
 <template>
-    <div>
-      <div class="pam-consultant-login">
-        <div class="pam-consultant-login__header mt-30">憿批��</div>
-        <div class="pam-consultant-login__title mt-30">撣唾��</div>
+  <div>
+    <div class="pam-consultant-login">
+      <div class="pam-consultant-login__header pam-paragraph">憿批��</div>
+      <div class="pam-paragraph">
+        <div class="pam-consultant-login__title">撣唾��</div>
         <div class="position-r mt-10">
           <input type="text"
-            :model="loginDto.account"
+            v-model="consultantDto.username"
             class="pam-consultant-login__input"
             placeholder="頛詨eService撣唾��">
-          <div class="pam-consultant-login__inputIcon text--primary cursor--pointer" @click="cookieAccount">
-              <i :class="[isRemember ? 'icon-checkbox-1' : 'icon-checkbox','pr-5']"></i>
-              閮��
+          <div class="pam-consultant-login__inputIcon text--primary cursor--pointer fix-chrome-click--issue"
+            @click="isRememberChange">
+            <i :class="[isRememberUserName ? 'icon-checkbox-1' : 'icon-checkbox','pr-5']"></i>
+            閮��
           </div>
         </div>
-        <div class="pam-consultant-login__title mt-30">
-           <div>撖Ⅳ</div>
-           <div class="text--primary fs-16 cursor--pointer" @click="forgetPassword">敹��Ⅳ嚗�</div>
-         </div>
+      </div>
+      <div class="pam-paragraph">
+        <div class="pam-consultant-login__title ">撖Ⅳ</div>
         <div class="position-r mt-10">
-          <input :type="[isShowPassword ? 'text' : 'password']"
-            :model="loginDto.password"
+          <input :type="[ isShowPassword ? 'text' : 'password']"
+            v-model="consultantDto.password"
             class="pam-consultant-login__input"
             placeholder="頛詨eService撖Ⅳ">
-          <div class="pam-consultant-login__inputIcon cursor--pointer" @click="isShowPassword = !isShowPassword">
-            <i :class="[isShowPassword ? 'icon-eye-1 fs-25' : 'icon-eye' , 'text--primary']"></i>
+          <div class="pam-consultant-login__inputIcon cursor--pointer fix-chrome-click--issue"
+            @click="isShowPassword = !isShowPassword">
+            <i :class="[isShowPassword ? 'icon-eye':'icon-eye-1 fs-25', 'text--primary']"></i>
           </div>
         </div>
-        <div class="pam-consultant-login__title mt-30">
-           <div>撽�Ⅳ</div>
-           <div class="text--dark-blue fs-16 cursor--pointer" @click="regenerateCode">������</div>
-         </div>
+      </div>
+      <div class="pam-paragraph">
+        <div class="pam-consultant-login__title">
+          <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"
-              :modal="loginDto.verificationCode"
-              class="pam-consultant-login__input" >
+              v-model="verificationCode"
+              maxlength="4"
+              class="pam-consultant-login__input">
           </div>
-          <div class="pam-consultant-login__verifyImg"></div>
-        </div>
-        <div class="pam-consultant-login__confirmBlock mt-30">
-           <button class="pam-consultant-login__confirm cursor--pointer" @click="login">�</button>
+          <div class="pam-consultant-login__verifyImg">
+            <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="sendInfo">�</button>
+      </div>
     </div>
+  </div>
 </template>
 
 <script lang="ts">
-import { Vue, Component } from 'vue-property-decorator';
+  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'
 
-@Component({
-  layout:'home'
-})
-export default class ConsultantLogin extends Vue {
-  isRemember=false;
-  isShowPassword=false;
-  loginDto={
-    account:'',
-    password:'',
-    verificationCode:'',
-  }
-
-
-  login():void{
-    console.log('login');
-  }
-
-  cookieAccount():void{
-    this.isRemember = !this.isRemember;
-    if(this.isRemember){
-      console.log('sotre account');
+  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;
+    isRememberUserName = false;
+    isShowPassword = false;
+    imgSrc = '';
+    verificationCode='';
+    consultantDto = {
+      username: '',
+      password: '',
     }
-  }
 
-  forgetPassword():void{
-    console.log('forget password');
-  }
+    ////////////////////////////////////////////////////////////////////
+    mounted() {
+      this.getInitUserName();
+      this.regenerateImgOfVerification();
+    };
 
-  regenerateCode():void{
-    console.log('call api regenerate verificationCode')
-  }
-}
+    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.isRememberUserName = true;
+      }
+    }
+
+    private verify():void{
+      loginService.getVerificationStatus(this.verificationCode).then( verifySuccess => {
+        if(verifySuccess.data){
+          this.loginWithConsultant()
+        }else{
+          this.clearValue();
+          this.regenerateImgOfVerification();
+          ErrorMessageBox('撽�Ⅳ頛詨�隤�');
+        }
+      });
+    }
+
+    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>
-  .mt-20{
+  .mt-20 {
     margin-top: 20px;
   }
-  .mt-25{
+
+  .mt-25 {
     margin-top: 25px;
   }
-  .w-55{
+
+  .w-55 {
     width: 55% !important;
   }
-  .position-r{
+
+  .position-r {
     position: relative;
   }
-  .pam-consultant-login{
+
+  .pam-consultant-login {
+    margin: auto;
     width: 336px;
-    margin: 40px auto 30px auto;
     font-size: 20px;
     color: $PRIMARY_BLACK;
-    &__header{
+
+    &__header {
       text-align: center;
       font-size: 24px;
       font-weight: bold;
       letter-spacing: 1.2;
       color: $PRIMARY_BLACK;
     }
-    &__title{
-      display:flex;
+
+    &__title {
+      display: flex;
       justify-content: space-between;
       align-items: center;
-      padding: 0px 10px;
     }
-    &__input{
+
+    &__input {
       width: 100%;
       outline: 0;
       border: 1px solid #CCCCCC;
@@ -125,7 +217,7 @@
       -webkit-box-sizing: border-box;
       -moz-box-sizing: border-box;
 
-      &Icon{
+      &Icon {
         position: absolute;
         display: flex;
         align-items: center;
@@ -133,25 +225,40 @@
         right: 15px;
       }
     }
-    &__verifyBlock{
+
+    &__forgot-password {
+      color: $PRIMARY_RED;
+      text-decoration: none;
+      font-size: 16px;
+    }
+
+    &__verifyBlock {
       display: flex;
       justify-content: space-between;
     }
-    &__verifyImg{
-      width:126px;
-      border:1px black solid;
+
+    &__verifyImg {
+      width: 126px;
+      height: 50px;
+      border:1px #cccccc solid;
+      img {
+        width: 100%;
+        height: 100%;
+      }
     }
-    &__confirmBlock{
+
+    &__confirmBlock {
       display: flex;
       justify-content: center;
     }
-    &__confirm{
+
+    &__confirm {
       color: $PRIMARY_WHITE;
       width: 80px;
       height: 50px;
       border-radius: 30px;
       border: 1px solid $LIGHT_GREY;
-      background-color:$PRIMARY_RED;
+      background-color: $PRIMARY_RED;
     }
   }
 

--
Gitblit v1.8.0