import { Space } from 'antd'; import _ from 'lodash'; import { useMemo } from 'react'; import { flatAuditList } from '../AuditList/util'; import PackageCard from './card'; const treeSet = (tree: Record[], o: Record) => { const run = (l: Record[]) => { return l.map((item) => { if (item.children && item.children.length > 0) { item.children = run(item.children); } return { ...item, ..._.cloneDeep(o) }; }); }; return run(tree); }; export type GroupType = { feature: any[]; option: any[]; policy: any[]; role: any[]; city: any[]; }; export interface PackageListProps { applyList?: any[]; } const PackageList = (props: PackageListProps) => { const { applyList } = props; const group = useMemo(() => { const o = { feature: [], option: [], policy: [], role: [], city: [], }; if (!Array.isArray(applyList)) return o; // 分组处理器 return applyList.reduce((pre: GroupType, cur: Record) => { const { auditList, appInfo } = cur ?? {}; if (!Array.isArray(auditList)) return pre; if (auditList[0]?.bpmAuditId) { // bpm const { feature, option, policy, role, city } = flatAuditList(auditList, (data) => ({ ...data, appId: appInfo?.id, appName: appInfo?.name, })); pre.feature.push(...feature); pre.option.push(...option.map((v) => ({ ...v, children: v.optionTree }))); pre.policy.push(...policy); pre.role.push(...role); pre.city.push(...city); return pre; } else { // uac return auditList.reduce((top: GroupType, audit: any) => { const { feature, option, policy, role, city, // 审批属性 auditType, bpmCanAudit, bpmAuditId, bpmAuditNode, } = audit ?? {}; const s = { auditType, bpmCanAudit, bpmAuditId, bpmAuditNode, appId: appInfo?.id, appName: appInfo?.name, }; top.feature.push(...treeSet(feature ?? [], s)); top.option.push( ...treeSet(option?.map((v: any) => ({ ...v, children: v.optionTree })) ?? [], s), ); top.policy.push(...treeSet(policy ?? [], s)); top.role.push(...treeSet(role ?? [], s)); top.city.push(...treeSet(city ?? [], s)); return top; }, pre); } }, o); }, [applyList]); return ( {group.feature.length > 0 && } {group.option.length > 0 && } {group.policy.length > 0 && } {group.role.length > 0 && } {group.city.length > 0 && } ); }; export default PackageList;