feat: 实现已确认的登录、采集和任务导出
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<script setup lang="ts">
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { NSelect } from "naive-ui";
|
||||
import { api, clearSession, token } from "../shared/http";
|
||||
import { setThemeChoice, themeChoice, type ThemeChoice } from "../shared/theme";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const role = sessionStorage.getItem("decom-role");
|
||||
const name = sessionStorage.getItem("decom-name") || "";
|
||||
const items = role === "admin"
|
||||
? [
|
||||
{ label: "登录方式", path: "/admin/settings" },
|
||||
{ label: "用户", path: "/admin/users" },
|
||||
{ label: "账号池", path: "/admin/pool" },
|
||||
{ label: "采集", path: "/admin/sources" },
|
||||
]
|
||||
: [{ label: "任务", path: "/tasks" }];
|
||||
const themes = [
|
||||
{ label: "跟随系统", value: "system" },
|
||||
{ label: "深色", value: "dark" },
|
||||
{ label: "浅色", value: "light" },
|
||||
];
|
||||
|
||||
function chooseTheme(value: ThemeChoice) {
|
||||
setThemeChoice(value);
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
if (token()) {
|
||||
try {
|
||||
await api("/api/auth/logout", { method: "POST" });
|
||||
} catch {
|
||||
/* 本地会话仍会清掉 */
|
||||
}
|
||||
}
|
||||
clearSession();
|
||||
router.push("/login");
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="shell">
|
||||
<aside class="sider">
|
||||
<div class="brand">DecomEval</div>
|
||||
<nav class="nav">
|
||||
<button v-for="item in items" :key="item.path" :class="{ on: route.path === item.path }" @click="router.push(item.path)">{{ item.label }}</button>
|
||||
</nav>
|
||||
<div class="sider-foot">
|
||||
<div class="who">{{ name }}</div>
|
||||
<n-select :value="themeChoice" :options="themes" size="small" @update:value="chooseTheme" />
|
||||
<button class="text-button" @click="logout">退出</button>
|
||||
</div>
|
||||
</aside>
|
||||
<section class="main"><slot /></section>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user