feat: 重做管理后台的导航、表单和登录页
This commit is contained in:
+181
-44
@@ -1,41 +1,76 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { useRoute, useRouter, RouterView } from "vue-router";
|
||||
import {
|
||||
NButton,
|
||||
NLayout,
|
||||
NLayoutContent,
|
||||
NLayoutHeader,
|
||||
NLayoutSider,
|
||||
NMenu,
|
||||
NSpace,
|
||||
NText,
|
||||
} from "naive-ui";
|
||||
import { computed, h, ref, type Component } from "vue";
|
||||
import { RouterView, useRoute, useRouter } from "vue-router";
|
||||
import { NAvatar, NButton, NDropdown, NIcon, NLayout, NLayoutContent, NLayoutSider, NMenu, NTooltip } from "naive-ui";
|
||||
import type { MenuOption } from "naive-ui";
|
||||
import {
|
||||
ChatbubblesOutline,
|
||||
DesktopOutline,
|
||||
GridOutline,
|
||||
KeyOutline,
|
||||
LogOutOutline,
|
||||
MoonOutline,
|
||||
PaperPlaneOutline,
|
||||
PeopleOutline,
|
||||
PhonePortraitOutline,
|
||||
SettingsOutline,
|
||||
SunnyOutline,
|
||||
} from "@vicons/ionicons5";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useAppTheme, type ThemeChoice } from "@/theme";
|
||||
import BrandMark from "@/components/BrandMark.vue";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const auth = useAuthStore();
|
||||
const { choice, setChoice } = useAppTheme();
|
||||
const collapsed = ref(false);
|
||||
|
||||
function renderIcon(icon: Component) {
|
||||
return () => h(NIcon, null, { default: () => h(icon) });
|
||||
}
|
||||
|
||||
const menuOptions: MenuOption[] = [
|
||||
{ label: "概览", key: "/overview" },
|
||||
{ label: "端", key: "/endpoints" },
|
||||
{ label: "注册设置", key: "/registration" },
|
||||
{ label: "群", key: "/groups" },
|
||||
{ label: "投递记录", key: "/messages" },
|
||||
{ label: "API 令牌", key: "/tokens" },
|
||||
{ label: "系统", key: "/settings" },
|
||||
{ label: "概览", key: "/overview", icon: renderIcon(GridOutline) },
|
||||
{
|
||||
label: "通讯",
|
||||
key: "comms",
|
||||
icon: renderIcon(ChatbubblesOutline),
|
||||
children: [
|
||||
{ label: "设备端", key: "/endpoints", icon: renderIcon(PhonePortraitOutline) },
|
||||
{ label: "群组", key: "/groups", icon: renderIcon(PeopleOutline) },
|
||||
],
|
||||
},
|
||||
{ label: "投递记录", key: "/messages", icon: renderIcon(PaperPlaneOutline) },
|
||||
{ label: "API 令牌", key: "/tokens", icon: renderIcon(KeyOutline) },
|
||||
{ label: "设置", key: "/settings", icon: renderIcon(SettingsOutline) },
|
||||
];
|
||||
|
||||
const activeKey = computed(() => {
|
||||
const path = route.path;
|
||||
const hit = menuOptions.find((m) => typeof m.key === "string" && path.startsWith(String(m.key)));
|
||||
return hit?.key ?? "/overview";
|
||||
const activeKey = computed(() => route.path);
|
||||
const initial = computed(() => (auth.username || "A").slice(0, 1).toUpperCase());
|
||||
const themeIcon = computed(() => {
|
||||
if (choice.value === "dark") return MoonOutline;
|
||||
if (choice.value === "light") return SunnyOutline;
|
||||
return DesktopOutline;
|
||||
});
|
||||
const themeLabel = computed(() => {
|
||||
if (choice.value === "dark") return "深色";
|
||||
if (choice.value === "light") return "浅色";
|
||||
return "跟随系统";
|
||||
});
|
||||
|
||||
const themeOptions = [
|
||||
{ label: "跟随系统", key: "auto", icon: renderIcon(DesktopOutline) },
|
||||
{ label: "浅色", key: "light", icon: renderIcon(SunnyOutline) },
|
||||
{ label: "深色", key: "dark", icon: renderIcon(MoonOutline) },
|
||||
];
|
||||
|
||||
function onMenuUpdate(key: string) {
|
||||
void router.push(key);
|
||||
if (key.startsWith("/")) void router.push(key);
|
||||
}
|
||||
|
||||
function onTheme(key: string) {
|
||||
setChoice(key as ThemeChoice);
|
||||
}
|
||||
|
||||
async function onLogout() {
|
||||
@@ -45,27 +80,129 @@ async function onLogout() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-layout has-sider style="height: 100vh">
|
||||
<n-layout-sider bordered :width="180" :native-scrollbar="false" content-style="padding-top: 8px">
|
||||
<div style="padding: 12px 16px">
|
||||
<n-text strong>NixMsg</n-text>
|
||||
<n-layout has-sider class="shell">
|
||||
<n-layout-sider
|
||||
bordered
|
||||
collapse-mode="width"
|
||||
:collapsed-width="64"
|
||||
:width="220"
|
||||
:collapsed="collapsed"
|
||||
show-trigger
|
||||
:native-scrollbar="false"
|
||||
content-style="display: flex; flex-direction: column; height: 100%;"
|
||||
@collapse="collapsed = true"
|
||||
@expand="collapsed = false"
|
||||
>
|
||||
<div class="brand" :class="{ 'is-collapsed': collapsed }">
|
||||
<BrandMark class="mark" />
|
||||
<span v-if="!collapsed" class="word">NixMsg</span>
|
||||
</div>
|
||||
|
||||
<n-menu
|
||||
class="nav"
|
||||
:value="activeKey"
|
||||
:collapsed="collapsed"
|
||||
:collapsed-width="64"
|
||||
:collapsed-icon-size="20"
|
||||
:icon-size="18"
|
||||
:options="menuOptions"
|
||||
@update:value="onMenuUpdate"
|
||||
/>
|
||||
|
||||
<div class="sider-foot" :class="{ 'is-collapsed': collapsed }">
|
||||
<div class="account">
|
||||
<n-dropdown trigger="click" placement="top-start" :options="themeOptions" @select="onTheme">
|
||||
<n-button quaternary circle :aria-label="`主题:${themeLabel}`" :title="themeLabel">
|
||||
<template #icon>
|
||||
<n-icon :component="themeIcon" />
|
||||
</template>
|
||||
</n-button>
|
||||
</n-dropdown>
|
||||
<n-avatar round :size="28" color="#18a058">{{ initial }}</n-avatar>
|
||||
<span v-if="!collapsed" class="name">{{ auth.username }}</span>
|
||||
<n-tooltip placement="right">
|
||||
<template #trigger>
|
||||
<n-button class="logout" quaternary circle aria-label="退出" @click="onLogout">
|
||||
<template #icon>
|
||||
<n-icon :component="LogOutOutline" />
|
||||
</template>
|
||||
</n-button>
|
||||
</template>
|
||||
退出
|
||||
</n-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<n-menu :value="activeKey" :options="menuOptions" @update:value="onMenuUpdate" />
|
||||
</n-layout-sider>
|
||||
<n-layout>
|
||||
<n-layout-header bordered style="height: 48px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between">
|
||||
<n-text depth="3">管理后台</n-text>
|
||||
<n-space align="center">
|
||||
<n-text>{{ auth.username }}</n-text>
|
||||
<n-button quaternary size="small" @click="onLogout">退出</n-button>
|
||||
</n-space>
|
||||
</n-layout-header>
|
||||
<n-layout-content
|
||||
:native-scrollbar="false"
|
||||
content-style="height: calc(100vh - 48px); display: flex; flex-direction: column; overflow: hidden"
|
||||
>
|
||||
<RouterView />
|
||||
</n-layout-content>
|
||||
</n-layout>
|
||||
<n-layout-content :native-scrollbar="false" content-style="height: 100vh; display: flex; flex-direction: column; overflow: hidden">
|
||||
<RouterView />
|
||||
</n-layout-content>
|
||||
</n-layout>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.shell {
|
||||
height: 100vh;
|
||||
}
|
||||
.brand {
|
||||
height: 56px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 0 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.brand.is-collapsed {
|
||||
padding: 0;
|
||||
justify-content: center;
|
||||
}
|
||||
.mark {
|
||||
font-size: 28px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.word {
|
||||
font-size: 16px;
|
||||
font-weight: 650;
|
||||
letter-spacing: 0.01em;
|
||||
min-width: 0;
|
||||
}
|
||||
.nav {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
.sider-foot {
|
||||
flex-shrink: 0;
|
||||
margin: 0 12px 12px;
|
||||
padding-top: 10px;
|
||||
border-top: 1px solid rgba(128, 128, 128, 0.18);
|
||||
}
|
||||
.sider-foot.is-collapsed {
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
.account {
|
||||
width: 100%;
|
||||
min-height: 36px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.sider-foot.is-collapsed .account {
|
||||
width: 64px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 13px;
|
||||
}
|
||||
.logout {
|
||||
margin-left: auto;
|
||||
}
|
||||
.sider-foot.is-collapsed .logout {
|
||||
margin-left: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user