2023-11-02 12:12:37 +00:00
|
|
|
|
<template>
|
|
|
|
|
<div
|
|
|
|
|
class="login-page"
|
|
|
|
|
:style="{
|
2024-02-01 13:33:34 +00:00
|
|
|
|
background: `url('/imgs/create/background.webp') no-repeat bottom right`,
|
2024-05-09 12:34:24 +00:00
|
|
|
|
'background-size': 'cover'
|
2023-11-02 12:12:37 +00:00
|
|
|
|
}"
|
|
|
|
|
>
|
|
|
|
|
<div class="login-top">
|
2024-02-01 13:33:34 +00:00
|
|
|
|
<img src="/imgs/Logo.webp" alt="logo" />
|
2023-11-02 12:12:37 +00:00
|
|
|
|
<span>您好,请登录</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="login-box">
|
|
|
|
|
<el-form
|
2023-12-26 06:52:25 +00:00
|
|
|
|
:model="formData"
|
2023-11-02 12:12:37 +00:00
|
|
|
|
:rules="rules"
|
2023-12-26 06:52:25 +00:00
|
|
|
|
ref="formData"
|
2023-11-02 12:12:37 +00:00
|
|
|
|
label-width="100px"
|
|
|
|
|
class="login-form"
|
2024-05-09 12:34:24 +00:00
|
|
|
|
@submit.prevent
|
2023-11-02 12:12:37 +00:00
|
|
|
|
>
|
|
|
|
|
<el-form-item label="账号" prop="name">
|
2024-05-09 12:34:24 +00:00
|
|
|
|
<el-input v-model="formData.name" size="large"></el-input>
|
2023-11-02 12:12:37 +00:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item label="密码" prop="password">
|
2024-05-09 12:34:24 +00:00
|
|
|
|
<el-input type="password" v-model="formData.password" size="large"></el-input>
|
2023-12-26 06:52:25 +00:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item label="验证码" prop="captcha">
|
|
|
|
|
<div class="captcha-wrapper">
|
2024-05-09 12:34:24 +00:00
|
|
|
|
<el-input style="width: 150px" v-model="formData.captcha" size="large"></el-input>
|
|
|
|
|
<div class="captcha-img" @click="refreshCaptcha" v-html="captchaImgData"></div>
|
2023-12-26 06:52:25 +00:00
|
|
|
|
</div>
|
2023-11-02 12:12:37 +00:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item class="button-group">
|
|
|
|
|
<el-button
|
2023-11-13 20:21:18 +00:00
|
|
|
|
:loading="loginPending"
|
2023-11-02 12:12:37 +00:00
|
|
|
|
size="small"
|
|
|
|
|
type="primary"
|
|
|
|
|
class="button"
|
2023-12-26 06:52:25 +00:00
|
|
|
|
@click="submitForm('formData', 'login')"
|
2023-11-02 12:12:37 +00:00
|
|
|
|
>登录</el-button
|
|
|
|
|
>
|
2023-11-13 20:21:18 +00:00
|
|
|
|
<el-button
|
|
|
|
|
:loading="registerPending"
|
|
|
|
|
class="button register-button"
|
2023-12-26 06:52:25 +00:00
|
|
|
|
@click="submitForm('formData', 'register')"
|
2023-11-02 12:12:37 +00:00
|
|
|
|
>注册</el-button
|
|
|
|
|
>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2024-05-09 12:34:24 +00:00
|
|
|
|
|
2023-11-02 12:12:37 +00:00
|
|
|
|
<script>
|
2024-05-09 12:34:24 +00:00
|
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
|
import 'element-plus/theme-chalk/src/message.scss'
|
|
|
|
|
|
|
|
|
|
import { login, register } from '@/management/api/auth'
|
|
|
|
|
import { refreshCaptcha } from '@/management/api/captcha'
|
|
|
|
|
import { CODE_MAP } from '@/management/api/base'
|
2023-11-02 12:12:37 +00:00
|
|
|
|
export default {
|
2024-05-09 12:34:24 +00:00
|
|
|
|
name: 'LoginPage',
|
2023-11-02 12:12:37 +00:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
2023-12-26 06:52:25 +00:00
|
|
|
|
formData: {
|
2023-11-02 12:12:37 +00:00
|
|
|
|
name: '',
|
|
|
|
|
password: '',
|
2023-12-26 06:52:25 +00:00
|
|
|
|
captcha: '',
|
2024-05-09 12:34:24 +00:00
|
|
|
|
captchaId: ''
|
2023-11-02 12:12:37 +00:00
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
name: [
|
|
|
|
|
{ required: true, message: '请输入账号', trigger: 'blur' },
|
|
|
|
|
{
|
|
|
|
|
min: 3,
|
|
|
|
|
max: 10,
|
|
|
|
|
message: '长度在 3 到 10 个字符',
|
2024-05-09 12:34:24 +00:00
|
|
|
|
trigger: 'blur'
|
|
|
|
|
}
|
2023-11-02 12:12:37 +00:00
|
|
|
|
],
|
|
|
|
|
password: [
|
|
|
|
|
{ required: true, message: '请输入密码', trigger: 'blur' },
|
|
|
|
|
{
|
|
|
|
|
min: 8,
|
|
|
|
|
max: 16,
|
|
|
|
|
message: '长度在 8 到 16 个字符',
|
2024-05-09 12:34:24 +00:00
|
|
|
|
trigger: 'blur'
|
|
|
|
|
}
|
2023-11-02 12:12:37 +00:00
|
|
|
|
],
|
2023-12-26 06:52:25 +00:00
|
|
|
|
captcha: [
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请输入验证码',
|
2024-05-09 12:34:24 +00:00
|
|
|
|
trigger: 'blur'
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-11-02 12:12:37 +00:00
|
|
|
|
},
|
2023-11-13 20:21:18 +00:00
|
|
|
|
loginPending: false,
|
|
|
|
|
registerPending: false,
|
2024-05-09 12:34:24 +00:00
|
|
|
|
captchaImgData: ''
|
|
|
|
|
}
|
2023-11-02 12:12:37 +00:00
|
|
|
|
},
|
2023-12-26 06:52:25 +00:00
|
|
|
|
created() {
|
2024-05-09 12:34:24 +00:00
|
|
|
|
this.refreshCaptcha()
|
2023-12-26 06:52:25 +00:00
|
|
|
|
},
|
2023-11-02 12:12:37 +00:00
|
|
|
|
methods: {
|
|
|
|
|
submitForm(formName, type) {
|
|
|
|
|
this.$refs[formName].validate(async (valid) => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
try {
|
|
|
|
|
const submitTypes = {
|
|
|
|
|
login,
|
2024-05-09 12:34:24 +00:00
|
|
|
|
register
|
|
|
|
|
}
|
|
|
|
|
this[`${type}Pending`] = true
|
2023-11-02 12:12:37 +00:00
|
|
|
|
const res = await submitTypes[type]({
|
2023-12-26 06:52:25 +00:00
|
|
|
|
username: this.formData.name,
|
|
|
|
|
password: this.formData.password,
|
|
|
|
|
captcha: this.formData.captcha,
|
2024-05-09 12:34:24 +00:00
|
|
|
|
captchaId: this.formData.captchaId
|
|
|
|
|
})
|
|
|
|
|
this[`${type}Pending`] = false
|
2023-11-02 12:12:37 +00:00
|
|
|
|
if (res.code !== CODE_MAP.SUCCESS) {
|
2024-05-09 12:34:24 +00:00
|
|
|
|
ElMessage.error(res.errmsg)
|
|
|
|
|
throw new Error('登录/注册失败' + res.errmsg)
|
2023-11-02 12:12:37 +00:00
|
|
|
|
}
|
|
|
|
|
this.$store.dispatch('user/login', {
|
|
|
|
|
username: res.data.username,
|
2024-05-09 12:34:24 +00:00
|
|
|
|
token: res.data.token
|
|
|
|
|
})
|
2023-11-02 12:12:37 +00:00
|
|
|
|
let redirect = {
|
2024-05-09 12:34:24 +00:00
|
|
|
|
name: 'survey'
|
|
|
|
|
}
|
2023-11-02 12:12:37 +00:00
|
|
|
|
if (this.$route.query.redirect) {
|
2024-05-09 12:34:24 +00:00
|
|
|
|
redirect = decodeURIComponent(this.$route.query.redirect)
|
2023-11-02 12:12:37 +00:00
|
|
|
|
}
|
2024-05-09 12:34:24 +00:00
|
|
|
|
this.$router.replace(redirect)
|
2023-11-02 12:12:37 +00:00
|
|
|
|
} catch (error) {
|
2024-05-09 12:34:24 +00:00
|
|
|
|
this[`${type}Pending`] = false
|
2023-11-02 12:12:37 +00:00
|
|
|
|
}
|
2024-05-09 12:34:24 +00:00
|
|
|
|
return true
|
2023-11-02 12:12:37 +00:00
|
|
|
|
} else {
|
2024-05-09 12:34:24 +00:00
|
|
|
|
return false
|
2023-11-02 12:12:37 +00:00
|
|
|
|
}
|
2024-05-09 12:34:24 +00:00
|
|
|
|
})
|
2023-11-02 12:12:37 +00:00
|
|
|
|
},
|
2023-12-26 06:52:25 +00:00
|
|
|
|
async refreshCaptcha() {
|
2024-01-30 14:19:45 +00:00
|
|
|
|
try {
|
|
|
|
|
const res = await refreshCaptcha({
|
2024-05-09 12:34:24 +00:00
|
|
|
|
captchaId: this.formData.captchaId
|
|
|
|
|
})
|
2024-01-30 14:19:45 +00:00
|
|
|
|
if (res.code === 200) {
|
2024-05-09 12:34:24 +00:00
|
|
|
|
const { id, img } = res.data
|
|
|
|
|
this.formData.captchaId = id
|
|
|
|
|
this.captchaImgData = img
|
2024-01-30 14:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2024-05-09 12:34:24 +00:00
|
|
|
|
ElMessage.error('获取验证码失败')
|
2023-12-26 06:52:25 +00:00
|
|
|
|
}
|
2024-05-09 12:34:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-02 12:12:37 +00:00
|
|
|
|
</script>
|
2024-05-09 12:34:24 +00:00
|
|
|
|
|
2023-11-02 12:12:37 +00:00
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.login-page {
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
height: 100vh;
|
2023-12-26 06:52:25 +00:00
|
|
|
|
|
2023-11-02 12:12:37 +00:00
|
|
|
|
.login-top {
|
|
|
|
|
color: #4a4c5b;
|
|
|
|
|
height: 56px;
|
|
|
|
|
background: #fff;
|
|
|
|
|
padding: 0 20px;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
2023-12-26 06:52:25 +00:00
|
|
|
|
|
2023-11-02 12:12:37 +00:00
|
|
|
|
img {
|
|
|
|
|
width: 90px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-26 06:52:25 +00:00
|
|
|
|
|
2023-11-02 12:12:37 +00:00
|
|
|
|
.login-box {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
2023-12-26 06:52:25 +00:00
|
|
|
|
|
2023-11-02 12:12:37 +00:00
|
|
|
|
.login-form {
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
padding: 60px 60px 60px 0;
|
|
|
|
|
background: #fff;
|
2023-11-13 20:21:18 +00:00
|
|
|
|
box-shadow: 4px 0 20px 0 rgba(82, 82, 102, 0.15);
|
2023-11-02 12:12:37 +00:00
|
|
|
|
margin-top: -150px;
|
2023-12-26 06:52:25 +00:00
|
|
|
|
|
2023-11-02 12:12:37 +00:00
|
|
|
|
.button-group {
|
|
|
|
|
margin-top: 40px;
|
|
|
|
|
}
|
2023-12-26 06:52:25 +00:00
|
|
|
|
|
2023-11-02 12:12:37 +00:00
|
|
|
|
.button {
|
|
|
|
|
width: 160px;
|
|
|
|
|
height: 40px;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
}
|
2023-12-26 06:52:25 +00:00
|
|
|
|
|
2023-11-02 12:12:37 +00:00
|
|
|
|
.register-button {
|
|
|
|
|
border-color: #faa600;
|
|
|
|
|
color: #faa600;
|
|
|
|
|
margin-left: 20px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-26 06:52:25 +00:00
|
|
|
|
|
2023-11-02 12:12:37 +00:00
|
|
|
|
.tips {
|
|
|
|
|
color: #999;
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 15px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
margin-left: 50%;
|
|
|
|
|
transform: translateX(-50%);
|
|
|
|
|
}
|
2023-12-26 06:52:25 +00:00
|
|
|
|
|
|
|
|
|
.captcha-wrapper {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
.captcha-img {
|
|
|
|
|
height: 40px;
|
|
|
|
|
cursor: pointer;
|
2024-05-09 12:34:24 +00:00
|
|
|
|
:deep(> svg) {
|
2023-12-26 06:52:25 +00:00
|
|
|
|
max-height: 40px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-02 12:12:37 +00:00
|
|
|
|
}
|
|
|
|
|
</style>
|