2018-01-20 10:17:35 +08:00
|
|
|
<template>
|
2018-01-21 23:30:01 +08:00
|
|
|
<div class="login-page">
|
|
|
|
|
<div class="layer bg" id="login"></div>
|
2018-01-22 00:04:39 +08:00
|
|
|
<div class="layer flex-center">
|
2018-01-25 20:03:59 +08:00
|
|
|
<!-- logo部分 -->
|
2018-01-22 00:04:39 +08:00
|
|
|
<div class="logo-group">
|
|
|
|
|
<img src="@/assets/image/logo/w500.png" alt="logo">
|
|
|
|
|
</div>
|
2018-01-25 20:03:59 +08:00
|
|
|
<!-- 表单部分 -->
|
2018-01-22 00:04:39 +08:00
|
|
|
<div class="form-group">
|
|
|
|
|
<el-card>
|
2018-01-24 22:26:12 +08:00
|
|
|
<el-form ref="loginForm" label-position="top" :rules="rules" :model="formLogin">
|
2018-01-22 00:04:39 +08:00
|
|
|
<el-form-item prop="username">
|
2018-01-24 22:26:12 +08:00
|
|
|
<el-input type="text" v-model="formLogin.username" placeholder="用户名">
|
2018-01-22 00:04:39 +08:00
|
|
|
<i slot="prepend" class="fa fa-user-circle-o"></i>
|
|
|
|
|
</el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item prop="password">
|
2018-01-24 22:26:12 +08:00
|
|
|
<el-input type="password" v-model="formLogin.password" placeholder="密码">
|
2018-01-22 00:04:39 +08:00
|
|
|
<i slot="prepend" class="fa fa-keyboard-o"></i>
|
|
|
|
|
</el-input>
|
|
|
|
|
</el-form-item>
|
2018-01-24 22:26:12 +08:00
|
|
|
<el-button @click="submit" type="primary" class="button-login">登陆</el-button>
|
2018-01-22 00:04:39 +08:00
|
|
|
</el-form>
|
|
|
|
|
</el-card>
|
|
|
|
|
</div>
|
2018-01-25 20:03:59 +08:00
|
|
|
<!-- 帮助按钮 -->
|
|
|
|
|
<el-button type="info" class="button-help">
|
|
|
|
|
需要帮助
|
|
|
|
|
<i class="fa fa-question-circle"></i>
|
|
|
|
|
</el-button>
|
2018-01-21 23:30:01 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2018-01-20 10:17:35 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
/* eslint-disable */
|
|
|
|
|
require('particles.js')
|
|
|
|
|
// 配置地址
|
|
|
|
|
// https://vincentgarreau.com/particles.js/#default
|
2018-01-21 23:03:28 +08:00
|
|
|
import config from './config/default'
|
2018-01-27 10:01:22 +08:00
|
|
|
import Cookies from 'js-cookie'
|
2018-01-20 10:17:35 +08:00
|
|
|
export default {
|
2018-01-22 00:04:39 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
formLogin: {
|
2018-01-25 20:03:59 +08:00
|
|
|
username: 'admin',
|
|
|
|
|
password: 'admin'
|
2018-01-22 00:04:39 +08:00
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
username: [
|
|
|
|
|
{ required: true, message: '请输入用户名', trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
password: [
|
|
|
|
|
{ required: true, message: '请输入密码', trigger: 'blur' }
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-01-20 10:17:35 +08:00
|
|
|
mounted () {
|
2018-01-22 16:56:57 +08:00
|
|
|
// 初始化例子插件
|
2018-01-20 10:17:35 +08:00
|
|
|
particlesJS('login', config)
|
2018-01-22 00:04:39 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
2018-01-22 16:56:57 +08:00
|
|
|
// 提交登陆信息
|
2018-01-22 00:04:39 +08:00
|
|
|
submit () {
|
|
|
|
|
this.$refs.loginForm.validate((valid) => {
|
|
|
|
|
if (valid) {
|
2018-01-25 20:03:59 +08:00
|
|
|
// 开始请求登录接口
|
2018-01-28 23:22:25 +08:00
|
|
|
this.$axios({
|
2018-01-22 13:49:11 +08:00
|
|
|
method: 'post',
|
|
|
|
|
url: '/login',
|
|
|
|
|
data: {
|
|
|
|
|
username: this.formLogin.username,
|
|
|
|
|
password: this.formLogin.password
|
|
|
|
|
}
|
|
|
|
|
})
|
2018-01-27 09:45:46 +08:00
|
|
|
.then(res => {
|
2018-01-25 23:47:19 +08:00
|
|
|
this.$log('登录结果', res)
|
2018-01-27 10:01:22 +08:00
|
|
|
const setting = {
|
|
|
|
|
expires: 1
|
|
|
|
|
}
|
|
|
|
|
Cookies.set('username', res.username, setting)
|
|
|
|
|
Cookies.set('password', res.password, setting)
|
2018-01-27 10:25:59 +08:00
|
|
|
Cookies.set('token', res.token, setting)
|
2018-01-27 10:08:39 +08:00
|
|
|
this.$router.push({
|
|
|
|
|
name: 'index'
|
|
|
|
|
})
|
2018-01-22 13:49:11 +08:00
|
|
|
})
|
2018-01-27 09:45:46 +08:00
|
|
|
.catch(err => {
|
2018-01-27 09:51:23 +08:00
|
|
|
this.$log('错误信息', err)
|
2018-01-27 09:45:46 +08:00
|
|
|
})
|
2018-01-22 00:04:39 +08:00
|
|
|
} else {
|
2018-01-22 13:49:11 +08:00
|
|
|
return false
|
2018-01-22 00:04:39 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2018-01-20 10:17:35 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2018-01-21 23:19:19 +08:00
|
|
|
<style lang="scss">
|
2018-01-25 20:03:59 +08:00
|
|
|
@import './style.scss';
|
2018-01-20 10:17:35 +08:00
|
|
|
</style>
|
|
|
|
|
|