gg

** 期间轴:非 dynamic 项做固定列,dynamic 项按月份分组 */
  const buildColumnsForTableDateRange = useCallback(
    (dates: string[]) => {
      const totalDate = getMonthsInRange(dates);
      const staticItems = PROPOSAL_LIST.filter((item: any) => !item.dynamic);
      const dynamicItems = PROPOSAL_LIST.filter((item: any) => item.dynamic);
 
      const staticColumns = staticItems.map((item: any) => {
        const baseCol: any = {
          title: item.itemName,
          dataIndex: item.itemVar,
          key: item.itemVar,
          width: 120,
        };
        return withHasTotalRender(baseCol, item.itemName, expandedKeys, setExpandedKeys);
      });
 
      const monthGroups = totalDate.map((month) => ({
        title: <MonthHeaderLabel monthStr={month} />,
        key: `group-${month}`,
        align: 'center' as const,
        onHeaderCell: () => ({ style: currentMonthCellStyle(month) }),
        children: dynamicItems.map((item: any) => ({
          title: item.itemName,
          key: `${toMonthlyKey(month)}__${item.itemVar}`,
          dataIndex: [toMonthlyKey(month), item.itemVar],
          align: 'left' as const,
          width: 180,
          onHeaderCell: () => ({ style: currentMonthCellStyle(month) }),
          onCell: () => ({ style: currentMonthCellStyle(month) }),
        })),
      }));
 
      return [...staticColumns, ...monthGroups];
    },
    [expandedKeys],
  );
 
  const columnsForProject = useMemo(
    () => buildColumnsForTableProject(selectDate),
    [buildColumnsForTableProject, selectDate],
  );
 
  const columnsForDateRange = useMemo(
    () => buildColumnsForTableDateRange(selectDate),
    [buildColumnsForTableDateRange, selectDate],
  );
posted @ 2026-10-09 15:30  小兔子09  阅读(5)  评论(0)    收藏  举报