diff --git a/build/Table.css b/build/Table.css index 9108c27..cbba388 100644 --- a/build/Table.css +++ b/build/Table.css @@ -315,7 +315,7 @@ .u-table-thead th { background: #f7f7f7; } .u-table-thead .th-drag { - cursor: move; } + cursor: pointer; } .u-table-thead .th-drag-hover { background: #ccc; } .u-table-thead-th { diff --git a/build/lib/dragColumn.js b/build/lib/dragColumn.js index c3ded48..f4bcada 100644 --- a/build/lib/dragColumn.js +++ b/build/lib/dragColumn.js @@ -14,7 +14,7 @@ var _react2 = _interopRequireDefault(_react); var _util = require('./util'); -var _utils = require('../utils'); +var _util2 = require('../util'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } diff --git a/build/lib/dragColumnWidth.js b/build/lib/dragColumnWidth.js new file mode 100644 index 0000000..43b5ed2 --- /dev/null +++ b/build/lib/dragColumnWidth.js @@ -0,0 +1,122 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +exports["default"] = dragWidthColumn; + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var _util = require('./util'); + +var _util2 = require('../util'); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } + +function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +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); } + +/** + * 参数: 列拖拽 + * @param {*} Table + */ +// 0、定义一个拖拽dom +// 1、当移动到表头可以显示当前操作列的move图标。 +// 2、添加start、move事件、drop事件 +function dragWidthColumn(Table) { + + return function (_Component) { + _inherits(DragWidthColumn, _Component); + + function DragWidthColumn(props) { + _classCallCheck(this, DragWidthColumn); + + var _this = _possibleConstructorReturn(this, _Component.call(this, props)); + + _this.setColumOrderByIndex = function (_column) { + _column.forEach(function (da, i) { + da.dragIndex = i; + da.drgHover = false; + }); + return _column; + }; + + _this.onDragStart = function (event, data) { + if (_this.props.onDragStart) { + _this.props.onDragStart(event, data); + } + }; + + _this.onDragOver = function (event, data) { + if (_this.props.onDragOver) { + _this.props.onDragOver(event, data); + } + }; + + _this.onDragEnter = function (event, data) {}; + + _this.onDrop = function (event, data) {}; + + _this.getTarget = function (evt) { + return evt.target || evt.srcElement; + }; + + _this.state = { + columns: _this.setColumOrderByIndex(props.columns) + }; + return _this; + } + + DragWidthColumn.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { + if (nextProps.columns != this.props.columns) { + this.setState({ + columns: this.setColumOrderByIndex(nextProps.columns) + }); + } + }; + + DragWidthColumn.prototype.render = function render() { + var _props = this.props, + data = _props.data, + dragborder = _props.dragborder, + draggable = _props.draggable, + className = _props.className, + columns = _props.columns, + onDragStart = _props.onDragStart, + onDragEnter = _props.onDragEnter, + onDragOver = _props.onDragOver, + onDrop = _props.onDrop, + others = _objectWithoutProperties(_props, ['data', 'dragborder', 'draggable', 'className', 'columns', 'onDragStart', 'onDragEnter', 'onDragOver', 'onDrop']); + + var key = new Date().getTime(); + return _react2["default"].createElement(Table, _extends({}, others, { + columns: this.state.columns, + data: data, + className: className + ' u-table-drag-border', + onDragStart: this.onDragWidthStart, + onDragOver: this.onDragWidthOver, + onDrop: this.onDropWidth, + onDragEnter: this.onDragWidthEnter, + draggable: draggable + // dragborder={dragborder} + , dragborder: false, + dragborderKey: key + })); + }; + + return DragWidthColumn; + }(_react.Component); +} +module.exports = exports['default']; \ No newline at end of file diff --git a/build/lib/filterColumn.js b/build/lib/filterColumn.js index 13bc427..02c55d6 100644 --- a/build/lib/filterColumn.js +++ b/build/lib/filterColumn.js @@ -20,7 +20,7 @@ var _beeIcon = require("bee-icon"); var _beeIcon2 = _interopRequireDefault(_beeIcon); -var _utils = require("../utils"); +var _util = require("./util"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } @@ -56,7 +56,7 @@ function filterColumn(Table, Popover) { var columns = props.columns; _this.state = { - columns: _this.setColumOrderByIndex((0, _utils.ObjectAssign)(columns)), + columns: _this.setColumOrderByIndex((0, _util.ObjectAssign)(columns)), showModal: false, screenY: 0 }; @@ -66,7 +66,7 @@ function filterColumn(Table, Popover) { FilterColumn.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { if (nextProps.columns != this.props.columns) { this.setState({ - columns: this.setColumOrderByIndex((0, _utils.ObjectAssign)(nextProps.columns)) + columns: this.setColumOrderByIndex((0, _util.ObjectAssign)(nextProps.columns)) }); } this.setState({ diff --git a/build/lib/newMultiSelect.js b/build/lib/newMultiSelect.js index 601d9c6..d39e758 100644 --- a/build/lib/newMultiSelect.js +++ b/build/lib/newMultiSelect.js @@ -16,7 +16,7 @@ var _beeCheckbox = require('bee-checkbox'); var _beeCheckbox2 = _interopRequireDefault(_beeCheckbox); -var _utils = require('../utils'); +var _util = require('./util'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } @@ -128,7 +128,7 @@ function newMultiSelect(Table, Checkbox) { _this.state = { checkedAll: false, // columns:this.getDefaultColumns(props.columns,"init"), - data: (0, _utils.ObjectAssign)(props.data) + data: (0, _util.ObjectAssign)(props.data) }; return _this; } @@ -141,7 +141,7 @@ function newMultiSelect(Table, Checkbox) { // } if (this.props.data != nextProps.data) { this.setState({ - data: (0, _utils.ObjectAssign)(nextProps.data) + data: (0, _util.ObjectAssign)(nextProps.data) }); } }; diff --git a/build/lib/util.js b/build/lib/util.js index c22dfd2..9ea2e19 100644 --- a/build/lib/util.js +++ b/build/lib/util.js @@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + exports.sortBy = sortBy; exports.compare = compare; +exports.ObjectAssign = ObjectAssign; /* * 快速排序,按某个属性,或按“获取排序依据的函数”,来排序. * @method soryBy @@ -52,4 +56,24 @@ function compare(property) { var value2 = b[property]; return value1 - value2; }; +} + +/** + * 简单数组数据对象拷贝 + * @param {*} obj 要拷贝的对象 + */ +function ObjectAssign(obj) { + var b = obj instanceof Array; + var tagObj = b ? [] : {}; + if (b) { + //数组 + obj.forEach(function (da) { + var _da = {}; + _extends(_da, da); + tagObj.push(_da); + }); + } else { + _extends(tagObj, obj); + } + return tagObj; } \ No newline at end of file diff --git a/package.json b/package.json index a14abc1..7a479aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bee-table", - "version": "1.3.7", + "version": "1.3.8", "description": "Table ui component for react", "keywords": [ "react",