Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_57822050
vue-element-admin
提交
8b382e1e
V
vue-element-admin
项目概览
weixin_57822050
/
vue-element-admin
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vue-element-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8b382e1e
编写于
3月 18, 2019
作者:
P
Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine code
上级
c93d88a3
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
165 addition
and
163 deletion
+165
-163
mock/article.js
mock/article.js
+1
-1
mock/mocks.js
mock/mocks.js
+2
-2
mock/remoteSearch.js
mock/remoteSearch.js
+6
-4
mock/user.js
mock/user.js
+30
-21
src/api/user.js
src/api/user.js
+9
-13
src/layout/components/Navbar.vue
src/layout/components/Navbar.vue
+1
-1
src/permission.js
src/permission.js
+4
-4
src/store/modules/permission.js
src/store/modules/permission.js
+1
-1
src/store/modules/user.js
src/store/modules/user.js
+28
-54
src/utils/request.js
src/utils/request.js
+1
-1
src/views/login/authredirect.vue
src/views/login/authredirect.vue
+8
-3
src/views/login/index.vue
src/views/login/index.vue
+73
-57
src/views/permission/components/SwitchRoles.vue
src/views/permission/components/SwitchRoles.vue
+1
-1
未找到文件。
mock/article.js
浏览文件 @
8b382e1e
...
...
@@ -13,7 +13,7 @@ for (let i = 0; i < count; i++) {
author
:
'
@first
'
,
reviewer
:
'
@first
'
,
title
:
'
@title(5, 10)
'
,
content_short
:
'
我是测试数据
'
,
content_short
:
'
mock data
'
,
content
:
baseContent
,
forecast
:
'
@float(0, 100, 2, 2)
'
,
importance
:
'
@integer(1, 3)
'
,
...
...
mock/mocks.js
浏览文件 @
8b382e1e
import
login
from
'
./login
'
import
user
from
'
./user
'
import
role
from
'
./role
'
import
article
from
'
./article
'
import
search
from
'
./remoteSearch
'
export
default
[
...
login
,
...
user
,
...
role
,
...
article
,
...
search
...
...
mock/remoteSearch.js
浏览文件 @
8b382e1e
...
...
@@ -8,9 +8,10 @@ for (let i = 0; i < count; i++) {
name
:
'
@first
'
}))
}
NameList
.
push
({
name
:
'
mockPan
'
})
NameList
.
push
({
name
:
'
mock
-
Pan
'
})
export
default
[
// username search
{
url
:
'
/search/user
'
,
type
:
'
get
'
,
...
...
@@ -23,14 +24,15 @@ export default [
return
{
items
:
mockNameList
}
}
},
// transaction list
{
url
:
'
/transaction/list
'
,
type
:
'
get
'
,
response
:
_
=>
{
const
count
=
20
return
{
total
:
count
,
[
`items|
${
count
}
`
]
:
[{
total
:
20
,
'
items|20
'
:
[{
order_no
:
'
@guid()
'
,
timestamp
:
+
Mock
.
Random
.
date
(
'
T
'
),
username
:
'
@name()
'
,
...
...
mock/
login
.js
→
mock/
user
.js
浏览文件 @
8b382e1e
const
userMap
=
{
const
tokens
=
{
admin
:
{
token
:
'
admin-token
'
},
editor
:
{
token
:
'
editor-token
'
}
}
const
users
=
{
'
admin-token
'
:
{
roles
:
[
'
admin
'
],
token
:
'
admin
'
,
introduction
:
'
我是超级管理员
'
,
introduction
:
'
I am a super administrator
'
,
avatar
:
'
https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif
'
,
name
:
'
Super Admin
'
},
editor
:
{
'
editor-token
'
:
{
roles
:
[
'
editor
'
],
token
:
'
editor
'
,
introduction
:
'
我是编辑
'
,
introduction
:
'
I am an editor
'
,
avatar
:
'
https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif
'
,
name
:
'
Normal Editor
'
}
}
export
default
[
// user login
{
url
:
'
/
login
/login
'
,
url
:
'
/
user
/login
'
,
type
:
'
post
'
,
response
:
config
=>
{
const
{
username
}
=
config
.
body
return
userMap
[
username
]
}
},
{
url
:
'
/login/logout
'
,
type
:
'
post
'
,
response
:
_
=>
{
return
{
data
:
'
success
'
}
return
tokens
[
username
]
}
},
// get user info
{
url
:
'
/user/info
\
.*
'
,
type
:
'
get
'
,
response
:
config
=>
{
const
{
token
}
=
config
.
query
if
(
userMap
[
token
])
{
return
userMap
[
token
]
}
else
{
return
false
return
users
[
token
]
}
},
// user logout
{
url
:
'
/user/logout
'
,
type
:
'
post
'
,
response
:
_
=>
{
return
{
data
:
'
success
'
}
}
}
...
...
src/api/
login
.js
→
src/api/
user
.js
浏览文件 @
8b382e1e
import
request
from
'
@/utils/request
'
export
function
loginByUsername
(
username
,
password
)
{
const
data
=
{
username
,
password
}
export
function
login
(
data
)
{
return
request
({
url
:
'
/
login
/login
'
,
url
:
'
/
user
/login
'
,
method
:
'
post
'
,
data
})
}
export
function
logout
(
)
{
export
function
getInfo
(
token
)
{
return
request
({
url
:
'
/login/logout
'
,
method
:
'
post
'
url
:
'
/user/info
'
,
method
:
'
get
'
,
params
:
{
token
}
})
}
export
function
getUserInfo
(
token
)
{
export
function
logout
(
)
{
return
request
({
url
:
'
/user/info
'
,
method
:
'
get
'
,
params
:
{
token
}
url
:
'
/user/logout
'
,
method
:
'
post
'
})
}
src/layout/components/Navbar.vue
浏览文件 @
8b382e1e
...
...
@@ -83,7 +83,7 @@ export default {
this
.
$store
.
dispatch
(
'
toggleSideBar
'
)
},
logout
()
{
this
.
$store
.
dispatch
(
'
Log
O
ut
'
).
then
(()
=>
{
this
.
$store
.
dispatch
(
'
Log
o
ut
'
).
then
(()
=>
{
location
.
reload
()
// In order to re-instantiate the vue-router object to avoid bugs
})
}
...
...
src/permission.js
浏览文件 @
8b382e1e
...
...
@@ -29,18 +29,18 @@ router.beforeEach((to, from, next) => {
if
(
store
.
getters
.
roles
.
length
===
0
)
{
// 判断当前用户是否已拉取完user_info信息
store
.
dispatch
(
'
GetUserInfo
'
)
.
dispatch
(
'
getInfo
'
)
// dispatch @/store/modules/user login getInfo
.
then
(
res
=>
{
// 拉取user_info
const
roles
=
res
.
data
.
rol
es
// note: roles must be a object array! such as: [{id: '1', name: 'editor'}, {id: '2', name: 'developer'}]
store
.
dispatch
(
'
G
enerateRoutes
'
,
{
roles
}).
then
(
accessRoutes
=>
{
const
{
roles
}
=
r
es
// note: roles must be a object array! such as: [{id: '1', name: 'editor'}, {id: '2', name: 'developer'}]
store
.
dispatch
(
'
g
enerateRoutes
'
,
{
roles
}).
then
(
accessRoutes
=>
{
// 根据roles权限生成可访问的路由表
router
.
addRoutes
(
accessRoutes
)
// 动态添加可访问路由表
next
({
...
to
,
replace
:
true
})
// hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
})
})
.
catch
(
err
=>
{
store
.
dispatch
(
'
FedLogOut
'
).
then
(()
=>
{
store
.
dispatch
(
'
resetToken
'
).
then
(()
=>
{
Message
.
error
(
err
)
next
({
path
:
'
/
'
})
})
...
...
src/store/modules/permission.js
浏览文件 @
8b382e1e
...
...
@@ -46,7 +46,7 @@ const permission = {
}
},
actions
:
{
G
enerateRoutes
({
commit
},
data
)
{
g
enerateRoutes
({
commit
},
data
)
{
return
new
Promise
(
resolve
=>
{
const
{
roles
}
=
data
let
accessedRoutes
...
...
src/store/modules/user.js
浏览文件 @
8b382e1e
import
{
login
ByUsername
,
logout
,
getUserInfo
}
from
'
@/api/login
'
import
{
login
,
logout
,
getInfo
}
from
'
@/api/user
'
import
{
getToken
,
setToken
,
removeToken
}
from
'
@/utils/auth
'
const
user
=
{
state
:
{
user
:
''
,
status
:
''
,
code
:
''
,
token
:
getToken
(),
name
:
''
,
avatar
:
''
,
introduction
:
''
,
roles
:
[],
setting
:
{
articlePlatform
:
[]
}
roles
:
[]
},
mutations
:
{
SET_CODE
:
(
state
,
code
)
=>
{
state
.
code
=
code
},
SET_TOKEN
:
(
state
,
token
)
=>
{
state
.
token
=
token
},
SET_INTRODUCTION
:
(
state
,
introduction
)
=>
{
state
.
introduction
=
introduction
},
SET_SETTING
:
(
state
,
setting
)
=>
{
state
.
setting
=
setting
},
SET_STATUS
:
(
state
,
status
)
=>
{
state
.
status
=
status
},
SET_NAME
:
(
state
,
name
)
=>
{
state
.
name
=
name
},
...
...
@@ -44,12 +29,12 @@ const user = {
},
actions
:
{
//
用户名登录
LoginByUsername
({
commit
},
userInfo
)
{
const
username
=
userInfo
.
username
.
trim
()
//
user login
login
({
commit
},
userInfo
)
{
const
{
username
,
password
}
=
userInfo
return
new
Promise
((
resolve
,
reject
)
=>
{
login
ByUsername
(
username
,
userInfo
.
password
).
then
(
response
=>
{
const
data
=
response
.
data
login
({
username
:
username
.
trim
(),
password
:
password
}
).
then
(
response
=>
{
const
{
data
}
=
response
commit
(
'
SET_TOKEN
'
,
data
.
token
)
setToken
(
response
.
data
.
token
)
resolve
()
...
...
@@ -59,48 +44,36 @@ const user = {
})
},
//
获取用户信息
GetUser
Info
({
commit
,
state
})
{
//
get user info
get
Info
({
commit
,
state
})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
getUserInfo
(
state
.
token
).
then
(
response
=>
{
// 由于mockjs 不支持自定义状态码只能这样hack
if
(
!
response
.
data
)
{
reject
(
'
Verification failed, please login again.
'
)
getInfo
(
state
.
token
).
then
(
response
=>
{
const
{
data
}
=
response
if
(
!
data
)
{
reject
(
'
Verification failed, please Login again.
'
)
}
const
data
=
response
.
data
if
(
data
.
roles
&&
data
.
roles
.
length
>
0
)
{
// 验证返回的roles是否是一个非空数组
commit
(
'
SET_ROLES
'
,
data
.
roles
)
}
else
{
const
{
roles
}
=
data
// roles must be a non-empty array
if
(
!
roles
||
roles
.
length
<=
0
)
{
reject
(
'
getInfo: roles must be a non-null array!
'
)
}
commit
(
'
SET_ROLES
'
,
data
.
roles
)
commit
(
'
SET_NAME
'
,
data
.
name
)
commit
(
'
SET_AVATAR
'
,
data
.
avatar
)
commit
(
'
SET_INTRODUCTION
'
,
data
.
introduction
)
resolve
(
response
)
resolve
(
data
)
}).
catch
(
error
=>
{
reject
(
error
)
})
})
},
// 第三方验证登录
// LoginByThirdparty({ commit, state }, code) {
// return new Promise((resolve, reject) => {
// commit('SET_CODE', code)
// loginByThirdparty(state.status, state.email, state.code).then(response => {
// commit('SET_TOKEN', response.data.token)
// setToken(response.data.token)
// resolve()
// }).catch(error => {
// reject(error)
// })
// })
// },
// 登出
LogOut
({
commit
,
state
})
{
// user logout
Logout
({
commit
,
state
})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
logout
(
state
.
token
).
then
(()
=>
{
commit
(
'
SET_TOKEN
'
,
''
)
...
...
@@ -113,27 +86,28 @@ const user = {
})
},
//
前端 登出
FedLogOut
({
commit
})
{
//
remove token
resetToken
({
commit
})
{
return
new
Promise
(
resolve
=>
{
commit
(
'
SET_TOKEN
'
,
''
)
commit
(
'
SET_ROLES
'
,
[])
removeToken
()
resolve
()
})
},
// 动态修改权限
C
hangeRoles
({
commit
,
dispatch
},
role
)
{
c
hangeRoles
({
commit
,
dispatch
},
role
)
{
return
new
Promise
(
resolve
=>
{
commit
(
'
SET_TOKEN
'
,
role
)
setToken
(
role
)
get
User
Info
(
role
).
then
(
response
=>
{
getInfo
(
role
).
then
(
response
=>
{
const
data
=
response
.
data
commit
(
'
SET_ROLES
'
,
data
.
roles
)
commit
(
'
SET_NAME
'
,
data
.
name
)
commit
(
'
SET_AVATAR
'
,
data
.
avatar
)
commit
(
'
SET_INTRODUCTION
'
,
data
.
introduction
)
dispatch
(
'
G
enerateRoutes
'
,
data
)
// 动态修改权限后 重绘侧边菜单
dispatch
(
'
g
enerateRoutes
'
,
data
)
// 动态修改权限后 重绘侧边菜单
resolve
()
})
})
...
...
src/utils/request.js
浏览文件 @
8b382e1e
...
...
@@ -53,7 +53,7 @@ service.interceptors.response.use(
// cancelButtonText: '取消',
// type: 'warning'
// }).then(() => {
// store.dispatch('
FedLogOut
').then(() => {
// store.dispatch('
resetToken
').then(() => {
// location.reload() // 为了重新实例化vue-router对象 避免bug
// })
// })
...
...
src/views/login/authredirect.vue
浏览文件 @
8b382e1e
<
script
>
export
default
{
name
:
'
Auth
R
edirect
'
,
name
:
'
Auth
r
edirect
'
,
created
()
{
const
hash
=
window
.
location
.
search
.
slice
(
1
)
window
.
opener
.
location
.
href
=
window
.
location
.
origin
+
'
/login#
'
+
hash
window
.
close
()
if
(
window
.
localStorage
)
{
window
.
localStorage
.
setItem
(
'
x-admin-oauth-code
'
,
hash
)
window
.
close
()
}
},
render
:
function
(
h
)
{
return
h
()
// avoid warning message
}
}
</
script
>
src/views/login/index.vue
浏览文件 @
8b382e1e
<
template
>
<div
class=
"login-container"
>
<el-form
ref=
"loginForm"
:model=
"loginForm"
:rules=
"loginRules"
class=
"login-form"
auto-complete=
"on"
label-position=
"left"
>
<div
class=
"title-container"
>
<h3
class=
"title"
>
{{
$t
(
'
login.title
'
)
}}
...
...
@@ -117,10 +118,10 @@ export default {
}
},
created
()
{
// window.addEventListener('
hashchan
ge', this.afterQRScan)
// window.addEventListener('
stora
ge', this.afterQRScan)
},
destroyed
()
{
// window.removeEventListener('
hashchan
ge', this.afterQRScan)
// window.removeEventListener('
stora
ge', this.afterQRScan)
},
methods
:
{
showPwd
()
{
...
...
@@ -134,7 +135,8 @@ export default {
this
.
$refs
.
loginForm
.
validate
(
valid
=>
{
if
(
valid
)
{
this
.
loading
=
true
this
.
$store
.
dispatch
(
'
LoginByUsername
'
,
this
.
loginForm
).
then
(()
=>
{
// dispatch @/store/modules/user login action
this
.
$store
.
dispatch
(
'
login
'
,
this
.
loginForm
).
then
(()
=>
{
this
.
loading
=
false
this
.
$router
.
push
({
path
:
this
.
redirect
||
'
/
'
})
}).
catch
(()
=>
{
...
...
@@ -145,74 +147,79 @@ export default {
return
false
}
})
},
afterQRScan
()
{
// const hash = window.location.hash.slice(1)
// const hashObj = getQueryObject(hash)
// const originUrl = window.location.origin
// history.replaceState({}, '', originUrl)
// const codeMap = {
// wechat: 'code',
// tencent: 'code'
// }
// const codeName = hashObj[codeMap[this.auth_type]]
// if (!codeName) {
// alert('第三方登录失败')
// } else {
// this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
// this.$router.push({ path: '/' })
// })
// }
}
// afterQRScan() {
// if (e.key === 'x-admin-oauth-code') {
// const code = getQueryObject(e.newValue)
// const codeMap = {
// wechat: 'code',
// tencent: 'code'
// }
// const type = codeMap[this.auth_type]
// const codeName = code[type]
// if (codeName) {
// this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
// this.$router.push({ path: this.redirect || '/' })
// })
// } else {
// alert('第三方登录失败')
// }
// }
// }
}
}
</
script
>
<
style
rel=
"stylesheet/scss"
lang=
"scss"
>
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
$bg
:
#283443
;
$light_gray
:
#eee
;
$cursor
:
#fff
;
$bg
:
#283443
;
$light_gray
:
#eee
;
$cursor
:
#fff
;
@supports
(
-webkit-mask
:
none
)
and
(
not
(
cater-color
:
$
cursor
))
{
.login-container
.el-input
input
{
color
:
$cursor
;
&
::first-line
{
color
:
$light_gray
;
}
@supports
(
-webkit-mask
:
none
)
and
(
not
(
cater-color
:
$
cursor
))
{
.login-container
.el-input
input
{
color
:
$cursor
;
&
::first-line
{
color
:
$light_gray
;
}
}
}
/* reset element-ui css */
.login-container
{
.el-input
{
display
:
inline-block
;
/* 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
;
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
{
-webkit-box-shadow
:
0
0
0px
1000px
$bg
inset
!
important
;
-webkit-text-fill-color
:
$cursor
!
important
;
}
caret-color
:
$cursor
;
&
:-webkit-autofill
{
-webkit-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
;
}
}
.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
rel=
"stylesheet/scss"
lang=
"scss"
scoped
>
...
...
@@ -225,6 +232,7 @@ $light_gray:#eee;
width
:
100%
;
background-color
:
$bg
;
overflow
:
hidden
;
.login-form
{
position
:
relative
;
width
:
520px
;
...
...
@@ -233,16 +241,19 @@ $light_gray:#eee;
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
;
...
...
@@ -250,8 +261,10 @@ $light_gray:#eee;
width
:
30px
;
display
:
inline-block
;
}
.title-container
{
position
:
relative
;
.title
{
font-size
:
26px
;
color
:
$light_gray
;
...
...
@@ -259,15 +272,17 @@ $light_gray:#eee;
text-align
:
center
;
font-weight
:
bold
;
}
.set-language
{
color
:
#fff
;
position
:
absolute
;
top
:
3px
;
font-size
:
18px
;
font-size
:
18px
;
right
:
0px
;
cursor
:
pointer
;
}
}
.show-pwd
{
position
:
absolute
;
right
:
10px
;
...
...
@@ -277,6 +292,7 @@ $light_gray:#eee;
cursor
:
pointer
;
user-select
:
none
;
}
.thirdparty-button
{
position
:
absolute
;
right
:
0
;
...
...
src/views/permission/components/SwitchRoles.vue
浏览文件 @
8b382e1e
...
...
@@ -22,7 +22,7 @@ export default {
return
this
.
roles
[
0
]
},
set
(
val
)
{
this
.
$store
.
dispatch
(
'
C
hangeRoles
'
,
val
).
then
(()
=>
{
this
.
$store
.
dispatch
(
'
c
hangeRoles
'
,
val
).
then
(()
=>
{
this
.
$emit
(
'
change
'
)
})
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录