import styles from './GridCell.scss'; import React, { CSSProperties } from 'react'; import { Cell, CellType, DataType } from '@/types/GridCell'; export const GRow: React.FC = props => { return
{props.children}
; }; export class GCol extends React.Component<{ key?: string | number; inherit?: boolean; span?: number; children?: React.ReactNode; }> { constructor(props: { key?: string | number; inherit?: boolean; span?: number; children?: React.ReactNode; }) { super(props); } render() { return (
{this.props.children}
); } } const getCol = (span: number | undefined) => { switch (span) { case 1: return styles.col1; case 2: return styles.col2; case 3: return styles.col3; case 4: return styles.col4; case 5: return styles.col5; case 6: return styles.col6; case 7: return styles.col7; case 8: return styles.col8; case 9: return styles.col9; case 10: return styles.col10; case 11: return styles.col11; case 12: return styles.col12; case 13: return styles.col13; case 14: return styles.col14; case 15: return styles.col15; case 16: return styles.col16; case 17: return styles.col17; case 18: return styles.col18; case 19: return styles.col19; case 20: return styles.col20; case 21: return styles.col21; case 22: return styles.col22; case 23: return styles.col23; case 24: return styles.col24; default: return styles.col; } }; export default class GridCell extends React.Component<{ cell: Cell; lineColor?: string; inner?: boolean; }> { constructor(props: { cell: Cell; lineColor?: string; inner?: boolean }) { super(props); } private buildGrid = (): JSX.Element => { return this.buildCell(this.props.cell, 0); }; buildCell = (cell: Cell, index: number): JSX.Element => { if (cell.type === CellType.Text || cell.type === undefined) { return (
{cell.text}
); } if (cell.type === CellType.Custom) { return (
{cell.render === undefined ? '' : cell.render()}
); } if (cell.type === CellType.InnerCell) { return (
); } let childContent; if (cell.type === CellType.Group) { if (cell.child !== null && cell.child !== undefined) { childContent = this.buildGroup(cell); if (cell.dataType === DataType.Default || cell.dataType === undefined) { return (
{childContent?.map(ct => { return ct; })}
); } else { return (
{childContent?.map(ct => { return (
ct
); })}
); } } else { //显示group名称 return (
{cell.text}
); } } return
can't support cell
; }; buildGroup = (cell: Cell): JSX.Element[] => { let content: JSX.Element[] = []; if (cell.child !== undefined) { cell.child.forEach((c, index) => { let curContent = this.buildCell(c, index); if (!(curContent instanceof String)) { content.push(curContent); } }); } return content; }; render() { let tableStyle; if (this.props.inner === undefined) { tableStyle = styles.defaultGrid; } if (this.props.inner === true) { tableStyle = styles.innerGrid; } else { tableStyle = styles.defaultGrid; } return (
{this.buildGrid()}
); } }