Commit 881774e7 authored by zhangwenshuai's avatar zhangwenshuai

update apolloTable daterange

parent 26e5e06e
...@@ -19,6 +19,7 @@ const Cell = (props: CellProps) => { ...@@ -19,6 +19,7 @@ const Cell = (props: CellProps) => {
cellClassName, cellClassName,
cellStyle, cellStyle,
record, record,
columnData,
value: cellData, value: cellData,
emitChangeCell, emitChangeCell,
columnIndex, columnIndex,
...@@ -33,6 +34,7 @@ const Cell = (props: CellProps) => { ...@@ -33,6 +34,7 @@ const Cell = (props: CellProps) => {
selectedCell, selectedCell,
cellKey, cellKey,
changeSelectedCell, changeSelectedCell,
position = 'center',
} = props; } = props;
const { const {
columnType, columnType,
...@@ -158,14 +160,22 @@ const Cell = (props: CellProps) => { ...@@ -158,14 +160,22 @@ const Cell = (props: CellProps) => {
return <Checkbox checked={checked} onClick={onToggle} />; return <Checkbox checked={checked} onClick={onToggle} />;
}; };
const { dynamicCellConfigDTO } = columnData;
const detail = ( const detail = (
<div <div
className={selectedCell === cellKey ? classNames(s.detailCell, s.selected) : s.detailCell} className={
selectedCell === `${position}_${cellKey}` ? classNames(s.detailCell, s.selected) : s.detailCell
}
onClick={() => { onClick={() => {
if (selectedCell === cellKey) { // 不可编辑状态
cellEditable && !readOnlyFlag && setStatus('edit'); if (!cellEditable || readOnlyFlag || (dynamicCellConfigDTO && dynamicCellConfigDTO.readonlyFlag)) {
return false;
}
if (selectedCell === `${position}_${cellKey}`) {
setStatus('edit');
} else { } else {
changeSelectedCell && changeSelectedCell(cellKey); changeSelectedCell && changeSelectedCell(`${position}_${cellKey}`);
} }
}} }}
// onDoubleClick={() => { // onDoubleClick={() => {
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
border: 1px solid @borderColor; border: 1px solid @borderColor;
&.scroll { &.scroll {
height: 100%; height: 100%;
.loading{ .loading {
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%,-50%); transform: translate(-50%, -50%);
} }
} }
.leftSideContainer { .leftSideContainer {
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
right: 0; right: 0;
z-index: 1; z-index: 1;
} }
:global(.ReactVirtualized__Grid__innerScrollContainer){ :global(.ReactVirtualized__Grid__innerScrollContainer) {
overflow: unset !important; overflow: unset !important;
} }
} }
...@@ -59,6 +59,9 @@ ...@@ -59,6 +59,9 @@
} }
.centerGrid { .centerGrid {
outline: none; outline: none;
}
.bodyRow {
} }
.bodyCell { .bodyCell {
font-size: 20px; font-size: 20px;
...@@ -100,6 +103,6 @@ ...@@ -100,6 +103,6 @@
right: 0; right: 0;
pointer-events: none; pointer-events: none;
} }
.defaultEmpty{ .defaultEmpty {
padding-top: 100px; padding-top: 100px;
} }
...@@ -209,11 +209,11 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -209,11 +209,11 @@ export default class AirTable extends Component<TableProps, TableState> {
} }
}; };
changeSelectedCell=(key)=>{ changeSelectedCell = (key) => {
this.setState({ this.setState({
selectedCell:key selectedCell: key,
}) });
} };
// 渲染表头 // 渲染表头
renderHeaderCell = ( renderHeaderCell = (
...@@ -253,66 +253,14 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -253,66 +253,14 @@ export default class AirTable extends Component<TableProps, TableState> {
); );
}; };
renderBodyRow = (
{ showColumns, showData, position }: { showColumns: ColumnProps[]; showData: RowProps; position?: string },
{ columnIndex, key, rowIndex, style }: any,
) => {
const { rowClassName, rowStyle, bordered = false } = this.props;
// 默认边框覆盖掉传过来的样式
const rowBorderStyle: any = {
borderLeft: 'none',
borderRight: 'none',
borderTop: 'none',
borderBottom: borderStyle,
};
if (bordered) {
rowBorderStyle.borderRight = borderStyle;
if (columnIndex === 0) {
rowBorderStyle.borderLeft = borderStyle;
}
}
const className = getMergeClassName(styles.bodyCell, rowClassName, { rowIndex });
const rowStyleObject = getMergeStyle(style, rowStyle, { rowIndex });
const mergedRowStyle = {
...rowStyleObject,
...rowBorderStyle,
};
return this.renderBodyCellContainer(
{ showColumns, showData, position },
{
columnIndex,
key,
rowIndex,
rowClassName: className,
rowStyle: mergedRowStyle,
},
);
};
renderBodyCellContainer = (
{ showColumns, showData, position }: { showColumns: ColumnProps[]; showData: RowProps; position?: string },
{ columnIndex, key, rowIndex, rowClassName, rowStyle }: any,
) => {
const columnConfig = showColumns[columnIndex];
const { cellClassName, cellStyle } = columnConfig;
const className = getMergeClassName(rowClassName, cellClassName, { columnIndex, columnConfig });
const mergedCellStyle = getMergeStyle(rowStyle, cellStyle, { columnIndex, columnConfig });
return this.renderBodyCell(
{ showColumns, showData, position },
{
columnIndex,
key,
rowIndex,
cellClassName: className,
cellStyle: mergedCellStyle,
},
);
};
// 渲染数据 // 渲染数据
renderBodyCell = ( renderBodyCell = (
{ showColumns, showData, position }: { showColumns: ColumnProps[]; showData: RowProps; position?: string }, {
{ columnIndex, key, rowIndex, cellClassName, cellStyle }: any, showColumns,
showData,
position = 'center',
}: { showColumns: ColumnProps[]; showData: RowProps; position?: string },
{ columnIndex, key, rowIndex, style }: any,
) => { ) => {
const { columns, dataSource, selectedCell } = this.state; const { columns, dataSource, selectedCell } = this.state;
const { const {
...@@ -323,6 +271,8 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -323,6 +271,8 @@ export default class AirTable extends Component<TableProps, TableState> {
cellEditable, cellEditable,
rowSelection, rowSelection,
contentMenu, contentMenu,
rowClassName,
rowStyle,
} = this.props; } = this.props;
if (showColumns.length === 0 || showData.length === 0) { if (showColumns.length === 0 || showData.length === 0) {
return; return;
...@@ -332,6 +282,38 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -332,6 +282,38 @@ export default class AirTable extends Component<TableProps, TableState> {
const columnConfig: any = showColumns[columnIndex]; // 列属性 const columnConfig: any = showColumns[columnIndex]; // 列属性
const columnData: any = rowData.rowData[columnIndex]; // 列数据 const columnData: any = rowData.rowData[columnIndex]; // 列数据
const cellData: any = columnData && columnData.cellValueList; // 列数据 const cellData: any = columnData && columnData.cellValueList; // 列数据
const { cellClassName, cellStyle, bordered = false } = columnConfig;
const rowClassNameStr = getMergeClassName(styles.bodyRow, rowClassName, { rowIndex });
const rowStyleObj = getMergeStyle({}, rowStyle, { rowIndex });
// 默认边框覆盖掉传过来的样式
const cellBorderStyle: any = {
borderLeft: 'none',
borderRight: 'none',
borderTop: 'none',
borderBottom: borderStyle,
};
if (bordered) {
cellBorderStyle.borderRight = borderStyle;
if (columnIndex === 0) {
cellBorderStyle.borderLeft = borderStyle;
}
}
const cellClassNameStr = getMergeClassName(styles.bodyCell, cellClassName, {
columnIndex,
columnConfig,
columnData,
cellData,
});
const cellStyleObj = getMergeStyle({ ...style, ...cellBorderStyle }, cellStyle, {
columnIndex,
columnConfig,
columnData,
cellData,
});
return ( return (
<Cell <Cell
key={key} key={key}
...@@ -339,10 +321,11 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -339,10 +321,11 @@ export default class AirTable extends Component<TableProps, TableState> {
columnIndex={columnIndex} columnIndex={columnIndex}
columnConfig={columnConfig} columnConfig={columnConfig}
value={cellData} value={cellData}
columnData={columnData}
record={record} record={record}
emitChangeCell={emitChangeCell} emitChangeCell={emitChangeCell}
cellClassName={cellClassName} cellClassName={classNames(rowClassNameStr, cellClassNameStr)}
cellStyle={cellStyle} cellStyle={{ ...rowStyleObj, ...cellStyleObj }}
columns={columns} columns={columns}
paginationConfig={paginationConfig} paginationConfig={paginationConfig}
showIndex={position === 'right' ? false : showIndex} showIndex={position === 'right' ? false : showIndex}
...@@ -353,6 +336,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -353,6 +336,7 @@ export default class AirTable extends Component<TableProps, TableState> {
selectedCell={selectedCell} selectedCell={selectedCell}
changeSelectedCell={this.changeSelectedCell} changeSelectedCell={this.changeSelectedCell}
cellKey={key} cellKey={key}
position={position}
/> />
); );
}; };
...@@ -451,9 +435,10 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -451,9 +435,10 @@ export default class AirTable extends Component<TableProps, TableState> {
}} }}
className={styles.sideGrid} className={styles.sideGrid}
overscanRowCount={overscanRowCount} overscanRowCount={overscanRowCount}
cellRenderer={this.renderBodyRow.bind(this, { cellRenderer={this.renderBodyCell.bind(this, {
showColumns: leftColumns, showColumns: leftColumns,
showData: leftData, showData: leftData,
position: 'left',
})} })}
columnWidth={this.getColumnWidth.bind(this, { columnWidth={this.getColumnWidth.bind(this, {
columns: showColumns, columns: showColumns,
...@@ -540,9 +525,10 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -540,9 +525,10 @@ export default class AirTable extends Component<TableProps, TableState> {
this.onScroll(arg[0]); this.onScroll(arg[0]);
}} }}
height={totalHeight} height={totalHeight}
cellRenderer={this.renderBodyRow.bind(this, { cellRenderer={this.renderBodyCell.bind(this, {
showColumns, showColumns,
showData, showData,
position: 'center',
})} })}
/> />
) : ( ) : (
...@@ -616,7 +602,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -616,7 +602,7 @@ export default class AirTable extends Component<TableProps, TableState> {
}} }}
className={styles.sideGrid} className={styles.sideGrid}
overscanRowCount={overscanRowCount} overscanRowCount={overscanRowCount}
cellRenderer={this.renderBodyRow.bind(this, { cellRenderer={this.renderBodyCell.bind(this, {
showColumns: rightColumns, showColumns: rightColumns,
showData: rightData, showData: rightData,
position: 'right', position: 'right',
......
...@@ -77,12 +77,10 @@ export const GetFormatter = { ...@@ -77,12 +77,10 @@ export const GetFormatter = {
return obj.value ? moment(obj.value) : undefined; return obj.value ? moment(obj.value) : undefined;
}, },
DATERANGE: (val) => { DATERANGE: (val) => {
if (Array.isArray(val)) { const obj = Array.isArray(val) && val.length > 0 ? val[0] : {};
return val.map((item) => { const newVal = obj.value ? obj.value.split('~') : [];
return moment(item.value); const [startTime, endTime] = newVal;
}); return [startTime && moment(startTime), endTime && moment(endTime)];
}
return undefined;
}, },
LINK: (val) => { LINK: (val) => {
return Array.isArray(val) && val.length > 0 ? val : []; return Array.isArray(val) && val.length > 0 ? val : [];
......
...@@ -103,15 +103,49 @@ export const SetFormatter = { ...@@ -103,15 +103,49 @@ export const SetFormatter = {
val = val.format ? val.format(setFormat) : val; val = val.format ? val.format(setFormat) : val;
return [{ value: val, text: val }]; return [{ value: val, text: val }];
}, },
DATERANGE: (val, config) => { DATERANGE: (val, config = {}) => {
if (Array.isArray(val)) { const arr = Array.isArray(val) ? val : [];
let res: any[] = []; const { format, showTime } = config;
val.map((item) => { let setStartFormat = format || formatStr;
res = res.concat(SetFormatter.DATE(item, config)); let setEndFormat = format || formatStr;
}); // 如果没有传showTime,则默认按照0点到23点处理
return res; if (showTime) {
// airTable中需对日期类数据处理,没有时分秒时补全为0
if (setStartFormat.indexOf('H') === -1) {
setStartFormat += ' 00';
} }
return emptyModel; if (setStartFormat.indexOf('m') === -1) {
setStartFormat += ':00';
}
if (setStartFormat.indexOf('s') === -1) {
setStartFormat += ':00';
}
// 结束日期
// airTable中需对日期类数据处理,没有时分秒时补全为0
if (setEndFormat.indexOf('H') === -1) {
setEndFormat += ' 23';
}
if (setEndFormat.indexOf('m') === -1) {
setEndFormat += ':59';
}
if (setEndFormat.indexOf('s') === -1) {
setEndFormat += ':59';
}
} else {
setStartFormat = 'YYYY-MM-DD 00:00:00';
setEndFormat = 'YYYY-MM-DD 23:59:59';
}
const formateArr = arr
.map((ls, index) => {
return ls.format ? ls.format(index === 0 ? setStartFormat : setEndFormat) : ls;
})
.join('~');
return [
{
value: formateArr,
text: formateArr,
},
];
}, },
LINK: (val) => { LINK: (val) => {
return Array.isArray(val) && val.length > 0 ? val : emptyModel; return Array.isArray(val) && val.length > 0 ? val : emptyModel;
......
import React from 'react'; import React, { useEffect, useRef, useState } from 'react';
import { Tooltip } from 'antd';
import classNames from 'classnames';
import { formatStr } from '../../_utils/setFormatter'; import { formatStr } from '../../_utils/setFormatter';
import s from '../input/index.less';
import { DateProps } from '../detailInterface'; import { DateProps } from '../detailInterface';
import styles from '../input/index.less';
export const ApolloDateRangeDetail = (props: DateProps) => { export const ApolloDateRangeDetail = (props: DateProps) => {
const { value, formatter, componentAttr } = props; const { value, formatter, componentAttr, className } = props;
const formatValue = formatter ? formatter(value) : value; const formatValue = formatter ? formatter(value) : value;
if (!formatValue) return null; if (!formatValue || !Array.isArray(formatValue)) return null;
const { format = formatStr } = componentAttr || {}; const [dotVisible, setDotVisible] = useState(false);
const container = useRef(null);
let valueStr = ''; const dom = useRef(null);
if (typeof formatValue === 'string') { useEffect(() => {
valueStr = formatValue; const containerTarget: any = container.current;
const target: any = dom.current;
if (containerTarget && target) {
if (target.clientWidth > containerTarget.clientWidth) {
setDotVisible(true);
} else { } else {
valueStr = formatValue.format ? formatValue.format(format) : formatValue; setDotVisible(false);
} }
return <div className={s.text}>{valueStr}</div>; }
}, [value]);
const { format = formatStr } = componentAttr || {};
const arr: any[] = [];
formatValue.map((item) => {
arr.push(item.format ? item.format(format) : item);
});
const dateStr = arr.join('~');
return (
<div className={styles.container} ref={container}>
{dotVisible ? (
<Tooltip title={dateStr}>
<div className={classNames(styles.text, className)}>{dateStr}</div>
</Tooltip>
) : (
<div className={classNames(styles.text, className)}>{dateStr}</div>
)}
<div className={styles.itemBgTxt} ref={dom}>
{dateStr}
</div>
</div>
);
}; };
...@@ -6,7 +6,6 @@ import extendIcon from '../../../../assets/extend.png'; ...@@ -6,7 +6,6 @@ import extendIcon from '../../../../assets/extend.png';
export const ApolloLinkDetail = (props: any) => { export const ApolloLinkDetail = (props: any) => {
const { value, origin } = props; const { value, origin } = props;
debugger
if (!Array.isArray(value) || value.length === 0) return null; if (!Array.isArray(value) || value.length === 0) return null;
const [dotVisible, setDotVisible] = useState(false); const [dotVisible, setDotVisible] = useState(false);
const outer = useRef(null); const outer = useRef(null);
......
...@@ -16,7 +16,7 @@ export const ApolloDateRange = (props: any) => { ...@@ -16,7 +16,7 @@ export const ApolloDateRange = (props: any) => {
<RangePicker <RangePicker
className={styles.date} className={styles.date}
dropdownClassName={styles.dropdownClassName} dropdownClassName={styles.dropdownClassName}
popupStyle={{ width: '350px' }} // popupStyle={{ width: '350px' }}
{...selfProps} {...selfProps}
onChange={changeValue} onChange={changeValue}
/> />
......
...@@ -78,7 +78,7 @@ export interface TableState { ...@@ -78,7 +78,7 @@ export interface TableState {
dataSource: RowProps[]; dataSource: RowProps[];
tableHeight?: number; tableHeight?: number;
tableWidth?: number; tableWidth?: number;
selectedCell?:any; selectedCell?: any;
} }
export interface CommonProps extends TableProps { export interface CommonProps extends TableProps {
operateConfig?: OperateConfigProps; operateConfig?: OperateConfigProps;
...@@ -100,11 +100,12 @@ export interface BaseComponentState { ...@@ -100,11 +100,12 @@ export interface BaseComponentState {
columnConfig: ColumnProps; columnConfig: ColumnProps;
} }
export interface CellProps { export interface CellProps {
cellKey:string; cellKey: string;
rowIndex: number; rowIndex: number;
columnIndex: number; columnIndex: number;
columnConfig: ColumnProps; columnConfig: ColumnProps;
value: CellDataProps[]; value: CellDataProps[];
columnData: any;
record: RowProps; record: RowProps;
columns: ColumnProps[]; columns: ColumnProps[];
emitChangeCell?: Function; emitChangeCell?: Function;
...@@ -117,8 +118,9 @@ export interface CellProps { ...@@ -117,8 +118,9 @@ export interface CellProps {
cellEditable?: boolean; cellEditable?: boolean;
rowSelection?: any; rowSelection?: any;
contentMenu?: any; contentMenu?: any;
selectedCell?:any; selectedCell?: any;
changeSelectedCell?:Function; changeSelectedCell?: Function;
position:string;
} }
export interface EditCellProps { export interface EditCellProps {
......
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