mental-health-student/src/views/Login/index.vue

127 lines
2.9 KiB
Vue
Raw Normal View History

2024-04-11 09:02:17 +00:00
<template>
<div class="login-container">
2024-04-15 09:33:01 +00:00
<div class="logo">
<div class="second_bg"></div>
</div>
2024-04-11 09:02:17 +00:00
<div class="form">
2024-04-15 09:33:01 +00:00
<h1>云舒心理健康云平台</h1>
2024-04-11 09:02:17 +00:00
<el-card shadow="never" class="login-card">
2024-04-15 09:33:01 +00:00
<el-form ref="formRef" :model="loginForm" :rules="loginRules" v-loading="loading" element-loading-text="登录中...">
2024-04-11 09:02:17 +00:00
<el-form-item prop="username">
2024-04-15 09:33:01 +00:00
<el-input :prefix-icon="User" v-model="loginForm.username" placeholder="请输入学号" @keyup.enter="login" />
2024-04-11 09:02:17 +00:00
</el-form-item>
<el-form-item prop="password">
2024-04-15 09:33:01 +00:00
<el-input :prefix-icon="Lock" v-model="loginForm.password" show-password placeholder="请输入密码"
@keyup.enter="login" />
2024-04-11 09:02:17 +00:00
</el-form-item>
<el-form-item>
2024-04-16 08:36:38 +00:00
<el-button size="large" round style="width:350px" type="primary" @click="login">登录</el-button>
2024-04-11 09:02:17 +00:00
</el-form-item>
</el-form>
</el-card>
</div>
</div>
</template>
2024-03-28 02:46:41 +00:00
<script setup>
2024-04-16 08:36:38 +00:00
import { ref } from 'vue'
2024-03-28 02:46:41 +00:00
import { useRouter } from 'vue-router'
2024-04-11 09:02:17 +00:00
import { loginAPI } from '@/apis/user'
import { User, Lock } from '@element-plus/icons-vue'
2024-03-28 02:46:41 +00:00
2024-04-11 09:02:17 +00:00
const router = useRouter();
2024-03-28 02:46:41 +00:00
2024-04-11 09:02:17 +00:00
const loginForm = ref({
username: '',
password: '',
clientId: 'e5cd7e4891bf95d1d19206ce24a7b32e',
grantType: 'password'
2024-03-28 02:46:41 +00:00
})
2024-04-15 09:33:01 +00:00
const loading = ref(false)
2024-04-11 09:02:17 +00:00
const loginRules = ref({
username: [
{ required: true, message: '请输入学号', trigger: 'blur' },
2024-03-28 02:46:41 +00:00
],
password: [
2024-04-11 09:02:17 +00:00
{ required: true, message: '请输入密码', trigger: 'blur' },
2024-03-28 02:46:41 +00:00
]
2024-04-11 09:02:17 +00:00
})
2024-03-28 02:46:41 +00:00
const formRef = ref(null)
2024-04-11 09:02:17 +00:00
async function login() {
2024-03-28 02:46:41 +00:00
formRef.value.validate(async (valid) => {
if (valid) {
2024-04-15 09:33:01 +00:00
loading.value = true
2024-04-11 09:02:17 +00:00
const res = await loginAPI(loginForm.value)
if (res.code == 200) {
localStorage.setItem('token', res.data.access_token)
router.push('/')
} else {
ElMessage.error(res.msg)
}
2024-04-15 09:33:01 +00:00
loading.value = false
2024-03-28 02:46:41 +00:00
}
2024-04-11 09:02:17 +00:00
2024-03-28 02:46:41 +00:00
})
}
2024-04-11 09:02:17 +00:00
</script>
2024-03-28 02:46:41 +00:00
2024-04-11 09:02:17 +00:00
<style lang="scss" scoped>
.login-container {
2024-03-28 02:46:41 +00:00
display: flex;
2024-04-11 09:02:17 +00:00
align-items: stretch;
height: 100vh;
2024-03-28 02:46:41 +00:00
2024-04-11 09:02:17 +00:00
.logo {
2024-04-16 08:36:38 +00:00
flex: 3;
2024-04-15 09:33:01 +00:00
background: rgba(38, 72, 176) url(../../assets/images/bg1.png) no-repeat center / cover;
2024-04-11 09:02:17 +00:00
display: flex;
flex-direction: column;
justify-content: center;
2024-04-15 09:33:01 +00:00
align-items: stretch;
2024-04-11 09:02:17 +00:00
2024-04-15 09:33:01 +00:00
.second_bg {
width: 100%;
height: 100%;
background: url(../../assets/images/bg2.png) 50% no-repeat;
background-size: cover;
2024-03-28 02:46:41 +00:00
}
}
.form {
2024-04-15 09:33:01 +00:00
flex: 1;
2024-04-11 09:02:17 +00:00
display: flex;
flex-direction: column;
justify-content: center;
2024-04-16 08:36:38 +00:00
padding-left: 40px;
2024-04-11 09:02:17 +00:00
background-color: #fff;
2024-04-15 09:33:01 +00:00
h1 {
color: #A2A2A3;
letter-spacing: 16px;
font-weight: normal;
}
2024-04-11 09:02:17 +00:00
.el-card {
border: none;
padding: 0;
2024-03-28 02:46:41 +00:00
}
2024-04-11 09:02:17 +00:00
h1 {
padding-left: 20px;
font-size: 24px;
2024-03-28 02:46:41 +00:00
}
2024-04-11 09:02:17 +00:00
.el-input {
width: 350px;
height: 44px;
2024-03-28 02:46:41 +00:00
2024-04-11 09:02:17 +00:00
.el-input__inner {
background: #f4f5fb;
2024-03-28 02:46:41 +00:00
}
}
}
}
2024-04-11 09:02:17 +00:00
</style>