@@ -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 >