保誠-保戶業務員媒合平台
Tomas
2021-12-22 724f4c529a8ee3fa0a4f24d0fe55f79b70181a25
add: auth.service
修改3個檔案
新增1個檔案
62 ■■■■ 已變更過的檔案
PAMapp/components/Consultant/ConsultantList.vue 22 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
PAMapp/pages/questionnaire/_agentNo.vue 9 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
PAMapp/shared/services/auth.service.ts 16 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
PAMapp/shared/services/login.service.ts 15 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
PAMapp/components/Consultant/ConsultantList.vue
@@ -23,16 +23,20 @@
</template>
<script lang="ts">
import { Vue, Component, Prop, namespace } from 'nuxt-property-decorator';
import { Consultant } from '~/shared/models/consultant.model';
import { Vue, Component, Prop } from 'nuxt-property-decorator';
const roleStorage = namespace('localStorage');
import authService from '~/shared/services/auth.service';
import { Consultant } from '~/shared/models/consultant.model';
@Component
export default class ConsultantList extends Vue {
    @Prop() agents!: Consultant[];
    @Prop() title! : string;
    @roleStorage.Getter isUserLogin!:boolean;
    @Prop()
    agents!: Consultant[];
    @Prop()
    title! : string;
    isUserLogin = false;
    get agentList(){
        return this.agents.map((agentDto)=>
@@ -46,6 +50,12 @@
                          : '您目前無已選顧問';
    }
    //////////////////////////////////////////////////////////////////////
    mounted() {
      this.isUserLogin = authService.isUserLogin();
    }
}
</script>
PAMapp/pages/questionnaire/_agentNo.vue
@@ -143,8 +143,9 @@
import { getRequestsFromStorage, removeRequestQuestionFromStorage, setRequestsToStorage } from '~/shared/storageRequests';
import _ from 'lodash';
import queryConsultantService from '~/shared/services/query-consultant.service';
import appointmentService from '~/shared/services/appointment.service';
import authService from '~/shared/services/auth.service';
import queryConsultantService from '~/shared/services/query-consultant.service';
import { Consultant } from '~/shared/models/consultant.model';
import { ContactType } from '~/shared/models/enum/ContactType';
import { Gender } from '~/shared/models/enum/Gender';
@@ -280,7 +281,7 @@
    beforeRouteEnter(to: any, from: any, next: any) {
      next(vm => {
        const isUserLogin = vm.$store.getters['localStorage/isUserLogin'];
        const isUserLogin = authService.isUserLogin();
        if (from.name === 'login' && !isUserLogin) {
          vm.$router.go(-1);
          return;
@@ -293,7 +294,7 @@
    }
    async fetch() {
      if (this.isUserLogin) {
      if (authService.isUserLogin()) {
        await this.storeConsultantList();
      };
    }
@@ -451,7 +452,7 @@
                  : appointmentInfo.appointmentDate;
    }
    @Watch('myConsultantList') onMyConsultantListChange() {
      if (this.isUserLogin && this.myConsultantList.length > 0) {
      if (authService.isUserLogin() && this.myConsultantList.length > 0) {
          const editAppointment = this.getLatestReserved(this.$route.params.agentNo);
          if (editAppointment && editAppointment.agentNo) {
PAMapp/shared/services/auth.service.ts
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,16 @@
import { Role } from "../models/enum/role";
class AuthService {
  private idToken = localStorage.getItem('id_token');
  private currentRole = localStorage.getItem('current_role');
  isAdminLogin(): boolean {
    return this.currentRole === Role.ADMIN;
  }
  isUserLogin(): boolean {
    return this.currentRole === Role.USER;
  }
}
export default new AuthService();
PAMapp/shared/services/login.service.ts
@@ -1,31 +1,32 @@
import { http } from "./httpClient";
import { AxiosResponse } from 'axios';
import _ from "lodash";
import { ConsultantLoginInfo } from "../models/ConsultantLoginInfo";
import { LoginRequest } from "../models/loginRequest.model";
import { LoginSuccessToken } from "../models/loginSuccessToken.model";
import { LoginVerify } from "../models/loginVerify.model";
import { OtpInfo } from "../models/otpInfo.model";
import { RegisterInfo } from "../models/registerInfo";
import { http } from "./httpClient";
import { AxiosResponse } from 'axios';
import _ from "lodash";
class LoginService {
    /** é¡§å®¢ç™»å…¥-發送OTP **/
  sendOtp(loginInfo: LoginRequest):Promise<OtpInfo> {
  async sendOtp(loginInfo: LoginRequest):Promise<OtpInfo> {
    return http.post('/otp/sendOtp', loginInfo).then( res => res.data );
  }
  /** é¡§å®¢ç™»å…¥-驗證OTP **/
  loginVerify(loginVerify: LoginVerify):Promise<LoginSuccessToken>{
  async loginVerify(loginVerify: LoginVerify):Promise<LoginSuccessToken>{
    return http.post('/otp/verify', loginVerify).then(res => res.data);
  }
  /** é¡§å®¢è¨»å†Š **/
  register(registerInfo: RegisterInfo):Promise<LoginSuccessToken>{
  async register(registerInfo: RegisterInfo):Promise<LoginSuccessToken>{
    return http.post('/otp/register', registerInfo).then(res => res.data);
  }
  /** å–得驗證碼圖片 **/
  getImgOfVerification():Promise<string>{
  async getImgOfVerification():Promise<string>{
    return http.get('/login/validate/get_img_code',{ responseType : 'arraybuffer' })
      .then( response => {
        const toBase64 = window.btoa(