Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
Support
提交反馈
为 GitLab 提交贡献
登录
切换导航
兵
兵役_吉林工业
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
麦嘉得
兵役_吉林工业
提交
9abd44f5
提交
9abd44f5
编写于
10月 18, 2017
作者:
Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: remove_permission-control
上级
05ed30b5
变更
7
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
37 行增加
和
107 行删除
+37
-107
permission.js
src/permission.js
+3
-7
index.js
src/router/index.js
+15
-16
getters.js
src/store/getters.js
+1
-3
index.js
src/store/index.js
+1
-3
permission.js
src/store/modules/permission.js
+0
-62
Sidebar.vue
src/views/layout/Sidebar.vue
+4
-5
index.vue
src/views/login/index.vue
+13
-11
未找到文件。
src/permission.js
浏览文件 @
9abd44f5
...
...
@@ -4,7 +4,7 @@ import NProgress from 'nprogress' // Progress 进度条
import
'
nprogress/nprogress.css
'
// Progress 进度条样式
import
{
getToken
}
from
'
@/utils/auth
'
// 验权
const
whiteList
=
[
'
/login
'
]
const
whiteList
=
[
'
/login
'
]
// 不重定向白名单
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
NProgress
.
start
()
if
(
getToken
())
{
...
...
@@ -12,12 +12,8 @@ router.beforeEach((to, from, next) => {
next
({
path
:
'
/
'
})
}
else
{
if
(
store
.
getters
.
roles
.
length
===
0
)
{
store
.
dispatch
(
'
GetInfo
'
).
then
(
res
=>
{
const
roles
=
res
.
data
.
role
store
.
dispatch
(
'
GenerateRoutes
'
,
{
roles
}).
then
(()
=>
{
router
.
addRoutes
(
store
.
getters
.
addRouters
)
next
({
...
to
})
})
store
.
dispatch
(
'
GetInfo
'
).
then
(
res
=>
{
// 拉取用户信息
next
()
})
}
else
{
next
()
...
...
src/router/index.js
浏览文件 @
9abd44f5
...
...
@@ -8,13 +8,13 @@ import Layout from '../views/layout/Layout'
Vue
.
use
(
Router
)
/**
* icon : the icon show in the sidebar
* hidden : if `hidden:true` will not show in the sidebar
* redirect : if `redirect:noredirect` will not redirct in the levelbar
* noDropdown : if `noDropdown:true` will not has submenu in the sidebar
* meta : `{ role: ['admin'] }` will control the page role
**/
/**
* icon : the icon show in the sidebar
* hidden : if `hidden:true` will not show in the sidebar
* redirect : if `redirect:noredirect` will not redirct in the levelbar
* noDropdown : if `noDropdown:true` will not has submenu in the sidebar
* meta : `{ role: ['admin'] }` will control the page role
**/
export
const
constantRouterMap
=
[
{
path
:
'
/login
'
,
component
:
_import
(
'
login/index
'
),
hidden
:
true
},
{
path
:
'
/404
'
,
component
:
_import
(
'
404
'
),
hidden
:
true
},
...
...
@@ -25,16 +25,8 @@ export const constantRouterMap = [
name
:
'
Dashboard
'
,
hidden
:
true
,
children
:
[{
path
:
'
dashboard
'
,
component
:
_import
(
'
dashboard/index
'
)
}]
}
]
export
default
new
Router
({
// mode: 'history', //后端支持可开
scrollBehavior
:
()
=>
({
y
:
0
}),
routes
:
constantRouterMap
})
},
export
const
asyncRouterMap
=
[
{
path
:
'
/example
'
,
component
:
Layout
,
...
...
@@ -57,3 +49,10 @@ export const asyncRouterMap = [
{
path
:
'
*
'
,
redirect
:
'
/404
'
,
hidden
:
true
}
]
export
default
new
Router
({
// mode: 'history', //后端支持可开
scrollBehavior
:
()
=>
({
y
:
0
}),
routes
:
constantRouterMap
})
src/store/getters.js
浏览文件 @
9abd44f5
...
...
@@ -3,8 +3,6 @@ const getters = {
token
:
state
=>
state
.
user
.
token
,
avatar
:
state
=>
state
.
user
.
avatar
,
name
:
state
=>
state
.
user
.
name
,
roles
:
state
=>
state
.
user
.
roles
,
permission_routers
:
state
=>
state
.
permission
.
routers
,
addRouters
:
state
=>
state
.
permission
.
addRouters
roles
:
state
=>
state
.
user
.
roles
}
export
default
getters
src/store/index.js
浏览文件 @
9abd44f5
...
...
@@ -2,7 +2,6 @@ import Vue from 'vue'
import
Vuex
from
'
vuex
'
import
app
from
'
./modules/app
'
import
user
from
'
./modules/user
'
import
permission
from
'
./modules/permission
'
import
getters
from
'
./getters
'
Vue
.
use
(
Vuex
)
...
...
@@ -10,8 +9,7 @@ Vue.use(Vuex)
const
store
=
new
Vuex
.
Store
({
modules
:
{
app
,
user
,
permission
user
},
getters
})
...
...
src/store/modules/permission.js
已删除
100644 → 0
浏览文件 @
05ed30b5
import
{
asyncRouterMap
,
constantRouterMap
}
from
'
@/router/index
'
/**
* 通过meta.role判断是否与当前用户权限匹配
* @param roles
* @param route
*/
function
hasPermission
(
roles
,
route
)
{
if
(
route
.
meta
&&
route
.
meta
.
role
)
{
return
roles
.
some
(
role
=>
route
.
meta
.
role
.
indexOf
(
role
)
>=
0
)
}
else
{
return
true
}
}
/**
* 递归过滤异步路由表,返回符合用户角色权限的路由表
* @param asyncRouterMap
* @param roles
*/
function
filterAsyncRouter
(
asyncRouterMap
,
roles
)
{
const
accessedRouters
=
asyncRouterMap
.
filter
(
route
=>
{
if
(
hasPermission
(
roles
,
route
))
{
if
(
route
.
children
&&
route
.
children
.
length
)
{
route
.
children
=
filterAsyncRouter
(
route
.
children
,
roles
)
}
return
true
}
return
false
})
return
accessedRouters
}
const
permission
=
{
state
:
{
routers
:
constantRouterMap
,
addRouters
:
[]
},
mutations
:
{
SET_ROUTERS
:
(
state
,
routers
)
=>
{
state
.
addRouters
=
routers
state
.
routers
=
constantRouterMap
.
concat
(
routers
)
}
},
actions
:
{
GenerateRoutes
({
commit
},
data
)
{
return
new
Promise
(
resolve
=>
{
const
{
roles
}
=
data
let
accessedRouters
if
(
roles
.
indexOf
(
'
admin
'
)
>=
0
)
{
accessedRouters
=
asyncRouterMap
}
else
{
accessedRouters
=
filterAsyncRouter
(
asyncRouterMap
,
roles
)
}
commit
(
'
SET_ROUTERS
'
,
accessedRouters
)
resolve
()
})
}
}
}
export
default
permission
src/views/layout/Sidebar.vue
浏览文件 @
9abd44f5
<
template
>
<el-menu
mode=
"vertical"
theme=
"dark"
:default-active=
"$route.path"
>
<sidebar-item
:routes=
'permission_routers'
></sidebar-item>
<sidebar-item
:routes=
"routes"
></sidebar-item>
</el-menu>
</
template
>
<
script
>
import
{
mapGetters
}
from
'
vuex
'
import
SidebarItem
from
'
./SidebarItem
'
export
default
{
components
:
{
SidebarItem
},
computed
:
{
...
mapGetters
([
'
permission_routers
'
])
routes
()
{
return
this
.
$router
.
options
.
routes
}
}
}
</
script
>
...
...
src/views/login/index.vue
浏览文件 @
9abd44f5
...
...
@@ -2,27 +2,29 @@
<div
class=
"login-container"
>
<el-form
autoComplete=
"on"
:model=
"loginForm"
:rules=
"loginRules"
ref=
"loginForm"
label-position=
"left"
label-width=
"0px"
class=
"card-box login-form"
>
<h3
class=
"title"
>
系统登录
</h3>
<h3
class=
"title"
>
vue-element-admin
</h3>
<el-form-item
prop=
"username"
>
<span
class=
"svg-container svg-container_login"
>
<icon-svg
icon-class=
"yonghuming"
/>
</span>
<el-input
name=
"username"
type=
"text"
v-model=
"loginForm.username"
autoComplete=
"on"
placeholder=
"
邮箱
"
/>
<el-input
name=
"username"
type=
"text"
v-model=
"loginForm.username"
autoComplete=
"on"
placeholder=
"
username
"
/>
</el-form-item>
<el-form-item
prop=
"password"
>
<span
class=
"svg-container"
>
<icon-svg
icon-class=
"mima"
></icon-svg>
<icon-svg
icon-class=
"mima"
></icon-svg>
</span>
<el-input
name=
"password"
type=
"password"
@
keyup.enter.native=
"handleLogin"
v-model=
"loginForm.password"
autoComplete=
"on"
placeholder=
"
密码
"
></el-input>
placeholder=
"
password
"
></el-input>
</el-form-item>
<el-form-item>
<el-button
type=
"primary"
style=
"width:100%;"
:loading=
"loading"
@
click.native.prevent=
"handleLogin"
>
登录
Sign in
</el-button>
</el-form-item>
<div
class=
'tips'
>
账号:admin 密码随便填
</div>
<div
class=
'tips'
>
账号:editor 密码随便填
</div>
<div
class=
'tips'
>
<span
style=
"margin-right:20px;"
>
username: admin
</span>
</span>
password: admin
</span>
</div>
</el-form>
</div>
</
template
>
...
...
@@ -41,8 +43,8 @@ export default {
}
}
const
validatePass
=
(
rule
,
value
,
callback
)
=>
{
if
(
value
.
length
<
6
)
{
callback
(
new
Error
(
'
密码不能小于
6
位
'
))
if
(
value
.
length
<
5
)
{
callback
(
new
Error
(
'
密码不能小于
5
位
'
))
}
else
{
callback
()
}
...
...
@@ -50,7 +52,7 @@ export default {
return
{
loginForm
:
{
username
:
'
admin
'
,
password
:
'
111111
'
password
:
'
admin
'
},
loginRules
:
{
username
:
[{
required
:
true
,
trigger
:
'
blur
'
,
validator
:
validateUsername
}],
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录