feat: 按 NqiTools 的方案生成登录页和侧栏
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user