diff --git a/src/TableHeader.js b/src/TableHeader.js index 7a5f83e..5aa8953 100644 --- a/src/TableHeader.js +++ b/src/TableHeader.js @@ -227,11 +227,14 @@ class TableHeader extends Component { }; clearDragBorder(){ - if (!this.props.dragborder) return; - + // if (!this.props.dragborder || !this.props.draggable) return; + if(!this.drag)return; this.drag = { option:"" }; + if (!this.props.draggable){ + this.removeDragAbleEvent(); + } } //---拖拽列宽代码逻辑----start----- @@ -254,7 +257,7 @@ class TableHeader extends Component { {key:'dragstart',fun:this.onDragStart},//用户开始拖动元素时触发 {key:'dragover', fun:this.onDragOver},//当某被拖动的对象在另一对象容器范围内拖动时触发此事件 {key:'drop', fun:this.onDrop}, //在一个拖动过程中,释放鼠标键时触发此事件 - {key:'dragenter', fun:this.onDragEnter} //当被鼠标拖动的对象进入其容器范围内时触发此事件 + // {key:'dragenter', fun:this.onDragEnter} //当被鼠标拖动的对象进入其容器范围内时触发此事件 ]; this.thEventListen(events,'',true); // this.bodyEventListen([{key:'mouseup',fun:this.bodyonDragMouseMove}]); @@ -291,12 +294,12 @@ class TableHeader extends Component { * 当被鼠标拖动的对象进入其容器范围内时触发此事件。【目标事件】 * @memberof TableHeader */ - onDragEnter = (e) => { - if (!this.props.draggable) return; - if(this.drag.option === 'border'){return;} - let data = this.getCurrentEventData(e); - if (!this.currentObj || this.currentObj.key == data.key) return; - }; + // onDragEnter = (e) => { + // if (!this.props.draggable) return; + // if(this.drag.option === 'border'){return;} + // let data = this.getCurrentEventData(e); + // if (!this.currentObj || this.currentObj.key == data.key) return; + // }; /** * 在一个拖动过程中,释放鼠标键时触发此事件。【目标事件】 diff --git a/src/lib/dragColumn.js b/src/lib/dragColumn.js index c25bfe9..d987722 100644 --- a/src/lib/dragColumn.js +++ b/src/lib/dragColumn.js @@ -31,24 +31,59 @@ export default function dragColumn(Table) { }); return _column; } - + + cloneDeep(obj){ + if( typeof obj !== 'object' || Object.keys(obj).length === 0 ){ + return obj + } + let resultData = {} + return this.recursion(obj, resultData) + } + + recursion(obj, data={}){ + for(key in obj){ + if( typeof obj[key] == 'object' && Object.keys(obj[key].length>0 )){ + data[key] = recursion(obj[key]) + }else{ + data[key] = obj[key] + } + } + return data + } + onDrop=(event,data)=>{ let {dragSource,dragTarg} = data; - let {columns} = this.state; + let {columns} = this.state; let dragSourceColum = columns.find((da,i)=>da.key == dragSource.key); let dragTargColum = columns.find((da,i)=>da.key == dragTarg.key); - for (let index = 0; index < columns.length; index++) { const da = columns[index]; if(da.key === dragSource.key){ - columns[index] = dragTargColum; + columns[index] = dragTargColum; } if(da.key === dragTarg.key){ columns[index] = dragSourceColum; } } + let titles = []; + columns.forEach(da=>{ + if(typeof da.title != "string"){ + titles.push(da.title); + delete da.title; + } + }); + let newColumns = null; + if(titles.length != 0){ + newColumns = JSON.parse(JSON.stringify(columns)); + for (let index = 0; index < newColumns.length; index++) { + newColumns[index].title = titles[index]; + } + console.log("----columns----",newColumns); + }else{ + newColumns = JSON.parse(JSON.stringify(columns)); + } this.setState({ - columns:JSON.parse(JSON.stringify(columns)) + columns:newColumns }); }