feat: show role
This commit is contained in:
parent
d453f0ba3e
commit
4c5d23970c
1 changed files with 39 additions and 18 deletions
|
|
@ -13,8 +13,9 @@ import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import useLoader from 'stores/loader';
|
import useLoader from 'stores/loader';
|
||||||
import DrawerComponent from 'components/DrawerComponent.vue';
|
import DrawerComponent from 'components/DrawerComponent.vue';
|
||||||
import GlobalDialog from 'components/GlobalDialog.vue';
|
|
||||||
import useUserStore from 'src/stores/user';
|
import useUserStore from 'src/stores/user';
|
||||||
|
import { Option } from 'src/stores/user/types';
|
||||||
|
import { dialog } from 'src/stores/utils';
|
||||||
|
|
||||||
interface NotificationButton {
|
interface NotificationButton {
|
||||||
item: string;
|
item: string;
|
||||||
|
|
@ -34,11 +35,12 @@ const loaderStore = useLoader();
|
||||||
|
|
||||||
const { visible } = storeToRefs(loaderStore);
|
const { visible } = storeToRefs(loaderStore);
|
||||||
const { locale } = useI18n({ useScope: 'global' });
|
const { locale } = useI18n({ useScope: 'global' });
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const logoutModal = ref(false);
|
|
||||||
const leftDrawerOpen = ref(false);
|
const leftDrawerOpen = ref(false);
|
||||||
const filterUnread = ref(false);
|
const filterUnread = ref(false);
|
||||||
const unread = ref<number>(1);
|
const unread = ref<number>(1);
|
||||||
|
const filterRole = ref<string[]>();
|
||||||
|
|
||||||
const currentLanguage = ref<string>('ไทย');
|
const currentLanguage = ref<string>('ไทย');
|
||||||
const language: {
|
const language: {
|
||||||
|
|
@ -100,21 +102,46 @@ function setActive(button: NotificationButton) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doLogout(confirm: boolean = false) {
|
function doLogout() {
|
||||||
logoutModal.value = true;
|
dialog({
|
||||||
if (confirm) {
|
icon: 'mdi-logout-variant',
|
||||||
logoutModal.value = false;
|
title: 'ยืนยันการออกจากระบบ',
|
||||||
|
persistent: true,
|
||||||
|
message: 'คุณต้องการออกจากระบบ ใช่หรือไม่',
|
||||||
|
action: async () => {
|
||||||
logout();
|
logout();
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRoleName(userRoleValue?: string[], roleOptions: Option[]) {
|
||||||
|
if (!userRoleValue || !roleOptions) return;
|
||||||
|
|
||||||
|
const matchingRole: string | undefined = roleOptions.find(
|
||||||
|
(role) => role.value === userRoleValue[0],
|
||||||
|
)?.label;
|
||||||
|
|
||||||
|
return matchingRole ? matchingRole : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const user = getUsername();
|
const user = getUsername();
|
||||||
const uid = getUserId();
|
const uid = getUserId();
|
||||||
|
|
||||||
|
const userRoles = getRole();
|
||||||
|
if (userRoles) {
|
||||||
|
console.log(userRoles);
|
||||||
|
filterRole.value = userRoles.filter(
|
||||||
|
(role) =>
|
||||||
|
role !== 'default-roles-dev' &&
|
||||||
|
role !== 'offline_access' &&
|
||||||
|
role !== 'uma_authorization',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (user === 'admin') return;
|
if (user === 'admin') return;
|
||||||
if (uid) {
|
if (uid) {
|
||||||
const res = await useUserStore().fetchById(uid);
|
const res = await userStore.fetchById(uid);
|
||||||
|
|
||||||
if (res && res.profileImageUrl) userImage.value = res.profileImageUrl;
|
if (res && res.profileImageUrl) userImage.value = res.profileImageUrl;
|
||||||
}
|
}
|
||||||
|
|
@ -260,7 +287,9 @@ onMounted(async () => {
|
||||||
{{ getName() }}
|
{{ getName() }}
|
||||||
</span>
|
</span>
|
||||||
<div style="font-size: 11px; color: var(--surface)">
|
<div style="font-size: 11px; color: var(--surface)">
|
||||||
{{ getRole()?.includes('admin') ? 'Admin' : 'User' }}
|
{{
|
||||||
|
getRoleName(filterRole, userStore.userOption.roleOpts)
|
||||||
|
}}
|
||||||
</div>
|
</div>
|
||||||
</q-item-label>
|
</q-item-label>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
|
|
@ -347,14 +376,6 @@ onMounted(async () => {
|
||||||
|
|
||||||
<drawer-component v-model:leftDrawerOpen="leftDrawerOpen" />
|
<drawer-component v-model:leftDrawerOpen="leftDrawerOpen" />
|
||||||
|
|
||||||
<GlobalDialog
|
|
||||||
v-model="logoutModal"
|
|
||||||
title="ยืนยันการออกจากระบบ"
|
|
||||||
message="คุณต้องการออกจากระบบ ใช่หรือไม่"
|
|
||||||
icon="mdi-logout-variant"
|
|
||||||
:persistent="true"
|
|
||||||
:action="() => doLogout(true)"
|
|
||||||
/>
|
|
||||||
<global-loading :visibility="visible" />
|
<global-loading :visibility="visible" />
|
||||||
</q-layout>
|
</q-layout>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue