Skip to content

Commit

Permalink
v1.5 正式版发布 ,详情查看发行版说明
Browse files Browse the repository at this point in the history
  • Loading branch information
郑杰 committed Jan 21, 2019
1 parent 45655e2 commit 685985c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 63 deletions.
24 changes: 0 additions & 24 deletions src/api/myTest.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import router from './router'
import store from './store'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css'// progress bar style
import { getToken, getStorageToken } from '@/utils/auth' // getToken from cookie
import { getToken } from '@/utils/auth' // getToken from cookie
import { buildMenus } from '@/api/menu'
import { filterAsyncRouter } from './store/modules/permission'

Expand All @@ -12,7 +12,7 @@ const whiteList = ['/login']// no redirect whitelist

router.beforeEach((to, from, next) => {
NProgress.start() // start progress bar
if (getToken() || getStorageToken()) {
if (getToken()) {
// 已登录且要跳转的页面是登录页
if (to.path === '/login') {
next({ path: '/' })
Expand Down
7 changes: 2 additions & 5 deletions src/store/modules/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { login, getInfo } from '@/api/login'
import { getToken, setToken, setStorageToken, removeToken } from '@/utils/auth'
import { getToken, setToken, removeToken } from '@/utils/auth'
import { parseTime } from '@/utils/index'

const user = {
Expand Down Expand Up @@ -41,11 +41,8 @@ const user = {
const rememberMe = userInfo.rememberMe
return new Promise((resolve, reject) => {
login(username, password).then(res => {
setToken(res.token)
setToken(res.token, rememberMe)
commit('SET_TOKEN', res.token)
if (rememberMe) {
setStorageToken(res.token)
}
resolve()
}).catch(error => {
reject(error)
Expand Down
16 changes: 4 additions & 12 deletions src/utils/auth.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'
const storageTokenKey = 'EL_ADMIN_COOKIE_TOKEN'

export function getToken() {
return Cookies.get(TokenKey)
}

export function getStorageToken() {
return localStorage.getItem(storageTokenKey)
}

export function setToken(token) {
return Cookies.set(TokenKey, token)
}

export function setStorageToken(token) {
return localStorage.setItem(storageTokenKey, token)
export function setToken(token, rememberMe) {
if (rememberMe) {
return Cookies.set(TokenKey, token, { expires: 1 })
} else return Cookies.set(TokenKey, token)
}

export function removeToken() {
localStorage.removeItem(storageTokenKey)
return Cookies.remove(TokenKey)
}
4 changes: 1 addition & 3 deletions src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import router from '@/router'
import { Notification, MessageBox } from 'element-ui'
import store from '../store'
import { getToken, getStorageToken } from '@/utils/auth'
import { getToken } from '@/utils/auth'

// 创建axios实例
const service = axios.create({
Expand All @@ -15,8 +15,6 @@ service.interceptors.request.use(
config => {
if (getToken()) {
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
} else if (getStorageToken()) {
config.headers['Authorization'] = 'Bearer ' + getStorageToken()
}
config.headers['Content-Type'] = 'application/json'
return config
Expand Down
49 changes: 37 additions & 12 deletions src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,36 @@
<svg-icon slot="prefix" icon-class="password" class="el-input__icon" style="height: 39px;width: 13px;margin-left: 2px;" />
</el-input>
</el-form-item>
<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 35px 0px;">记住密码</el-checkbox>
<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
<el-form-item style="width:100%;">
<el-button :loading="loading" size="medium" type="primary" style="width:100%;" @click.native.prevent="handleLogin">
<span v-if="!loading">登 录</span>
<span v-else>登 录 中...</span>
</el-button>
</el-form-item>
<p class="login-tip">系统默认用户名:admin,密码:123456</p>
</el-form>
</div>
</template>

<script>
import { md5 } from '@/utils/md5'
import Cookies from 'js-cookie'
export default {
name: 'Login',
data() {
return {
checked: false,
md5Pwd: '',
loginForm: {
username: 'admin',
password: '123456',
username: '',
password: '',
rememberMe: false
},
loginRules: {
username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
},
loading: false,
pwdType: 'password',
redirect: undefined
}
},
Expand All @@ -52,19 +53,38 @@ export default {
immediate: true
}
},
created() {
this.getCookie()
},
methods: {
showPwd() {
if (this.pwdType === 'password') {
this.pwdType = ''
} else {
this.pwdType = 'password'
getCookie() {
const username = Cookies.get('username')
const password = Cookies.get('password')
const rememberMe = Cookies.get('rememberMe')
// 保存cookie里面的加密后的密码
this.md5Pwd = password === undefined ? '' : password
this.loginForm = {
username: username === undefined ? '' : username,
password: this.md5Pwd,
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
}
},
handleLogin() {
this.$refs.loginForm.validate(valid => {
const user = { username: this.loginForm.username, password: md5(this.loginForm.password), rememberMe: this.loginForm.rememberMe }
let pass = this.loginForm.password
if (pass !== this.md5Pwd) { pass = md5(pass) }
const user = { username: this.loginForm.username, password: pass, rememberMe: this.loginForm.rememberMe }
if (valid) {
this.loading = true
if (user.rememberMe) {
Cookies.set('username', user.username, { expires: 1 })
Cookies.set('password', user.password, { expires: 1 })
Cookies.set('rememberMe', user.rememberMe, { expires: 1 })
} else {
Cookies.remove('username')
Cookies.remove('password')
Cookies.remove('rememberMe')
}
this.$store.dispatch('Login', user).then(() => {
this.loading = false
this.$router.push({ path: this.redirect || '/' })
Expand Down Expand Up @@ -92,7 +112,7 @@ export default {
.title {
margin: 0px auto 40px auto;
text-align: center;
color: #555;
color: #707070;
}
.login-form {
Expand All @@ -107,4 +127,9 @@ export default {
}
}
}
.login-tip {
font-size: 13px;
text-align: center;
color: #bfbfbf;
}
</style>
27 changes: 22 additions & 5 deletions src/views/monitor/log/msg.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div class="container">
<div :style="'width:' + width" class="container">
<el-tooltip :content="content" class="lock item" effect="dark" placement="left">
<el-button type="info" size="mini" circle @click="doLock"><svg-icon :icon-class="ico"/></el-button>
</el-tooltip>
<div id="console" :style="'height:'+ height" class="console">
<div v-for="item in data" :key="item.time">
<span>{{ item.name }}</span>
Expand All @@ -24,7 +27,9 @@ export default {
name: 'Msg',
data() {
return {
height: document.documentElement.clientHeight - 95 + 'px;',
ico: 'unlock', unlock: true, content: '锁定滚动条',
height: document.documentElement.clientHeight - 94.5 + 'px;',
width: document.documentElement.clientWidth - 185 + 'px;',
data: [{ name: 'elAdmin-', timestamp: new Date(), threadName: 'system-prompt-message', level: 'INFO', className: 'me.zhengjie.AppRun' + ' :', body: 'Welcome, no log output~' }],
// level
INFO: '#0000ff', WARN: '#FFFF00', ERROR: '#FF0000', DEBUG: '#DEA000'
Expand All @@ -40,8 +45,10 @@ export default {
data: {
handler(val, oldVal) {
this.$nextTick(() => {
var div = document.getElementById('console')
div.scrollTop = div.scrollHeight
if (this.unlock) {
var div = document.getElementById('console')
div.scrollTop = div.scrollHeight
}
})
}
}
Expand Down Expand Up @@ -106,11 +113,21 @@ export default {
} else {
return this.ERROR
}
},
doLock() {
if (this.unlock) {
this.content = '解除锁定'
this.ico = 'lock'
} else {
this.content = '锁定滚动条'
this.ico = 'unlock'
}
this.unlock = !this.unlock
}
}
}
</script>

<style scoped>
button,input,textarea{outline:0}.container .buttons .closes,.container .buttons .maximize,.container .buttons .minimize{padding:0;margin:0;margin-right:6px;width:12px;height:12px;border:1px solid transparent;border-radius:6px}.container{width:100%;margin:5px}.container .console{font-family:consolas;overflow-y:scroll;background:#494949;color:#f7f7f7;padding:10px;font-size:14px}
button,input,textarea{outline:0}.container .buttons .closes,.container .buttons .maximize,.container .buttons .minimize{padding:0;margin:0;margin-right:6px;width:12px;height:12px;border:1px solid transparent;border-radius:6px}.container{width:100%;margin:5px}.container .console{font-family:consolas;overflow-y:scroll;background:#494949;color:#f7f7f7;padding:10px;font-size:14px} .lock {position: fixed;right: 45px;bottom: 6.8%;z-index: 100000}
</style>

0 comments on commit 685985c

Please sign in to comment.