You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

590 lines
14 KiB

4 years ago
<template>
<div class="login-container">
1 year ago
<div class="login-logo">
<img src="../../assets/login_logo.png" alt="">
</div>
<div class="login-wrap">
<div class="login-logo1">
<img src="../../assets/login_logo2.png" alt="">
</div>
<div class="login-form1">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="" auto-complete="on"
label-position="left">
<div class="title-container">
<h3 class="title">欢迎登录</h3>
<div class="title-change">
1 year ago
<span @click="changeLoginType" :class="{color:!changeLogin}">账号登录</span>
<span @click="changeLoginType" :class="{color:changeLogin}">短信登录</span>
1 year ago
</div>
</div>
<template v-if="!changeLogin">
<el-form-item prop="username">
1 year ago
<el-input ref="username" v-model="loginForm.username" placeholder="用户名" name="username" type="text"
1 year ago
tabindex="1" auto-complete="on" />
</el-form-item>
<el-form-item prop="password">
<el-input :key="passwordType" ref="password" v-model="loginForm.password" :type="passwordType"
placeholder="密码" name="password" tabindex="2" auto-complete="on" @keyup.enter.native="handleLogin" />
<span class="show-pwd" @click="showPwd">
<svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
</span>
</el-form-item>
</template>
<template v-else>
1 year ago
<el-form-item prop="mobile">
<el-input ref="mobile" v-model="loginForm.mobile" placeholder="手机号" name="mobile" type="text" tabindex="1"
auto-complete="on" />
1 year ago
</el-form-item>
<el-form-item prop="code" class="send_item">
<el-input ref="code" v-model="loginForm.code" placeholder="验证码" name="code" type="text" tabindex="1"
auto-complete="on">
</el-input>
1 year ago
<span :class="hasSend?'hasCode':'senndCode'" @click="sendMsg">{{hasSend?'':''}}
<span v-if="hasSend">({{count}}s)</span>
</span>
1 year ago
</el-form-item>
</template>
4 years ago
4 years ago
1 year ago
<el-button v-if="!changeLogin" :loading="loading" type="primary" class="loginBtn"
@click.native.prevent="handleLogin">登录</el-button>
<el-button v-else :loading="loading" type="primary" class="loginBtn"
@click.native.prevent="handleMsgLogin">登录</el-button>
1 year ago
</el-form>
4 years ago
</div>
1 year ago
</div>
4 years ago
1 year ago
<div class="login-footer">版权所有苏州未来科技产业发展有限公司</div>
4 years ago
</div>
</template>
<script>
import {
validUsername
} from '@/utils/validate'
1 year ago
import {
getMsg,
loginMsg
} from "@/api/user.js"
import {
setToken
} from '@/utils/auth'
3 years ago
const defaultSettings = require('../../../src/settings.js')
4 years ago
export default {
name: 'Login',
data() {
const validateUsername = (rule, value, callback) => {
if (!validUsername(value)) {
callback(new Error('请正确输入登录名'))
} else {
callback()
}
}
const validatePassword = (rule, value, callback) => {
if (value.length < 6) {
callback(new Error('密码输入错误'))
} else {
callback()
}
}
3 years ago
return {
title: "",
1 year ago
changeLogin: false,
1 year ago
hasSend: false,
count: 60,
sendTimer: null,
4 years ago
loginForm: {
3 years ago
username: '',
password: ''
4 years ago
},
loginRules: {
username: [{
required: true,
trigger: 'blur',
validator: validateUsername
}],
password: [{
required: true,
trigger: 'blur',
validator: validatePassword
}]
},
loading: false,
passwordType: 'password',
redirect: undefined
}
},
watch: {
$route: {
1 year ago
handler: function(route) {
if (route.query && route.query.redirect === '/') {
this.redirect = '/dashboard'
} else {
this.redirect = route.query && route.query.redirect
}
1 year ago
4 years ago
},
immediate: true
}
},
3 years ago
created() {
this.title = defaultSettings.title;
},
4 years ago
methods: {
1 year ago
// changeLogin(type){
// if(){}
// },
4 years ago
showPwd() {
if (this.passwordType === 'password') {
this.passwordType = ''
} else {
this.passwordType = 'password'
}
this.$nextTick(() => {
this.$refs.password.focus()
})
1 year ago
},
changeLoginType(){
this.changeLogin = !this.changeLogin
},
// 发短信
sendMsg() {
if(this.hasSend){
return
}
if (this.base.isNull(this.loginForm.mobile)) {
this.$Message.warning('请输入手机号')
return
}
if (!this.base.isPhone(this.loginForm.mobile)) {
this.$Message.warning('请输入正确的手机号')
return
}
getMsg({
mobile: this.loginForm.mobile
}).then(res => {
this.$Message.success('发送成功')
// 短信发送后 60s
this.hasSend = true
this.sendTimer = setInterval(() => {
if (this.count > 1) {
this.count--;
} else {
clearInterval(this.sendTimer);
this.hasSend = false;
}
}, 1000);
})
},
// 短信登录
handleMsgLogin(){
if (this.base.isNull(this.loginForm.mobile)) {
this.$Message.warning('请输入手机号')
return
}
if (this.base.isNull(this.loginForm.code)) {
this.$Message.warning('请输入验证码')
return
}
this.loading = true
loginMsg({
mobile:this.loginForm.mobile,
code:this.loginForm.code
}).then(res=>{
setToken(res.access_token)
this.$router.push({
path: this.redirect || '/dashboard'
})
this.loading = false
}).catch(res=>{
this.loading = false
})
1 year ago
},
1 year ago
//处理账号登录
4 years ago
handleLogin() {
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loading = true
4 years ago
this.$store.dispatch('user/login', this.loginForm).then(() => {
4 years ago
this.$router.push({
1 year ago
path: this.redirect || '/dashboard'
4 years ago
})
this.loading = false
}).catch(() => {
this.loading = false
})
} else {
console.log('error submit!!')
return false
}
})
1 year ago
},
// 处理短信登录
4 years ago
}
}
</script>
<style lang="scss">
4 years ago
#particles-js {
width: 100%;
3 years ago
height: 99%;
4 years ago
position: absolute;
}
4 years ago
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
1 year ago
$bg: #122583;
$light_gray: #122583;
4 years ago
$cursor: #122583;
4 years ago
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
.login-container .el-input input {
1 year ago
// color: $cursor;
4 years ago
}
}
/* reset element-ui css */
.login-container {
.el-input {
display: inline-block;
height: 47px;
width: 85%;
input {
background: transparent;
border: 0px;
-webkit-appearance: none;
border-radius: 0px;
padding: 12px 5px 12px 15px;
color: $light_gray;
height: 47px;
caret-color: $cursor;
&:-webkit-autofill {
3 years ago
//box-shadow: 0 0 0px 1000px $bg inset !important;
3 years ago
//-webkit-text-fill-color: $cursor !important;
4 years ago
}
}
}
.el-form-item {
1 year ago
border: 1px solid #cdcdcd;
background: #f4f4f4;
4 years ago
border-radius: 5px;
color: #454545;
1 year ago
margin-bottom: 30px;
4 years ago
}
}
</style>
<style lang="scss" scoped>
1 year ago
$bg: #122583;
$dark_gray: #122583;
$light_gray: #122583;
4 years ago
.login-container {
1 year ago
height: 100vh;
width: 100vw;
background: url("../../assets/login_bg.png") no-repeat;
4 years ago
overflow: hidden;
1 year ago
background-size: 100% 100%;
1 year ago
position: relative;
.login-footer {
text-align: center;
position: absolute;
bottom: 20px;
left: 0;
width: 100%;
color: #274999;
1 year ago
}
1 year ago
1 year ago
.login-logo {
// width: 20vw;
width: 383px;
margin: 0 auto;
margin-top: 9vh;
4 years ago
1 year ago
img {
width: 100%;
}
}
.login-wrap {
margin-top: 11vh;
margin-left: 20vw;
margin-right: 15vw;
display: flex;
justify-content: space-between;
align-items: end;
.login-logo1 {
// width: 16.5vw;
width: 270px;
img {
width: 100%;
}
}
.login-form1 {
width: 30vw;
// height: 49vh;
// width: 593px;
// height: 530px;
background: url('../../assets/login_form_bg.png') no-repeat;
background-size: 100% 100%;
padding: 45px;
padding-bottom: 90px;
padding-top: 35px;
// margin: 0 auto;
.title-container {
margin-bottom: 35px;
.title {
text-align: center;
font-size: 28px;
color: #274999;
text-align: center;
}
.title-change {
font-size: 18px;
display: flex;
justify-content: space-between;
padding-bottom: 10px;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
span {
cursor: pointer;
}
span.color {
color: #c69c6d;
}
}
}
.send_item {
.el-input {
width: 70%;
}
.senndCode {
background-color: #c69c6d;
display: inline-block;
width: 30%;
text-align: center;
color: #fff;
height: 47px;
line-height: 47px;
border-radius: 0 5px 5px 0;
1 year ago
cursor: pointer;
}
.hasCode{
background-color: #ddd;
display: inline-block;
width: 30%;
text-align: center;
color: #000;
height: 47px;
line-height: 47px;
border-radius: 0 5px 5px 0;
cursor: pointer;
1 year ago
}
}
.loginBtn {
width: 100%;
background: linear-gradient(to right, #284a99, #c69c6d);
border: none;
height: 47px;
line-height: 47px;
padding: 0;
font-size: 18px;
}
}
4 years ago
}
.tips {
font-size: 14px;
color: #fff;
margin-bottom: 10px;
span {
&:first-of-type {
margin-right: 16px;
}
}
}
.show-pwd {
position: absolute;
right: 10px;
top: 7px;
font-size: 16px;
color: $dark_gray;
cursor: pointer;
user-select: none;
}
}
1 year ago
1 year ago
@media (max-width:492px) {
1 year ago
.login-container {
.login-logo {
width: 100%;
1 year ago
}
1 year ago
1 year ago
.login-wrap {
margin-left: 0px;
margin-right: 0px;
.login-logo1 {
display: none;
}
.login-form1 {
width: 100%;
margin: 0 auto // height: 530px;
}
}
}
1 year ago
}
1 year ago
@media (min-width:493px) {
.login-container {
.login-wrap {
margin-left: 0px;
margin-right: 0px;
.login-logo1 {
display: none;
}
.login-form1 {
width: 493px;
margin: 0 auto // height: 530px;
}
}
}
}
@media (min-width:768px) {
.login-container {
.login-wrap {
margin-left: 100px;
margin-right: 50px;
.login-logo1 {
display: none;
}
.login-form1 {
width: 493px;
margin: 0 auto // height: 530px;
}
}
}
}
@media (min-width:992px) {
.login-container {
.login-wrap {
margin-left: 100px;
margin-right: 50px;
.login-logo1 {
display: block;
width: 217
}
.login-form1 {
width: 493px;
margin: 0;
// height: 530px;
}
}
}
}
@media (min-width:1220px) {
.login-container {
.login-wrap {
margin-left: 150px;
margin-right: 100px;
.login-logo1 {
display: block;
}
.login-form1 {
margin: 0
}
}
}
}
@media (min-width:1320px) {
.login-container {
.login-wrap {
margin-left: 15vw;
margin-right: 10vw;
.login-logo1 {
display: block;
}
.login-form1 {
margin: 0
}
}
}
}
@media (min-width:1440px) {
.login-container {
.login-wrap {
margin-left: 20vw;
margin-right: 10vw;
.login-logo1 {
display: block;
}
.login-form1 {
margin: 0
}
}
}
}
// @media (min-width:992px) {
// .login-container {
// .login-wrap {
// margin-left: 200px;
// margin-right: 150px;
// .login-logo1 {
// display: block;
// }
// // .login-form1 {
// // width: 593px;
// // // height: 530px;
// // }
// }
// }
// }
4 years ago
</style>