2023-09-15 09:40:35 +00:00
|
|
|
<template>
|
2023-10-12 08:36:16 +00:00
|
|
|
<login-layout v-loading="loading">
|
2023-11-02 10:25:09 +00:00
|
|
|
<LoginContainer subTitle="欢迎使用 MaxKB 管理平台">
|
2023-10-12 08:36:16 +00:00
|
|
|
<el-form class="login-form" :rules="rules" :model="loginForm" ref="loginFormRef">
|
|
|
|
|
<el-form-item>
|
|
|
|
|
<el-input
|
|
|
|
|
size="large"
|
|
|
|
|
class="input-item"
|
|
|
|
|
v-model="loginForm.username"
|
|
|
|
|
placeholder="请输入用户名"
|
|
|
|
|
>
|
|
|
|
|
<template #prepend>
|
|
|
|
|
<el-button icon="UserFilled" />
|
|
|
|
|
</template>
|
|
|
|
|
</el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item>
|
|
|
|
|
<el-input
|
|
|
|
|
type="password"
|
|
|
|
|
size="large"
|
|
|
|
|
class="input-item"
|
|
|
|
|
v-model="loginForm.password"
|
|
|
|
|
placeholder="请输入密码"
|
|
|
|
|
show-password
|
|
|
|
|
>
|
|
|
|
|
<template #prepend>
|
|
|
|
|
<el-button icon="Lock" />
|
|
|
|
|
</template>
|
|
|
|
|
</el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<div class="operate-container flex-between">
|
|
|
|
|
<el-button class="register" @click="router.push('/register')" link type="primary">
|
|
|
|
|
注册
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
class="forgot-password"
|
|
|
|
|
@click="router.push('/forgot_password')"
|
|
|
|
|
link
|
|
|
|
|
type="primary"
|
|
|
|
|
>
|
|
|
|
|
忘记密码
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
<el-button type="primary" class="login-submit-button w-full" @click="login">登录</el-button>
|
|
|
|
|
</LoginContainer>
|
|
|
|
|
</login-layout>
|
2023-09-15 09:40:35 +00:00
|
|
|
</template>
|
|
|
|
|
<script setup lang="ts">
|
2023-10-12 08:36:16 +00:00
|
|
|
import { ref } from 'vue'
|
2023-10-20 03:26:14 +00:00
|
|
|
import type { LoginRequest } from '@/api/type/user'
|
2023-10-12 08:36:16 +00:00
|
|
|
import { useRouter } from 'vue-router'
|
2023-09-15 09:40:35 +00:00
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
2023-10-19 10:18:45 +00:00
|
|
|
import useStore from '@/stores'
|
2023-09-15 09:40:35 +00:00
|
|
|
|
2023-10-12 08:36:16 +00:00
|
|
|
const loading = ref<boolean>(false)
|
2023-10-19 10:18:45 +00:00
|
|
|
const { user } = useStore()
|
2023-09-15 09:40:35 +00:00
|
|
|
const router = useRouter()
|
|
|
|
|
const loginForm = ref<LoginRequest>({
|
2023-10-12 08:36:16 +00:00
|
|
|
username: '',
|
|
|
|
|
password: ''
|
|
|
|
|
})
|
2023-09-15 09:40:35 +00:00
|
|
|
|
|
|
|
|
const rules = ref<FormRules<LoginRequest>>({
|
2023-10-12 08:36:16 +00:00
|
|
|
username: [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请输入用户名',
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
password: [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请输入密码',
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
min: 6,
|
|
|
|
|
max: 30,
|
|
|
|
|
message: '长度在 6 到 30 个字符',
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-09-15 09:40:35 +00:00
|
|
|
})
|
|
|
|
|
const loginFormRef = ref<FormInstance>()
|
|
|
|
|
|
|
|
|
|
const login = () => {
|
2023-10-12 08:36:16 +00:00
|
|
|
loginFormRef.value?.validate().then(() => {
|
|
|
|
|
loading.value = true
|
2023-10-19 10:18:45 +00:00
|
|
|
user
|
2023-10-12 08:36:16 +00:00
|
|
|
.login(loginForm.value.username, loginForm.value.password)
|
|
|
|
|
.then(() => {
|
|
|
|
|
router.push({ name: 'home' })
|
|
|
|
|
})
|
|
|
|
|
.finally(() => (loading.value = false))
|
|
|
|
|
})
|
2023-09-15 09:40:35 +00:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss" scope>
|
2023-10-12 08:36:16 +00:00
|
|
|
@import './index.scss';
|
2023-10-20 03:26:14 +00:00
|
|
|
</style>
|