feat: 增加 hideDragHandle 参数,隐藏行拖拽把手[#609]

This commit is contained in:
yangchch6 2020-07-14 16:43:10 +08:00
parent 3dd267d7a2
commit b5eab50b9a
8 changed files with 59 additions and 48 deletions

View File

@ -115,6 +115,7 @@ var propTypes = {
hoverContent: _propTypes2["default"].func, hoverContent: _propTypes2["default"].func,
size: _propTypes2["default"].oneOf(['sm', 'md', 'lg']), size: _propTypes2["default"].oneOf(['sm', 'md', 'lg']),
rowDraggAble: _propTypes2["default"].bool, rowDraggAble: _propTypes2["default"].bool,
hideDragHandle: _propTypes2["default"].bool, // 隐藏行拖拽把手
onDropRow: _propTypes2["default"].func, onDropRow: _propTypes2["default"].func,
onDragRowStart: _propTypes2["default"].func, onDragRowStart: _propTypes2["default"].func,
onBodyScroll: _propTypes2["default"].func, onBodyScroll: _propTypes2["default"].func,
@ -168,6 +169,7 @@ var defaultProps = {
heightConsistent: false, heightConsistent: false,
size: 'md', size: 'md',
rowDraggAble: false, rowDraggAble: false,
hideDragHandle: false,
onDropRow: function onDropRow() {}, onDropRow: function onDropRow() {},
onDragRowStart: function onDragRowStart() {}, onDragRowStart: function onDragRowStart() {},
onBodyScroll: function onBodyScroll() {}, onBodyScroll: function onBodyScroll() {},
@ -313,7 +315,8 @@ var Table = function (_Component) {
var expandedRowKeys = []; var expandedRowKeys = [];
var rows = [].concat(_toConsumableArray(props.data)); var rows = [].concat(_toConsumableArray(props.data));
_this.columnManager = new _ColumnManager2["default"](props.columns, props.children, props.originWidth, props.rowDraggAble, props.showRowNum); // 加入props.showRowNum参数 var showDragHandle = !props.hideDragHandle && props.rowDraggAble;
_this.columnManager = new _ColumnManager2["default"](props.columns, props.children, props.originWidth, showDragHandle, props.showRowNum); // 加入props.showRowNum参数
_this.store = (0, _createStore2["default"])({ currentHoverKey: null }); _this.store = (0, _createStore2["default"])({ currentHoverKey: null });
_this.firstDid = true; _this.firstDid = true;
if (props.defaultExpandAllRows) { if (props.defaultExpandAllRows) {
@ -397,6 +400,7 @@ var Table = function (_Component) {
Table.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { Table.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
var _props = this.props, var _props = this.props,
hideDragHandle = _props.hideDragHandle,
rowDraggAble = _props.rowDraggAble, rowDraggAble = _props.rowDraggAble,
showRowNum = _props.showRowNum; showRowNum = _props.showRowNum;
@ -411,12 +415,12 @@ var Table = function (_Component) {
}); });
} }
if (nextProps.columns && nextProps.columns !== this.props.columns) { if (nextProps.columns && nextProps.columns !== this.props.columns) {
this.columnManager.reset(nextProps.columns, null, showRowNum, rowDraggAble); // 加入this.props.showRowNum参数 this.columnManager.reset(nextProps.columns, null, showRowNum, !hideDragHandle && rowDraggAble); // 加入this.props.showRowNum参数
if (nextProps.columns.length !== this.props.columns.length && this.refs && this.bodyTable) { if (nextProps.columns.length !== this.props.columns.length && this.refs && this.bodyTable) {
this.scrollTop = this.bodyTable.scrollTop; this.scrollTop = this.bodyTable.scrollTop;
} }
} else if (nextProps.children !== this.props.children) { } else if (nextProps.children !== this.props.children) {
this.columnManager.reset(null, nextProps.children, showRowNum, rowDraggAble); // 加入this.props.showRowNum参数 this.columnManager.reset(null, nextProps.children, showRowNum, !hideDragHandle && rowDraggAble); // 加入this.props.showRowNum参数
} }
//适配lazyload //适配lazyload
if (nextProps.scrollTop > -1) { if (nextProps.scrollTop > -1) {

View File

@ -23,7 +23,7 @@ const data = [
{ a: "ASVAL_201903120002", b: "小红", c: "女", d: "财务一科", key: "3" } { a: "ASVAL_201903120002", b: "小红", c: "女", d: "财务一科", key: "3" }
]; ];
class Demo1 extends Component { class Demo11 extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
} }
@ -59,4 +59,4 @@ class Demo1 extends Component {
} }
} }
export default Demo1; export default Demo11;

View File

