publish 1.6.2

This commit is contained in:
“jonyshi” 2018-12-03 16:03:32 +08:00
parent f9f4dcfdf5
commit de51cfedc0
7 changed files with 2008 additions and 191 deletions

BIN
build.zip Normal file

Binary file not shown.

View File

@ -46,8 +46,6 @@ var propTypes = {
rows: _propTypes2["default"].array
};
var grap = 16; //偏移数值
var TableHeader = function (_Component) {
_inherits(TableHeader, _Component);
@ -156,7 +154,10 @@ var TableHeader = function (_Component) {
if (_this.drag.option === 'border') {
return;
}
var currentIndex = parseInt(_utils.Event.getTarget(event).getAttribute("data-line-index"));
// console.log('-------onDragStart----------',event.target);
var th = _this.getThDome(event.target);
if (!th) return;
var currentIndex = parseInt(th.getAttribute("data-line-index"));
var currentKey = event.target.getAttribute('data-line-key');
event.dataTransfer.effectAllowed = "move";
@ -176,6 +177,7 @@ var TableHeader = function (_Component) {
}
var data = _this.getCurrentEventData(e);
if (!data) return;
// console.log('-------onDrop----------',event.target);
if (!_this.currentObj || _this.currentObj.key == data.key) return;
if (!_this.props.onDrop) return;
_this.props.onDrop(event, { dragSource: _this.currentObj, dragTarg: data });
@ -299,25 +301,12 @@ var TableHeader = function (_Component) {
};
_this.currentObj = null;
//拖拽宽度处理
if (!props.dragborder) return _possibleConstructorReturn(_this);
_this.border = false;
_this.theadKey = new Date().getTime();
_this.drag = {
initPageLeftX: 0,
initLeft: 0,
x: 0,
width: 0,
option: ''
};
_this.minWidth = 80; //确定最小宽度就是80
_this.table = null;
var _row = [];
_this.props.rows[0] && _this.props.rows[0].forEach(function (item) {
var newItem = item.key != "checkbox" ? (0, _utils.ObjectAssign)(item) : item;
_row.push(newItem);
});
_this.drag.data = _row; //JSON.parse(JSON.stringify(this.props.rows[0]));
return _this;
}
@ -334,8 +323,15 @@ var TableHeader = function (_Component) {
for (var index = 0; index < ths.length; index++) {
var element = ths[index]; //.getAttribute('data-type');
if (!element.getAttribute('data-th-fixed')) {
var colLine = element.children.length > 1 ? element.lastElementChild : element.children[0];
// const colLine = element.children[0];
var colLine = null;
if (element.children.length === 0) {
colLine = element;
} else if (element.children.length > 0) {
colLine = element.lastElementChild;
} else if (element.children.length === 1) {
colLine = element.children[0];
}
// const colLine = element.children.length > 1?element.lastElementChild:element.children[0];
for (var i = 0; i < events.length; i++) {
var _event = events[i];
var _dataSource = eventSource ? element : colLine;
@ -483,7 +479,12 @@ var TableHeader = function (_Component) {
TableHeader.prototype.getCurrentEventData = function getCurrentEventData(e) {
var event = _utils.Event.getEvent(e);
var key = event.target.getAttribute('data-line-key');
var th = this.getThDome(event.target);
if (!th) {
console.log(" event target is not th ! ");
return null;
}
var key = th.getAttribute('data-line-key');
var data = this.props.rows[0].find(function (da) {
return da.key == key;
});
@ -494,7 +495,27 @@ var TableHeader = function (_Component) {
return null;
}
};
/**
*根据拖拽获取当前的Th属性
* @param {*} element
* @returns
* @memberof TableHeader
*/
TableHeader.prototype.getThDome = function getThDome(element) {
var _tagName = element.tagName.toLowerCase();
if (_tagName === 'i') return null;
if (_tagName != 'th') {
return this.getThDome(element.parentElement);
} else {
return element;
}
};
//---拖拽列交换----end-----
/**
* 过滤输入后或下拉条件的回调函数
*/

View File

@ -28,6 +28,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
var cloneDeep = require('lodash.clonedeep');
/**
* 参数: 列拖拽
* @param {*} Table
@ -71,26 +72,36 @@ function dragColumn(Table) {
columns[index] = dragSourceColum;
}
}
var titles = [];
columns.forEach(function (da) {
if (typeof da.title != "string") {
titles.push(da.title);
delete da.title;
}
});
var newColumns = null;
if (titles.length != 0) {
newColumns = JSON.parse(JSON.stringify(columns));
for (var _index = 0; _index < newColumns.length; _index++) {
newColumns[_index].title = titles[_index];
}
console.log("----columns----", newColumns);
} else {
newColumns = JSON.parse(JSON.stringify(columns));
}
// let titles = [];
// columns.forEach(da=>{
// for(let attr of 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:newColumns
// });
_this.setState({
columns: newColumns
columns: cloneDeep(columns)
});
if (_this.props.dragDrop) {
_this.props.dragDrop(event, data, newColumns);
}
};
_this.getTarget = function (evt) {

1874
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

@ -1,6 +1,6 @@
{
"name": "bee-table",
"version": "1.6.1",
"version": "1.6.2",
"description": "Table ui component for react",
"keywords": [
"react",

View File

@ -271,7 +271,10 @@ class TableHeader extends Component {
let event = Event.getEvent(e);
if (!this.props.draggable) return;
if(this.drag.option === 'border'){return;}
let currentIndex = parseInt(Event.getTarget(event).getAttribute("data-line-index"));
// console.log('-------onDragStart----------',event.target);
let th = this.getThDome(event.target);
if(!th)return;
let currentIndex = parseInt(th.getAttribute("data-line-index"));
let currentKey = event.target.getAttribute('data-line-key');
event.dataTransfer.effectAllowed = "move";
@ -304,6 +307,7 @@ class TableHeader extends Component {
if(this.drag.option === 'border'){return;}
let data = this.getCurrentEventData(e);
if(!data)return;
// console.log('-------onDrop----------',event.target);
if (!this.currentObj || this.currentObj.key == data.key) return;
if(!this.props.onDrop)return;
this.props.onDrop(event,{dragSource:this.currentObj,dragTarg:data});
@ -311,7 +315,12 @@ class TableHeader extends Component {
getCurrentEventData(e){
let event = Event.getEvent(e);
let key = event.target.getAttribute('data-line-key');
let th = this.getThDome(event.target)
if(!th){
console.log(" event target is not th ! ");
return null;
}
let key = th.getAttribute('data-line-key');
let data = this.props.rows[0].find(da=>da.key == key);
if(data){
return data;
@ -320,7 +329,25 @@ class TableHeader extends Component {
return null;
}
}
/**
*根据拖拽获取当前的Th属性
* @param {*} element
* @returns
* @memberof TableHeader
*/
getThDome(element){
let _tagName = element.tagName.toLowerCase();
if(_tagName === 'i')return null;
if(_tagName != 'th'){
return this.getThDome(element.parentElement);
}else{
return element;
}
}
//---拖拽列交换----end-----
/**
* 过滤输入后或下拉条件的回调函数
*/