From 76c1ce3c2eb001560bfb785f7b2f62d4ec64dcb6 Mon Sep 17 00:00:00 2001 From: Mila <Mila@pollex.com.tw> Date: 星期五, 10 十二月 2021 09:49:50 +0800 Subject: [PATCH] update 使用 currentRole 判斷目前是否為顧問/客戶登入狀態 --- /dev/null | 3 --- PAMapp/components/BackActionBar.vue | 5 ++--- PAMapp/components/Consultant/ConsultantCard.vue | 10 ++++++---- PAMapp/store/index.ts | 11 +++++------ PAMapp/pages/questionnaire/_agentNo.vue | 14 ++++++++------ PAMapp/pages/myConsultantList/consultantList.vue | 3 +-- PAMapp/components/Consultant/ConsultantList.vue | 9 ++++++--- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/PAMapp/assets/ts/auth.ts b/PAMapp/assets/ts/auth.ts deleted file mode 100644 index fa81eeb..0000000 --- a/PAMapp/assets/ts/auth.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function isLogin() { - return !!localStorage.getItem('id_token') -} \ No newline at end of file diff --git a/PAMapp/components/BackActionBar.vue b/PAMapp/components/BackActionBar.vue index ea00720..83d03bb 100644 --- a/PAMapp/components/BackActionBar.vue +++ b/PAMapp/components/BackActionBar.vue @@ -7,11 +7,10 @@ </template> <script lang="ts"> -import { namespace, Watch } from 'nuxt-property-decorator'; +import { namespace } from 'nuxt-property-decorator'; import { Vue, Component,} from 'vue-property-decorator'; import { Role } from '~/assets/ts/models/enum/Role'; import * as _ from 'lodash'; -import { isLogin } from '~/assets/ts/auth'; const roleStorage = namespace('localStorage'); @Component @@ -69,7 +68,7 @@ } set label(value) { - this.questionnaireState = value === '�脰����' ? isLogin() : true; + this.questionnaireState = value === '�脰����' ? this.currentRole === Role.USER : true; } } </script> diff --git a/PAMapp/components/Consultant/ConsultantCard.vue b/PAMapp/components/Consultant/ConsultantCard.vue index b983b50..2e7937e 100644 --- a/PAMapp/components/Consultant/ConsultantCard.vue +++ b/PAMapp/components/Consultant/ConsultantCard.vue @@ -122,13 +122,13 @@ </template> <script lang="ts"> -import { Vue, Component, Prop, Action } from 'nuxt-property-decorator'; +import { Vue, Component, Prop, Action, namespace } from 'nuxt-property-decorator'; import { getAppointmentDetail, UserReviewsConsultantsParams, userReviewsConsultants, cancelAppointment } from '~/assets/ts/api/consultant'; import { Consultant, Appointment } from '~/assets/ts/models/consultant.model'; -import { isLogin } from '~/assets/ts/auth'; import { isMobileDevice } from '~/assets/ts/device'; +import { Role } from '~/assets/ts/models/enum/Role'; - +const roleStorage = namespace('localStorage'); @Component({ filters: { formatNumber(index: number) { @@ -152,6 +152,8 @@ @Action removeFromMyConsultantList!: (agentNo: string) => Promise<boolean>; @Action storeConsultantList!: any; @Prop() agentInfo!: Consultant; + @roleStorage.Getter currentRole!:string; + isVisibleDialog = false; reviewsBtn = false; status = false; @@ -246,7 +248,7 @@ reserveCommunication() { const contactStatus = this.agentInfo.contactStatus; if (!contactStatus || contactStatus === 'picked') { - isLogin() + this.currentRole === Role.USER ? this.$router.push(`/questionnaire/${this.agentInfo.agentNo}`) : this.$router.push('/login'); } else { diff --git a/PAMapp/components/Consultant/ConsultantList.vue b/PAMapp/components/Consultant/ConsultantList.vue index 90bd709..1a1b3fb 100644 --- a/PAMapp/components/Consultant/ConsultantList.vue +++ b/PAMapp/components/Consultant/ConsultantList.vue @@ -23,16 +23,19 @@ </template> <script lang="ts"> -import { Vue, Component, Prop } from 'nuxt-property-decorator'; +import { Vue, Component, Prop, namespace } from 'nuxt-property-decorator'; import { Consultant } from '~/assets/ts/models/consultant.model'; -import { isLogin } from '~/assets/ts/auth'; +import { Role } from '~/assets/ts/models/enum/Role'; + +const roleStorage = namespace('localStorage'); @Component export default class ConsultantList extends Vue { @Prop() agents!: Consultant[]; + @roleStorage.Getter currentRole!:string; get isLogin() { - return isLogin(); + return this.currentRole === Role.USER; } get agentList(){ return this.agents.map((agentDto)=> diff --git a/PAMapp/pages/myConsultantList/consultantList.vue b/PAMapp/pages/myConsultantList/consultantList.vue index b1b0a5c..356baeb 100644 --- a/PAMapp/pages/myConsultantList/consultantList.vue +++ b/PAMapp/pages/myConsultantList/consultantList.vue @@ -12,14 +12,13 @@ </template> <script lang="ts"> -import { Vue, Component, Prop, Getter } from 'nuxt-property-decorator'; +import { Vue, Component, Prop } from 'nuxt-property-decorator'; import { Consultant } from '~/assets/ts/models/consultant.model'; @Component export default class ConsultantPage extends Vue { @Prop() consultantList!: Consultant[]; - @Getter isLogin!: boolean; pageList: Consultant[] = []; changePage(pageList: Consultant[]) { diff --git a/PAMapp/pages/questionnaire/_agentNo.vue b/PAMapp/pages/questionnaire/_agentNo.vue index d792506..402e190 100644 --- a/PAMapp/pages/questionnaire/_agentNo.vue +++ b/PAMapp/pages/questionnaire/_agentNo.vue @@ -136,19 +136,21 @@ </template> <script lang="ts"> -import { Vue, Component, State, Action, Watch } from 'nuxt-property-decorator'; +import { Vue, Component, State, Action, Watch, namespace } from 'nuxt-property-decorator'; import { addFavoriteConsultant, appointmentDemand, AppointmentParams, AppointmentRequests ,editAppointment,RegisterInfo } from '~/assets/ts/api/consultant'; import { getRequestQuestionFromStorage, getRequestsFromStorage, removeRequestQuestionFromStorage, setRequestsToStorage } from '~/assets/ts/storageRequests'; import _ from 'lodash'; -import { isLogin } from '~/assets/ts/auth'; import { Consultant } from '~/assets/ts/models/consultant.model'; import { ContactType } from '~/assets/ts/models/enum/ContactType'; import { Gender } from '~/assets/ts/models/enum/Gender'; +import { Role } from '~/assets/ts/models/enum/Role'; + const roleStorage = namespace('localStorage'); @Component export default class Questionnaire extends Vue { @State('myConsultantList') myConsultantList!: Consultant[]; @Action storeConsultantList!: () => Promise<number>; + @roleStorage.Getter currentRole!:string; genderOptions=[ { @@ -270,19 +272,19 @@ beforeRouteEnter(to: any, from: any, next: any) { next(vm => { - if (from.name === 'login' && !isLogin()) { + if (from.name === 'login' && !vm.isLogin) { vm.$router.go(-1); return; } - if (!isLogin()) { + if (!vm.isLogin) { vm.$router.push('/login'); } }) } async fetch() { - if (isLogin()) { + if (this.isLogin) { await this.storeConsultantList(); }; } @@ -335,7 +337,7 @@ } get isLogin() { - return isLogin(); + return this.currentRole === Role.USER; } private isHopeContactTimeDone():boolean{ diff --git a/PAMapp/store/index.ts b/PAMapp/store/index.ts index 6e91e76..7b8173f 100644 --- a/PAMapp/store/index.ts +++ b/PAMapp/store/index.ts @@ -1,11 +1,10 @@ import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators' -import { ClientInfo, getMyAppointmentList, getMyReviewLog, allAppointmentsView } from '~/assets/ts/api/appointment'; -// import * as consultant from '~/assets/ts/api/consultant'; +import { ClientInfo, getMyAppointmentList, getMyReviewLog } from '~/assets/ts/api/appointment'; import { recommend, AgentOfStrictQuery, getFavoriteConsultant, addFavoriteConsultant, deleteConsultant, strictQuery } from '~/assets/ts/api/consultant'; import { Consultant } from '~/assets/ts/models/consultant.model'; -import { isLogin } from '~/assets/ts/auth'; import { AppointmentLog } from '~/assets/ts/models/appointment.model'; import { getFavoriteFromStorage, setFavoriteToStorage } from '~/assets/ts/storageConsultant'; +import { Role } from '~/assets/ts/models/enum/Role'; @Module export default class Store extends VuexModule { @@ -46,7 +45,7 @@ @Action async storeConsultantList() { const localData = getFavoriteFromStorage(); - if (!isLogin()) { + if (this.context.getters['localStorage/currentRole'] !== Role.USER) { this.context.commit('updateConsultantList', localData) return; }; @@ -71,7 +70,7 @@ // no agent was removed if (left.length === this.myConsultantList.length) return false; - if (!isLogin()) { + if (this.context.getters['localStorage/currentRole'] !== Role.USER) { setFavoriteToStorage(left); } else { await deleteConsultant(agentNo) @@ -89,7 +88,7 @@ if (!found) { const newData = [consultantToAdd].concat(this.myConsultantList); - if (isLogin()) { + if (this.context.getters['localStorage/currentRole'] === Role.USER) { await addFavoriteConsultant([consultantToAdd.agentNo]) } else { setFavoriteToStorage(newData); -- Gitblit v1.8.0