-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
783be91
commit 146ad8d
Showing
9 changed files
with
138 additions
and
97 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<script> | ||
import { page } from '$app/stores'; | ||
import { base } from '$app/paths'; | ||
import { goto } from '$app/navigation'; | ||
import * as Avatar from '$lib/components/ui/avatar'; | ||
import * as DropdownMenu from '$lib/components/ui/dropdown-menu'; | ||
import { Button } from '$lib/components/ui/button/index.js'; | ||
import LifeBuoy from 'lucide-svelte/icons/life-buoy'; | ||
import LogOut from 'lucide-svelte/icons/log-out'; | ||
import Settings from 'lucide-svelte/icons/settings'; | ||
import User from 'lucide-svelte/icons/user'; | ||
const user = $page.data?.user; | ||
const src = user?.photo || `${base}/defavatar.png`; | ||
async function handleLogout() { | ||
const response = await fetch(`${base}/logout?/logout`, { | ||
method: 'POST', | ||
body: Object.create({}), | ||
headers: { | ||
'x-sveltekit-action': 'true' | ||
} | ||
}); | ||
if (response.ok) { | ||
goto(`${base}/login`); | ||
} else { | ||
// 退出失败,你可以在这里处理错误 | ||
} | ||
} | ||
</script> | ||
<DropdownMenu.Root> | ||
{#if user} | ||
<DropdownMenu.Trigger> | ||
<Avatar.Root> | ||
<Avatar.Image {src} alt="用户头像" /> | ||
<Avatar.Fallback>未登录</Avatar.Fallback> | ||
</Avatar.Root> | ||
</DropdownMenu.Trigger> | ||
{:else} | ||
<Button variant="link" href="{base}/login">登录</Button> | ||
{/if} | ||
<DropdownMenu.Content class="w-56"> | ||
{#if user} | ||
<DropdownMenu.Label>我的账户</DropdownMenu.Label> | ||
<DropdownMenu.Separator /> | ||
<DropdownMenu.Group> | ||
<DropdownMenu.Item class="cursor-pointer" href="{base}/user"> | ||
<User class="mr-2 h-4 w-4" /> | ||
<span>控制台</span> | ||
</DropdownMenu.Item> | ||
<DropdownMenu.Item class="cursor-pointer" href="{base}/settings"> | ||
<Settings class="mr-2 h-4 w-4" /> | ||
<span>个人中心</span> | ||
</DropdownMenu.Item> | ||
</DropdownMenu.Group> | ||
<DropdownMenu.Separator /> | ||
<DropdownMenu.Item class="cursor-pointer"> | ||
<LifeBuoy class="mr-2 h-4 w-4" /> | ||
<span>支持</span> | ||
</DropdownMenu.Item> | ||
<DropdownMenu.Separator /> | ||
<DropdownMenu.Item class="cursor-pointer"> | ||
<LogOut class="mr-2 h-4 w-4" /> | ||
<button on:click={handleLogout}>退出</button> | ||
</DropdownMenu.Item> | ||
{/if} | ||
</DropdownMenu.Content> | ||
</DropdownMenu.Root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Root from "./separator.svelte"; | ||
export { | ||
Root, | ||
// | ||
Root as Separator, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script> | ||
import { Separator as SeparatorPrimitive } from "bits-ui"; | ||
import { cn } from "$lib/utils.js"; | ||
let className = undefined; | ||
export let orientation = "horizontal"; | ||
export let decorative = undefined; | ||
export { className as class }; | ||
</script> | ||
|
||
<SeparatorPrimitive.Root | ||
class={cn( | ||
"bg-border shrink-0", | ||
orientation === "horizontal" ? "h-[1px] w-full" : "min-h-full w-[1px]", | ||
className | ||
)} | ||
{orientation} | ||
{decorative} | ||
{...$$restProps} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
/** | ||
* Represents a user with various properties. | ||
*/ | ||
export interface User { | ||
id: number | string; | ||
email: string | null; | ||
provider: string; | ||
socialId?: string | null; | ||
firstName: string | null; | ||
lastName: string | null; | ||
photo?: FileType | null; | ||
role?: Role | null; | ||
status?: Status; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
deletedAt: Date; | ||
} | ||
|
||
export interface FileType { | ||
id: string; | ||
path: string; | ||
} | ||
|
||
export interface Role { | ||
id: number | string; | ||
name?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,10 @@ | ||
<script> | ||
import { page } from '$app/stores'; | ||
import { base } from '$app/paths'; | ||
import * as Avatar from '$lib/components/ui/avatar'; | ||
import * as Popover from '$lib/components/ui/popover'; | ||
import { Button } from '$lib/components/ui/button/index.js'; | ||
import { cn } from '$lib/utils.js'; | ||
import LogOut from 'lucide-svelte/icons/log-out'; | ||
import NavAvatar from '$lib/components/NavAvatar.svelte'; | ||
let className = undefined; | ||
const user = $page.data?.user; | ||
const src = user?.photo || `${base}/defavatar.png`; | ||
</script> | ||
|
||
<div class={cn('h-12 w-12', className)} {...$$restProps}> | ||
<Popover.Root> | ||
<Popover.Trigger> | ||
<Avatar.Root> | ||
<Avatar.Image {src} alt="用户头像" /> | ||
<Avatar.Fallback>未登录</Avatar.Fallback> | ||
</Avatar.Root> | ||
</Popover.Trigger> | ||
<Popover.Content> | ||
{#if user} | ||
<form method="post" action="{base}/logout?/logout"> | ||
<div class="flex cursor-pointer flex-col items-center"> | ||
<Button variant="outline" size="icon" type="submit"> | ||
<LogOut class="mr-2 h-4 w-4" /> | ||
</Button> | ||
</div> | ||
</form> | ||
{:else} | ||
<Button variant="link" href="{base}/login" class="w-full">登录</Button> | ||
{/if} | ||
</Popover.Content> | ||
</Popover.Root> | ||
<NavAvatar></NavAvatar> | ||
</div> |