From 2cb3fe5fe40a73fde58157a07ad7ea6273f6ac87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cjonyshi=E2=80=9D?= Date: Sun, 2 Dec 2018 17:19:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A4=E6=8D=A2=E5=88=97=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TableHeader.js | 14 +++++++------- src/lib/dragColumn.js | 45 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/TableHeader.js b/src/TableHeader.js index 94c15b3..2e75f98 100644 --- a/src/TableHeader.js +++ b/src/TableHeader.js @@ -253,7 +253,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}]); @@ -290,12 +290,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 }); }