2018-11-07 17:11:25 +08:00
|
|
|
|
import React, { Component } from "react";
|
2018-12-01 17:51:01 +08:00
|
|
|
|
import ReactDOM from 'react-dom';
|
2018-11-07 17:11:25 +08:00
|
|
|
|
import PropTypes from "prop-types";
|
2018-12-11 17:21:02 +08:00
|
|
|
|
import { debounce } from "throttle-debounce";
|
2019-07-26 09:47:18 +08:00
|
|
|
|
import { Event,EventUtil} from "./lib/utils";
|
2018-11-07 17:11:25 +08:00
|
|
|
|
import FilterType from "./FilterType";
|
2016-12-26 16:52:39 +08:00
|
|
|
|
|
2017-01-11 17:01:50 +08:00
|
|
|
|
const propTypes = {
|
2018-09-20 16:24:06 +08:00
|
|
|
|
clsPrefix: PropTypes.string,
|
|
|
|
|
rowStyle: PropTypes.object,
|
2018-11-07 17:11:25 +08:00
|
|
|
|
rows: PropTypes.array
|
|
|
|
|
};
|
2017-01-11 17:01:50 +08:00
|
|
|
|
|
2019-04-22 10:24:21 +08:00
|
|
|
|
|
|
|
|
|
function getDiv(id){
|
|
|
|
|
let div = document.createElement("div");
|
2019-04-23 18:25:34 +08:00
|
|
|
|
div.className = "u-table-drag-hidden-cont";
|
2019-04-22 10:24:21 +08:00
|
|
|
|
div.id = id;
|
|
|
|
|
return div;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-20 16:24:06 +08:00
|
|
|
|
class TableHeader extends Component {
|
|
|
|
|
constructor(props) {
|
2018-05-07 10:58:24 +08:00
|
|
|
|
super(props);
|
2019-08-09 10:59:06 +08:00
|
|
|
|
this.currentObj = null;
|
2018-05-13 16:28:08 +08:00
|
|
|
|
this.theadKey = new Date().getTime();
|
2018-05-11 09:29:43 +08:00
|
|
|
|
this.drag = {
|
2018-12-01 17:51:01 +08:00
|
|
|
|
option:''
|
2018-11-07 17:11:25 +08:00
|
|
|
|
};
|
2020-02-12 15:02:13 +08:00
|
|
|
|
this.minWidth = parseInt(props.minColumnWidth);
|
2018-11-30 16:14:29 +08:00
|
|
|
|
this.table = null;
|
2018-12-11 17:21:02 +08:00
|
|
|
|
this._thead = null;//当前对象
|
2019-04-25 13:53:39 +08:00
|
|
|
|
this.event = false;//避免多次绑定问题
|
2019-06-26 16:18:39 +08:00
|
|
|
|
this.lastColumWidth = null;//非固定列最后一列的初始化宽度
|
2019-07-18 11:25:29 +08:00
|
|
|
|
this.fixedTable = {};
|
2018-09-12 14:14:05 +08:00
|
|
|
|
}
|
2018-12-03 14:37:15 +08:00
|
|
|
|
|
2018-09-12 14:14:05 +08:00
|
|
|
|
static defaultProps = {
|
2018-09-20 16:24:06 +08:00
|
|
|
|
contentWidthDiff: 0
|
2018-11-07 17:11:25 +08:00
|
|
|
|
};
|
2018-12-11 17:21:02 +08:00
|
|
|
|
|
2020-03-13 14:59:32 +08:00
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
|
// 表格column改变时,要重新绑定拖拽事件,否则拖拽不生效
|
|
|
|
|
const { columnsChildrenList:oldCols } = this.props;
|
|
|
|
|
const { columnsChildrenList:newCols } = nextProps;
|
|
|
|
|
if (this._thead) {
|
|
|
|
|
if(newCols.length !== oldCols.length){
|
|
|
|
|
this.event = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
oldCols.some((item, index) => {
|
|
|
|
|
if (newCols[index] && newCols[index].dataIndex !== item.dataIndex) {
|
|
|
|
|
this.event = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-30 16:14:29 +08:00
|
|
|
|
componentDidUpdate(){
|
2019-04-19 10:58:38 +08:00
|
|
|
|
this.initTable();
|
2018-11-30 16:14:29 +08:00
|
|
|
|
this.initEvent();
|
2019-04-22 10:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
|
let uid = "_table_uid_"+new Date().getTime();
|
|
|
|
|
this._table_none_cont_id = uid;
|
|
|
|
|
let div = getDiv(uid);
|
|
|
|
|
document.querySelector("body").appendChild(div);
|
2018-11-30 16:14:29 +08:00
|
|
|
|
}
|
2018-05-11 09:29:43 +08:00
|
|
|
|
|
2019-04-22 16:02:32 +08:00
|
|
|
|
componentWillUnmount(){
|
2019-07-18 11:25:29 +08:00
|
|
|
|
this.fixedTable = null;
|
2019-04-22 16:02:32 +08:00
|
|
|
|
if(!this.table)return;
|
|
|
|
|
if (this.props.draggable){
|
|
|
|
|
this.removeDragAbleEvent();
|
|
|
|
|
}
|
|
|
|
|
if(this.props.dragborder){
|
|
|
|
|
this.removeDragBorderEvent();
|
|
|
|
|
}
|
2019-11-12 16:18:09 +08:00
|
|
|
|
this.doEventList(this.table.tr,(tr)=>{
|
|
|
|
|
this.eventListen([{key:'mousedown',fun:this.onTrMouseDown}],'remove',tr);
|
|
|
|
|
})
|
|
|
|
|
// this.eventListen([{key:'mousedown',fun:this.onTrMouseDown}],'remove',this.table.tr[0]);
|
2019-07-18 11:25:29 +08:00
|
|
|
|
this.eventListen([{key:'mouseup',fun:this.bodyonLineMouseUp}],'remove',document.body);
|
2019-04-22 16:02:32 +08:00
|
|
|
|
}
|
2019-03-20 12:36:12 +08:00
|
|
|
|
|
2018-11-30 16:14:29 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取table的属性存放在this.table 中。(公用方法)
|
2018-12-11 17:21:02 +08:00
|
|
|
|
* @returns
|
|
|
|
|
* @memberof TableHeader
|
2018-11-30 16:14:29 +08:00
|
|
|
|
*/
|
|
|
|
|
initTable(){
|
2019-03-18 10:59:11 +08:00
|
|
|
|
const {contentTable} = this.props;
|
2018-12-01 17:51:01 +08:00
|
|
|
|
if(!this.props.dragborder && !this.props.draggable)return;
|
2018-12-11 17:21:02 +08:00
|
|
|
|
let tableDome = this._thead.parentNode;
|
2018-11-30 16:14:29 +08:00
|
|
|
|
let table = {};
|
|
|
|
|
if(tableDome && tableDome.nodeName && tableDome.nodeName.toUpperCase() == "TABLE"){
|
|
|
|
|
table.table = tableDome;
|
|
|
|
|
table.cols = tableDome.getElementsByTagName("col");
|
|
|
|
|
table.ths = tableDome.getElementsByTagName("th");
|
2019-04-19 10:58:38 +08:00
|
|
|
|
table.tr = tableDome.getElementsByTagName("tr");
|
2020-12-28 10:16:11 +08:00
|
|
|
|
table.tableHeaderCols = contentTable.querySelector('.u-table-scroll .u-table-header') && contentTable.querySelector('.u-table-scroll .u-table-header').getElementsByTagName("col");
|
2019-08-17 10:00:40 +08:00
|
|
|
|
table.tableBody = contentTable.querySelector('.u-table-scroll .u-table-body') && contentTable.querySelector('.u-table-scroll .u-table-body');
|
2019-07-03 21:12:17 +08:00
|
|
|
|
table.tableBodyCols = contentTable.querySelector('.u-table-scroll .u-table-body') && contentTable.querySelector('.u-table-scroll .u-table-body').getElementsByTagName("col");
|
2020-08-29 13:56:10 +08:00
|
|
|
|
table.bodyRows = table.tableBody && table.tableBody.querySelectorAll('tr') || [];
|
2020-09-07 13:48:01 +08:00
|
|
|
|
|
|
|
|
|
table.fixedLeftHeaderTable = contentTable.querySelector('.u-table-fixed-left .u-table-header') ;
|
|
|
|
|
table.fixedRighHeadertTable = contentTable.querySelector('.u-table-fixed-right .u-table-header');
|
|
|
|
|
table.contentTableHeader = contentTable.querySelector('.u-table-scroll .u-table-header');
|
|
|
|
|
table.fixedLeftBodyTable = contentTable.querySelectorAll('.u-table-fixed-left .u-table-body-outer') ;
|
|
|
|
|
if (table.fixedLeftBodyTable) {
|
|
|
|
|
const leftBodyTableIndex = table.fixedLeftBodyTable.length-1 < 0 ? 0 : table.fixedLeftBodyTable.length-1
|
|
|
|
|
table.fixedLeftBodyTable = table.fixedLeftBodyTable[leftBodyTableIndex]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
table.fixedRightBodyTable = contentTable.querySelectorAll('.u-table-fixed-right .u-table-body-outer') ;
|
|
|
|
|
if (table.fixedRightBodyTable) {
|
|
|
|
|
const rightBodyTableIndex = table.fixedRightBodyTable.length-1 < 0 ? 0 : table.fixedRightBodyTable.length-1
|
|
|
|
|
table.fixedRightBodyTable = table.fixedRightBodyTable[rightBodyTableIndex]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
table.innerTableBody= contentTable.querySelector('.u-table-scroll .u-table-body table');
|
|
|
|
|
table.fixedLeftBodyRows = table.fixedLeftBodyTable && table.fixedLeftBodyTable.querySelectorAll('tr') || [];
|
|
|
|
|
table.fixedRightBodyRows = table.fixedRightBodyTable && table.fixedRightBodyTable.querySelectorAll('tr') || [];
|
2018-11-13 18:50:50 +08:00
|
|
|
|
}
|
2019-03-18 10:59:11 +08:00
|
|
|
|
|
2020-09-07 13:48:01 +08:00
|
|
|
|
|
2018-11-30 16:14:29 +08:00
|
|
|
|
this.table = table;
|
2018-12-01 17:51:01 +08:00
|
|
|
|
|
|
|
|
|
if(!this.props.dragborder)return;
|
|
|
|
|
if(document.getElementById("u-table-drag-thead-" + this.theadKey)){
|
|
|
|
|
this.fixedTable = {};
|
|
|
|
|
let _fixedParentContext = document.getElementById("u-table-drag-thead-" + this.theadKey).parentNode;
|
|
|
|
|
let siblingDom = _fixedParentContext.parentNode.nextElementSibling;
|
|
|
|
|
if (siblingDom) {
|
2019-08-09 10:59:06 +08:00
|
|
|
|
let fixedTable = siblingDom.querySelector("table");
|
2018-12-01 17:51:01 +08:00
|
|
|
|
this.fixedTable.table = fixedTable
|
|
|
|
|
this.fixedTable.cols = fixedTable.getElementsByTagName("col");
|
|
|
|
|
// this.fixedTable.ths = fixedTable.tableDome.getElementsByTagName("th");
|
|
|
|
|
}
|
2018-11-26 20:34:43 +08:00
|
|
|
|
}
|
2018-11-30 16:14:29 +08:00
|
|
|
|
}
|
2019-04-19 10:58:38 +08:00
|
|
|
|
|
2019-04-22 10:24:21 +08:00
|
|
|
|
/**
|
|
|
|
|
* 事件初始化
|
|
|
|
|
*/
|
2019-04-19 10:58:38 +08:00
|
|
|
|
initEvent(){
|
2019-07-22 13:53:10 +08:00
|
|
|
|
let {dragborder,draggable,rows} = this.props;
|
|
|
|
|
// 当传入的 columns 为空时,不绑定拖拽事件
|
|
|
|
|
if(Object.prototype.toString.call(rows) === '[object Array]' && rows.length === 0){
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-25 13:53:39 +08:00
|
|
|
|
if(!this.event){ //避免多次绑定问题。
|
|
|
|
|
this.event = true;
|
|
|
|
|
if(dragborder){
|
|
|
|
|
this.dragBorderEventInit();//列宽
|
|
|
|
|
}
|
2019-07-15 10:59:26 +08:00
|
|
|
|
if(draggable){
|
2019-04-25 13:53:39 +08:00
|
|
|
|
this.dragAbleEventInit();//交换列
|
|
|
|
|
}
|
|
|
|
|
if(this.table && this.table.tr){
|
2019-11-12 16:18:09 +08:00
|
|
|
|
// this.eventListen([{key:'mousedown',fun:this.onTrMouseDown}],'',this.table.tr[0]);//body mouseup
|
|
|
|
|
this.doEventList(this.table.tr,(tr)=>{
|
|
|
|
|
this.eventListen([{key:'mousedown',fun:this.onTrMouseDown}],'',tr);//body mouseup
|
|
|
|
|
})
|
2019-04-25 13:53:39 +08:00
|
|
|
|
}
|
|
|
|
|
this.eventListen([{key:'mouseup',fun:this.bodyonLineMouseUp}],'',document.body);//body mouseup
|
2019-04-23 17:02:07 +08:00
|
|
|
|
}
|
2019-04-22 10:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-12 16:18:09 +08:00
|
|
|
|
|
|
|
|
|
doEventList(trs,action){
|
2021-03-21 17:50:59 +08:00
|
|
|
|
if (trs && HTMLCollection.prototype.isPrototypeOf(trs) && action) {
|
2021-03-18 16:37:51 +08:00
|
|
|
|
for (let index = 0; index < trs.length; index++) {
|
|
|
|
|
action(trs[index]);
|
|
|
|
|
}
|
2019-11-12 16:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 10:24:21 +08:00
|
|
|
|
/**
|
|
|
|
|
* 拖拽列宽事件的监听
|
|
|
|
|
*/
|
|
|
|
|
dragBorderEventInit (){
|
2019-04-22 19:09:29 +08:00
|
|
|
|
if(!this.props.dragborder )return;
|
2020-12-28 10:16:11 +08:00
|
|
|
|
this.eventListen([{key:'mouseup', fun:this.onTrMouseUp}],'',document.body);
|
|
|
|
|
this.eventListen([{key:'mousemove', fun:this.onTrMouseMove}],'',document.body);
|
|
|
|
|
|
|
|
|
|
// let events = [
|
|
|
|
|
// {key:'mouseup', fun:this.onTrMouseUp},
|
|
|
|
|
// {key:'mousemove', fun:this.onTrMouseMove},
|
|
|
|
|
// // {key:'mousemove', fun:debounce(50,this.onTrMouseMove)},//函数节流后体验很差
|
|
|
|
|
// ];
|
|
|
|
|
// this.doEventList(this.table.tr,(tr)=>{
|
|
|
|
|
// this.eventListen(events,'',tr);//表示把事件添加到th元素上
|
|
|
|
|
// })
|
2019-11-12 16:18:09 +08:00
|
|
|
|
// this.eventListen(events,'',this.table.tr[0]);//表示把事件添加到th元素上
|
2019-04-19 10:58:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 16:02:32 +08:00
|
|
|
|
/**
|
|
|
|
|
* 删除拖动改变列宽的事件监听
|
|
|
|
|
*/
|
|
|
|
|
removeDragBorderEvent(){
|
|
|
|
|
let events = [
|
|
|
|
|
{key:'mouseup', fun:this.onTrMouseUp},
|
|
|
|
|
{key:'mousemove', fun:this.onTrMouseMove},
|
|
|
|
|
];
|
2019-11-12 16:18:09 +08:00
|
|
|
|
// this.eventListen(events,'remove',this.table.tr[0]);
|
|
|
|
|
this.doEventList(this.table.tr,(tr)=>{
|
|
|
|
|
this.eventListen(events,'remove',this.table.tr);
|
|
|
|
|
})
|
2019-04-22 16:02:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-19 10:58:38 +08:00
|
|
|
|
eventListen(events,type,eventSource){
|
2019-04-22 19:09:29 +08:00
|
|
|
|
if(!this.table)return;
|
2019-07-02 17:09:36 +08:00
|
|
|
|
if(!eventSource){
|
|
|
|
|
console.log("Please set the attributes of column !");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-19 10:58:38 +08:00
|
|
|
|
let {tr} = this.table;
|
|
|
|
|
for (let i = 0; i < events.length; i++) {
|
|
|
|
|
const _event = events[i];
|
|
|
|
|
if(type === "remove"){
|
|
|
|
|
EventUtil.removeHandler(eventSource,_event.key,_event.fun);
|
|
|
|
|
}else{
|
|
|
|
|
EventUtil.addHandler(eventSource,_event.key,_event.fun);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-26 16:57:00 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
2019-04-19 10:58:38 +08:00
|
|
|
|
*根据 data-type 来获取当前拖拽的对象的Object,如果为null表示拖动的对象并非是online
|
2019-02-26 16:57:00 +08:00
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
2019-04-19 10:58:38 +08:00
|
|
|
|
getOnLineObject = (_element) =>{
|
|
|
|
|
let type = _element.getAttribute('data-type'),elementObj = null;
|
|
|
|
|
if(!type){
|
|
|
|
|
let element = _element.parentElement||parentNode;//兼容写法。
|
|
|
|
|
if(element.getAttribute('data-type')){
|
|
|
|
|
elementObj = element;
|
2019-02-26 16:57:00 +08:00
|
|
|
|
}
|
2019-04-19 10:58:38 +08:00
|
|
|
|
}else{
|
|
|
|
|
elementObj = _element;
|
2019-02-26 16:57:00 +08:00
|
|
|
|
}
|
2019-04-19 10:58:38 +08:00
|
|
|
|
return elementObj;
|
2019-02-26 16:57:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-19 10:58:38 +08:00
|
|
|
|
/**
|
|
|
|
|
* 调整列宽的down事件
|
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
|
|
|
|
onTrMouseDown = (e) => {
|
2020-09-21 11:05:41 +08:00
|
|
|
|
const { eventNoStop } = this.props;
|
|
|
|
|
!eventNoStop && Event.stopPropagation(e);
|
2019-04-19 10:58:38 +08:00
|
|
|
|
let event = Event.getEvent(e) ,
|
|
|
|
|
targetEvent = Event.getTarget(event);
|
2019-11-12 16:18:09 +08:00
|
|
|
|
const { clsPrefix, contentTable,lastShowIndex,columnsChildrenList } = this.props;
|
2019-08-05 21:32:15 +08:00
|
|
|
|
// let currentElement = this.getOnLineObject(targetEvent);
|
|
|
|
|
let currentElement = this.getTargetToType(targetEvent);
|
2019-04-19 10:58:38 +08:00
|
|
|
|
if(!currentElement)return;
|
|
|
|
|
let type = currentElement.getAttribute('data-type');
|
2020-12-28 10:16:11 +08:00
|
|
|
|
const fixedType = currentElement.getAttribute('data-th-fixed');
|
2019-04-19 10:58:38 +08:00
|
|
|
|
if(!this.props.dragborder && !this.props.draggable)return;
|
|
|
|
|
if(type == 'online' && this.props.dragborder){
|
2020-01-10 11:39:13 +08:00
|
|
|
|
// if(!this.props.dragborder)return;
|
2019-04-22 10:24:21 +08:00
|
|
|
|
targetEvent.setAttribute('draggable',false);//添加交换列效果
|
2019-12-04 17:55:17 +08:00
|
|
|
|
let currentIndex = -1;
|
2019-11-12 16:18:09 +08:00
|
|
|
|
let defaultWidth = currentElement.getAttribute("data-th-width");
|
2019-04-19 10:58:38 +08:00
|
|
|
|
this.drag.option = "border";//拖拽操作
|
2019-11-12 16:18:09 +08:00
|
|
|
|
if(columnsChildrenList){
|
|
|
|
|
let columnKey = currentElement.getAttribute("data-line-key");
|
|
|
|
|
if(columnKey){
|
2019-12-25 14:53:03 +08:00
|
|
|
|
currentIndex = columnsChildrenList.findIndex(da=> (da.key && da.key.toLowerCase()) === columnKey.toLowerCase());
|
2019-11-12 16:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-28 20:57:09 +08:00
|
|
|
|
if(currentIndex < 0){
|
|
|
|
|
console.log('Key must be set for column!')
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-11-12 16:18:09 +08:00
|
|
|
|
let currentObj = this.table.cols[currentIndex];
|
2019-04-19 10:58:38 +08:00
|
|
|
|
this.drag.currIndex = currentIndex;
|
2020-12-10 20:54:53 +08:00
|
|
|
|
this.drag.oldLeft = event.clientX;
|
2019-04-19 10:58:38 +08:00
|
|
|
|
this.drag.oldWidth = parseInt((currentObj).style.width);
|
|
|
|
|
this.drag.minWidth = currentObj.style.minWidth != ""?parseInt(currentObj.style.minWidth):defaultWidth;
|
|
|
|
|
this.drag.tableWidth = parseInt(this.table.table.style.width ?this.table.table.style.width:this.table.table.scrollWidth);
|
2019-06-26 16:18:39 +08:00
|
|
|
|
if(!this.tableOldWidth){
|
|
|
|
|
this.tableOldWidth = this.drag.tableWidth;//this.getTableWidth();
|
|
|
|
|
}
|
2020-12-28 10:16:11 +08:00
|
|
|
|
|
|
|
|
|
// if(!this.lastColumWidth){
|
|
|
|
|
const contentT = this.table.tableHeaderCols || this.table.cols ;
|
|
|
|
|
this.lastColumWidth = parseInt(contentT[lastShowIndex].style.width);
|
|
|
|
|
// console.log('begin--lastColumnWidth',this.lastColumWidth);
|
|
|
|
|
// }
|
|
|
|
|
this.drag.contentTableCWidth = this.table.contentTableHeader.clientWidth;
|
|
|
|
|
this.drag.contentTableSWidth = this.table.contentTableHeader.scrollWidth;
|
|
|
|
|
if(fixedType) {
|
|
|
|
|
const contentTablePar = this.table.contentTableHeader.parentNode;
|
|
|
|
|
|
|
|
|
|
if(contentTablePar) {
|
|
|
|
|
const originL = parseInt(contentTablePar.style.marginLeft);
|
|
|
|
|
const originR = parseInt(contentTablePar.style.marginRight);
|
|
|
|
|
// 内容区表格marginLef
|
|
|
|
|
this.drag.contentTableML = originL;
|
|
|
|
|
this.drag.contentTableMR = originR;
|
|
|
|
|
}
|
2019-06-26 16:18:39 +08:00
|
|
|
|
}
|
2020-12-28 10:16:11 +08:00
|
|
|
|
this.drag.fixedType = fixedType;
|
2019-04-19 10:58:38 +08:00
|
|
|
|
}else if(type != 'online' && this.props.draggable){
|
2019-08-09 10:59:06 +08:00
|
|
|
|
// if (!this.props.draggable || targetEvent.nodeName.toUpperCase() != "TH") return;
|
|
|
|
|
if (!this.props.draggable) return;
|
|
|
|
|
let th = this.getTargetToType(targetEvent);
|
2019-06-06 16:13:07 +08:00
|
|
|
|
th.setAttribute('draggable',true);//添加交换列效果
|
2019-04-22 10:24:21 +08:00
|
|
|
|
this.drag.option = 'dragAble';
|
2019-06-06 16:13:07 +08:00
|
|
|
|
this.currentDome = th;
|
|
|
|
|
let currentIndex = parseInt(th.getAttribute("data-line-index"));
|
2019-04-22 10:24:21 +08:00
|
|
|
|
this.drag.currIndex = currentIndex;
|
2019-04-19 10:58:38 +08:00
|
|
|
|
}else{
|
2019-04-23 17:02:07 +08:00
|
|
|
|
// console.log("onTrMouseDown dragborder or draggable is all false !");
|
2019-04-19 10:58:38 +08:00
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-08-09 10:59:06 +08:00
|
|
|
|
|
2019-06-26 16:18:39 +08:00
|
|
|
|
getTableWidth = ()=>{
|
|
|
|
|
let tableWidth = 0,offWidth = 0;//this.table.cols.length;
|
|
|
|
|
for (let index = 0; index < this.table.cols.length; index++) {
|
|
|
|
|
let da = this.table.cols[index];
|
|
|
|
|
tableWidth += parseInt((da).style.width);
|
|
|
|
|
}
|
|
|
|
|
return (tableWidth-offWidth);
|
|
|
|
|
}
|
2019-08-09 10:59:06 +08:00
|
|
|
|
|
2019-08-05 21:32:15 +08:00
|
|
|
|
/**
|
|
|
|
|
* 根据当前节点查找到有data-type类型的容器返回。
|
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
|
|
|
|
getTargetToType = (targetEvent) => {
|
|
|
|
|
let tag = targetEvent;
|
|
|
|
|
if(targetEvent && !targetEvent.getAttribute("data-type")){
|
|
|
|
|
tag = this.getTargetToType(targetEvent.parentElement);
|
|
|
|
|
}
|
|
|
|
|
return tag;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 10:59:06 +08:00
|
|
|
|
|
2019-06-06 16:13:07 +08:00
|
|
|
|
/**
|
|
|
|
|
* 判断当前的target 是否是 th,如果不是,直接递归查找。
|
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
|
|
|
|
getTargetToTh = (targetEvent) => {
|
|
|
|
|
let th = targetEvent;
|
|
|
|
|
if(targetEvent.nodeName.toUpperCase() != "TH"){
|
|
|
|
|
th = this.getThDome(targetEvent);
|
|
|
|
|
}
|
2019-12-25 14:53:03 +08:00
|
|
|
|
// console.log(" getTargetToTh: ", th);
|
2019-06-06 16:13:07 +08:00
|
|
|
|
return th;
|
|
|
|
|
}
|
2018-12-11 17:21:02 +08:00
|
|
|
|
/**
|
|
|
|
|
* 调整列宽的move事件
|
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
2019-04-19 10:58:38 +08:00
|
|
|
|
onTrMouseMove = (e) => {
|
2019-04-23 18:25:34 +08:00
|
|
|
|
if(!this.props.dragborder && !this.props.draggable)return;
|
2020-09-21 11:05:41 +08:00
|
|
|
|
const { clsPrefix ,dragborder,contentDomWidth,scrollbarWidth,contentTable,headerScroll,lastShowIndex,onDraggingBorder, leftFixedWidth, rightFixedWidth, bodyDisplayInRow, eventNoStop} = this.props;
|
|
|
|
|
!eventNoStop && Event.stopPropagation(e);
|
2019-08-09 10:59:06 +08:00
|
|
|
|
let event = Event.getEvent(e);
|
2019-04-19 10:58:38 +08:00
|
|
|
|
if(this.props.dragborder && this.drag.option == "border"){
|
2018-11-30 16:14:29 +08:00
|
|
|
|
//移动改变宽度
|
|
|
|
|
let currentCols = this.table.cols[this.drag.currIndex];
|
2020-12-10 20:54:53 +08:00
|
|
|
|
let diff = (event.clientX - this.drag.oldLeft);
|
2018-11-30 16:14:29 +08:00
|
|
|
|
let newWidth = this.drag.oldWidth + diff;
|
2019-07-01 16:22:24 +08:00
|
|
|
|
this.drag.newWidth = newWidth > 0 ? newWidth : this.minWidth;
|
2018-12-03 11:17:39 +08:00
|
|
|
|
if(newWidth > this.minWidth){
|
2018-11-30 16:14:29 +08:00
|
|
|
|
currentCols.style.width = newWidth +'px';
|
2020-12-28 10:16:11 +08:00
|
|
|
|
|
2020-08-29 15:22:36 +08:00
|
|
|
|
// displayinrow 判断、 固定行高判断
|
|
|
|
|
if(!bodyDisplayInRow) {
|
|
|
|
|
this.table.bodyRows.forEach((row,index)=>{
|
|
|
|
|
const leftRow = this.table.fixedLeftBodyRows[index];
|
|
|
|
|
const rightRow = this.table.fixedRightBodyRows[index];
|
|
|
|
|
if(leftRow || rightRow) {
|
|
|
|
|
const height = row.getBoundingClientRect().height;
|
|
|
|
|
leftRow && (leftRow.style.height = height + "px")
|
|
|
|
|
rightRow && (rightRow.style.height = height + "px")
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-02 16:15:01 +08:00
|
|
|
|
//hao 支持固定表头拖拽 修改表体的width
|
|
|
|
|
if(this.fixedTable.cols){
|
|
|
|
|
this.fixedTable.cols[this.drag.currIndex].style.width = newWidth + "px";
|
|
|
|
|
}
|
2019-06-26 16:18:39 +08:00
|
|
|
|
|
2020-12-28 10:16:11 +08:00
|
|
|
|
const contentTableSWidth = this.drag.contentTableSWidth - this.drag.contentTableCWidth;
|
|
|
|
|
// console.log('contentTableSWidth+diff',contentTableSWidth+diff,'diff',diff);
|
|
|
|
|
if(diff<0 && contentTableSWidth+diff < 0) {
|
|
|
|
|
const headerCols = this.table.tableHeaderCols || this.table.cols;
|
|
|
|
|
const lastWidth =this.lastColumWidth - (contentTableSWidth+diff);
|
|
|
|
|
// console.log('lastWidth',lastWidth,'lastShowIndex',lastShowIndex);
|
|
|
|
|
headerCols[lastShowIndex].style.width = lastWidth +"px";//同步表头
|
|
|
|
|
this.table.tableBodyCols[lastShowIndex].style.width = lastWidth + "px";//同步表体
|
|
|
|
|
}
|
|
|
|
|
// 内容区非固定列场景拖拽
|
|
|
|
|
if(!this.drag.fixedType) {
|
2020-08-29 13:56:10 +08:00
|
|
|
|
|
2020-12-28 10:16:11 +08:00
|
|
|
|
// let newDiff = (parseInt(currentCols.style.minWidth) - parseInt(currentCols.style.width));
|
|
|
|
|
// if(newDiff > 0){//缩小
|
|
|
|
|
// let lastWidth = this.lastColumWidth + newDiff;
|
|
|
|
|
// this.table.cols[lastShowIndex].style.width = lastWidth +"px";//同步表头
|
|
|
|
|
// this.table.tableBodyCols[lastShowIndex].style.width = lastWidth + "px";//同步表体
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
let showScroll = contentDomWidth - (leftFixedWidth + rightFixedWidth) - (this.drag.tableWidth + diff) - scrollbarWidth ;
|
|
|
|
|
|
|
|
|
|
//表头滚动条处理
|
|
|
|
|
if(headerScroll){
|
2019-08-17 10:00:40 +08:00
|
|
|
|
if(showScroll < 0){ //小于 0 出现滚动条
|
2018-12-02 16:15:01 +08:00
|
|
|
|
//找到固定列表格,设置表头的marginBottom值为scrollbarWidth;
|
2019-03-18 10:59:11 +08:00
|
|
|
|
this.table.contentTableHeader.style.overflowX = 'scroll';
|
2019-04-19 10:58:38 +08:00
|
|
|
|
this.optTableMargin( this.table.fixedLeftHeaderTable,scrollbarWidth);
|
|
|
|
|
this.optTableMargin( this.table.fixedRighHeadertTable,scrollbarWidth);
|
2019-08-17 10:00:40 +08:00
|
|
|
|
}else{ //大于 0 不显示滚动条
|
2019-03-18 10:59:11 +08:00
|
|
|
|
this.table.contentTableHeader.style.overflowX = 'hidden';
|
|
|
|
|
this.optTableMargin( this.table.fixedLeftHeaderTable,0);
|
2019-04-19 10:58:38 +08:00
|
|
|
|
this.optTableMargin( this.table.fixedRighHeadertTable,0);
|
2018-12-02 16:15:01 +08:00
|
|
|
|
}
|
2020-12-28 10:16:11 +08:00
|
|
|
|
}else{
|
2021-03-28 19:23:41 +08:00
|
|
|
|
const scrollContainers = this.table.tableBody.querySelectorAll('.scroll-container') || []
|
2019-02-26 16:57:00 +08:00
|
|
|
|
if(showScroll < 0){
|
2021-03-28 19:23:41 +08:00
|
|
|
|
scrollContainers[0] ? scrollContainers[0].style.overflowX = 'auto' : null
|
2019-04-19 10:58:38 +08:00
|
|
|
|
this.optTableMargin( this.table.fixedLeftBodyTable,'-'+scrollbarWidth);
|
|
|
|
|
this.optTableMargin( this.table.fixedRightBodyTable,'-'+scrollbarWidth);
|
|
|
|
|
this.optTableScroll( this.table.fixedLeftBodyTable,{x:'scroll'});
|
|
|
|
|
this.optTableScroll( this.table.fixedRightBodyTable,{x:'scroll'});
|
2019-02-26 16:57:00 +08:00
|
|
|
|
}else{
|
2021-03-28 19:23:41 +08:00
|
|
|
|
scrollContainers[0] ? scrollContainers[0].style.overflowX = 'hidden' : null
|
2019-03-18 10:59:11 +08:00
|
|
|
|
this.optTableMargin( this.table.fixedLeftBodyTable,0);
|
|
|
|
|
this.optTableMargin( this.table.fixedRightBodyTable,0);
|
|
|
|
|
this.optTableScroll( this.table.fixedLeftBodyTable,{x:'auto'});
|
2019-04-19 10:58:38 +08:00
|
|
|
|
this.optTableScroll( this.table.fixedRightBodyTable,{x:'auto'});
|
2019-02-26 16:57:00 +08:00
|
|
|
|
}
|
2020-12-28 10:16:11 +08:00
|
|
|
|
}
|
|
|
|
|
}else if(this.drag.fixedType) {
|
|
|
|
|
if(this.table.ths[this.drag.currIndex]) {
|
|
|
|
|
this.table.ths[this.drag.currIndex].width = newWidth
|
|
|
|
|
}
|
|
|
|
|
// console.log('this.drag.contentTableML',this.drag.contentTableML,'diff',diff);
|
|
|
|
|
// debugger
|
|
|
|
|
|
|
|
|
|
const contentTablePar = this.table.contentTableHeader.parentNode;
|
|
|
|
|
// left、right缩小的内容,在没有滚动条时,需要将宽度同步到到最后一列
|
|
|
|
|
// diff<0 往里拖,
|
|
|
|
|
// const contentTableSWidth = this.drag.contentTableSWidth - this.drag.contentTableCWidth;
|
|
|
|
|
// console.log('contentTableSWidth+diff',contentTableSWidth+diff,'diff',diff);
|
|
|
|
|
// if(diff<0 && contentTableSWidth+diff < 0) {
|
|
|
|
|
// const headerCols = this.table.tableHeaderCols || this.table.cols;
|
|
|
|
|
// const lastWidth =this.lastColumWidth - (contentTableSWidth+diff);
|
|
|
|
|
// console.log('lastWidth',lastWidth,'lastShowIndex',lastShowIndex);
|
|
|
|
|
// headerCols[lastShowIndex].style.width = lastWidth +"px";//同步表头
|
|
|
|
|
// this.table.tableBodyCols[lastShowIndex].style.width = lastWidth + "px";//同步表体
|
|
|
|
|
// }
|
|
|
|
|
if(this.drag.fixedType == 'left') {
|
|
|
|
|
contentTablePar.style.marginLeft = this.drag.contentTableML + diff + 'px'
|
|
|
|
|
}else {
|
|
|
|
|
contentTablePar.style.marginRight = this.drag.contentTableMR + diff + 'px'
|
|
|
|
|
}
|
2021-03-28 19:23:41 +08:00
|
|
|
|
const containerWidth = contentTablePar.getBoundingClientRect().width
|
|
|
|
|
const tableWidth = this.table.innerTableBody.getBoundingClientRect().width
|
|
|
|
|
const scrollContainers = this.table.tableBody.querySelectorAll('.scroll-container') || []
|
|
|
|
|
if (tableWidth > containerWidth) {
|
|
|
|
|
scrollContainers[0] ? scrollContainers[0].style.overflowX = 'auto' : null
|
|
|
|
|
this.optTableMargin( this.table.fixedLeftBodyTable,'-'+scrollbarWidth);
|
|
|
|
|
this.optTableMargin( this.table.fixedRightBodyTable,'-'+scrollbarWidth);
|
|
|
|
|
this.optTableScroll( this.table.fixedLeftBodyTable,{x:'scroll'});
|
|
|
|
|
this.optTableScroll( this.table.fixedRightBodyTable,{x:'scroll'});
|
|
|
|
|
} else {
|
|
|
|
|
scrollContainers[0] ? scrollContainers[0].style.overflowX = 'hidden' : null
|
|
|
|
|
this.optTableMargin( this.table.fixedLeftBodyTable,0);
|
|
|
|
|
this.optTableMargin( this.table.fixedRightBodyTable,0);
|
|
|
|
|
this.optTableScroll( this.table.fixedLeftBodyTable,{x:'auto'});
|
|
|
|
|
this.optTableScroll( this.table.fixedRightBodyTable,{x:'auto'});
|
|
|
|
|
}
|
2018-12-02 16:15:01 +08:00
|
|
|
|
}
|
2020-12-28 10:16:11 +08:00
|
|
|
|
|
2019-07-01 16:22:24 +08:00
|
|
|
|
}else {
|
|
|
|
|
this.drag.newWidth = this.minWidth;
|
|
|
|
|
}
|
2019-04-19 10:58:38 +08:00
|
|
|
|
}
|
2019-08-01 14:39:57 +08:00
|
|
|
|
// 增加拖拽列宽动作的回调函数
|
|
|
|
|
this.drag.newWidth && onDraggingBorder && onDraggingBorder(event, this.drag.newWidth);
|
2019-04-19 10:58:38 +08:00
|
|
|
|
}
|
2018-11-30 16:14:29 +08:00
|
|
|
|
|
2019-04-19 10:58:38 +08:00
|
|
|
|
/**
|
2018-12-11 17:21:02 +08:00
|
|
|
|
* 调整列宽的up事件
|
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
2019-04-19 10:58:38 +08:00
|
|
|
|
onTrMouseUp = (e) => {
|
2019-08-09 10:59:06 +08:00
|
|
|
|
let event = Event.getEvent(e);
|
2019-01-28 10:24:37 +08:00
|
|
|
|
let width = this.drag.newWidth;
|
2020-01-10 11:39:13 +08:00
|
|
|
|
let opt = this.drag.option;
|
2019-04-19 10:58:38 +08:00
|
|
|
|
this.mouseClear();
|
2020-01-10 11:39:13 +08:00
|
|
|
|
if(opt !== "border") return; // fix:点击表头会触发onDropBorder事件的问题
|
2019-03-01 16:59:17 +08:00
|
|
|
|
this.props.onDropBorder && this.props.onDropBorder(event,width);
|
2018-11-07 17:11:25 +08:00
|
|
|
|
};
|
2018-12-11 17:21:02 +08:00
|
|
|
|
|
2018-09-20 16:24:06 +08:00
|
|
|
|
|
2019-08-09 10:59:06 +08:00
|
|
|
|
mouseClear(){
|
2018-12-05 12:39:29 +08:00
|
|
|
|
if(!this.drag || !this.drag.option)return;
|
|
|
|
|
let {rows} = this.props;
|
2019-04-22 15:39:20 +08:00
|
|
|
|
let data = {rows:rows[0],cols:this.table.cols,currIndex:this.drag.currIndex};
|
|
|
|
|
this.props.afterDragColWidth && this.props.afterDragColWidth(data);
|
2018-11-30 16:14:29 +08:00
|
|
|
|
this.drag = {
|
|
|
|
|
option:""
|
|
|
|
|
};
|
2019-04-22 10:24:21 +08:00
|
|
|
|
this.clearThsDr();
|
2019-04-19 10:58:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 10:24:21 +08:00
|
|
|
|
clearThsDr =()=>{
|
|
|
|
|
let ths = this.table.ths;
|
|
|
|
|
for (let index = 0; index < ths.length; index++) {
|
|
|
|
|
ths[index].setAttribute('draggable',false);//去掉交换列效果
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-19 10:58:38 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当前对象上绑定全局事件,用于拖拽区域以外时的事件处理
|
|
|
|
|
* @param {*} events
|
|
|
|
|
* @param {*} type
|
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
|
|
|
|
bodyonLineMouseUp = (events,type) =>{
|
|
|
|
|
if(!this.drag || !this.drag.option)return;
|
|
|
|
|
this.mouseClear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*相关滚动条联动操作
|
|
|
|
|
*
|
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
|
|
|
|
optTableMargin =(table,scrollbarWidth)=>{
|
|
|
|
|
if(table){
|
|
|
|
|
table.style.marginBottom = scrollbarWidth + "px"
|
2018-09-12 14:14:05 +08:00
|
|
|
|
}
|
2018-11-30 16:14:29 +08:00
|
|
|
|
}
|
2018-06-25 00:40:21 +08:00
|
|
|
|
|
2019-04-19 10:58:38 +08:00
|
|
|
|
optTableScroll = (table,overflow ={})=>{
|
|
|
|
|
if(table){
|
|
|
|
|
const innerTable = table.querySelector('.u-table-body-inner');
|
|
|
|
|
if(innerTable){
|
2019-07-26 12:46:52 +08:00
|
|
|
|
//fixbug: 拖拽列宽后,滚动条滚到表格底部,会导致固定列和非固定列错行
|
2021-03-28 19:23:41 +08:00
|
|
|
|
if (overflow.x) {
|
|
|
|
|
const fixedScrollContainers = innerTable.querySelectorAll('.fixed-scroll-container')
|
|
|
|
|
if (fixedScrollContainers && fixedScrollContainers.length) {
|
|
|
|
|
fixedScrollContainers[0] && (fixedScrollContainers[0].style.overflowX = overflow.x);
|
|
|
|
|
fixedScrollContainers[1] && (fixedScrollContainers[1].style.overflowX = overflow.x);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-19 10:58:38 +08:00
|
|
|
|
overflow.y && (innerTable.style.overflowY = overflow.y);
|
|
|
|
|
}
|
2019-08-09 10:59:06 +08:00
|
|
|
|
|
2019-04-19 10:58:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 10:24:21 +08:00
|
|
|
|
//---拖拽交换列代码----start-----
|
2018-11-30 16:14:29 +08:00
|
|
|
|
/**
|
2018-12-11 17:21:02 +08:00
|
|
|
|
* 添加换列的事件监听
|
2018-11-30 16:14:29 +08:00
|
|
|
|
*/
|
2019-04-22 10:24:21 +08:00
|
|
|
|
dragAbleEventInit (){
|
|
|
|
|
if (!this.props.draggable) return;
|
2018-11-30 16:14:29 +08:00
|
|
|
|
let events = [
|
2018-12-01 13:45:06 +08:00
|
|
|
|
{key:'dragstart',fun:this.onDragStart},//用户开始拖动元素时触发
|
|
|
|
|
{key:'dragover', fun:this.onDragOver},//当某被拖动的对象在另一对象容器范围内拖动时触发此事件
|
2019-08-09 10:59:06 +08:00
|
|
|
|
{key:'drop', fun:this.onDrop}, //在一个拖动过程中,释放鼠标键时触发此事件
|
2019-04-22 10:24:21 +08:00
|
|
|
|
|
2019-08-09 10:59:06 +08:00
|
|
|
|
{key:'dragenter', fun:this.onDragEnter},
|
2019-04-22 10:24:21 +08:00
|
|
|
|
{key:'dragend', fun:this.onDragEnd},
|
|
|
|
|
{key:'dragleave', fun:this.onDragLeave},
|
2018-11-30 16:14:29 +08:00
|
|
|
|
];
|
2019-04-22 10:24:21 +08:00
|
|
|
|
this.eventListen(events,'',this.table.tr[0]);//表示把事件添加到th元素上
|
2018-12-01 17:51:01 +08:00
|
|
|
|
}
|
2018-09-20 16:24:06 +08:00
|
|
|
|
|
2019-04-22 16:02:32 +08:00
|
|
|
|
/**
|
|
|
|
|
* 删除换列的事件监听
|
|
|
|
|
*/
|
|
|
|
|
removeDragAbleEvent(){
|
|
|
|
|
let events = [
|
|
|
|
|
{key:'dragstart',fun:this.onDragStart},
|
|
|
|
|
{key:'dragover', fun:this.onDragOver},
|
|
|
|
|
{key:'drop', fun:this.onDrop},
|
2019-08-09 10:59:06 +08:00
|
|
|
|
{key:'dragenter', fun:this.onDragEnter},
|
2019-04-22 16:02:32 +08:00
|
|
|
|
{key:'dragend', fun:this.onDragEnd},
|
|
|
|
|
{key:'dragleave', fun:this.onDragLeave},
|
|
|
|
|
];
|
|
|
|
|
this.eventListen(events,'remove',this.table.tr[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-11 17:21:02 +08:00
|
|
|
|
/**
|
|
|
|
|
* 开始调整交换列的事件
|
|
|
|
|
*/
|
2018-12-01 13:45:06 +08:00
|
|
|
|
onDragStart = (e) => {
|
2018-12-01 17:51:01 +08:00
|
|
|
|
if (!this.props.draggable) return;
|
2019-08-09 10:59:06 +08:00
|
|
|
|
if(this.drag && this.drag.option != 'dragAble'){return;}
|
2019-04-22 10:24:21 +08:00
|
|
|
|
let event = Event.getEvent(e) ,
|
2019-06-06 16:13:07 +08:00
|
|
|
|
// target = Event.getTarget(event);
|
|
|
|
|
target = this.getTargetToTh(Event.getTarget(event));
|
2019-04-22 10:24:21 +08:00
|
|
|
|
let currentIndex = parseInt(target.getAttribute("data-line-index"));
|
|
|
|
|
let currentKey = target.getAttribute('data-line-key');
|
|
|
|
|
|
2019-04-23 17:02:07 +08:00
|
|
|
|
if(event.dataTransfer.setDragImage){
|
|
|
|
|
var crt = target.cloneNode(true);
|
|
|
|
|
crt.style.backgroundColor = "#ebecf0";
|
|
|
|
|
crt.style.width = this.table.cols[currentIndex].style.width;//拖动后再交换列的时候,阴影效果可同步
|
|
|
|
|
crt.style.height = "40px";
|
|
|
|
|
// crt.style['line-height'] = "40px";
|
|
|
|
|
// document.body.appendChild(crt);
|
|
|
|
|
document.getElementById(this._table_none_cont_id).appendChild(crt);
|
|
|
|
|
event.dataTransfer.setDragImage(crt, 0, 0);
|
|
|
|
|
}
|
2019-04-22 10:24:21 +08:00
|
|
|
|
|
2018-05-09 14:51:01 +08:00
|
|
|
|
event.dataTransfer.effectAllowed = "move";
|
2018-12-01 13:45:06 +08:00
|
|
|
|
event.dataTransfer.setData("Text", currentKey);
|
|
|
|
|
this.currentObj = this.props.rows[0][currentIndex];
|
2018-11-07 17:11:25 +08:00
|
|
|
|
};
|
2018-06-25 00:39:18 +08:00
|
|
|
|
|
2018-12-01 13:45:06 +08:00
|
|
|
|
onDragOver = (e) => {
|
2019-04-25 13:53:39 +08:00
|
|
|
|
let event = Event.getEvent(e);
|
2018-05-09 14:51:01 +08:00
|
|
|
|
event.preventDefault();
|
2018-11-07 17:11:25 +08:00
|
|
|
|
};
|
2018-11-22 23:09:53 +08:00
|
|
|
|
|
2019-04-22 10:24:21 +08:00
|
|
|
|
/**
|
2018-12-01 13:45:06 +08:00
|
|
|
|
* 在一个拖动过程中,释放鼠标键时触发此事件。【目标事件】
|
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
|
|
|
|
onDrop = (e) => {
|
2018-12-01 17:51:01 +08:00
|
|
|
|
if (!this.props.draggable) return;
|
2019-08-30 13:43:25 +08:00
|
|
|
|
let props = this.getCurrentEventData(this._dragCurrent)
|
|
|
|
|
e.column = {props};
|
2019-08-27 15:08:17 +08:00
|
|
|
|
if(this.drag && this.drag.option != 'dragAble'){
|
|
|
|
|
this.props.onDrop(e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-22 10:24:21 +08:00
|
|
|
|
let event = Event.getEvent(e) ,
|
|
|
|
|
target = Event.getTarget(event);
|
2020-09-24 15:48:20 +08:00
|
|
|
|
event.preventDefault()
|
|
|
|
|
event.stopPropagation();
|
2019-04-23 18:25:34 +08:00
|
|
|
|
this.currentDome.setAttribute('draggable',false);//添加交换列效果
|
2019-08-30 11:39:59 +08:00
|
|
|
|
// let data = this.getCurrentEventData(this._dragCurrent);
|
|
|
|
|
// if(!data){
|
|
|
|
|
// this.props.onDrop(e);
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2019-08-21 16:29:11 +08:00
|
|
|
|
if(!this.props.onDrop)return;
|
|
|
|
|
// this.props.onDrop(event,target);
|
2019-09-04 15:23:58 +08:00
|
|
|
|
this.props.onDrop(event,{dragSource:this.currentObj,dragTarg:e.column});
|
2018-11-07 17:11:25 +08:00
|
|
|
|
};
|
2018-09-19 10:46:14 +08:00
|
|
|
|
|
2019-04-22 10:24:21 +08:00
|
|
|
|
|
|
|
|
|
onDragEnter = (e) => {
|
|
|
|
|
let event = Event.getEvent(e) ,
|
|
|
|
|
target = Event.getTarget(event);
|
|
|
|
|
this._dragCurrent = target;
|
|
|
|
|
let currentIndex = target.getAttribute("data-line-index");
|
|
|
|
|
if(!currentIndex || parseInt(currentIndex) === this.drag.currIndex)return;
|
|
|
|
|
if(target.nodeName.toUpperCase() === "TH"){
|
2019-04-23 17:02:07 +08:00
|
|
|
|
// target.style.border = "2px dashed rgba(5,0,0,0.25)";
|
2019-07-03 21:12:17 +08:00
|
|
|
|
target.setAttribute("style","border-right:2px dashed rgb(30, 136, 229)");
|
2019-04-22 15:39:20 +08:00
|
|
|
|
// target.style.backgroundColor = 'rgb(235, 236, 240)';
|
2019-04-22 10:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDragEnd = (e) => {
|
|
|
|
|
let event = Event.getEvent(e) ,
|
|
|
|
|
target = Event.getTarget(event);
|
2019-04-23 17:02:07 +08:00
|
|
|
|
this._dragCurrent.setAttribute("style","");
|
2020-09-24 15:48:20 +08:00
|
|
|
|
event.preventDefault()
|
|
|
|
|
event.stopPropagation();
|
2019-04-23 17:02:07 +08:00
|
|
|
|
// this._dragCurrent.style = "";
|
2019-04-22 10:24:21 +08:00
|
|
|
|
document.getElementById(this._table_none_cont_id).innerHTML = "";
|
2019-08-09 10:59:06 +08:00
|
|
|
|
|
2019-04-22 15:39:20 +08:00
|
|
|
|
let data = this.getCurrentEventData(this._dragCurrent);
|
|
|
|
|
if(!data)return;
|
|
|
|
|
if (!this.currentObj || this.currentObj.key == data.key) return;
|
2019-08-21 16:29:11 +08:00
|
|
|
|
if(!this.props.onDragEnd)return;
|
|
|
|
|
this.props.onDragEnd(event,{dragSource:this.currentObj,dragTarg:data});
|
2019-04-22 10:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onDragLeave = (e) => {
|
|
|
|
|
let event = Event.getEvent(e) ,
|
|
|
|
|
target = Event.getTarget(event);
|
|
|
|
|
let currentIndex = target.getAttribute("data-line-index");
|
|
|
|
|
if(!currentIndex || parseInt(currentIndex) === this.drag.currIndex)return;
|
|
|
|
|
if(target.nodeName.toUpperCase() === "TH"){
|
2019-04-23 17:02:07 +08:00
|
|
|
|
target.setAttribute("style","");
|
2019-04-22 10:24:21 +08:00
|
|
|
|
// this._dragCurrent.style = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 10:59:06 +08:00
|
|
|
|
|
|
|
|
|
|
2018-12-11 17:21:02 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取当前th上的对象数据
|
|
|
|
|
* @param {*} e
|
|
|
|
|
* @returns
|
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
2019-04-22 10:24:21 +08:00
|
|
|
|
getCurrentEventData(th){
|
2018-12-03 16:03:32 +08:00
|
|
|
|
if(!th){
|
|
|
|
|
console.log(" event target is not th ! ");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
let key = th.getAttribute('data-line-key');
|
2018-12-01 13:45:06 +08:00
|
|
|
|
let data = this.props.rows[0].find(da=>da.key == key);
|
|
|
|
|
if(data){
|
|
|
|
|
return data;
|
|
|
|
|
}else{
|
|
|
|
|
console.log(" getCurrentEventData data is null ");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-06 16:13:07 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据当前鼠标点击的节点,进行递归遍历,最终找到th
|
|
|
|
|
* @param {*} element
|
|
|
|
|
* @returns <th />对象
|
|
|
|
|
* @memberof TableHeader
|
|
|
|
|
*/
|
|
|
|
|
getThDome(element){
|
|
|
|
|
let _tagName = element.tagName.toLowerCase();
|
|
|
|
|
if(element.getAttribute('data-filter-type') === 'filterContext')return null;
|
|
|
|
|
if(_tagName === 'i')return null;
|
|
|
|
|
if(_tagName != 'th'){
|
|
|
|
|
return this.getThDome(element.parentElement);
|
|
|
|
|
}else{
|
|
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 10:59:06 +08:00
|
|
|
|
|
|
|
|
|
//---拖拽列交换----end-----
|
2018-12-03 16:03:32 +08:00
|
|
|
|
|
2018-09-20 16:24:06 +08:00
|
|
|
|
/**
|
2018-11-29 23:29:26 +08:00
|
|
|
|
* 过滤输入后或下拉条件的回调函数
|
2018-09-20 16:24:06 +08:00
|
|
|
|
*/
|
2018-11-29 23:29:26 +08:00
|
|
|
|
handlerFilterChange = (key, value, condition) => {
|
|
|
|
|
let { onFilterChange } = this.props;
|
|
|
|
|
if (onFilterChange) {
|
|
|
|
|
onFilterChange(key, value, condition);
|
2018-09-20 16:24:06 +08:00
|
|
|
|
}
|
2018-11-07 17:11:25 +08:00
|
|
|
|
};
|
2018-11-29 23:29:26 +08:00
|
|
|
|
|
2018-09-20 16:24:06 +08:00
|
|
|
|
/**
|
2018-11-29 23:29:26 +08:00
|
|
|
|
* 过滤行清除回调
|
2018-09-20 16:24:06 +08:00
|
|
|
|
*/
|
2018-11-29 23:29:26 +08:00
|
|
|
|
handlerFilterClear = (field) => {
|
|
|
|
|
let { onFilterClear } = this.props;
|
|
|
|
|
if (onFilterClear) {
|
|
|
|
|
onFilterClear(field);
|
2018-09-20 16:24:06 +08:00
|
|
|
|
}
|
2018-11-29 23:29:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-20 16:24:06 +08:00
|
|
|
|
/**
|
2018-11-29 23:29:26 +08:00
|
|
|
|
* 过滤渲染的组件类型
|
2018-09-20 16:24:06 +08:00
|
|
|
|
*/
|
|
|
|
|
filterRenderType = (type, dataIndex, index) => {
|
2018-11-07 17:11:25 +08:00
|
|
|
|
const { clsPrefix, rows, filterDelay, locale } = this.props;
|
2018-09-20 16:24:06 +08:00
|
|
|
|
switch (type) {
|
|
|
|
|
//文本输入
|
2018-11-07 17:11:25 +08:00
|
|
|
|
case "text":
|
|
|
|
|
return (
|
|
|
|
|
<FilterType
|
2018-11-29 23:29:26 +08:00
|
|
|
|
locale={locale}//多语
|
|
|
|
|
rendertype={type}//渲染类型
|
|
|
|
|
clsPrefix={clsPrefix}//css前缀
|
2018-11-07 17:11:25 +08:00
|
|
|
|
className={`${clsPrefix} filter-text`}
|
2018-11-29 23:29:26 +08:00
|
|
|
|
dataIndex={dataIndex}//字段
|
2020-07-17 14:37:35 +08:00
|
|
|
|
onFilterChange={debounce(filterDelay || 300, this.handlerFilterChange)}//输入框回调
|
2018-11-29 23:29:26 +08:00
|
|
|
|
onFilterClear={this.handlerFilterClear}//清除回调
|
|
|
|
|
filterDropdown={rows[1][index]["filterdropdown"]}//是否显示下拉条件
|
2018-11-26 19:26:52 +08:00
|
|
|
|
filterDropdownType={rows[1][index]["filterdropdowntype"]}//下拉的条件类型为string,number
|
2018-12-10 22:51:45 +08:00
|
|
|
|
filterDropdownIncludeKeys={rows[1][index]["filterdropdownincludekeys"]}//下拉条件按照指定的keys去显示
|
2018-11-26 19:26:52 +08:00
|
|
|
|
/>
|
|
|
|
|
);
|
2018-11-29 23:29:26 +08:00
|
|
|
|
//数值输入
|
2018-11-26 19:26:52 +08:00
|
|
|
|
case "number":
|
|
|
|
|
return (
|
|
|
|
|
<FilterType
|
|
|
|
|
locale={locale}
|
|
|
|
|
rendertype={type}
|
|
|
|
|
clsPrefix={clsPrefix}
|
|
|
|
|
className={`${clsPrefix} filter-text`}
|
2018-11-29 23:29:26 +08:00
|
|
|
|
dataIndex={dataIndex}//字段
|
|
|
|
|
onFilterChange={debounce(filterDelay || 300, this.handlerFilterChange)}//输入框回调并且函数防抖动
|
|
|
|
|
onFilterClear={this.handlerFilterClear}//清除回调
|
2018-11-07 17:11:25 +08:00
|
|
|
|
filterDropdown={rows[1][index]["filterdropdown"]}
|
2018-11-26 17:59:53 +08:00
|
|
|
|
filterDropdownType={rows[1][index]["filterdropdowntype"]}//下拉的条件类型为string,number
|
2018-12-10 22:51:45 +08:00
|
|
|
|
filterDropdownIncludeKeys={rows[1][index]["filterdropdownincludekeys"]}//下拉条件按照指定的keys去显示
|
2018-12-14 10:52:32 +08:00
|
|
|
|
filterInputNumberOptions={rows[1][index]["filterinputnumberoptions"]}//设置数值框内的详细属性
|
2018-11-07 17:11:25 +08:00
|
|
|
|
/>
|
|
|
|
|
);
|
2018-09-20 16:24:06 +08:00
|
|
|
|
//下拉框选择
|
2018-11-07 17:11:25 +08:00
|
|
|
|
case "dropdown":
|
2018-09-20 16:24:06 +08:00
|
|
|
|
let selectDataSource = [];
|
2018-11-29 23:29:26 +08:00
|
|
|
|
//处理没有输入数据源的时候,系统自动查找自带的数据筛选后注入
|
|
|
|
|
if (rows.length > 0 && (rows[1][index]["filterdropdownauto"] || "auto") == "auto") {
|
2018-09-20 16:24:06 +08:00
|
|
|
|
let hash = {};
|
|
|
|
|
//处理下拉重复对象组装dropdown
|
2018-11-07 17:11:25 +08:00
|
|
|
|
selectDataSource = Array.from(rows[1][0].datasource, x => ({
|
|
|
|
|
key: x[dataIndex],
|
|
|
|
|
value: x[dataIndex]
|
|
|
|
|
}));
|
2018-09-20 16:24:06 +08:00
|
|
|
|
selectDataSource = selectDataSource.reduceRight((item, next) => {
|
2018-11-07 17:11:25 +08:00
|
|
|
|
hash[next.key] ? "" : (hash[next.key] = true && item.push(next));
|
|
|
|
|
return item;
|
2018-09-20 16:24:06 +08:00
|
|
|
|
}, []);
|
2018-10-11 20:15:00 +08:00
|
|
|
|
} else {
|
2018-11-29 23:29:26 +08:00
|
|
|
|
//从外部数据源加载系统数据
|
2018-11-07 17:11:25 +08:00
|
|
|
|
selectDataSource = rows[1][index]["filterdropdowndata"];
|
2018-09-20 16:24:06 +08:00
|
|
|
|
}
|
2018-11-07 17:11:25 +08:00
|
|
|
|
return (
|
|
|
|
|
<FilterType
|
|
|
|
|
locale={locale}
|
|
|
|
|
rendertype={type}
|
|
|
|
|
className={`${clsPrefix} filter-dropdown`}
|
|
|
|
|
data={selectDataSource}
|
2018-12-15 15:24:15 +08:00
|
|
|
|
notFoundContent={"Loading"}//没有数据显示的默认字
|
2018-11-29 23:29:26 +08:00
|
|
|
|
dataIndex={dataIndex}//字段
|
|
|
|
|
onFilterChange={this.handlerFilterChange}//输入框回调
|
|
|
|
|
onFilterClear={this.handlerFilterClear}//清除回调
|
2018-11-07 17:11:25 +08:00
|
|
|
|
filterDropdown={rows[1][index]["filterdropdown"]}
|
|
|
|
|
onFocus={rows[1][index]["filterdropdownfocus"]}
|
2018-11-26 17:59:53 +08:00
|
|
|
|
filterDropdownType={rows[1][index]["filterdropdowntype"]}//下拉的条件类型为string,number
|
2018-12-10 22:51:45 +08:00
|
|
|
|
filterDropdownIncludeKeys={rows[1][index]["filterdropdownincludekeys"]}//下拉条件按照指定的keys去显示
|
2018-11-07 17:11:25 +08:00
|
|
|
|
/>
|
|
|
|
|
);
|
2018-09-20 16:24:06 +08:00
|
|
|
|
//日期
|
2018-11-07 17:11:25 +08:00
|
|
|
|
case "date":
|
|
|
|
|
return (
|
|
|
|
|
<FilterType
|
|
|
|
|
locale={locale}
|
|
|
|
|
rendertype={type}
|
|
|
|
|
className={`filter-date`}
|
2018-11-29 23:29:26 +08:00
|
|
|
|
onClick={() => { }}
|
2018-11-07 17:11:25 +08:00
|
|
|
|
format={rows[1][index]["format"] || "YYYY-MM-DD"}
|
2018-11-29 23:29:26 +08:00
|
|
|
|
dataIndex={dataIndex}//字段
|
|
|
|
|
onFilterChange={this.handlerFilterChange}//输入框回调
|
|
|
|
|
onFilterClear={this.handlerFilterClear}//清除回调
|
2018-11-07 17:11:25 +08:00
|
|
|
|
filterDropdown={rows[1][index]["filterdropdown"]}
|
2018-11-26 21:08:20 +08:00
|
|
|
|
filterDropdownType={rows[1][index]["filterdropdowntype"]}//下拉的条件类型为string,number
|
2020-03-02 14:32:05 +08:00
|
|
|
|
filterDropdownIncludeKeys={rows[1][index]["filterdropdownincludekeys"]}//下拉条件按照指定的keys去显示
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
//日期 年
|
|
|
|
|
case "dateyear":
|
|
|
|
|
return (
|
|
|
|
|
<FilterType
|
|
|
|
|
locale={locale}
|
|
|
|
|
rendertype={type}
|
|
|
|
|
className={`filter-date`}
|
|
|
|
|
onClick={() => { }}
|
|
|
|
|
format={rows[1][index]["format"] || "YYYY"}
|
|
|
|
|
dataIndex={dataIndex}//字段
|
|
|
|
|
onFilterChange={this.handlerFilterChange}//输入框回调
|
|
|
|
|
onFilterClear={this.handlerFilterClear}//清除回调
|
|
|
|
|
filterDropdown={rows[1][index]["filterdropdown"]}
|
|
|
|
|
filterDropdownType={rows[1][index]["filterdropdowntype"]}//下拉的条件类型为string,number
|
|
|
|
|
filterDropdownIncludeKeys={rows[1][index]["filterdropdownincludekeys"]}//下拉条件按照指定的keys去显示
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
//日期 月
|
|
|
|
|
case "datemonth":
|
|
|
|
|
return (
|
|
|
|
|
<FilterType
|
|
|
|
|
locale={locale}
|
|
|
|
|
rendertype={type}
|
|
|
|
|
className={`filter-date`}
|
|
|
|
|
onClick={() => { }}
|
|
|
|
|
format={rows[1][index]["format"] || "YYYY-MM"}
|
|
|
|
|
dataIndex={dataIndex}//字段
|
|
|
|
|
onFilterChange={this.handlerFilterChange}//输入框回调
|
|
|
|
|
onFilterClear={this.handlerFilterClear}//清除回调
|
|
|
|
|
filterDropdown={rows[1][index]["filterdropdown"]}
|
|
|
|
|
filterDropdownType={rows[1][index]["filterdropdowntype"]}//下拉的条件类型为string,number
|
|
|
|
|
filterDropdownIncludeKeys={rows[1][index]["filterdropdownincludekeys"]}//下拉条件按照指定的keys去显示
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
//日期 周
|
|
|
|
|
case "dateweek":
|
|
|
|
|
return (
|
|
|
|
|
<FilterType
|
|
|
|
|
locale={locale}
|
|
|
|
|
rendertype={type}
|
|
|
|
|
className={`filter-date`}
|
|
|
|
|
onClick={() => { }}
|
|
|
|
|
format={rows[1][index]["format"] || "YYYY-Wo"}
|
|
|
|
|
dataIndex={dataIndex}//字段
|
|
|
|
|
onFilterChange={this.handlerFilterChange}//输入框回调
|
|
|
|
|
onFilterClear={this.handlerFilterClear}//清除回调
|
|
|
|
|
filterDropdown={rows[1][index]["filterdropdown"]}
|
|
|
|
|
filterDropdownType={rows[1][index]["filterdropdowntype"]}//下拉的条件类型为string,number
|
2018-12-10 22:51:45 +08:00
|
|
|
|
filterDropdownIncludeKeys={rows[1][index]["filterdropdownincludekeys"]}//下拉条件按照指定的keys去显示
|
2018-11-26 21:08:20 +08:00
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
//日期范围
|
|
|
|
|
case "daterange":
|
|
|
|
|
return (
|
|
|
|
|
<FilterType
|
|
|
|
|
locale={locale}
|
|
|
|
|
rendertype={type}
|
|
|
|
|
className={`filter-date`}
|
2018-11-29 23:29:26 +08:00
|
|
|
|
onClick={() => { }}
|
2018-11-26 21:08:20 +08:00
|
|
|
|
format={rows[1][index]["format"] || "YYYY-MM-DD"}
|
2018-11-29 23:29:26 +08:00
|
|
|
|
dataIndex={dataIndex}//字段
|
|
|
|
|
onFilterChange={this.handlerFilterChange}//输入框回调
|
|
|
|
|
onFilterClear={this.handlerFilterClear}//清除回调
|
2018-11-26 21:08:20 +08:00
|
|
|
|
filterDropdown={rows[1][index]["filterdropdown"]}
|
2018-11-26 17:59:53 +08:00
|
|
|
|
filterDropdownType={rows[1][index]["filterdropdowntype"]}//下拉的条件类型为string,number
|
2018-12-10 22:51:45 +08:00
|
|
|
|
filterDropdownIncludeKeys={rows[1][index]["filterdropdownincludekeys"]}//下拉条件按照指定的keys去显示
|
2018-11-07 17:11:25 +08:00
|
|
|
|
/>
|
|
|
|
|
);
|
2018-09-20 16:24:06 +08:00
|
|
|
|
default:
|
|
|
|
|
//不匹配类型默认文本输入
|
2018-11-07 17:11:25 +08:00
|
|
|
|
return <div />;
|
2018-09-20 16:24:06 +08:00
|
|
|
|
}
|
2018-11-07 17:11:25 +08:00
|
|
|
|
};
|
2018-09-20 16:24:06 +08:00
|
|
|
|
|
2020-09-29 09:45:11 +08:00
|
|
|
|
onCopy = (data,index, event) => {
|
|
|
|
|
if(this.props.onCopy) {
|
|
|
|
|
this.props.onCopy(Object.assign(data,{col: index}),event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-27 14:32:30 +08:00
|
|
|
|
|
2019-08-09 10:59:06 +08:00
|
|
|
|
render() {
|
2018-12-11 17:21:02 +08:00
|
|
|
|
const { clsPrefix, rowStyle,draggable,
|
2019-11-12 16:18:09 +08:00
|
|
|
|
dragborder, rows,filterable,fixed,lastShowIndex,columnsChildrenList
|
2018-09-20 16:24:06 +08:00
|
|
|
|
} = this.props;
|
2018-11-07 17:11:25 +08:00
|
|
|
|
let attr = dragborder ? { id: `u-table-drag-thead-${this.theadKey}` } : {};
|
2019-11-12 16:18:09 +08:00
|
|
|
|
let lastObj = columnsChildrenList[columnsChildrenList.length-1];
|
2016-12-26 16:52:39 +08:00
|
|
|
|
return (
|
2018-12-11 17:21:02 +08:00
|
|
|
|
<thead className={`${clsPrefix}-thead`} {...attr} data-theader-fixed='scroll' ref={_thead=>this._thead = _thead} >
|
2019-04-19 10:58:38 +08:00
|
|
|
|
{rows.map((row, index) => {
|
|
|
|
|
let _rowLeng = (row.length-1);
|
2019-04-25 15:44:18 +08:00
|
|
|
|
return(<tr key={index} style={rowStyle} className={(filterable && index == rows.length - 1)?'filterable':''}>
|
2018-11-30 16:14:29 +08:00
|
|
|
|
{row.map((da, columIndex, arr) => {
|
2019-11-25 17:58:02 +08:00
|
|
|
|
da.children = da.required ? <span><span className='required'>*</span>{da.children}</span> : da.children;
|
2018-11-07 17:11:25 +08:00
|
|
|
|
let thHover = da.drgHover
|
|
|
|
|
? ` ${clsPrefix}-thead th-drag-hover`
|
|
|
|
|
: "";
|
|
|
|
|
delete da.drgHover;
|
|
|
|
|
let fixedStyle = "";
|
|
|
|
|
let canDotDrag = "";
|
2018-12-06 19:13:28 +08:00
|
|
|
|
//主表格下、固定列或者是过滤行中含有固定列时添加该属性
|
|
|
|
|
if (!fixed && (da.fixed || (filterable && index == rows.length - 1 && rows[0][columIndex].fixed)) ) {
|
2018-12-19 17:11:33 +08:00
|
|
|
|
fixedStyle = ` ${clsPrefix}-row-fixed-columns-in-body`;
|
2018-11-07 17:11:25 +08:00
|
|
|
|
}
|
2019-08-09 10:59:06 +08:00
|
|
|
|
|
2018-11-30 16:14:29 +08:00
|
|
|
|
if (lastShowIndex == columIndex) {
|
2018-11-07 17:11:25 +08:00
|
|
|
|
canDotDrag = "th-can-not-drag";
|
|
|
|
|
}
|
2019-01-17 18:36:22 +08:00
|
|
|
|
let thClassName = `${da.className}`?`${da.className}`:'';
|
2019-08-24 15:37:12 +08:00
|
|
|
|
if(da.titleAlign){
|
|
|
|
|
thClassName += ` text-${da.titleAlign} `;
|
|
|
|
|
}
|
|
|
|
|
else if(da.textAlign){
|
2019-01-23 11:12:59 +08:00
|
|
|
|
thClassName += ` text-${da.textAlign} `;
|
2019-01-17 18:36:22 +08:00
|
|
|
|
}
|
2019-08-24 15:37:12 +08:00
|
|
|
|
|
2019-01-17 18:41:20 +08:00
|
|
|
|
delete da.textAlign;
|
2019-08-24 15:37:12 +08:00
|
|
|
|
delete da.titleAlign;
|
2019-01-10 19:42:30 +08:00
|
|
|
|
const keyTemp = {};
|
|
|
|
|
//避免key为undefined
|
2019-01-16 13:57:31 +08:00
|
|
|
|
// if(da.dataindex && da.key ===undefined ){
|
|
|
|
|
keyTemp.key = da.key || da.dataindex || index+'-'+columIndex
|
2019-08-09 10:59:06 +08:00
|
|
|
|
|
|
|
|
|
// }
|
2018-11-07 17:11:25 +08:00
|
|
|
|
if (filterable && index == rows.length - 1) {
|
|
|
|
|
da.children = this.filterRenderType(
|
|
|
|
|
da["filtertype"],
|
|
|
|
|
da.dataindex,
|
2018-11-30 16:14:29 +08:00
|
|
|
|
columIndex
|
2018-11-07 17:11:25 +08:00
|
|
|
|
);
|
2019-01-10 19:42:30 +08:00
|
|
|
|
if(da.key ===undefined ){
|
2019-01-16 13:57:31 +08:00
|
|
|
|
keyTemp.key = keyTemp.key + '-filterable'
|
2019-01-10 19:42:30 +08:00
|
|
|
|
}
|
2018-11-07 17:11:25 +08:00
|
|
|
|
delete da.filterdropdownfocus;
|
|
|
|
|
}
|
2018-11-13 18:50:50 +08:00
|
|
|
|
|
2018-12-01 17:51:01 +08:00
|
|
|
|
let thDefaultObj = {};
|
2019-08-09 10:59:06 +08:00
|
|
|
|
|
2019-04-22 10:24:21 +08:00
|
|
|
|
if(draggable){
|
|
|
|
|
thClassName += ` ${clsPrefix}-thead th-drag ${thHover} `;
|
|
|
|
|
}
|
|
|
|
|
if(dragborder){
|
|
|
|
|
thClassName += ` ${clsPrefix}-thead-th ${canDotDrag}`;
|
|
|
|
|
}
|
|
|
|
|
thClassName += ` ${fixedStyle}`;
|
|
|
|
|
if(!da.fixed ){
|
2019-08-09 10:59:06 +08:00
|
|
|
|
return (<th {...da} {...keyTemp} className={thClassName} data-th-fixed={da.fixed} data-line-key={da.key}
|
2020-09-29 09:45:11 +08:00
|
|
|
|
data-line-index={columIndex} data-th-width={da.width} data-type="draggable" onCopy={(event) => {this.onCopy(da,columIndex,event)}}>
|
2019-04-22 10:24:21 +08:00
|
|
|
|
{da.children}
|
|
|
|
|
{
|
2019-11-12 16:18:09 +08:00
|
|
|
|
// && columIndex != _rowLeng
|
2019-12-24 14:29:26 +08:00
|
|
|
|
dragborder && lastObj && da.key != lastObj.key ? <div ref={el => (this.gap = el)} data-line-key={da.key}
|
2019-04-22 10:24:21 +08:00
|
|
|
|
data-line-index={columIndex} data-th-width={da.width}
|
2020-12-28 10:16:11 +08:00
|
|
|
|
data-type="online" data-th-fixed={da.fixed} className = {`${clsPrefix}-thead-th-drag-gap`}>
|
2019-04-22 10:24:21 +08:00
|
|
|
|
<div className='online' /></div>:""
|
|
|
|
|
}
|
|
|
|
|
</th>)
|
2018-11-13 18:50:50 +08:00
|
|
|
|
}else{
|
|
|
|
|
thDefaultObj = {
|
|
|
|
|
...da,
|
2019-01-17 18:36:22 +08:00
|
|
|
|
className:`${thClassName} ${fixedStyle}`,
|
2018-11-13 18:50:50 +08:00
|
|
|
|
};
|
|
|
|
|
da.onClick ?thDefaultObj.onClick = (e)=>{da.onClick(da, e)}:"";
|
2020-12-28 10:16:11 +08:00
|
|
|
|
return (<th {...thDefaultObj} {...keyTemp} data-th-fixed={da.fixed} style={{maxWidth: da.width}} onCopy={this.onCopy}>
|
|
|
|
|
{da.children}
|
|
|
|
|
{
|
|
|
|
|
// && columIndex != _rowLeng
|
|
|
|
|
dragborder ? <div ref={el => (this.gap = el)} data-line-key={da.key}
|
|
|
|
|
data-line-index={columIndex} data-th-width={da.width}
|
|
|
|
|
data-type="online" data-th-fixed={da.fixed} className = {`${clsPrefix}-thead-th-drag-gap`}>
|
|
|
|
|
<div className='online' /></div>:""
|
|
|
|
|
}
|
|
|
|
|
</th>)
|
2018-11-07 17:11:25 +08:00
|
|
|
|
}
|
|
|
|
|
})}
|
|
|
|
|
</tr>
|
2019-04-19 10:58:38 +08:00
|
|
|
|
)})}
|
2016-12-26 16:52:39 +08:00
|
|
|
|
</thead>
|
|
|
|
|
);
|
2017-01-11 17:01:50 +08:00
|
|
|
|
}
|
2018-11-07 17:11:25 +08:00
|
|
|
|
}
|
2017-01-11 17:01:50 +08:00
|
|
|
|
|
|
|
|
|
TableHeader.propTypes = propTypes;
|
|
|
|
|
export default TableHeader;
|