Commit 237fde78 authored by 前端-钟卫鹏's avatar 前端-钟卫鹏

feat: TableOperation添加按钮权限

parent aec9acd8
......@@ -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></AuthButton> : null))
}
</>)
}
......
......@@ -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}
/>
)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment