feat: 实现管理后台 W1-W3 假数据界面
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { NButton, NCard, NForm, NFormItem, NInput, NSpace, NText } from "naive-ui";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
const auth = useAuthStore();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
const username = ref("admin");
|
||||
const password = ref("");
|
||||
const loading = ref(false);
|
||||
const formError = ref("");
|
||||
|
||||
async function onSubmit() {
|
||||
formError.value = "";
|
||||
loading.value = true;
|
||||
try {
|
||||
await auth.login(username.value.trim(), password.value);
|
||||
const redirect = typeof route.query.redirect === "string" ? route.query.redirect : "/overview";
|
||||
await router.replace(redirect || "/overview");
|
||||
} catch (e) {
|
||||
formError.value = e instanceof Error ? e.message : "登录失败";
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="login-page">
|
||||
<n-card title="NixMsg 管理后台" style="width: 380px" size="small">
|
||||
<n-form label-placement="left" label-width="72" :show-feedback="false" @submit.prevent="onSubmit">
|
||||
<n-form-item label="用户名">
|
||||
<n-input v-model:value="username" autocomplete="username" placeholder="admin" />
|
||||
</n-form-item>
|
||||
<n-form-item label="密码">
|
||||
<n-input
|
||||
v-model:value="password"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
autocomplete="current-password"
|
||||
placeholder="请输入密码"
|
||||
@keyup.enter="onSubmit"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-text v-if="formError" type="error" style="display: block; margin-bottom: 8px">{{ formError }}</n-text>
|
||||
<n-space justify="end">
|
||||
<n-button type="primary" :loading="loading" data-testid="login-submit" @click="onSubmit">
|
||||
登录
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-form>
|
||||
<n-text depth="3" style="display: block; margin-top: 12px; font-size: 12px">
|
||||
假数据模式:用户名 admin,密码 adminpassword
|
||||
</n-text>
|
||||
</n-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.login-page {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f5f5f7;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user