import type { ProColumns } from '@ant-design/pro-table'; import { Button, Card, Popconfirm, Space, Tooltip, Typography } from 'antd'; import _ from 'lodash'; import type { Key } from 'react'; import { useCallback, useMemo } from 'react'; import { FormattedMessage, useIntl } from 'umi'; import AuditCountersign from '../AuditCountersign'; import AuditPassOn from '../AuditPassOn'; import AuditProgress from '../AuditProgress'; import BindAllPermission from '../BindAllPermission'; import CustomTable from '../CustomTable'; import ExpandIcon from '../ExpandIcon'; import Tips from '../Tips'; import publicConst from '../utils/const'; import type { BpmTableProps } from './BpmTable'; import { AduitStatus } from './const'; import type { RowType } from './hooks'; import lessStyle from './index.less'; import { flatAuditDataKey, flatAuditRowKey } from './util'; const { DataSensitiveLevelTips, DataSensitiveTips } = Tips; const { Text } = Typography; export interface PermissionTableProps { auditDetail: any; data: any; pageReadOnly?: boolean; chainId?: string; rowSelectionKeys?: BpmTableProps['rowSelectionKeys']; setSelectionKeys?: BpmTableProps['setSelectionKeys']; approvalHandler?: BpmTableProps['approvalHandler']; requestDetail?: BpmTableProps['requestDetail']; } const PermissionTable = (props: PermissionTableProps) => { const { auditDetail, data, pageReadOnly, chainId, rowSelectionKeys, setSelectionKeys, approvalHandler, requestDetail, } = props; const { formatMessage } = useIntl(); const { appInfo } = auditDetail || {}; const columns = useCallback( (type: string) => { const { DataSensitiveMap, DataSensitiveLevelMap } = publicConst(formatMessage); const res: ProColumns[] = [ { title: ( ), dataIndex: 'name', search: false, className: lessStyle.nameColumn, render: (__, record) => { const { name, id } = record; return ( <> {name} {type === 'role' && ( )} ); }, }, { title: , dataIndex: 'dataSensitive', search: false, tooltip: DataSensitiveLevelTips, valueType: 'select', valueEnum: DataSensitiveLevelMap, }, { title: , dataIndex: 'sensitiveLevel', search: false, tooltip: DataSensitiveTips, valueType: 'select', valueEnum: DataSensitiveMap, }, { title: , dataIndex: 'expiredAt', search: false, ellipsis: true, render: (__, record) => { const expiredAt = type === 'city' ? 0 : record.expiredAt; return ( _.isNumber(expiredAt) && ( {expiredAt === 0 ? formatMessage({ id: 'pages.setting.base.defaultExpirationTime.forever' }) : expiredAt / 86400} ) ); }, }, ]; if (approvalHandler) { res.push( { title: ( ), dataIndex: 'bpmAuditNode', search: false, render: (__: any, record: any) => { const auditData = record[flatAuditDataKey]; if (!auditData) return null; const { bpmAuditNode } = auditData; if (!Array.isArray(bpmAuditNode) || !bpmAuditNode.length) return null; const last = bpmAuditNode[bpmAuditNode.length - 1]; return ( {formatMessage({ id: AduitStatus[last?.state] })} ); }, }, { title: , dataIndex: 'bpmAuditNode', search: false, render: (__: any, record: any) => { const auditData = record[flatAuditDataKey]; if (!auditData) return null; const { bpmAuditNode } = auditData; return ( ); }, }, { title: , dataIndex: 'permissionOption', valueType: 'option', fixed: 'right', align: 'center', search: false, width: 240, hideInTable: pageReadOnly, render: (__: any, record: any) => { const auditData = record[flatAuditDataKey]; if (!auditData) return null; const { bpmCanAudit, bpmAuditId } = auditData; if (!chainId || !bpmCanAudit) return null; return ( { approvalHandler([bpmAuditId], 1, 'bpm'); }} > { approvalHandler([bpmAuditId], 3, 'bpm'); }} > ); }, }, ); } return res; }, [ appInfo?.id, approvalHandler, auditDetail, chainId, formatMessage, pageReadOnly, requestDetail, ], ); const dataSource = useMemo(() => { const { feature, role, policy, option, city } = data || {}; // 分类列表 const res: { type: string; list: any[] }[] = []; // 功能 if (feature?.length) { res.push({ type: 'feature', list: feature }); } // 角色 if (role?.length) { res.push({ type: 'role', list: role }); } // 策略 if (policy?.length) { res.push({ type: 'policy', list: policy }); } // 数据 if (option?.length) { res.push({ type: 'option', list: option.map((v: any) => ({ ...v, children: v.optionTree })), }); } // 城市 if (city?.length) { res.push({ type: 'city', list: city }); } return res; }, [data]); const rowSelection = useCallback( (type: string) => { if (pageReadOnly || !approvalHandler) return false; return { getCheckboxProps: (record: any) => { const auditData = record[flatAuditDataKey]; if (!auditData) { return { disabled: true }; } const { bpmCanAudit } = auditData as any; return { disabled: !chainId || !bpmCanAudit, }; }, selectedRowKeys: rowSelectionKeys?.[type], onChange: (rowKey: Key[]) => { setSelectionKeys?.((oldVal: RowType) => ({ ...oldVal, [type]: rowKey })); }, }; }, [approvalHandler, chainId, pageReadOnly, rowSelectionKeys, setSelectionKeys], ); return ( {dataSource.map((v) => { const { type, list } = v; return ( , }} rowSelection={rowSelection(type)} dataSource={list} /> ); })} ); }; export default PermissionTable;