修改lib 文件夹下util.js路径

This commit is contained in:
wanghaoo 2018-09-06 19:12:12 +08:00
parent acb1a72bb8
commit 67983948a9
7 changed files with 139 additions and 129 deletions

182
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 @@
import React, { Component } from "react";
import {compare} from './util';
import {ObjectAssign} from '../utils';
import {ObjectAssign} from '../util';
/**
* 参数: 列拖拽
* @param {*} Table

View File

@ -1,14 +1,16 @@
import React, { Component } from "react";
import {compare} from './util';
import {ObjectAssign} from '../utils';
import {ObjectAssign} from '../util';
/**
* 参数: 列拖拽
* @param {*} Table
*/
export default function dragColumn(Table) {
// 0、定义一个拖拽dom
// 1、当移动到表头可以显示当前操作列的move图标。
// 2、添加start、move事件、drop事件
export default function dragWidthColumn(Table) {
return class DragColumn extends Component {
return class DragWidthColumn extends Component {
constructor(props) {
super(props);
@ -47,46 +49,11 @@ export default function dragColumn(Table) {
}
onDragEnter=(event,data)=>{
if(data.key == "checkbox")return;
const {columns:_columns} = this.state;
let columns = [];
Object.assign(columns,_columns);
columns.forEach((da)=>da.drgHover = false)
let current = columns.find((da)=>da.key == data.key);
if(current.fixed)return;
current.drgHover = true;
this.setState({
columns
});
if(this.props.onDragEnter){
this.props.onDragEnter(event,data);
}
}
onDrop=(event,data)=>{
if(data.key == "checkbox")return;
let {columns} = this.state;
const id = event.dataTransfer.getData("Text");
let objIndex = columns.findIndex((_da,i)=>_da.key == id);
let targetIndex = columns.findIndex((_da,i)=>_da.key == data.key);
if(columns[objIndex].fixed)return;//固定列不让拖拽
if(columns[targetIndex].fixed)return;//固定列不让拖拽
columns.forEach((da,i)=>{
da.drgHover = false;
if(da.key == id){//obj
da.dragIndex = targetIndex
}
if(da.key == data.key){//targetObj
da.dragIndex = objIndex;
}
});
let _columns = columns.sort(compare('dragIndex'));
this.setState({
columns: JSON.parse(JSON.stringify(_columns)),
});
if(this.props.onDrop){
this.props.onDrop(event,data);
}
}
getTarget=(evt)=>{
@ -113,10 +80,10 @@ export default function dragColumn(Table) {
columns={this.state.columns}
data={data}
className={`${className} u-table-drag-border`}
onDragStart={this.onDragStart}
onDragOver={this.onDragOver}
onDrop={this.onDrop}
onDragEnter={this.onDragEnter}
onDragStart={this.onDragWidthStart}
onDragOver={this.onDragWidthOver}
onDrop={this.onDropWidth}
onDragEnter={this.onDragWidthEnter}
draggable={draggable}
// dragborder={dragborder}
dragborder={false}

View File

@ -1,7 +1,7 @@
import React, { Component } from "react";
import Checkbox from 'bee-checkbox';
import Icon from "bee-icon";
import {ObjectAssign} from '../utils';
import {ObjectAssign} from './util';
function noop() {}
/**
* 参数: 过滤表头

View File

@ -1,6 +1,6 @@
import React, { Component } from "react";
import Checkbox from 'bee-checkbox';
import {ObjectAssign} from '../utils';
import {ObjectAssign} from './util';
/**
* 参数: 过滤表头
* @param {*} Table

View File

@ -47,4 +47,23 @@ export function compare(property){
var value2 = b[property];
return value1 - value2;
}
}
}
/**
* 简单数组数据对象拷贝
* @param {*} obj 要拷贝的对象
*/
export function ObjectAssign(obj){
let b = obj instanceof Array;
let tagObj = b?[]:{};
if(b){//数组
obj.forEach(da => {
let _da = {};
Object.assign(_da,da);
tagObj.push(_da);
});
}else{
Object.assign(tagObj,obj);
}
return tagObj;
}