辅助 StLoginPage1 组件展示的组件
基于 Navie UI 编写的一些辅助 StLoginPage1 组件示例展示的组件。
由于 Navie UI 组件库的暗黑模式,我在 Vitepress 中没有配置成功,目前为了更好的展示效果,我将其中的表单、表单项、输入框等组件换成了 Element Plus 的组件。
表单组件
vue
<script setup lang="ts">
/**
* 组件参数
*/
withDefaults(
defineProps<{
// 表单标题
title?: string;
// 表单标签宽度
labelWidth?: number | string | "auto";
// 按钮文本
btnText?: string;
}>(),
{
title: "登录",
labelWidth: 'auto',
btnText: "登录",
}
)
</script>
<template>
<div class="login-form box-bg box-shadow">
<h1 class="login-form__title">
{{ title }}
</h1>
<div class="login-form__form">
<el-form :label-width="labelWidth" label-position="left">
<slot></slot>
<el-form-item>
<n-button type="primary" block round attr-type="submit">{{ btnText }}</n-button>
</el-form-item>
</el-form>
</div>
</div>
</template>
<style scoped lang="scss">
.login-form {
width: 95%;
max-width: 425px;
padding: 2rem 0;
margin: 0 2rem;
border-radius: 1rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
.login-form__title {
width: fit-content;
margin-bottom: 0.5rem;
background-image: linear-gradient(to bottom right, #92fe9d, #18A058);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 2rem;
font-weight: bold;
line-height: 1.5;
}
}
</style>
密码登录表单组件
vue
<script setup lang="ts">
import LoginForm from "./login-form.vue"
</script>
<template>
<div class="login-form-by-pwd">
<LoginForm>
<el-form-item label="用户名">
<el-input placeholder="请输入用户名" clearable/>
</el-form-item>
<el-form-item label="密码">
<el-input placeholder="请输入密码" type="password" clearable show-password-on="click"/>
</el-form-item>
</LoginForm>
</div>
</template>
<style scoped>
</style>
邮箱登录表单组件
vue
<script setup lang="ts">
import LoginForm from "./login-form.vue"
</script>
<template>
<div class="login-form-by-email">
<LoginForm title="邮箱登录">
<el-form-item label="邮箱">
<el-input placeholder="请输入邮箱" clearable/>
</el-form-item>
<el-form-item label="验证码">
<el-input placeholder="请输入验证码" clearable/>
</el-form-item>
</LoginForm>
</div>
</template>
<style scoped>
</style>
表单切换组件
vue
<script setup lang="ts">
/**
* 组件参数
*/
withDefaults(
defineProps<{
// 标题
title?: string;
// 副标题
subTitle?: string;
// 切换按钮文字
toggleBtnText: string;
// 切换按钮点击事件处理函数
toggleHandler?: () => void;
}>(),
{
title: '',
subTitle: '',
toggleBtnText: '',
toggleHandler: () => {}
}
)
</script>
<template>
<div class="login-form-toggle">
<div class="login-form-toggle__title">{{ title }}</div>
<div class="login-form-toggle__sub-title">{{ subTitle }}</div>
<div class="login-form-toggle__toggle-btn">
<n-button
class="btn"
color="transparent"
type="primary"
size="large"
round
@click="toggleHandler"
>{{ toggleBtnText }}</n-button>
</div>
</div>
</template>
<style scoped lang="scss">
.login-form-toggle {
color: #fff;
.login-form-toggle__title {
margin-bottom: 0.25rem;
font-size: 1.5rem;
font-weight: bold;
}
.login-form-toggle__sub-title {
max-width: 240px;
margin-bottom: 0.75rem;
font-size: 0.875rem;
}
.login-form-toggle__toggle-btn {
.btn {
border: 2px solid #fff;
}
}
}
</style>