@ -10,7 +10,7 @@ import React, { Component } from 'react';
import Table from '../../src'; import Table from '../../src';
import dragColumn from '../../src/lib/dragColumn'; import dragColumn from '../../src/lib/dragColumn';
const columns23 = [ const columns = [
{ {
title: "订单编号", title: "订单编号",
dataIndex: "a", dataIndex: "a",
@ -38,7 +38,7 @@ const columns23 = [
} }
]; ];
const data23 = [ const data = [
{ a: "NU0391001", b: "2019-03-01", c: "xx供应商",d:'Tom', key: "2" }, { a: "NU0391001", b: "2019-03-01", c: "xx供应商",d:'Tom', key: "2" },
{ a: "NU0391002", b: "2018-11-02", c: "yy供应商",d:'Jack', key: "1" }, { a: "NU0391002", b: "2018-11-02", c: "yy供应商",d:'Jack', key: "1" },
{ a: "NU0391003", b: "2019-05-03", c: "zz供应商",d:'Jane', key: "3" } { a: "NU0391003", b: "2019-05-03", c: "zz供应商",d:'Jane', key: "3" }
@ -46,15 +46,15 @@ const data23 = [
const DragColumnTable = dragColumn(Table); const DragColumnTable = dragColumn(Table);
class Demo23 extends Component { class Demo30 extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
} }
render() { render() {
return <DragColumnTable return <DragColumnTable
columns={columns23} columns={columns}
data={data23} data={data}
bordered bordered
scroll={{y:200}} scroll={{y:200}}
dragborder={true} dragborder={true}
@ -65,4 +65,4 @@ class Demo23 extends Component {
} }
} }
export default Demo23; export default Demo30;

View File

@ -30,7 +30,7 @@ const data = [
{ a: "ASVAL_201903120007", b: "小杨", c: "女", d: "财务四科", e: "T2", key: "1009" } { a: "ASVAL_201903120007", b: "小杨", c: "女", d: "财务四科", e: "T2", key: "1009" }
]; ];
class Demo1201 extends Component { class Demo38 extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -77,4 +77,4 @@ class Demo1201 extends Component {
} }
} }
export default Demo1201; export default Demo38;

File diff suppressed because one or more lines are too long

62
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -59,6 +59,7 @@ const propTypes = {
hoverContent:PropTypes.func, hoverContent:PropTypes.func,
size: PropTypes.oneOf(['sm', 'md', 'lg']), size: PropTypes.oneOf(['sm', 'md', 'lg']),
rowDraggAble: PropTypes.bool, rowDraggAble: PropTypes.bool,
hideDragHandle: PropTypes.bool, // 隐藏行拖拽把手
onDropRow: PropTypes.func, onDropRow: PropTypes.func,
onDragRowStart: PropTypes.func, onDragRowStart: PropTypes.func,
onBodyScroll: PropTypes.func, onBodyScroll: PropTypes.func,
@ -103,6 +104,7 @@ const defaultProps = {
heightConsistent:false, heightConsistent:false,
size: 'md', size: 'md',
rowDraggAble:false, rowDraggAble:false,
hideDragHandle:false,
onDropRow: ()=>{}, onDropRow: ()=>{},
onDragRowStart: ()=>{}, onDragRowStart: ()=>{},
onBodyScroll: ()=>{}, onBodyScroll: ()=>{},
@ -119,7 +121,8 @@ class Table extends Component {
super(props); super(props);
let expandedRowKeys = []; let expandedRowKeys = [];
let rows = [...props.data]; let rows = [...props.data];
this.columnManager = new ColumnManager(props.columns, props.children, props.originWidth, props.rowDraggAble, props.showRowNum); // 加入props.showRowNum参数 const showDragHandle = !props.hideDragHandle && props.rowDraggAble;
this.columnManager = new ColumnManager(props.columns, props.children, props.originWidth, showDragHandle, props.showRowNum); // 加入props.showRowNum参数
this.store = createStore({ currentHoverKey: null }); this.store = createStore({ currentHoverKey: null });
this.firstDid = true; this.firstDid = true;
if (props.defaultExpandAllRows) { if (props.defaultExpandAllRows) {
@ -203,7 +206,7 @@ class Table extends Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
let { rowDraggAble, showRowNum } = this.props; let { hideDragHandle, rowDraggAble, showRowNum } = this.props;
if ('data' in nextProps) { if ('data' in nextProps) {
this.setState({ this.setState({
data: nextProps.data, data: nextProps.data,
@ -215,12 +218,12 @@ class Table extends Component {
}); });
} }
if (nextProps.columns && nextProps.columns !== this.props.columns) { if (nextProps.columns && nextProps.columns !== this.props.columns) {
this.columnManager.reset(nextProps.columns, null, showRowNum, rowDraggAble); // 加入this.props.showRowNum参数 this.columnManager.reset(nextProps.columns, null, showRowNum, !hideDragHandle && rowDraggAble); // 加入this.props.showRowNum参数
if(nextProps.columns.length !== this.props.columns.length && this.refs && this.bodyTable){ if(nextProps.columns.length !== this.props.columns.length && this.refs && this.bodyTable){
this.scrollTop = this.bodyTable.scrollTop; this.scrollTop = this.bodyTable.scrollTop;
} }
} else if (nextProps.children !== this.props.children) { } else if (nextProps.children !== this.props.children) {
this.columnManager.reset(null, nextProps.children, showRowNum, rowDraggAble); // 加入this.props.showRowNum参数 this.columnManager.reset(null, nextProps.children, showRowNum, !hideDragHandle && rowDraggAble); // 加入this.props.showRowNum参数
} }
//适配lazyload //适配lazyload
if(nextProps.scrollTop > -1){ if(nextProps.scrollTop > -1){