From 544f91e63a01f37e7b79db99609eec99b1afafd9 Mon Sep 17 00:00:00 2001 From: Mila <Mila@pollex.com.tw> Date: 星期一, 13 十二月 2021 11:07:31 +0800 Subject: [PATCH] fixed: 使用 isUserLogin / isAdminLogin 判斷顧問/客戶是否登入 --- PAMapp/components/BackActionBar.vue | 6 -- PAMapp/store/index.ts | 12 ++++-- PAMapp/pages/questionnaire/_agentNo.vue | 17 +++----- PAMapp/store/localStorage.ts | 9 ++++ PAMapp/components/Consultant/ConsultantList.vue | 9 +--- PAMapp/middleware/myAppointmentMiddleware.ts | 4 +- PAMapp/middleware/errorRouteMiddleware.ts | 4 +- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/PAMapp/components/BackActionBar.vue b/PAMapp/components/BackActionBar.vue index 83d03bb..11cfcaf 100644 --- a/PAMapp/components/BackActionBar.vue +++ b/PAMapp/components/BackActionBar.vue @@ -1,6 +1,6 @@ <template> <nav class="pam-back-action-bar fix-chrome-click--issue"> - <a @click="pushRouterByLoginRole" v-if="questionnaireState"> + <a @click="pushRouterByLoginRole"> <i class="icon-left "></i>{{ label }} </a> </nav> @@ -16,7 +16,6 @@ @Component export default class UiCarousel extends Vue { @roleStorage.Getter currentRole!:string; - questionnaireState: boolean = true; get label(): string { if (this.$route.name) { const routeName = this.$route.name.split('-')[0]; @@ -67,9 +66,6 @@ pathName?.includes('myConsultantList') ? this.$router.push('/') : this.$router.go(-1); } - set label(value) { - this.questionnaireState = value === '�脰����' ? this.currentRole === Role.USER : true; - } } </script> diff --git a/PAMapp/components/Consultant/ConsultantList.vue b/PAMapp/components/Consultant/ConsultantList.vue index 1a1b3fb..57c8e06 100644 --- a/PAMapp/components/Consultant/ConsultantList.vue +++ b/PAMapp/components/Consultant/ConsultantList.vue @@ -8,12 +8,12 @@ :agentInfo="agent" ></ConsultantCard> </template> - <template v-if="isLogin && agentList.length === 0"> + <template v-if="isUserLogin && agentList.length === 0"> <div class="emptyRowStyle"> <div class="smTxt txt">����撌脤憿批��</div> </div> </template> - <template v-if="!isLogin"> + <template v-if="!isUserLogin"> <div class="emptyRowStyle"> <div class="mdTxt login fix-chrome-click--issue" @click="$router.push('/login')">�� | 閮餃��</div> <div class="smTxt txt ">���憭�</div> @@ -32,11 +32,8 @@ @Component export default class ConsultantList extends Vue { @Prop() agents!: Consultant[]; - @roleStorage.Getter currentRole!:string; + @roleStorage.Getter isUserLogin!:boolean; - get isLogin() { - return this.currentRole === Role.USER; - } get agentList(){ return this.agents.map((agentDto)=> ({...agentDto,customerScore:0,}) diff --git a/PAMapp/middleware/errorRouteMiddleware.ts b/PAMapp/middleware/errorRouteMiddleware.ts index 5cf1133..fa4d199 100644 --- a/PAMapp/middleware/errorRouteMiddleware.ts +++ b/PAMapp/middleware/errorRouteMiddleware.ts @@ -1,9 +1,9 @@ import { Middleware } from '@nuxt/types'; -import { Role } from '~/assets/ts/models/enum/Role'; const errorRouteMiddleware: Middleware = (context) => { if (!context.route.name) { - if (context.store.getters['localStorage/currentRole'] === Role.ADMIN) { + const isAdminLogin = context.store.getters['localStorage/isAdminLogin']; + if (isAdminLogin) { context.redirect('/myAppointmentList/appointmentList'); return; } diff --git a/PAMapp/middleware/myAppointmentMiddleware.ts b/PAMapp/middleware/myAppointmentMiddleware.ts index eab3b12..a8dd473 100644 --- a/PAMapp/middleware/myAppointmentMiddleware.ts +++ b/PAMapp/middleware/myAppointmentMiddleware.ts @@ -1,8 +1,8 @@ import { Middleware } from '@nuxt/types'; -import { Role } from '~/assets/ts/models/enum/Role'; const myAppointmentMiddleware: Middleware = (context) => { - if (context.store.getters['localStorage/currentRole'] === Role.ADMIN) { + const isAdminLogin = context.store.getters['localStorage/isAdminLogin']; + if (isAdminLogin) { if (context.route.name === 'myAppointmentList') { context.redirect('/myAppointmentList/appointmentList') } diff --git a/PAMapp/pages/questionnaire/_agentNo.vue b/PAMapp/pages/questionnaire/_agentNo.vue index 402e190..1ed02c8 100644 --- a/PAMapp/pages/questionnaire/_agentNo.vue +++ b/PAMapp/pages/questionnaire/_agentNo.vue @@ -1,5 +1,5 @@ <template> - <div class="ques-page--reset" v-if="isLogin"> + <div class="ques-page--reset" v-if="isUserLogin"> <div class="ques-header"> <div class="ques-header__mob-banner"></div> <div @@ -150,7 +150,7 @@ export default class Questionnaire extends Vue { @State('myConsultantList') myConsultantList!: Consultant[]; @Action storeConsultantList!: () => Promise<number>; - @roleStorage.Getter currentRole!:string; + @roleStorage.Getter isUserLogin!:boolean; genderOptions=[ { @@ -272,19 +272,20 @@ beforeRouteEnter(to: any, from: any, next: any) { next(vm => { - if (from.name === 'login' && !vm.isLogin) { + const isUserLogin = vm.$store.getters['localStorage/isUserLogin']; + if (from.name === 'login' && !isUserLogin) { vm.$router.go(-1); return; } - if (!vm.isLogin) { + if (!isUserLogin) { vm.$router.push('/login'); } }) } async fetch() { - if (this.isLogin) { + if (this.isUserLogin) { await this.storeConsultantList(); }; } @@ -334,10 +335,6 @@ return _.includes(this.myRequest.contactType,ContactType.PHONE) ? !this.isHopeContactTimeDone() : !this.phoneValid; - } - - get isLogin() { - return this.currentRole === Role.USER; } private isHopeContactTimeDone():boolean{ @@ -450,7 +447,7 @@ } @Watch('myConsultantList') onMyConsultantListChange() { - if (this.isLogin && this.myConsultantList.length > 0) { + if (this.isUserLogin && this.myConsultantList.length > 0) { const editAppointment = this.getLatestReserved(this.$route.params.agentNo); if (editAppointment.agentNo) { diff --git a/PAMapp/store/index.ts b/PAMapp/store/index.ts index 7b8173f..b26be7e 100644 --- a/PAMapp/store/index.ts +++ b/PAMapp/store/index.ts @@ -16,6 +16,10 @@ myAppointmentReviewLogList: AppointmentLog[] = []; + get isUserLogin() { + return this.context.getters['localStorage/isUserLogin']; + } + @Mutation updateRecommend(data: Consultant[]) { this.recommendList = data; } @@ -45,7 +49,8 @@ @Action async storeConsultantList() { const localData = getFavoriteFromStorage(); - if (this.context.getters['localStorage/currentRole'] !== Role.USER) { + + if (!this.isUserLogin) { this.context.commit('updateConsultantList', localData) return; }; @@ -70,7 +75,7 @@ // no agent was removed if (left.length === this.myConsultantList.length) return false; - if (this.context.getters['localStorage/currentRole'] !== Role.USER) { + if (!this.isUserLogin) { setFavoriteToStorage(left); } else { await deleteConsultant(agentNo) @@ -87,8 +92,7 @@ const found = this.myConsultantList.find(item => item.agentNo === consultantToAdd.agentNo); if (!found) { const newData = [consultantToAdd].concat(this.myConsultantList); - - if (this.context.getters['localStorage/currentRole'] === Role.USER) { + if (this.isUserLogin) { await addFavoriteConsultant([consultantToAdd.agentNo]) } else { setFavoriteToStorage(newData); diff --git a/PAMapp/store/localStorage.ts b/PAMapp/store/localStorage.ts index d93aa2c..84f5bb0 100644 --- a/PAMapp/store/localStorage.ts +++ b/PAMapp/store/localStorage.ts @@ -1,5 +1,6 @@ import { Selected } from '~/components/QuickFilter/QuickFilterSelector.vue'; import { Module, Mutation, VuexModule ,Action } from 'vuex-module-decorators'; +import { Role } from '~/assets/ts/models/enum/Role'; @Module export default class LocalStorage extends VuexModule { id_token = localStorage.getItem('id_token'); @@ -24,6 +25,14 @@ return JSON.parse(this.quickFilterSelectedItem || '[]') as Selected[]; } + get isAdminLogin(): boolean { + return this.currentRole === Role.ADMIN; + } + + get isUserLogin(): boolean { + return this.currentRole === Role.USER; + } + @Mutation storageIdToken(token: string): void { -- Gitblit v1.8.0