Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
SHR
/
tFIMS
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f73b3e42
authored
Sep 02, 2019
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改权限按钮渲染方式
1 parent
31c96fba
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
103 deletions
src/components/d2-auth/d2-auth-btn.js
src/components/d2-auth/d2-auth-btn.vue
src/components/index.js
src/router/routes.js
src/store/modules/d2admin/modules/auth.js
src/views/userManage/user/index.vue
src/components/d2-auth/d2-auth-btn.js
0 → 100644
View file @
f73b3e4
export
default
{
name
:
'AuthButton'
,
props
:
{
label
:
{
type
:
String
,
default
:
'Button'
},
size
:
{
type
:
String
,
default
:
'mini'
},
type
:
{
type
:
String
,
default
:
'text'
},
loading
:
{
type
:
Boolean
,
default
:
false
},
disabled
:
{
type
:
Boolean
,
default
:
false
},
id
:
{
type
:
String
,
default
:
null
},
accept
:
{
type
:
String
,
default
:
null
},
mapping
:
{
type
:
Object
,
default
:
null
},
data
:
Object
,
},
functional
:
true
,
// 开启函数化组件
render
:
(
h
,
ctx
)
=>
{
const
_this
=
ctx
.
parent
//获取 vue this 实例
/**
* 获取传入参数
* type 非必填 button 类型 默认 text ----- route 中不标明 视为默认值 text
* data 点击按钮时 需要得到的参数 比如 table 中的 当前行数据 row
* mapping 非必填 但: 当列表中的操作选项 根据 某个字段 变化的话 必填 且 必须 注明 field: 字段名
*/
const
{
type
,
data
,
mapping
}
=
ctx
.
props
/**
* 判断一个按钮(btn)是否存在与当前行(data) 的映射关系(mapping)中
* @param {*} btn
*/
const
filter
=
btn
=>
mapping
?
mapping
[
data
[
mapping
[
'field'
]]].
includes
(
btn
.
label
):
true
/**
* 拿到当前模块(页面) 所拥有按钮列表 过滤type属性 与 映射关系 返回需要显示的按钮列表
*/
const
curBtns
=
_this
.
$store
.
getters
[
'd2admin/auth/curBtns'
].
filter
(
btn
=>
{
if
(
type
===
'text'
||
!
type
){
return
(
btn
.
type
===
'text'
||
!
btn
.
type
)
&&
filter
(
btn
)
}
return
btn
.
type
===
type
&&
filter
(
btn
)
})
const
__aBtns
=
[]
/**
* 循环最终显示的按钮列表
* 并渲染到页面
*/
curBtns
.
forEach
(
btn
=>
__aBtns
.
push
(
h
(
'el-button'
,
{
props
:
{
type
},
on
:
{
click
:
()
=>
_this
[
btn
.
handle
](
data
)
}
},
[
btn
.
label
])))
return
h
(
'div'
,
{},
__aBtns
)
}
}
\ No newline at end of file
src/components/d2-auth/d2-auth-btn.vue
deleted
100644 → 0
View file @
31c96fb
<
template
>
<el-button
:size=
"size"
:type=
"type"
:loading=
"loading"
v-if=
"isInRole"
@
click=
"handleClick"
>
{{
label
}}
<input
v-if=
"label == '导入'"
type=
"file"
class=
"import-input"
:accept=
"accept"
@
change=
"handleImport"
/>
</el-button>
</
template
>
<
script
>
import
{
mapGetters
}
from
'vuex'
export
default
{
name
:
'AuthButton'
,
props
:
{
label
:
{
type
:
String
,
default
:
'Button'
},
size
:
{
type
:
String
,
default
:
'mini'
},
type
:
{
type
:
String
,
default
:
'text'
},
loading
:
{
type
:
Boolean
,
default
:
false
},
disabled
:
{
type
:
Boolean
,
default
:
false
},
id
:
{
type
:
String
,
default
:
null
},
accept
:
{
type
:
String
,
default
:
null
}
},
computed
:
{
...
mapGetters
(
'd2admin/auth'
,
[
'curBtns'
])
},
data
()
{
return
{
isInRole
:
false
}
},
created
()
{
// this.$vrm.setRoles(this.btnIdAll)
if
(
this
.
curBtns
){
// const { action, operation } = this.curBtns
// console.log(this.label);
this
.
isInRole
=
this
.
curBtns
.
find
(
obj
=>
obj
.
id
===
this
.
id
||
obj
.
label
===
this
.
label
)
}
},
methods
:
{
handleClick
:
function
()
{
this
.
$emit
(
'e-auth-click'
,
{})
},
handleImport
(
e
)
{
this
.
$emit
(
'import-file'
,
e
)
}
}
}
</
script
>
<
style
scoped
>
.import-input
{
opacity
:
0
;
position
:
absolute
;
left
:
0
;
top
:
0
;
width
:
70px
;
height
:
100%
;
cursor
:
pointer
;
font-size
:
0
}
</
style
>
src/components/index.js
View file @
f73b3e4
import
Vue
from
'vue'
import
d2Container
from
'./d2-container'
import
authButton
from
'./d2-auth/d2-auth-btn.
vue
'
import
authButton
from
'./d2-auth/d2-auth-btn.
js
'
// 注意 有些组件使用异步加载会有影响
Vue
.
component
(
'd2-container'
,
d2Container
)
...
...
src/router/routes.js
View file @
f73b3e4
...
...
@@ -306,7 +306,8 @@ export const resources = {
auth
:
[{
// 列表操作
id
:
'1070101'
,
pid
:
'10701'
,
label
:
'审核'
label
:
'审核'
,
handle
:
'handleEdit'
},
{
//
id
:
'1070102'
,
pid
:
'10701'
,
...
...
@@ -330,7 +331,9 @@ export const resources = {
},
{
// 列表操作
id
:
'1070107'
,
pid
:
'10701'
,
label
:
'创建用户'
label
:
'创建用户'
,
type
:
'button'
,
handle
:
'handleEdit'
}],
component
:
_import
(
'userManage/user'
)
},
...
...
src/store/modules/d2admin/modules/auth.js
View file @
f73b3e4
...
...
@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-08-27 17:25:12
* @Last Modified by: limin
* @Last Modified time: 2019-09-02 16:
30:11
* @Last Modified time: 2019-09-02 16:
57:35
*/
import
util
from
'@/libs/util.js'
import
router
from
'@/router'
...
...
@@ -118,7 +118,7 @@ export default {
// 获取权限资源点
const
__source
=
await
dispatch
(
'load'
)
// 过滤资源点 并动态添加到路由
const
{
route
,
btn
}
=
util
.
permision
.
packRoutesBtns
({...
sources
,
'101'
:
home
},
__source
)
const
{
route
,
btn
}
=
util
.
permision
.
packRoutesBtns
({...
sources
,
[
home
.
meta
.
id
]
:
home
},
__source
)
frameInRoutes
[
0
].
children
=
[
home
,
...
route
,
...
sys
]
router
.
addRoutes
(
frameInRoutes
)
state
.
btns
=
btn
...
...
src/views/userManage/user/index.vue
View file @
f73b3e4
...
...
@@ -67,7 +67,8 @@
<el-row
style=
"height: 40px; line-height: 40px"
>
<el-col
:span=
"12"
>
用户列表
</el-col>
<el-col
:span=
"12"
style=
"text-align: right"
>
<el-button
@
click=
"register()"
>
创建用户
</el-button>
<!--
<el-button
@
click=
"register()"
>
创建用户
</el-button>
-->
<auth-button
type=
"button"
></auth-button>
</el-col>
</el-row>
<el-table
:data=
"tableData"
v-loading=
"tableLoading"
border
style=
"margin: 20px 0;"
>
...
...
@@ -87,12 +88,12 @@
</el-table-column>
<el-table-column
align=
"center"
label=
"操作"
>
<
template
slot-scope=
"scope"
>
<auth-button
type=
"text"
label=
"重置密码"
@
click=
"handleEdit(scope.row, scope.$index)
"
></auth-button>
<
auth-button
type=
"text"
label=
"审核
"
@
click=
"handleEdit(scope.row, scope.$index)"
></auth-button>
<auth-button
type=
"text"
label=
"编辑"
@
click=
"handleEdit(scope.row, scope.$index)"
></auth-button>
<auth-button
type=
"text"
label=
"延期"
@
click=
"handleEdit(scope.row, scope.$index)"
></auth-button>
<auth-button
type=
"text"
label=
"禁用"
@
click=
"handleEdit(scope.row, scope.$index)"
></auth-button>
<auth-button
type=
"text"
label=
"激活"
@
click=
"handleEdit(scope.row, scope.$index)"
></auth-button
>
<auth-button
:mapping=
"mapping"
:data=
"scope.row
"
></auth-button>
<
!--
<auth-button
type=
"text"
label=
"审核"
:mapping=
"mapping
"
@
click=
"handleEdit(scope.row, scope.$index)"
></auth-button>
<auth-button
type=
"text"
label=
"编辑"
:mapping=
"mapping"
@
click=
"handleEdit(scope.row, scope.$index)"
></auth-button>
<auth-button
type=
"text"
label=
"延期"
:mapping=
"mapping"
@
click=
"handleEdit(scope.row, scope.$index)"
></auth-button>
<auth-button
type=
"text"
label=
"禁用"
:mapping=
"mapping"
@
click=
"handleEdit(scope.row, scope.$index)"
></auth-button>
<auth-button
type=
"text"
label=
"激活"
:mapping=
"mapping"
@
click=
"handleEdit(scope.row, scope.$index)"
></auth-button>
--
>
</
template
>
</el-table-column>
</el-table>
...
...
@@ -127,6 +128,13 @@ export default {
},
data
()
{
return
{
mapping
:
Object
.
freeze
({
'field'
:
'status'
,
'1'
:[
'重置密码'
,
'编辑'
,
'延期'
,
'禁用'
],
'2'
:[
'重置密码'
,
'编辑'
,
'激活'
],
'3'
:[
'重置密码'
,
'编辑'
,
'激活'
],
'4'
:[
'审核'
]
}),
// 新增/编辑弹窗
editVisible
:
false
,
editForm
:
{
...
...
@@ -173,7 +181,8 @@ export default {
return
{
1
:
"正常"
,
2
:
"已过期"
,
3
:
'禁用'
3
:
'禁用'
,
4
:
'待审核'
}[
cellValue
.
status
];
}
},
...
...
@@ -277,7 +286,9 @@ export default {
// 调接口
this
.
loadUserList
();
},
handleEdit
(
row
){
console
.
log
(
row
);
},
handleDelete
(
index
,
row
)
{
this
.
$confirm
(
"确认删除?"
,
"删除"
,
{
comfirmButtonText
:
"确认"
,
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment