Commit ce24a1ce authored by zhangwenshuai's avatar zhangwenshuai

update

parent d6707733
import React from 'react';
import { ResizableBox } from 'react-resizable';
import styles from '@/submodule/components/apolloTable/component/Table.less';
const DragResized = (props: any) => {
const { style, columnName, onDragFixed, tableId, onResizeCb } = props;
// 表格
const container: any = document.querySelector(`#apolloTable_${tableId}`);
// 分割线wrap
const dividerWrap: any = document.querySelector('#dividerWrap');
// 分割线
const divider: any = document.querySelector('#divider');
// 列伸缩开始
const onResizeWidthStart = (e: any) => {
const { x } = container.getBoundingClientRect();
divider.style.left = `${e.x - x}px`;
dividerWrap.style.display = 'block';
};
// 列伸缩回调
const onResizeWidth = (e: any) => {
const { x } = container.getBoundingClientRect();
divider.style.left = `${e.x - x}px`;
};
// 列伸缩结束
const onResizeWidthStop = (e: any, { size }: { size: { width: number } }) => {
dividerWrap.style.display = 'none';
if (typeof onDragFixed === 'function') {
onDragFixed([{ columnName, width: size.width }]);
}
if (typeof onResizeCb === 'function') {
onResizeCb(columnName, size.width);
}
};
return (
<ResizableBox
style={style}
width={style.width}
height={style.height}
handle={
<span
className={styles.handleWidth}
onClick={(e) => {
e.stopPropagation();
}}
/>
}
minConstraints={[100, 100]}
onResizeStart={onResizeWidthStart}
onResize={onResizeWidth}
onResizeStop={onResizeWidthStop}
draggableOpts={{ enableUserSelectHack: false }}
>
{props.children}
</ResizableBox>
);
};
export default DragResized;
@import '../common'; @import '../common';
.draggableDiv{ .sortedWrap {
width: 100%;
height: 100%;
}
.draggableDiv {
cursor: move; cursor: move;
} }
\ No newline at end of file
import React, { useCallback, useRef } from 'react'; import React, { useCallback, useRef } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import s from './DragSorted.less';
const DragSorted = (props: any) => { const DragSorted = (props: any) => {
const { const { className, columnName, orderNo, onDropFinish, onScroll, canDrag, tableId } = props;
className, style, columnName, orderNo, onDropFinish, onScroll, canDrag,
} = props;
// 长按计时器 // 长按计时器
const timer: any = useRef(null); const timer: any = useRef(null);
// 表格滚动计时器 // 表格滚动计时器
const timerInterval: any = useRef(null); const timerInterval: any = useRef(null);
// 表格 // 表格
const container: any = document.querySelector('#tableContainer'); const container: any = document.querySelector(`#apolloTable_${tableId}`);
// 拖拽列时的影子div // 拖拽列时的影子div
const columnCopyDiv: any = document.querySelector('#columnCopyDiv'); const columnCopyDiv: any = document.querySelector('#columnCopyDiv');
// 分割线wrap // 分割线wrap
...@@ -27,7 +26,8 @@ const DragSorted = (props: any) => { ...@@ -27,7 +26,8 @@ const DragSorted = (props: any) => {
// 所有列 // 所有列
const draggableColumns = document.querySelectorAll('.draggableColumn'); const draggableColumns = document.querySelectorAll('.draggableColumn');
const leftFixedHandleWrapRectX = (leftFixedHandleWrap && leftFixedHandleWrap.getBoundingClientRect().x) || 0; const leftFixedHandleWrapRectX = (leftFixedHandleWrap && leftFixedHandleWrap.getBoundingClientRect().x) || 0;
const rightFixedHandleWrapRectX = (rightFixedHandleWrap && rightFixedHandleWrap.getBoundingClientRect().x) || tableRect.right; const rightFixedHandleWrapRectX =
(rightFixedHandleWrap && rightFixedHandleWrap.getBoundingClientRect().x) || tableRect.right;
const columnCopyDivRect = columnCopyDiv.getBoundingClientRect(); const columnCopyDivRect = columnCopyDiv.getBoundingClientRect();
const columnCopyDivWidth = columnCopyDivRect.width; const columnCopyDivWidth = columnCopyDivRect.width;
...@@ -44,10 +44,10 @@ const DragSorted = (props: any) => { ...@@ -44,10 +44,10 @@ const DragSorted = (props: any) => {
const domRect = dom.getBoundingClientRect(); const domRect = dom.getBoundingClientRect();
// 当前节点在左侧固定列与右侧固定列之间有效 // 当前节点在左侧固定列与右侧固定列之间有效
if ( if (
domRect.x > leftFixedHandleWrapRectX domRect.x > leftFixedHandleWrapRectX &&
&& domRect.x < rightFixedHandleWrapRectX domRect.x < rightFixedHandleWrapRectX &&
&& columnCopyDivMid > domRect.x columnCopyDivMid > domRect.x &&
&& columnCopyDivMid < domRect.x + domRect.width columnCopyDivMid < domRect.x + domRect.width
) { ) {
// 影子div中点在投放目标中 // 影子div中点在投放目标中
divider.style.left = `${domRect.x - tableRect.x}px`; divider.style.left = `${domRect.x - tableRect.x}px`;
...@@ -185,8 +185,7 @@ const DragSorted = (props: any) => { ...@@ -185,8 +185,7 @@ const DragSorted = (props: any) => {
return ( return (
<div <div
className={classNames('draggableColumn', className)} className={classNames('draggableColumn', s.sortedWrap, className)}
style={style}
onMouseDown={onMouseDown} onMouseDown={onMouseDown}
onMouseUp={onMouseUp} onMouseUp={onMouseUp}
data-column-name={columnName} data-column-name={columnName}
......
...@@ -3,7 +3,6 @@ import classNames from 'classnames'; ...@@ -3,7 +3,6 @@ import classNames from 'classnames';
import memoizeOne from 'memoize-one'; import memoizeOne from 'memoize-one';
import { Empty, Spin } from 'antd'; import { Empty, Spin } from 'antd';
import { ScrollSync, Grid, AutoSizer } from 'react-virtualized'; import { ScrollSync, Grid, AutoSizer } from 'react-virtualized';
import { Resizable, ResizableBox } from 'react-resizable';
import _ from 'lodash'; import _ from 'lodash';
import scrollbarSize from 'dom-helpers/scrollbarSize'; import scrollbarSize from 'dom-helpers/scrollbarSize';
import styles from './Table.less'; import styles from './Table.less';
...@@ -13,6 +12,7 @@ import Cell from './Cell'; ...@@ -13,6 +12,7 @@ import Cell from './Cell';
import LeftDragFixed from './DragFixed'; import LeftDragFixed from './DragFixed';
import RightDragFixed from './RightDragFixed'; import RightDragFixed from './RightDragFixed';
import DragSorted from './DragSorted'; import DragSorted from './DragSorted';
import DragResized from './DragResized';
import { getMergeClassName, getMergeStyle } from '../utils/utils'; import { getMergeClassName, getMergeStyle } from '../utils/utils';
import { Consumer } from './context'; import { Consumer } from './context';
...@@ -32,9 +32,6 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -32,9 +32,6 @@ export default class AirTable extends Component<TableProps, TableState> {
grid5: any; grid5: any;
grid6: any; grid6: any;
tableContainer: any;
widthHandleWrapper: any;
widthHandle: any;
memoizeData: Function; memoizeData: Function;
...@@ -105,7 +102,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -105,7 +102,7 @@ export default class AirTable extends Component<TableProps, TableState> {
// 获取表格显示列 // 获取表格显示列
getShowColumns = (columns: ColumnProps[]) => { getShowColumns = (columns: ColumnProps[]) => {
return columns.filter((item) => { return columns.filter((item) => {
return !!item.showStatus && (!item.hideScope || item.hideScope.indexOf('LIST') === -1); return !item.hideScope || item.hideScope.indexOf('LIST') === -1;
}); });
}; };
...@@ -213,34 +210,16 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -213,34 +210,16 @@ export default class AirTable extends Component<TableProps, TableState> {
} }
}; };
// 列伸缩回调
onResizeWidth = (e) => {
const originLeft = (this.tableContainer && this.tableContainer.getBoundingClientRect().x) || 0;
if (this.widthHandle) {
this.widthHandle.style.left = `${e.x - originLeft}px`;
}
};
// 列伸缩开始
onResizeWidthStart = (e) => {
const originLeft = (this.tableContainer && this.tableContainer.getBoundingClientRect().x) || 0;
if (this.widthHandleWrapper && this.widthHandle) {
this.widthHandle.style.left = `${e.x - originLeft}px`;
this.widthHandleWrapper.style.display = 'block';
}
};
// 列伸缩结束 // 列伸缩结束
onResizeWidthStop = (columnName: string, e, { size }) => { onResizeCb = (columnName: string, width: number) => {
const { columns } = this.state; const { columns } = this.state;
const newColumns: any = []; const newColumns: any = [];
columns.map((item) => { columns.map((item) => {
if (item.columnName === columnName) { if (item.columnName === columnName) {
item.width = size.width; item.width = width;
} }
newColumns.push(item); newColumns.push(item);
}); });
if (this.widthHandleWrapper) {
this.widthHandleWrapper.style.display = 'none';
}
this.setState( this.setState(
{ {
columns: newColumns, columns: newColumns,
...@@ -353,7 +332,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -353,7 +332,7 @@ export default class AirTable extends Component<TableProps, TableState> {
{ columnIndex, key, style }: any, { columnIndex, key, style }: any,
) => { ) => {
if (showColumns.length === 0) return null; if (showColumns.length === 0) return null;
const { sortConfig, showIndex, rowSelection, dataSource, onDragSorted } = this.props; const { sortConfig, showIndex, rowSelection, dataSource, onDragSorted, tableId, onDragFixed } = this.props;
const { const {
columnType = 1, columnType = 1,
columnName, columnName,
...@@ -366,32 +345,22 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -366,32 +345,22 @@ export default class AirTable extends Component<TableProps, TableState> {
orderNo, orderNo,
} = showColumns[columnIndex]; } = showColumns[columnIndex];
return ( return (
<DragSorted <DragResized
columnName={columnName} columnName={columnName}
orderNo={orderNo}
onDropFinish={this.onDragSorted}
onScroll={this.onScrollHor}
className={styles.headerCell}
key={key}
style={style} style={style}
canDrag={!!onDragSorted} onDragFixed={onDragFixed}
tableId={tableId}
onResizeCb={this.onResizeCb}
> >
<ResizableBox <DragSorted
width={style.width} columnName={columnName}
height={style.height} orderNo={orderNo}
handle={ onDropFinish={this.onDragSorted}
<span onScroll={this.onScrollHor}
className={styles.handleWidth} className={styles.headerCell}
onClick={(e) => { key={key}
e.stopPropagation(); canDrag={!!onDragSorted}
}} tableId={tableId}
/>
}
minConstraints={[100, 100]}
onResize={this.onResizeWidth}
onResizeStart={this.onResizeWidthStart}
onResizeStop={this.onResizeWidthStop.bind(this, columnName)}
draggableOpts={{ enableUserSelectHack: false }}
> >
<Column <Column
columnType={String(columnType)} columnType={String(columnType)}
...@@ -408,8 +377,8 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -408,8 +377,8 @@ export default class AirTable extends Component<TableProps, TableState> {
icon={icon} icon={icon}
required={requiredFlag} required={requiredFlag}
/> />
</ResizableBox> </DragSorted>
</DragSorted> </DragResized>
); );
}; };
...@@ -560,9 +529,6 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -560,9 +529,6 @@ export default class AirTable extends Component<TableProps, TableState> {
paddingRight: this.props.onScroll ? paddingRight : 0, paddingRight: this.props.onScroll ? paddingRight : 0,
}} }}
id={`apolloTable_${tableId}`} id={`apolloTable_${tableId}`}
ref={(dom) => {
this.tableContainer = dom;
}}
> >
{totalWidth > tableWidth && leftCount > 0 && ( {totalWidth > tableWidth && leftCount > 0 && (
<div <div
...@@ -842,16 +808,10 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -842,16 +808,10 @@ export default class AirTable extends Component<TableProps, TableState> {
<div <div
className={styles.widthHandleWrapper} className={styles.widthHandleWrapper}
id="dividerWrap" id="dividerWrap"
ref={(dom) => {
this.widthHandleWrapper = dom;
}}
> >
<div <div
className={styles.widthHandle} className={styles.widthHandle}
id="divider" id="divider"
ref={(dom) => {
this.widthHandle = dom;
}}
/> />
</div> </div>
<div id="columnCopyDiv" className={styles.columnCopyDiv} draggable={true} /> <div id="columnCopyDiv" className={styles.columnCopyDiv} draggable={true} />
......
...@@ -88,6 +88,7 @@ class AirTable extends React.Component<CommonProps, CommonState> { ...@@ -88,6 +88,7 @@ class AirTable extends React.Component<CommonProps, CommonState> {
onDragSorted, onDragSorted,
onEmitMsg, onEmitMsg,
tableId, tableId,
onDragFixed,
} = this.props; } = this.props;
const sortConfig = operateConfig const sortConfig = operateConfig
&& operateConfig.menusGroup && operateConfig.menusGroup
...@@ -149,6 +150,7 @@ class AirTable extends React.Component<CommonProps, CommonState> { ...@@ -149,6 +150,7 @@ class AirTable extends React.Component<CommonProps, CommonState> {
onDragSorted={onDragSorted} onDragSorted={onDragSorted}
onEmitMsg={onEmitMsg} onEmitMsg={onEmitMsg}
tableId={tableId} tableId={tableId}
onDragFixed={onDragFixed}
/> />
</div> </div>
</div> </div>
......
...@@ -77,6 +77,7 @@ export interface TableProps extends LoadConfigProps { ...@@ -77,6 +77,7 @@ export interface TableProps extends LoadConfigProps {
canSorted?: boolean;// 是否可以拖拽自定义列排序 canSorted?: boolean;// 是否可以拖拽自定义列排序
canResized?: boolean;// 是否可以拖拽自定义列伸缩 canResized?: boolean;// 是否可以拖拽自定义列伸缩
onDragSorted?:Function;// 拖拽更改列排序回调 onDragSorted?:Function;// 拖拽更改列排序回调
onDragFixed?:Function;// 拖拽更改列排序回调
onEmitMsg?: Function; onEmitMsg?: Function;
tableId?:string|number;// tableId tableId?:string|number;// tableId
} }
...@@ -96,7 +97,6 @@ export interface CommonProps extends TableProps { ...@@ -96,7 +97,6 @@ export interface CommonProps extends TableProps {
showCondition?: boolean; showCondition?: boolean;
id?:string; id?:string;
onEmitMsg?:Function; onEmitMsg?:Function;
tableId?:string|number;
} }
export interface CommonState extends TableState {} export interface CommonState extends TableState {}
......
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