Skip to content

Commit 685985c

Browse files
author
郑杰
committed
v1.5 正式版发布 ,详情查看发行版说明
1 parent 45655e2 commit 685985c

File tree

7 files changed

+68
-63
lines changed

7 files changed

+68
-63
lines changed

src/api/myTest.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/permission.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import router from './router'
22
import store from './store'
33
import NProgress from 'nprogress' // progress bar
44
import 'nprogress/nprogress.css'// progress bar style
5-
import { getToken, getStorageToken } from '@/utils/auth' // getToken from cookie
5+
import { getToken } from '@/utils/auth' // getToken from cookie
66
import { buildMenus } from '@/api/menu'
77
import { filterAsyncRouter } from './store/modules/permission'
88

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

1313
router.beforeEach((to, from, next) => {
1414
NProgress.start() // start progress bar
15-
if (getToken() || getStorageToken()) {
15+
if (getToken()) {
1616
// 已登录且要跳转的页面是登录页
1717
if (to.path === '/login') {
1818
next({ path: '/' })

src/store/modules/user.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { login, getInfo } from '@/api/login'
2-
import { getToken, setToken, setStorageToken, removeToken } from '@/utils/auth'
2+
import { getToken, setToken, removeToken } from '@/utils/auth'
33
import { parseTime } from '@/utils/index'
44

55
const user = {
@@ -41,11 +41,8 @@ const user = {
4141
const rememberMe = userInfo.rememberMe
4242
return new Promise((resolve, reject) => {
4343
login(username, password).then(res => {
44-
setToken(res.token)
44+
setToken(res.token, rememberMe)
4545
commit('SET_TOKEN', res.token)
46-
if (rememberMe) {
47-
setStorageToken(res.token)
48-
}
4946
resolve()
5047
}).catch(error => {
5148
reject(error)

src/utils/auth.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
import Cookies from 'js-cookie'
22

33
const TokenKey = 'Admin-Token'
4-
const storageTokenKey = 'EL_ADMIN_COOKIE_TOKEN'
54

65
export function getToken() {
76
return Cookies.get(TokenKey)
87
}
98

10-
export function getStorageToken() {
11-
return localStorage.getItem(storageTokenKey)
12-
}
13-
14-
export function setToken(token) {
15-
return Cookies.set(TokenKey, token)
16-
}
17-
18-
export function setStorageToken(token) {
19-
return localStorage.setItem(storageTokenKey, token)
9+
export function setToken(token, rememberMe) {
10+
if (rememberMe) {
11+
return Cookies.set(TokenKey, token, { expires: 1 })
12+
} else return Cookies.set(TokenKey, token)
2013
}
2114

2215
export function removeToken() {
23-
localStorage.removeItem(storageTokenKey)
2416
return Cookies.remove(TokenKey)
2517
}

src/utils/request.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import axios from 'axios'
22
import router from '@/router'
33
import { Notification, MessageBox } from 'element-ui'
44
import store from '../store'
5-
import { getToken, getStorageToken } from '@/utils/auth'
5+
import { getToken } from '@/utils/auth'
66

77
// 创建axios实例
88
const service = axios.create({
@@ -15,8 +15,6 @@ service.interceptors.request.use(
1515
config => {
1616
if (getToken()) {
1717
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
18-
} else if (getStorageToken()) {
19-
config.headers['Authorization'] = 'Bearer ' + getStorageToken()
2018
}
2119
config.headers['Content-Type'] = 'application/json'
2220
return config

src/views/login/index.vue

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,36 @@
1212
<svg-icon slot="prefix" icon-class="password" class="el-input__icon" style="height: 39px;width: 13px;margin-left: 2px;" />
1313
</el-input>
1414
</el-form-item>
15-
<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 35px 0px;">记住密码</el-checkbox>
15+
<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
1616
<el-form-item style="width:100%;">
1717
<el-button :loading="loading" size="medium" type="primary" style="width:100%;" @click.native.prevent="handleLogin">
1818
<span v-if="!loading">登 录</span>
1919
<span v-else>登 录 中...</span>
2020
</el-button>
2121
</el-form-item>
22+
<p class="login-tip">系统默认用户名:admin,密码:123456</p>
2223
</el-form>
2324
</div>
2425
</template>
2526

2627
<script>
2728
import { md5 } from '@/utils/md5'
29+
import Cookies from 'js-cookie'
2830
export default {
2931
name: 'Login',
3032
data() {
3133
return {
32-
checked: false,
34+
md5Pwd: '',
3335
loginForm: {
34-
username: 'admin',
35-
password: '123456',
36+
username: '',
37+
password: '',
3638
rememberMe: false
3739
},
3840
loginRules: {
3941
username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
4042
password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
4143
},
4244
loading: false,
43-
pwdType: 'password',
4445
redirect: undefined
4546
}
4647
},
@@ -52,19 +53,38 @@ export default {
5253
immediate: true
5354
}
5455
},
56+
created() {
57+
this.getCookie()
58+
},
5559
methods: {
56-
showPwd() {
57-
if (this.pwdType === 'password') {
58-
this.pwdType = ''
59-
} else {
60-
this.pwdType = 'password'
60+
getCookie() {
61+
const username = Cookies.get('username')
62+
const password = Cookies.get('password')
63+
const rememberMe = Cookies.get('rememberMe')
64+
// 保存cookie里面的加密后的密码
65+
this.md5Pwd = password === undefined ? '' : password
66+
this.loginForm = {
67+
username: username === undefined ? '' : username,
68+
password: this.md5Pwd,
69+
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
6170
}
6271
},
6372
handleLogin() {
6473
this.$refs.loginForm.validate(valid => {
65-
const user = { username: this.loginForm.username, password: md5(this.loginForm.password), rememberMe: this.loginForm.rememberMe }
74+
let pass = this.loginForm.password
75+
if (pass !== this.md5Pwd) { pass = md5(pass) }
76+
const user = { username: this.loginForm.username, password: pass, rememberMe: this.loginForm.rememberMe }
6677
if (valid) {
6778
this.loading = true
79+
if (user.rememberMe) {
80+
Cookies.set('username', user.username, { expires: 1 })
81+
Cookies.set('password', user.password, { expires: 1 })
82+
Cookies.set('rememberMe', user.rememberMe, { expires: 1 })
83+
} else {
84+
Cookies.remove('username')
85+
Cookies.remove('password')
86+
Cookies.remove('rememberMe')
87+
}
6888
this.$store.dispatch('Login', user).then(() => {
6989
this.loading = false
7090
this.$router.push({ path: this.redirect || '/' })
@@ -92,7 +112,7 @@ export default {
92112
.title {
93113
margin: 0px auto 40px auto;
94114
text-align: center;
95-
color: #555;
115+
color: #707070;
96116
}
97117
98118
.login-form {
@@ -107,4 +127,9 @@ export default {
107127
}
108128
}
109129
}
130+
.login-tip {
131+
font-size: 13px;
132+
text-align: center;
133+
color: #bfbfbf;
134+
}
110135
</style>

src/views/monitor/log/msg.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
2-
<div class="container">
2+
<div :style="'width:' + width" class="container">
3+
<el-tooltip :content="content" class="lock item" effect="dark" placement="left">
4+
<el-button type="info" size="mini" circle @click="doLock"><svg-icon :icon-class="ico"/></el-button>
5+
</el-tooltip>
36
<div id="console" :style="'height:'+ height" class="console">
47
<div v-for="item in data" :key="item.time">
58
<span>{{ item.name }}</span>
@@ -24,7 +27,9 @@ export default {
2427
name: 'Msg',
2528
data() {
2629
return {
27-
height: document.documentElement.clientHeight - 95 + 'px;',
30+
ico: 'unlock', unlock: true, content: '锁定滚动条',
31+
height: document.documentElement.clientHeight - 94.5 + 'px;',
32+
width: document.documentElement.clientWidth - 185 + 'px;',
2833
data: [{ name: 'elAdmin-', timestamp: new Date(), threadName: 'system-prompt-message', level: 'INFO', className: 'me.zhengjie.AppRun' + ' :', body: 'Welcome, no log output~' }],
2934
// level
3035
INFO: '#0000ff', WARN: '#FFFF00', ERROR: '#FF0000', DEBUG: '#DEA000'
@@ -40,8 +45,10 @@ export default {
4045
data: {
4146
handler(val, oldVal) {
4247
this.$nextTick(() => {
43-
var div = document.getElementById('console')
44-
div.scrollTop = div.scrollHeight
48+
if (this.unlock) {
49+
var div = document.getElementById('console')
50+
div.scrollTop = div.scrollHeight
51+
}
4552
})
4653
}
4754
}
@@ -106,11 +113,21 @@ export default {
106113
} else {
107114
return this.ERROR
108115
}
116+
},
117+
doLock() {
118+
if (this.unlock) {
119+
this.content = '解除锁定'
120+
this.ico = 'lock'
121+
} else {
122+
this.content = '锁定滚动条'
123+
this.ico = 'unlock'
124+
}
125+
this.unlock = !this.unlock
109126
}
110127
}
111128
}
112129
</script>
113130

114131
<style scoped>
115-
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}
132+
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}
116133
</style>

0 commit comments

Comments
 (0)