114 lines
2.9 KiB
Vue
114 lines
2.9 KiB
Vue
<!--
|
||||
|
|
«در حال مشاهده بهعنوان …» — shown while a sales expert is working inside one
|
|||
|
|
of their customers' accounts. Same logic as user-app's copy; the colours are
|
|||
|
|
this app's own.
|
|||
|
|
|
|||
|
|
NOT in the reference, and added on purpose. There, impersonation was invisible
|
|||
|
|
once the token had been swapped (myDataStore.ts:163): the only way an expert
|
|||
|
|
could tell whose account they were in was to notice the data looked wrong.
|
|||
|
|
Placing an order on the wrong customer's account — their gold debt, their
|
|||
|
|
ledger — was a single tap away with nothing to catch it.
|
|||
|
|
|
|||
|
|
It is also the exit. The reference's only way out was the logout button, which
|
|||
|
|
dropped the expert's own session too (Dashboard.vue:781-789).
|
|||
|
|
-->
|
|||
|
|
<template>
|
|||
|
|
<div v-if="session.actingAs" class="aab" role="status">
|
|||
|
|
<span class="aab__dot" aria-hidden="true" />
|
|||
|
|
<span class="aab__text">
|
|||
|
|
در حال مشاهده بهعنوان <strong>{{ session.actingAs.name || 'مشتری' }}</strong>
|
|||
|
|
</span>
|
|||
|
|
<button type="button" class="aab__exit" :disabled="leaving" @click="leave">
|
|||
|
|
{{ leaving ? '…' : 'خروج' }}
|
|||
|
|
</button>
|
|||
|
|
</div>
|
|||
|
|
</template>
|
|||
|
|
|
|||
|
|
<script setup lang="ts">
|
|||
|
|
import { ref } from 'vue'
|
|||
|
|
import { useRouter } from 'vue-router'
|
|||
|
|
import { useSessionStore } from '../../stores/session'
|
|||
|
|
import { useCartStore } from '../../stores/cartStore'
|
|||
|
|
import { toast } from '../../composables/useToast'
|
|||
|
|
|
|||
|
|
const session = useSessionStore()
|
|||
|
|
const cart = useCartStore()
|
|||
|
|
const router = useRouter()
|
|||
|
|
const leaving = ref(false)
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Back to the expert's own account. The cart is cleared in this direction too:
|
|||
|
|
* a basket built inside the customer's account must not follow the expert out
|
|||
|
|
* and land on their own order.
|
|||
|
|
*/
|
|||
|
|
async function leave() {
|
|||
|
|
leaving.value = true
|
|||
|
|
try {
|
|||
|
|
cart.clear()
|
|||
|
|
session.setActingAs(null)
|
|||
|
|
await router.push({ name: 'home' })
|
|||
|
|
toast.info('به حساب خودتان بازگشتید')
|
|||
|
|
} finally {
|
|||
|
|
leaving.value = false
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
</script>
|
|||
|
|
|
|||
|
|
<style scoped lang="less">
|
|||
|
|
.aab {
|
|||
|
|
position: fixed;
|
|||
|
|
top: 0;
|
|||
|
|
left: 0;
|
|||
|
|
right: 0;
|
|||
|
|
z-index: 2000;
|
|||
|
|
display: flex;
|
|||
|
|
align-items: center;
|
|||
|
|
gap: 8px;
|
|||
|
|
padding: 7px 16px;
|
|||
|
|
/* Deliberately not a brand colour: this is a warning strip, and it has to be
|
|||
|
|
noticeable at a glance to do its job. */
|
|||
|
|
background: #8d6a46;
|
|||
|
|
color: #fff;
|
|||
|
|
font-size: 12px;
|
|||
|
|
font-weight: 600;
|
|||
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.aab__dot {
|
|||
|
|
width: 8px;
|
|||
|
|
height: 8px;
|
|||
|
|
border-radius: 50%;
|
|||
|
|
background: #ffd9a0;
|
|||
|
|
flex: 0 0 auto;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.aab__text {
|
|||
|
|
flex: 1 1 auto;
|
|||
|
|
overflow: hidden;
|
|||
|
|
text-overflow: ellipsis;
|
|||
|
|
white-space: nowrap;
|
|||
|
|
|
|||
|
|
strong {
|
|||
|
|
font-weight: 800;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.aab__exit {
|
|||
|
|
flex: 0 0 auto;
|
|||
|
|
border: 1px solid rgba(255, 255, 255, 0.55);
|
|||
|
|
background: transparent;
|
|||
|
|
color: #fff;
|
|||
|
|
border-radius: 8px;
|
|||
|
|
padding: 3px 12px;
|
|||
|
|
font-family: inherit;
|
|||
|
|
font-size: 12px;
|
|||
|
|
font-weight: 700;
|
|||
|
|
cursor: pointer;
|
|||
|
|
|
|||
|
|
&:disabled {
|
|||
|
|
opacity: 0.6;
|
|||
|
|
cursor: default;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
</style>
|