fix: update home page background image and remove unnecessary redirect code chore: update pnpm lock file with new dependencies for auto-animate and svg spinners delete: remove unused images from public directory refactor: modify course and user types for better clarity and structure feat: implement course API with CRUD operations and teacher team management feat: create user authentication page with login functionality and validation feat: add login state management with Pinia for user session handling style: create reusable UI components for cards and tabs chore: implement HTTP utility for API requests with error handling
81 lines
2.7 KiB
Vue
81 lines
2.7 KiB
Vue
<script setup lang="ts">
|
|
import { ChevronsUpDown } from "lucide-vue-next";
|
|
import { useSidebar } from "../ui/sidebar";
|
|
import type { IUser } from "~/types";
|
|
|
|
const props = defineProps<{
|
|
user: IUser;
|
|
}>();
|
|
|
|
const { isMobile } = useSidebar();
|
|
const { logout } = useLoginState();
|
|
|
|
const displayName = computed(() => {
|
|
return props.user?.nickName || props.user?.userName;
|
|
});
|
|
|
|
const compactUserLabel = computed(() => {
|
|
const name = displayName.value;
|
|
if (name?.length > 2) {
|
|
return name.slice(0, 2);
|
|
}
|
|
return name || "User";
|
|
});
|
|
</script>
|
|
<template>
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger as-child>
|
|
<SidebarMenuButton
|
|
size="lg"
|
|
class="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
|
>
|
|
<Avatar class="h-8 w-8 rounded-lg">
|
|
<AvatarImage :src="user.avatar || ''" :alt="user.userName" />
|
|
<AvatarFallback class="rounded-lg">
|
|
{{ compactUserLabel }}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
<div class="grid flex-1 text-left text-sm leading-tight">
|
|
<span class="truncate font-semibold">{{ displayName }}</span>
|
|
<span class="truncate text-xs">{{
|
|
user.email || user.phonenumber
|
|
}}</span>
|
|
</div>
|
|
<ChevronsUpDown class="ml-auto size-4" />
|
|
</SidebarMenuButton>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent
|
|
class="w-[--reka-dropdown-menu-trigger-width] min-w-56 rounded-lg"
|
|
:side="isMobile ? 'bottom' : 'right'"
|
|
:align="'end'"
|
|
:side-offset="4"
|
|
>
|
|
<DropdownMenuLabel class="p-0 font-normal">
|
|
<div class="flex items-center gap-2 px-1 py-1.5 text-left text-sm">
|
|
<Avatar class="h-8 w-8 rounded-lg">
|
|
<AvatarImage :src="user.avatar || ''" :alt="user.userName" />
|
|
<AvatarFallback class="rounded-lg">
|
|
{{ compactUserLabel }}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
<div class="grid flex-1 text-left text-sm leading-tight">
|
|
<span class="truncate font-semibold">{{ displayName }}</span>
|
|
<span class="truncate text-xs">{{
|
|
user.email || user.phonenumber
|
|
}}</span>
|
|
</div>
|
|
</div>
|
|
</DropdownMenuLabel>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem class="text-red-500" @click="logout">
|
|
<Icon name="tabler:logout" />
|
|
退出账号
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
</template>
|