feat: 增加登录页面、学时查询和定时同步

This commit is contained in:
2026-10-26 12:10:02 +08:00
parent cb935f081e
commit 626f9eab5c
32 changed files with 2924 additions and 249 deletions
+12
View File
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>EunivTools</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
+1696
View File
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
{
"name": "euniv-web",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build"
},
"dependencies": {
"naive-ui": "^2.43.2",
"vue": "^3.5.22"
},
"devDependencies": {
"@vitejs/plugin-vue": "^6.0.1",
"typescript": "^5.9.3",
"vite": "^7.1.12",
"vue-tsc": "^3.1.2"
}
}
+10
View File
@@ -0,0 +1,10 @@
<script setup lang="ts">
import { NMessageProvider } from "naive-ui";
import LoginPage from "./LoginPage.vue";
</script>
<template>
<n-message-provider>
<login-page />
</n-message-provider>
</template>
+165
View File
@@ -0,0 +1,165 @@
<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>
+6
View File
@@ -0,0 +1,6 @@
import { createApp } from "vue";
import naive from "naive-ui";
import App from "./App.vue";
import "./styles.css";
createApp(App).use(naive).mount("#app");
+10
View File
@@ -0,0 +1,10 @@
html,
body,
#app {
margin: 0;
height: 100%;
}
body {
background: #f5f7f6;
}
+13
View File
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"jsx": "preserve",
"noEmit": true,
"skipLibCheck": true,
"lib": ["ES2022", "DOM"]
},
"include": ["src"]
}
+11
View File
@@ -0,0 +1,11 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
export default defineConfig({
plugins: [vue()],
server: {
proxy: {
"/api": "http://127.0.0.1:8000",
},
},
});