728x90
반응형
permission.js
더보기
import getPageTitle from '@/utils/get-page-title'
import NProgress from 'nprogress'
import router from './router'
import store from './store'
import { getToken } from '@/utils/auth'
import 'nprogress/nprogress.css'
NProgress.configure({ showSpinner: false })
const whiteList = ['/login', '/', '/auth-redirect']
router.beforeEach(async(to, from, next) => {
NProgress.start()
document.title = getPageTitle(to.meta.title)
const hasToken = getToken()
if (hasToken) {
/** ADMIN **/
if( hasToken === 'admin-token' ){
if(to.path === '/login'){
next({ path: '/' })
NProgress.done()
}else{
routerNext('admin', to, next )
}
/** EDITOR **/
}else if( hasToken === 'editor-token' ){
if(to.path === '/login'){
next({ path: '/' })
NProgress.done()
}else{
routerNext('editor', to, next )
}
/** VISITOR **/
}else{
if(to.path === '/login'){
store.dispatch('user/resetToken')
next()
}else{
routerNext('visitor', to, next )
}
}
/** 토큰이 없고 다른 페이지로 이동하려는 경우 **/
} else {
store.dispatch('user/resetToken')
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
next(`/login?redirect=${to.path}`)
NProgress.done()
}
}
})
router.afterEach(() => {
NProgress.done()
})
async function routerNext( roleName , to, next ){
if ( store.getters.permission_routes.length === 0) {
const role = [roleName]
const accessRoutes = await store.dispatch('permission/generateRoutes', role).catch((error) => {
console.log(error)
})
router.addRoutes(accessRoutes)
next({ path: to.path })
NProgress.done()
/** router.afterEach() 호출 **/
} else {
next()
}
}
login.vue
더보기
<template>
<div class="login-container">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" autocomplete="on" label-position="left">
<div class="title-container">
<h3 class="title">Login Form</h3>
</div>
<el-form-item prop="username">
<span class="svg-container">
<svg-icon icon-class="user" />
</span>
<el-input
ref="username"
v-model="loginForm.username"
placeholder="Username"
name="username"
type="text"
tabindex="1"
autocomplete="on"
/>
</el-form-item>
<el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
<el-form-item prop="password">
<span class="svg-container">
<svg-icon icon-class="password" />
</span>
<el-input
:key="passwordType"
ref="password"
v-model="loginForm.password"
:type="passwordType"
placeholder="Password"
name="password"
tabindex="2"
autocomplete="on"
@keyup.native="checkCapslock"
@blur="capsTooltip = false"
@keyup.enter.native="handleLogin"
/>
<span class="show-pwd" @click="showPwd">
<svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
</span>
</el-form-item>
</el-tooltip>
<el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">Login</el-button>
<div style="position:relative">
<div class="tips">
<span>Username : admin</span>
<span>Password : any</span>
</div>
<div class="tips">
<span style="margin-right:18px;">Username : editor</span>
<span>Password : any</span>
</div>
<el-button class="thirdparty-button" type="primary" @click="showDialog=true">
Or connect with
</el-button>
</div>
</el-form>
<el-dialog title="Or connect with" :visible.sync="showDialog">
Can not be simulated on local, so please combine you own business simulation! ! !
<br>
<br>
<br>
<social-sign />
</el-dialog>
</div>
</template>
<script>
import { validUsername } from '@/utils/validate'
import SocialSign from './components/SocialSignin'
import { removeToken } from '@/utils/auth'
export default {
name: 'Login',
components: {
SocialSign
, removeToken
}
, data() {
const validateUsername = (rule, value, callback) => {
if (!validUsername(value)) {
callback(new Error('Please enter the correct user name'))
} else {
callback()
}
}
const validatePassword = (rule, value, callback) => {
if (value.length < 6) {
callback(new Error('The password can not be less than 6 digits'))
} else {
callback()
}
}
return {
loginForm: {
username: 'admin'
, password: '111111'
}
, loginRules: {
username: [{ required: true, trigger: 'blur', validator: validateUsername }]
, password: [{ required: true, trigger: 'blur', validator: validatePassword }]
}
, passwordType: 'password'
, capsTooltip: false
, loading: false
, showDialog: false
, redirect: undefined
, otherQuery: {}
}
}
, watch: {
$route: {
handler: function(route) {
const query = route.query
if (query) {
this.redirect = query.redirect
this.otherQuery = this.getOtherQuery(query)
}
}
, immediate: true
}
}
, created() {
},
mounted() {
if (this.loginForm.username === '') {
this.$refs.username.focus()
} else if (this.loginForm.password === '') {
this.$refs.password.focus()
}
}
, created: function () {
/** 기존 Token 지우고 실행 **/
this.$store.dispatch('user/logout')
}
, methods: {
checkCapslock(e) {
const { key } = e
this.capsTooltip = key && key.length === 1 && (key >= 'A' && key <= 'Z')
}
, showPwd() {
if (this.passwordType === 'password') {
this.passwordType = ''
} else {
this.passwordType = 'password'
}
this.$nextTick(() => {
this.$refs.password.focus()
})
}
, handleLogin() {
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loading = true
this.login()
} else {
console.log('error submit!!')
return false
}
})
}
, async login(){
await this.$store.dispatch('user/login', this.loginForm)
.then(() => {
this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
this.loading = false
})
.catch(() => {
this.loading = false
})
}
, getOtherQuery(query) {
return Object.keys(query).reduce((acc, cur) => {
if (cur !== 'redirect') {
acc[cur] = query[cur]
}
return acc
}, {})
}
}
}
</script>
<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
$bg:#283443;
$light_gray:#fff;
$cursor: #fff;
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
.login-container .el-input input {
color: $cursor;
}
}
/* 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 {
box-shadow: 0 0 0px 1000px $bg inset !important;
-webkit-text-fill-color: $cursor !important;
}
}
}
.el-form-item {
border: 1px solid rgba(255, 255, 255, 0.1);
background: rgba(0, 0, 0, 0.1);
border-radius: 5px;
color: #454545;
}
}
</style>
<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;
.login-container {
min-height: 100%;
width: 100%;
background-color: $bg;
overflow: hidden;
.login-form {
position: relative;
width: 520px;
max-width: 100%;
padding: 160px 35px 0;
margin: 0 auto;
overflow: hidden;
}
.tips {
font-size: 14px;
color: #fff;
margin-bottom: 10px;
span {
&:first-of-type {
margin-right: 16px;
}
}
}
.svg-container {
padding: 6px 5px 6px 15px;
color: $dark_gray;
vertical-align: middle;
width: 30px;
display: inline-block;
}
.title-container {
position: relative;
.title {
font-size: 26px;
color: $light_gray;
margin: 0px auto 40px auto;
text-align: center;
font-weight: bold;
}
}
.show-pwd {
position: absolute;
right: 10px;
top: 7px;
font-size: 16px;
color: $dark_gray;
cursor: pointer;
user-select: none;
}
.thirdparty-button {
position: absolute;
right: 0;
bottom: 6px;
}
@media only screen and (max-width: 470px) {
.thirdparty-button {
display: none;
}
}
}
</style>
dashboard
더보기
<template>
<div>
<div class="main-logo-div">
<img :src="Logo" class="logo" style="">
</div>
<mainCategory />
<successfulStatus />
<div class="status-div">
<div class="status-div-realtime"><realTimeStatus /></div>
<div class="status-div-dday"><examinationDay /></div>
</div>
<notice />
<div class="main-bottom" />
</div>
</template>
<script>
import mainLogo from '@/assets/DDaJa-Logo/logo.png'
import mainCategory from './component/main-category'
import successfulStatus from './component/successful-status'
import examinationDay from './component/examination-day'
import realTimeStatus from './component/real-time-status'
import notice from './component/notice'
import { getToken } from '@/utils/auth'
export default {
components: {
mainCategory
, successfulStatus
, examinationDay
, realTimeStatus
, notice
, getToken
}
, data () {
return {
Logo: mainLogo
}
}
/** Token 이 없다면 visitor 부여 **/
, beforeCreate: function () {
var token = getToken();
if( token != 'admin-token' && token != 'editor-token' ){
var visitorInfo = {
username: 'visitor',
password: '111111'
}
this.$store.dispatch('user/login', visitorInfo )
.then(() => {
this.$router.push({ path: this.redirect || '/', query: '' })
})
}
}
}
</script>
<style lang="scss" scoped>
@import url('https://fonts.googleapis.com/css2?family=Kirang+Haerang&display=swap');
.status-div{
float: left;
width: 100%;
height: 100%;
padding-left: 7%;
padding-top: 30px;
padding-bottom: 30px;
background-color: rgb(11, 8, 49);
.status-div-realtime{
width: 800px;
height: 500px;
float: left;
margin-right: 28px;
margin-top: 20px;
margin-bottom: 20px;
}
.status-div-dday{
width: 800px;
height: 500px;
float: left;
margin-top: 20px;
margin-bottom: 20px;
}
}
.main-logo-div{
padding-left: 44%;
width: 100%;
float: left;
background-color: rgb(197, 241, 232);
.logo{
width: 200px;
height: 200px;
}
}
.main-bottom{
width: 100%;
height: 200px;
float: left;
background-color: rgb(197, 241, 232);
}
</style>
728x90
반응형
'PROJECT > JPA 사이드 프로젝트 기록' 카테고리의 다른 글
[ 사이드 프로젝트 (스프링 부트 / JPA / vue) ] 따자 드디어 배포하다. (0) | 2021.12.19 |
---|---|
Ddaja - Word 개발 (0) | 2021.10.10 |
따자 삽질 2021 08 16 (0) | 2021.08.16 |
Git을 활용한 협업 방식 기록 📚 🙄 📚 (0) | 2021.08.15 |
API 구상중 - 기록 (0) | 2021.06.24 |