You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fu-hsi-web/src/views/login/index.vue

210 lines
5.3 KiB
Vue

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<div class="login-container">
<div class="flex-column login-left">
<span>欢迎您</span>
<span>宁夏执法监督员</span>
<span>Welcome to the system</span>
</div>
<div class="login-form">
<div class="flex-column form-header">
<span>欢迎登录</span>
<span>Welcome to login</span>
</div>
<el-form ref="form" :model="loginForm" :rules="rules">
<el-form-item prop="username">
<div class="flex-row login-item">
<img src="~@/assets/login/dianhua@2x(1).png">
<el-input v-model="loginForm['username']" autofocus placeholder="请输入用户名" />
</div>
</el-form-item>
<el-form-item prop="password">
<div class="flex-row login-item">
<img src="~@/assets/login/mima@2x.png">
<el-input
ref="password"
v-model="loginForm['password']"
:type="passwordType"
placeholder="请输入密码"
clearable
/>
<span
v-if="passwordType === 'password'"
class="show-password"
@click="handlePassword"
>
<svg-icon icon-class="eye" />
</span>
<span
v-else
class="show-password"
@click="handlePassword"
>
<svg-icon icon-class="eye-open" />
</span>
</div>
</el-form-item>
<el-form-item>
<el-checkbox v-model="checked">记住密码</el-checkbox>
</el-form-item>
</el-form>
<el-button type="primary" :loading="loading" class="login-button" @click="handleLoginClick"></el-button>
</div>
</div>
</template>
<script>
import { title } from '@/config'
export default {
name: 'Login',
data() {
return {
title,
loginForm: {},
rules: {
username: [{ required: true, message: '用户名不能为空!' }],
password: [{ required: true, message: '密码不能为空!' }]
},
checked: false,
passwordType: 'password',
loading: false
}
},
created() {
document.body.style.overflow = 'hidden'
},
beforeUnmount() {
document.body.style.overflow = 'auto'
},
mounted() {
},
methods: {
handlePassword() {
this.passwordType === 'password'
? (this.passwordType = '')
: (this.passwordType = 'password')
this.$nextTick(() => {
this.$refs.password.focus()
})
},
// 登录
handleLoginClick() {
this.$refs.form.validate((valid) => {
if (valid) {
this.loading = true
this.$store
.dispatch('user/login', this.form)
.then(() => {
if (this.checked === true) {
// 传入账号名密码和保存天数3个参数
this.setCookie(this.form.account, this.form.password, 7)
} else {
// 清空Cookie
this.clearCookie()
}
const routerPath =
this.redirect === '/404' || this.redirect === '/401'
? '/'
: this.redirect
this.$router.push(routerPath).catch(() => {})
this.loading = false
})
.catch(() => {
this.loading = false
})
}
})
},
// 设置cookie
setCookie(c_name, c_pwd, exdays) {
const exdate = new Date() // 获取时间
exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays) // 保存的天数
// 字符串拼接cookie
window.document.cookie =
`base_account= ${c_name};path=/;expires=` + exdate.toGMTString()
window.document.cookie =
'base_userPwd' + '=' + this.$baseEncrypt(c_pwd) + ';path=/;expires=' + exdate.toGMTString()
}
}
}
</script>
<style lang="scss" scoped>
.login-container {
position: relative;
display: flex;
align-items: center;
width: 100vw;
height: 100vh;
background-image: url(../../assets/login/bg.png);
background-size: 100% 100%;
.login-left {
font-weight: bold;
font-size: 50px;
color: #FFFFFF;
margin-left: 260px;
span:nth-child(1) {
font-size: 50px;
letter-spacing: 3px;
}
span:nth-child(2) {
font-size: 80px;
letter-spacing: 13px;
margin-top: 14px;
}
span:nth-child(3) {
font-size: 40px;
margin-top: 24px;
}
}
.login-form {
position: absolute;
background: #FFFFFF;
border-radius: 8px;
right: 260px;
width: 500px;
min-height: 520px;
align-items: center;
padding: 0 30px;
box-sizing: border-box;
.form-header {
align-items: center;
padding: 65px 0;
font-size: 24px;
color: #333333;
span:nth-child(2) {
color: #666666;
margin-top: 10px;
}
}
.login-item {
align-items: center;
height: 48px;
line-height: 48px;
border: 1px solid #F5F5F5;
padding: 0 8px;
box-sizing: border-box;
border-radius: 5px;
img {
width: 15px;
height: 15px;
margin-right: 8px;
}
}
.login-button {
width: 100%;
margin-top: 20px;
height: 45px;
}
}
}
::v-deep {
.el-input__inner {
border: none;
}
}
</style>