| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <template>
- <div>
- <Button
- v-if="isSignedIn"
- class="border-none px-6! py-2.75"
- variant="text"
- aria-haspopup="true"
- aria-controls="user_menu"
- @click="toggleMenu"
- >
- <span class="font-semibold">
- {{ user.username }}
- </span>
- <Icon
- name="ph:user-circle-fill"
- size="1.25rem"
- />
- </Button>
- <Button
- v-else
- class="border-none px-6! py-2.75"
- variant="text"
- @click="showSignInDialog"
- >
- <span class="font-semibold">Sign In</span>
- <Icon
- name="ph:user-circle-light"
- size="1.25rem"
- />
- </Button>
- <Menu
- class="mt-0"
- id="user_menu"
- :model="model"
- :popup="true"
- ref="menu"
- >
- <template #item="{ item, props }">
- <!--suppress HtmlUnknownTarget -->
- <NuxtLink
- v-if="item.route"
- v-slot="{ href, navigate }"
- :to="item.route"
- custom
- >
- <a
- :href="href"
- v-bind="props.action"
- @click="navigate"
- >
- {{ item.label }}
- </a>
- </NuxtLink>
- <a
- v-else
- :href="item?.url"
- :target="item?.target"
- v-bind="props.action"
- >
- {{ item.label }}
- </a>
- </template>
- </Menu>
- </div>
- </template>
- <script setup>
- // const SignInDialog = defineLazyHydrationComponent(
- // "visible",
- // () => import("~/components/SignInDialog.vue")
- // )
- // const ChangePasswordDialog = defineLazyHydrationComponent(
- // "visible",
- // () => import("~/components/ChangePasswordDialog.vue")
- // )
- const { isSignedIn, signOut, user } = useAuthClient()
- // const dialog = useDialog()
- // const toast = useToast()
- const menu = useTemplateRef("menu")
- const model = computed(() => {
- const menu = [
- { label: "Change Password", command: showChangePasswordDialog },
- { label: "Sign Out", command: doSignOut }
- ]
- // noinspection JSUnresolvedReference
- if (isSignedIn.value && user.value.role === "admin") {
- menu.unshift({
- label: "Dashboard",
- command: async () => await navigateTo({ name: "admin:users" })
- })
- }
- return menu
- })
- async function doSignOut() {
- await signOut()
- closeMenu()
- // toast.add({
- // severity: "success",
- // summary: "Signed Out.",
- // detail: "You've been signed out.",
- // life: 3000
- // })
- }
- function toggleMenu(event) {
- menu.value.toggle(event)
- }
- function closeMenu(_) {
- menu.value.hide()
- }
- function showSignInDialog() {
- closeMenu()
- // useOpenDialog(dialog, SignInDialog)
- }
- function showChangePasswordDialog() {
- closeMenu()
- // useOpenDialog(dialog, ChangePasswordDialog)
- }
- </script>
- <style scoped></style>
|