2024-04-11 09:02:17 +00:00
|
|
|
<template>
|
|
|
|
<div class="login-container">
|
|
|
|
<div class="logo" />
|
|
|
|
<div class="form">
|
|
|
|
<h1 style="color: #A2A2A3;">云舒 心理健康平台</h1>
|
|
|
|
<el-card shadow="never" class="login-card">
|
|
|
|
<el-form ref="formRef" :model="loginForm" :rules="loginRules">
|
|
|
|
<el-form-item prop="username">
|
|
|
|
<el-input :prefix-icon="User" v-model="loginForm.username" placeholder="请输入学号" />
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item prop="password">
|
|
|
|
<el-input :prefix-icon="Lock" v-model="loginForm.password" show-password placeholder="请输入密码" />
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item>
|
|
|
|
<el-button style="width:350px" type="primary" @click="login">登录</el-button>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</el-card>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2024-03-28 02:46:41 +00:00
|
|
|
<script setup>
|
2024-04-11 09:02:17 +00:00
|
|
|
import { ref, onMounted } 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-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-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-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
|
|
|
onMounted(() => {
|
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;
|
|
|
|
background-color: #fff;
|
2024-03-28 02:46:41 +00:00
|
|
|
|
2024-04-11 09:02:17 +00:00
|
|
|
.logo {
|
|
|
|
flex: 3;
|
|
|
|
background: rgba(38, 72, 176) url(../../assets/images/login_back.png) no-repeat center / cover;
|
|
|
|
border-top-right-radius: 60px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: flex-end;
|
|
|
|
justify-content: center;
|
|
|
|
padding: 0 100px;
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
background: url(../../assets/images/logo.png) no-repeat 70px center / contain;
|
|
|
|
width: 300px;
|
|
|
|
height: 50px;
|
|
|
|
margin-bottom: 50px;
|
|
|
|
}
|
2024-03-28 02:46:41 +00:00
|
|
|
|
2024-04-11 09:02:17 +00:00
|
|
|
p {
|
|
|
|
color: #fff;
|
|
|
|
font-size: 18px;
|
|
|
|
margin-top: 20px;
|
|
|
|
width: 300px;
|
|
|
|
text-align: center;
|
2024-03-28 02:46:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.form {
|
2024-04-11 09:02:17 +00:00
|
|
|
flex: 2;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: center;
|
|
|
|
padding-left: 176px;
|
|
|
|
background-color: #fff;
|
|
|
|
|
|
|
|
.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>
|