fix: 侧边栏改成可收缩的 EunivTools 结构

This commit is contained in:
2026-10-30 11:23:59 +08:00
parent b052ce2ed0
commit 7be1679d64
4 changed files with 122 additions and 40 deletions
+7
View File
@@ -8,6 +8,7 @@
"name": "decomeval-web", "name": "decomeval-web",
"version": "0.1.0", "version": "0.1.0",
"dependencies": { "dependencies": {
"@vicons/ionicons5": "^0.13.0",
"naive-ui": "^2.43.2", "naive-ui": "^2.43.2",
"vue": "^3.5.13", "vue": "^3.5.13",
"vue-router": "^4.5.1" "vue-router": "^4.5.1"
@@ -406,6 +407,12 @@
"@types/lodash": "*" "@types/lodash": "*"
} }
}, },
"node_modules/@vicons/ionicons5": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/@vicons/ionicons5/-/ionicons5-0.13.0.tgz",
"integrity": "sha512-zvZKBPjEXKN7AXNo2Na2uy+nvuv6SP4KAMQxpKL2vfHMj0fSvuw7JZcOPCjQC3e7ayssKnaoFVAhbYcW6v41qQ==",
"license": "MIT"
},
"node_modules/@vitejs/plugin-vue": { "node_modules/@vitejs/plugin-vue": {
"version": "6.0.10", "version": "6.0.10",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-6.0.10.tgz", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-6.0.10.tgz",
+1
View File
@@ -9,6 +9,7 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@vicons/ionicons5": "^0.13.0",
"naive-ui": "^2.43.2", "naive-ui": "^2.43.2",
"vue": "^3.5.13", "vue": "^3.5.13",
"vue-router": "^4.5.1" "vue-router": "^4.5.1"
+63 -18
View File
@@ -1,20 +1,36 @@
<script setup lang="ts"> <script setup lang="ts">
import { h, onMounted, onUnmounted, ref } from "vue";
import type { Component } from "vue";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import { NButton, NIcon, NLayout, NLayoutSider, NMenu } from "naive-ui";
import { CloudDownloadOutline, KeyOutline, ListOutline, LogOutOutline, PeopleOutline, PersonOutline, SettingsOutline } from "@vicons/ionicons5";
import { api, clearSession, token } from "../shared/http"; import { api, clearSession, token } from "../shared/http";
import ThemeButton from "./ThemeButton.vue"; import ThemeButton from "./ThemeButton.vue";
function renderIcon(icon: Component) {
return () => h(NIcon, null, { default: () => h(icon) });
}
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const role = sessionStorage.getItem("decom-role"); const role = sessionStorage.getItem("decom-role");
const name = sessionStorage.getItem("decom-name") || ""; const name = sessionStorage.getItem("decom-name") || "";
const collapsed = ref(window.innerWidth < 800);
const items = role === "admin" const items = role === "admin"
? [ ? [
{ label: "设置", path: "/admin/settings" }, { label: "设置", key: "/admin/settings", icon: renderIcon(SettingsOutline) },
{ label: "用户", path: "/admin/users" }, { label: "用户", key: "/admin/users", icon: renderIcon(PeopleOutline) },
{ label: "账号池", path: "/admin/pool" }, { label: "账号池", key: "/admin/pool", icon: renderIcon(KeyOutline) },
{ label: "采集", path: "/admin/sources" }, { label: "采集", key: "/admin/sources", icon: renderIcon(CloudDownloadOutline) },
] ]
: [{ label: "任务", path: "/tasks" }]; : [{ label: "任务", key: "/tasks", icon: renderIcon(ListOutline) }];
function onResize() {
if (window.innerWidth < 800) collapsed.value = true;
}
onMounted(() => window.addEventListener("resize", onResize));
onUnmounted(() => window.removeEventListener("resize", onResize));
async function logout() { async function logout() {
if (token()) { if (token()) {
@@ -30,18 +46,47 @@ async function logout() {
</script> </script>
<template> <template>
<div class="shell"> <n-layout has-sider class="shell">
<aside class="sider"> <n-layout-sider
<div class="brand">DecomEval</div> bordered
<nav class="nav"> collapse-mode="width"
<button v-for="item in items" :key="item.path" :class="{ on: route.path === item.path }" @click="router.push(item.path)">{{ item.label }}</button> :collapsed-width="64"
</nav> :width="220"
<div class="sider-foot"> :collapsed="collapsed"
<div class="who">{{ name }}</div> show-trigger
<ThemeButton /> :native-scrollbar="false"
<button class="text-button" @click="logout">退出</button> :content-style="{ height: '100%', display: 'flex', flexDirection: 'column' }"
@collapse="collapsed = true"
@expand="collapsed = false"
>
<div class="sider-body">
<div class="sider-brand" :class="{ compact: collapsed }">
<div class="brand-mark" aria-hidden="true">D</div>
<strong v-if="!collapsed">DecomEval</strong>
</div>
<n-menu
:collapsed="collapsed"
:collapsed-width="64"
:collapsed-icon-size="22"
:value="route.path"
:options="items"
@update:value="(key) => router.push(String(key))"
/>
<div class="sider-user" :class="{ compact: collapsed }">
<n-icon :size="18"><PersonOutline /></n-icon>
<div v-if="!collapsed" class="who">
<strong>{{ name }}</strong>
<span>已登录</span>
</div>
<ThemeButton />
<n-button class="logout-btn" quaternary circle size="small" aria-label="退出" @click="logout">
<template #icon><n-icon><LogOutOutline /></n-icon></template>
</n-button>
</div>
</div> </div>
</aside> </n-layout-sider>
<section class="main"><slot /></section> <n-layout class="content" :native-scrollbar="false" content-style="height: 100%; min-height: 0; overflow: hidden; display: flex; flex-direction: column;">
</div> <slot />
</n-layout>
</n-layout>
</template> </template>
+51 -22
View File
@@ -11,44 +11,73 @@ button, input, select { font: inherit; }
::selection { background: var(--accent-soft); } ::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.shell { display: flex; height: 100%; min-height: 0; } .shell { height: 100%; background: var(--bg); color: var(--ink); }
.sider { .shell .n-layout,
width: 216px; .shell .n-layout-scroll-container,
flex: none; .content { background: var(--bg); }
.shell .n-layout-sider { background: var(--sidebar); }
.shell .n-layout-sider > .n-scrollbar,
.shell .n-layout-sider .n-scrollbar-container,
.shell .n-layout-sider .n-scrollbar-content { height: 100%; }
.sider-body {
flex: 1;
height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
background: var(--sidebar); min-height: 0;
border-right: 1px solid var(--line);
} }
.brand { .sider-brand {
height: 56px; height: 56px;
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px;
padding: 0 16px; padding: 0 16px;
border-bottom: 1px solid var(--line); border-bottom: 1px solid var(--line);
font-weight: 650; flex: none;
} }
.nav { padding-top: 8px; } .sider-brand.compact { justify-content: center; padding: 0; }
.nav button, .text-button { .sider-brand strong { font-size: 15px; font-weight: 650; letter-spacing: -0.02em; }
width: 100%; .sider-brand .brand-mark { width: 28px; height: 28px; font-size: 14px; }
text-align: left; .sider-body .n-menu { flex: 1; min-height: 0; padding-top: 8px; }
background: transparent; .shell .n-menu .n-menu-item-content--selected::before {
color: var(--muted); background-color: transparent !important;
border: 0; border-left: 2px solid var(--accent);
padding: 10px 16px; border-radius: 0;
cursor: pointer;
} }
.nav button.on { color: var(--ink); box-shadow: inset 2px 0 0 var(--accent); } .sider-user {
.sider-foot {
margin-top: auto; margin-top: auto;
padding: 12px; padding: 12px;
border-top: 1px solid var(--line); border-top: 1px solid var(--line);
display: flex; display: flex;
flex-direction: column; align-items: center;
gap: 8px; gap: 8px;
} }
.who { color: var(--muted); font-size: 12px; } .sider-user.compact { flex-direction: column; padding: 8px 0 12px; }
.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); } .sider-user .who { min-width: 0; flex: 1; }
.sider-user strong,
.sider-user span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sider-user span { color: var(--muted); font-size: 12px; }
.logout-btn.n-button {
color: var(--danger);
--n-text-color: var(--danger);
--n-text-color-hover: var(--danger);
--n-text-color-pressed: var(--danger);
--n-text-color-focus: var(--danger);
}
.sider-user .theme-switch { position: static; }
.content {
min-width: 0;
min-height: 0;
height: 100%;
display: flex;
flex-direction: column;
}
.content > .n-layout-scroll-container,
.content > .n-scrollbar,
.content > .n-scrollbar > .n-scrollbar-container {
height: 100%;
overflow: hidden;
}
.page { .page {
height: 100%; height: 100%;
min-height: 0; min-height: 0;