main
vue 40 lines 960 Bytes
Raw
1 <template>
2 <n-dropdown :options placement="bottom-end" trigger="click" @select="handleSelect">
3 <n-avatar round :size="32" :src="userPic" class="cursor-pointer" :img-props="{ alt: 'avatar' }" />
4 </n-dropdown>
5 </template>
6
7 <script lang="ts" setup>
8 import { NAvatar, NDropdown } from "naive-ui"
9 import { ref } from "vue"
10 import { useRouter } from "vue-router"
11 import { useAuthStore } from "@/stores/auth"
12 import { renderIcon } from "@/utils"
13
14 const UserIcon = "ion:person-outline"
15 const LogoutIcon = "ion:log-out-outline"
16
17 const router = useRouter()
18 const authStore = useAuthStore()
19
20 const userPic = authStore.userPic
21
22 const options = ref([
23 {
24 label: "Profile",
25 key: "route-Profile",
26 icon: renderIcon(UserIcon)
27 },
28 {
29 label: "Logout",
30 key: "route-Logout",
31 icon: renderIcon(LogoutIcon)
32 }
33 ])
34 function handleSelect(key: string) {
35 if (key.indexOf("route-") === 0) {
36 const path = key.split("route-")[1]
37 router.push({ name: path })
38 }
39 }
40 </script>