feat: 按 NqiTools 的方案生成登录页和侧栏

This commit is contained in:
2026-10-26 17:06:04 +08:00
parent 419c40b740
commit eaad01d5a8
74 changed files with 21165 additions and 175 deletions
+7
View File
@@ -6,6 +6,7 @@
"": {
"name": "euniv-web",
"dependencies": {
"@vicons/ionicons5": "^0.13.0",
"naive-ui": "^2.43.2",
"vue": "^3.5.22"
},
@@ -978,6 +979,12 @@
"@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": {
"version": "6.0.10",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-6.0.10.tgz",
+1
View File
@@ -7,6 +7,7 @@
"build": "vue-tsc --noEmit && vite build"
},
"dependencies": {
"@vicons/ionicons5": "^0.13.0",
"naive-ui": "^2.43.2",
"vue": "^3.5.22"
},
+15 -5
View File
@@ -1,12 +1,22 @@
<script setup lang="ts">
import { dateZhCN, NConfigProvider, NMessageProvider, zhCN } from "naive-ui";
import LoginPage from "./LoginPage.vue";
import { ref } from "vue";
import { darkTheme, dateZhCN, NConfigProvider, NDialogProvider, NMessageProvider, zhCN } from "naive-ui";
import LoginView from "./features/auth/LoginView.vue";
import Shell from "./shell/Shell.vue";
import { isDark, themeOverrides } from "./shared/theme";
const employeeId = ref("");
</script>
<template>
<n-config-provider :locale="zhCN" :date-locale="dateZhCN">
<n-message-provider>
<login-page />
<n-config-provider class="app-root" :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="themeOverrides">
<n-message-provider class="app-root">
<n-dialog-provider>
<div class="app-root">
<LoginView v-if="!employeeId" @success="employeeId = $event" />
<Shell v-else :employee-id="employeeId" @logout="employeeId = ''" />
</div>
</n-dialog-provider>
</n-message-provider>
</n-config-provider>
</template>
-165
View File
@@ -1,165 +0,0 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import {
NButton,
NCard,
NDataTable,
NForm,
NFormItem,
NInput,
NLayout,
NLayoutContent,
NLayoutHeader,
NSpace,
NSwitch,
NTooltip,
useMessage,
} from "naive-ui";
interface Account {
employee_id: string;
cn_name: string;
department_name: string;
level_name: string;
email: string;
actual_study_hour: string;
actual_study_score: string;
points: string;
today_hours: string;
today_score: string;
today: string;
class_count: string;
last_login_at: string;
}
const message = useMessage();
const loading = ref(false);
const employeeId = ref("");
const password = ref("");
const current = ref<Account | null>(null);
const accounts = ref<Account[]>([]);
const runTime = ref("08:00");
const enabled = ref(true);
const columns = [
{ title: "工号", key: "employee_id" },
{ title: "姓名", key: "cn_name" },
{ title: "部门", key: "department_name" },
{ title: "最近登录", key: "last_login_at" },
];
async function readError(response: Response): Promise<string> {
const payload = await response.json().catch(() => ({}));
return typeof payload.detail === "string" ? payload.detail : "请求失败";
}
async function loadAccounts(): Promise<void> {
const response = await fetch("/api/accounts");
if (response.ok) {
accounts.value = await response.json();
}
}
async function login(): Promise<void> {
loading.value = true;
try {
const response = await fetch("/api/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ employee_id: employeeId.value.trim(), password: password.value }),
});
if (!response.ok) {
message.error(await readError(response));
return;
}
current.value = await response.json();
password.value = "";
message.success("登录成功");
await loadAccounts();
} finally {
loading.value = false;
}
}
async function saveSchedule(): Promise<void> {
if (!current.value) {
return;
}
const response = await fetch("/api/schedules", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
employee_id: current.value.employee_id,
run_time: runTime.value,
enabled: enabled.value,
}),
});
if (!response.ok) {
message.error(await readError(response));
return;
}
message.success("已保存定时同步");
}
onMounted(loadAccounts);
</script>
<template>
<n-layout style="min-height: 100vh">
<n-layout-header bordered style="position: sticky; top: 0; z-index: 2; height: 56px; display: flex; align-items: center; padding: 0 20px; background: #fff">
<n-space align="center" :size="8">
<strong>EunivTools</strong>
<n-tooltip>
<template #trigger>
<span style="cursor: help; color: #6b7280">?</span>
</template>
使用 e 学工号登录。后台记录使用者和学时学分汇总。
</n-tooltip>
</n-space>
</n-layout-header>
<n-layout-content style="padding: 20px; max-width: 920px; margin: 0 auto">
<n-card title="登录">
<n-form label-placement="left" label-width="72">
<n-form-item label="工号">
<n-input v-model:value="employeeId" placeholder="e 学工号" />
</n-form-item>
<n-form-item label="密码">
<n-input v-model:value="password" type="password" show-password-on="click" placeholder="e 学密码" />
</n-form-item>
<n-form-item label=" ">
<n-button type="primary" :loading="loading" @click="login">登录</n-button>
</n-form-item>
</n-form>
</n-card>
<n-card v-if="current" title="用户信息" style="margin-top: 16px">
<p>工号:{{ current.employee_id }}</p>
<p>姓名:{{ current.cn_name }}</p>
<p>部门:{{ current.department_name }}</p>
<p>岗位层级:{{ current.level_name }}</p>
<p>邮箱:{{ current.email }}</p>
<p>累计学时:{{ current.actual_study_hour }}</p>
<p>累计学分:{{ current.actual_study_score }}</p>
<p>积分:{{ current.points }}</p>
<p>今日学时:{{ current.today_hours }}</p>
<p>今日学分:{{ current.today_score }}</p>
<p>我的班级:{{ current.class_count }}</p>
<n-form label-placement="left" label-width="72" style="margin-top: 12px">
<n-form-item label="时间">
<n-input v-model:value="runTime" placeholder="08:00" style="width: 120px" />
</n-form-item>
<n-form-item label="启用">
<n-switch v-model:value="enabled" />
</n-form-item>
<n-form-item label=" ">
<n-button @click="saveSchedule">保存定时同步</n-button>
</n-form-item>
</n-form>
</n-card>
<n-card title="使用者" style="margin-top: 16px">
<n-data-table :columns="columns" :data="accounts" :bordered="false" />
</n-card>
</n-layout-content>
</n-layout>
</template>
@@ -0,0 +1,22 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NDataTable } from "naive-ui";
const rows = ref<{ employee_id: string }[]>([]);
const columns = [{ title: "工号", key: "employee_id" }];
onMounted(async () => {
const response = await fetch("/api/accounts");
if (response.ok) rows.value = await response.json();
});
</script>
<template>
<section class="page">
<header class="page-head">
<h2>使用者</h2>
</header>
<n-data-table :columns="columns" :data="rows" :bordered="false" />
</section>
</template>
+68
View File
@@ -0,0 +1,68 @@
<script setup lang="ts">
import { ref } from "vue";
import { NAlert, NButton, NIcon, NInput, NTooltip } from "naive-ui";
import { MoonOutline, SunnyOutline } from "@vicons/ionicons5";
import { isDark, toggleTheme } from "../../shared/theme";
const emit = defineEmits<{ success: [employeeId: string] }>();
const employeeId = ref("");
const password = ref("");
const submitting = ref(false);
const errorText = ref("");
async function submit() {
errorText.value = "";
submitting.value = true;
try {
const response = await fetch("/api/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ employee_id: employeeId.value.trim(), password: password.value }),
});
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
errorText.value = typeof payload.detail === "string" ? payload.detail : "登录失败";
return;
}
password.value = "";
emit("success", String(payload.employee_id || employeeId.value.trim()));
} finally {
submitting.value = false;
}
}
</script>
<template>
<div class="gate">
<n-tooltip>
<template #trigger>
<n-button class="theme-switch" quaternary circle :aria-label="isDark ? '切换到日间' : '切换到夜间'" @click="toggleTheme">
<template #icon><n-icon><MoonOutline v-if="!isDark" /><SunnyOutline v-else /></n-icon></template>
</n-button>
</template>
{{ isDark ? "切换到日间" : "切换到夜间" }}
</n-tooltip>
<section class="gate-card">
<div class="brand">
<div class="brand-mark" aria-hidden="true">E</div>
<div>
<h1>EunivTools</h1>
</div>
</div>
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
<form @submit.prevent="submit">
<div class="form-row">
<label for="employee-id">工号</label>
<n-input id="employee-id" v-model:value="employeeId" placeholder="工号" autocomplete="username" />
</div>
<div class="form-row">
<label for="password">密码</label>
<n-input id="password" v-model:value="password" type="password" show-password-on="click" placeholder="密码" autocomplete="current-password" />
</div>
<div class="gate-actions">
<n-button type="primary" attr-type="submit" :loading="submitting" :disabled="!employeeId.trim() || !password">登录</n-button>
</div>
</form>
</section>
</div>
</template>
+1 -2
View File
@@ -1,6 +1,5 @@
import { createApp } from "vue";
import naive from "naive-ui";
import App from "./App.vue";
import "./styles.css";
createApp(App).use(naive).mount("#app");
createApp(App).mount("#app");
+77
View File
@@ -0,0 +1,77 @@
import { computed, ref, watch } from "vue";
import type { GlobalThemeOverrides } from "naive-ui";
export interface Scheme {
id: string;
dark: boolean;
primary: string;
primaryHover: string;
primaryPressed: string;
vars: Record<string, string>;
}
export const schemes: Scheme[] = [
{
id: "light",
dark: false,
primary: "#2563eb",
primaryHover: "#1d4ed8",
primaryPressed: "#1e40af",
vars: {
"--bg": "#f3f4f6",
"--panel": "#ffffff",
"--ink": "#111827",
"--muted": "#6b7280",
"--line": "#e5e7eb",
"--accent": "#2563eb",
"--accent-soft": "#eff6ff",
"--sidebar": "#ffffff",
},
},
{
id: "dark",
dark: true,
primary: "#60a5fa",
primaryHover: "#93c5fd",
primaryPressed: "#3b82f6",
vars: {
"--bg": "#0f172a",
"--panel": "#1e293b",
"--ink": "#f8fafc",
"--muted": "#94a3b8",
"--line": "#334155",
"--accent": "#60a5fa",
"--accent-soft": "#1e3a8a",
"--sidebar": "#111827",
},
},
];
const stored = localStorage.getItem("euniv-scheme");
export const schemeId = ref(schemes.some((item) => item.id === stored) ? stored! : "light");
export const scheme = computed(() => schemes.find((item) => item.id === schemeId.value) ?? schemes[0]);
export const isDark = computed(() => scheme.value.dark);
export const themeOverrides = computed<GlobalThemeOverrides>(() => ({
common: {
primaryColor: scheme.value.primary,
primaryColorHover: scheme.value.primaryHover,
primaryColorPressed: scheme.value.primaryPressed,
primaryColorSuppl: scheme.value.primary,
borderRadius: "6px",
fontFamily: '"Segoe UI", "Microsoft YaHei", sans-serif',
},
}));
watch(scheme, (value) => {
localStorage.setItem("euniv-scheme", value.id);
const root = document.documentElement;
root.dataset.theme = value.dark ? "dark" : "light";
root.dataset.scheme = value.id;
for (const [key, cssValue] of Object.entries(value.vars)) {
root.style.setProperty(key, cssValue);
}
}, { immediate: true });
export function toggleTheme() {
schemeId.value = scheme.value.dark ? "light" : "dark";
}
+71
View File
@@ -0,0 +1,71 @@
<script setup lang="ts">
import { ref } from "vue";
import { NButton, NIcon, NLayout, NLayoutSider, NMenu, NTooltip } from "naive-ui";
import { LogOutOutline, MoonOutline, PersonOutline, SunnyOutline } from "@vicons/ionicons5";
import { isDark, toggleTheme } from "../shared/theme";
import { navOptions, type PageKey } from "./navigation";
import AccountsView from "../features/accounts/AccountsView.vue";
const props = defineProps<{ employeeId: string }>();
const emit = defineEmits<{ logout: [] }>();
const page = ref<PageKey>("accounts");
const collapsed = ref(false);
function onMenu(key: string) {
if (key === "accounts") page.value = key;
}
</script>
<template>
<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="{ height: '100%', display: 'flex', flexDirection: 'column' }"
@collapse="collapsed = true"
@expand="collapsed = false"
>
<div class="sider-body">
<n-menu
:collapsed="collapsed"
:collapsed-width="64"
:collapsed-icon-size="22"
:value="page"
:options="navOptions"
@update:value="onMenu"
/>
<div class="sider-user" :class="{ compact: collapsed }">
<n-icon :size="18"><PersonOutline /></n-icon>
<div v-if="!collapsed" class="who">
<strong>{{ props.employeeId }}</strong>
<span>已登录</span>
</div>
<n-tooltip>
<template #trigger>
<n-button quaternary circle size="small" :aria-label="isDark ? '切换到日间' : '切换到夜间'" @click="toggleTheme">
<template #icon><n-icon><MoonOutline v-if="!isDark" /><SunnyOutline v-else /></n-icon></template>
</n-button>
</template>
{{ isDark ? "切换到日间" : "切换到夜间" }}
</n-tooltip>
<n-tooltip>
<template #trigger>
<n-button quaternary circle size="small" aria-label="退出" @click="emit('logout')">
<template #icon><n-icon><LogOutOutline /></n-icon></template>
</n-button>
</template>
退出
</n-tooltip>
</div>
</div>
</n-layout-sider>
<n-layout class="content">
<AccountsView v-if="page === 'accounts'" />
</n-layout>
</n-layout>
</template>
+14
View File
@@ -0,0 +1,14 @@
import type { Component } from "vue";
import { h } from "vue";
import { NIcon } from "naive-ui";
import { PeopleOutline } from "@vicons/ionicons5";
function renderIcon(icon: Component) {
return () => h(NIcon, null, { default: () => h(icon) });
}
export type PageKey = "accounts";
export const navOptions = [
{ label: "使用者", key: "accounts" as const, icon: renderIcon(PeopleOutline) },
];
+205 -3
View File
@@ -1,10 +1,212 @@
:root {
color: var(--ink);
background: var(--bg);
font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
font-size: 14px;
--bg: #f3f4f6;
--panel: #ffffff;
--ink: #111827;
--muted: #6b7280;
--line: #e5e7eb;
--accent: #2563eb;
--accent-soft: #eff6ff;
--sidebar: #ffffff;
}
:root[data-theme="dark"] {
--bg: #0f172a;
--panel: #1e293b;
--ink: #f8fafc;
--muted: #94a3b8;
--line: #334155;
--accent: #60a5fa;
--accent-soft: #1e3a8a;
--sidebar: #111827;
}
::selection {
background: var(--accent-soft);
color: var(--ink);
}
html,
body,
#app {
#app,
.app-root {
margin: 0;
height: 100%;
min-height: 0;
}
button,
input,
select {
font-family: inherit;
}
.gate {
position: relative;
box-sizing: border-box;
height: 100%;
min-height: 0;
display: flex;
align-items: center;
justify-content: center;
padding: 32px 16px;
background: var(--bg);
}
.theme-switch {
position: absolute;
top: 16px;
right: 16px;
}
.gate-card {
width: min(440px, 100%);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 12px;
box-shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
padding: 28px 28px 22px;
}
.brand {
display: flex;
gap: 14px;
align-items: center;
justify-content: center;
margin-bottom: 22px;
}
.brand-mark {
width: 44px;
height: 44px;
border-radius: 10px;
background: var(--accent);
color: #fff;
display: grid;
place-items: center;
flex: none;
font-size: 22px;
font-weight: 600;
line-height: 1;
}
.brand h1 {
margin: 0;
font-size: 20px;
line-height: 1.3;
}
.form-row {
display: grid;
grid-template-columns: 84px minmax(0, 1fr);
gap: 8px 12px;
align-items: center;
margin-bottom: 12px;
}
.form-row label {
display: flex;
align-items: center;
gap: 4px;
color: var(--ink);
}
.gate-actions {
display: flex;
justify-content: flex-end;
gap: 8px;
margin-top: 8px;
}
.shell {
height: 100%;
background: var(--bg);
color: var(--ink);
}
.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%;
}
body {
background: #f5f7f6;
.sider-body {
flex: 1;
height: 100%;
display: flex;
flex-direction: column;
min-height: 0;
}
.sider-body .n-menu {
flex: 1;
min-height: 0;
}
.sider-user {
margin-top: auto;
padding: 12px;
border-top: 1px solid var(--line);
display: flex;
align-items: center;
gap: 8px;
}
.sider-user.compact {
flex-direction: column;
padding: 8px 0 12px;
}
.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;
}
.content {
min-width: 0;
min-height: 0;
height: 100%;
display: flex;
flex-direction: column;
}
.page {
height: 100%;
min-height: 0;
display: flex;
flex-direction: column;
padding: 16px 20px;
box-sizing: border-box;
}
.page-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.page-head h2 {
margin: 0;
font-size: 16px;
}