Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄庭坚
jinfa-platform
Commits
237fde78
Commit
237fde78
authored
Dec 23, 2021
by
前端-钟卫鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: TableOperation添加按钮权限
parent
aec9acd8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
8 deletions
+27
-8
index.tsx
src/components/TableOperation/index.tsx
+14
-8
index.tsx
src/pages/commodity/products/index.tsx
+13
-0
No files found.
src/components/TableOperation/index.tsx
View file @
237fde78
...
...
@@ -3,36 +3,40 @@ import { Button, Dropdown, Menu } from 'antd'
import
{
CaretDownOutlined
}
from
'@ant-design/icons'
import
{
getIntl
}
from
'umi'
;
import
AuthButton
from
'@/components/AuthButton'
import
{
AuthUrl
}
from
'@/components/AuthButton/AuthUrl'
const
intl
=
getIntl
();
/**
* 表格行操作
* 操作显示隐藏受控接口返回字段
* 操作显示
或
隐藏受控接口返回字段
* 操作按钮大于两项 显示更多
*/
type
IButtonTextFieldMap
=
Record
<
string
,
boolean
>
;
type
IOperationHandler
=
Record
<
string
,
any
>
;
type
IButtonPermissionsMap
=
Record
<
string
,
string
>
;
export
interface
TableOperationProps
{
/** 按钮文本和字段值映射 */
buttonTextFieldMap
:
IButtonTextFieldMap
,
/** 按钮文本和操作函数映射 */
operationHandler
:
IOperationHandler
,
/** 按钮权限code和操作文本映射 */
buttonPermissionsMap
?:
IButtonPermissionsMap
,
/** 菜单父级关联code */
menuCode
?:
string
,
}
const
TableOperation
:
React
.
FC
<
TableOperationProps
>
=
(
props
)
=>
{
const
{
buttonTextFieldMap
,
operationHandler
}
=
props
// btnCode: 'products.add'
const
{
buttonTextFieldMap
,
operationHandler
,
buttonPermissionsMap
=
null
,
menuCode
=
null
}
=
props
const
keyNames
=
Object
.
keys
(
buttonTextFieldMap
)
console
.
log
(
keyNames
,
'operationHandler'
,
operationHandler
)
return
(<>
{
Object
.
values
(
buttonTextFieldMap
).
filter
(
Boolean
).
length
>
2
?
<>
<
AuthButton
btnCode=
'products.copy'
menuCode=
'commodityAbility'
>
<
AuthButton
btnCode=
{
buttonPermissionsMap
[
keyNames
[
0
]]
}
menuCode=
{
menuCode
}
>
<
Button
type=
'link'
onClick=
{
operationHandler
[
keyNames
[
0
]]
}
>
{
keyNames
[
0
]
}
</
Button
>
</
AuthButton
>
...
...
@@ -41,7 +45,9 @@ const TableOperation: React.FC<TableOperationProps> = (props) => {
{
keyNames
.
slice
(
1
,
keyNames
.
length
).
map
((
item
,
i
)
=>
buttonTextFieldMap
[
item
]
?
(
<
Menu
.
Item
key=
{
`menuItem${i}`
}
>
<
Button
type=
'link'
onClick=
{
operationHandler
[
item
]
}
>
{
item
}
</
Button
>
<
AuthButton
btnCode=
{
buttonPermissionsMap
[
item
]
}
menuCode=
{
menuCode
}
>
<
Button
type=
'link'
onClick=
{
operationHandler
[
item
]
}
>
{
item
}
</
Button
>
</
AuthButton
>
</
Menu
.
Item
>
)
:
null
)
}
...
...
@@ -53,7 +59,7 @@ const TableOperation: React.FC<TableOperationProps> = (props) => {
</
Dropdown
>
</>
:
keyNames
.
map
((
item
,
i
)
=>
(
buttonTextFieldMap
[
item
]
?
<
Button
key=
{
`btnItem${i}`
}
type=
'link'
onClick=
{
operationHandler
[
item
]
}
>
{
item
}
</
Button
>
:
null
))
keyNames
.
map
((
item
,
i
)
=>
(
buttonTextFieldMap
[
item
]
?
<
AuthButton
btnCode=
{
buttonPermissionsMap
[
item
]
}
menuCode=
{
menuCode
}
><
Button
key=
{
`btnItem${i}`
}
type=
'link'
onClick=
{
operationHandler
[
item
]
}
>
{
item
}
</
Button
></
Auth
Button
>
:
null
))
}
</>)
}
...
...
src/pages/commodity/products/index.tsx
View file @
237fde78
...
...
@@ -183,6 +183,17 @@ const Products: React.FC<{}> = () => {
/** 参照后台数据生成 */
const
renderOptionButton
=
(
record
)
=>
{
// 按钮权限code和操作字符映射
const
btnAuthOfOperationTextMap
=
{
[
intl
.
formatMessage
({
id
:
'commodity.products.buttonGroup.1'
})]:
'products.copy'
,
[
intl
.
formatMessage
({
id
:
'commodity.products.buttonGroup.2'
})]:
'products.examine'
,
[
intl
.
formatMessage
({
id
:
'commodity.products.buttonGroup.3'
})]:
'products.edit'
,
[
intl
.
formatMessage
({
id
:
'commodity.products.buttonGroup.4'
})]:
'products.del'
,
[
intl
.
formatMessage
({
id
:
'commodity.products.buttonGroup.5'
})]:
'products.putaway'
,
[
intl
.
formatMessage
({
id
:
'commodity.products.buttonGroup.6'
})]:
'products.pulloff'
,
[
intl
.
formatMessage
({
id
:
'commodity.products.buttonGroup.7'
})]:
'products.supply'
,
}
const
buttonGroup
=
{
[
intl
.
formatMessage
({
id
:
'commodity.products.buttonGroup.1'
})]:
true
,
[
intl
.
formatMessage
({
id
:
'commodity.products.buttonGroup.2'
})]:
record
.
isSubmit
,
...
...
@@ -207,6 +218,8 @@ const Products: React.FC<{}> = () => {
<
TableOperation
buttonTextFieldMap=
{
buttonGroup
}
operationHandler=
{
operationHandler
}
menuCode=
"commodityAbility"
buttonPermissionsMap=
{
btnAuthOfOperationTextMap
}
/>
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment