Former-commit-id: 9ffc312ee5944529ab68c79779f52fb5cfdc6b08 [formerly 9ffc312ee5944529ab68c79779f52fb5cfdc6b08 [formerly 9ffc312ee5944529ab68c79779f52fb5cfdc6b08 [formerly 9ffc312ee5944529ab68c79779f52fb5cfdc6b08 [formerly 58f24479353c8b52febe082a001e63cd41e7472c [formerly 77213ee5ca1b0eaaf5d1b28722b92bf91d523403]]]]] Former-commit-id: e487943672bf2110e7a8b42a38202aa38c8049a5 Former-commit-id: 8e5c055d54b0cd0691707f76d41ebae2d67997fe Former-commit-id: 8872a93499e446b5b102ec62e7b5b0701b9669a2 [formerly d589156a4be436cb550d73f50f9ad67f681125f7] Former-commit-id: 9a36351a2d5843e373b4be2621089861a7ae56b0 Former-commit-id: 5732ff0ac69b280e70bee43142a0e8634d9c4b83 Former-commit-id: a11780e8a2ec1c3728940848a3e1c517f029902a Former-commit-id: ac4f1aacc30da7a424584b2357bf9f6a8064680f Former-commit-id: 29d4aa3fc03f78db1474f7634e94fb66ed1becc6
127 lines
3.7 KiB
Vue
127 lines
3.7 KiB
Vue
<template>
|
||
<div class="login-page">
|
||
<div class="layer bg" id="login"></div>
|
||
<div class="layer flex-center">
|
||
<!-- logo部分 -->
|
||
<div class="logo-group">
|
||
<img :src="`${$assetsPublicPath}static/image/icon/500/d2admin.png`" alt="logo">
|
||
</div>
|
||
<!-- 表单部分 -->
|
||
<div class="form-group">
|
||
<el-card>
|
||
<el-form ref="loginForm" label-position="top" :rules="rules" :model="formLogin">
|
||
<el-form-item prop="username">
|
||
<el-input type="text" v-model="formLogin.username" placeholder="用户名">
|
||
<i slot="prepend" class="fa fa-user-circle-o"></i>
|
||
</el-input>
|
||
</el-form-item>
|
||
<el-form-item prop="password">
|
||
<el-input type="password" v-model="formLogin.password" placeholder="密码">
|
||
<i slot="prepend" class="fa fa-keyboard-o"></i>
|
||
</el-input>
|
||
</el-form-item>
|
||
<el-form-item prop="code">
|
||
<el-input type="text" v-model="formLogin.code" placeholder="- - - -">
|
||
<template slot="prepend">验证码</template>
|
||
<template slot="append">
|
||
<img class="login-code" :src="`${$assetsPublicPath}static/image/login-code.png`">
|
||
</template>
|
||
</el-input>
|
||
</el-form-item>
|
||
<el-button @click="submit" type="primary" class="button-login">登录</el-button>
|
||
</el-form>
|
||
</el-card>
|
||
</div>
|
||
<!-- 帮助按钮 -->
|
||
<el-button type="info" class="button-help">
|
||
需要帮助
|
||
<i class="fa fa-question-circle"></i>
|
||
</el-button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
/* eslint-disable */
|
||
require('particles.js')
|
||
// 配置地址
|
||
// https://vincentgarreau.com/particles.js/#default
|
||
import config from './config/default'
|
||
import Cookies from 'js-cookie'
|
||
import { mapMutations } from 'vuex'
|
||
|
||
export default {
|
||
data () {
|
||
return {
|
||
formLogin: {
|
||
username: 'admin',
|
||
password: 'admin',
|
||
code: 'v9am'
|
||
},
|
||
rules: {
|
||
username: [
|
||
{ required: true, message: '请输入用户名', trigger: 'blur' }
|
||
],
|
||
password: [
|
||
{ required: true, message: '请输入密码', trigger: 'blur' }
|
||
],
|
||
code: [
|
||
{ required: true, message: '请输入验证码', trigger: 'blur' }
|
||
]
|
||
}
|
||
}
|
||
},
|
||
mounted () {
|
||
// 初始化例子插件
|
||
particlesJS('login', config)
|
||
},
|
||
methods: {
|
||
...mapMutations([
|
||
'd2adminUsernameSet'
|
||
]),
|
||
// 提交登陆信息
|
||
submit () {
|
||
this.$refs.loginForm.validate((valid) => {
|
||
if (valid) {
|
||
// 开始请求登录接口
|
||
this.$axios({
|
||
method: 'post',
|
||
url: '/login',
|
||
data: {
|
||
username: this.formLogin.username,
|
||
password: this.formLogin.password
|
||
}
|
||
})
|
||
.then(res => {
|
||
this.$log('登录结果', res)
|
||
// cookie 一天的有效期
|
||
const setting = {
|
||
expires: 1
|
||
}
|
||
// 设置 cookie 一定要存 uuid 和 token 两个 cookie,整个系统依赖这两个数据进行校验和存储
|
||
Cookies.set('uuid', res.uuid, setting)
|
||
Cookies.set('token', res.token, setting)
|
||
// 设置 vuex
|
||
this.d2adminUsernameSet(res.name)
|
||
// 跳转路由
|
||
this.$router.push({
|
||
name: 'index'
|
||
})
|
||
})
|
||
.catch(err => {
|
||
this.$log('错误信息', err)
|
||
})
|
||
} else {
|
||
return false
|
||
}
|
||
})
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
@import './style.scss';
|
||
</style>
|
||
|