feat(支持节点双击事件): 节点双击事件

节点双击时,返回当前节点的key值和node信息
This commit is contained in:
wanghaoo 2018-04-08 15:29:15 +08:00
parent 54efd71c7e
commit ca8ddfcfb2
3 changed files with 30 additions and 3 deletions

View File

@ -340,6 +340,16 @@ var Tree = function (_React$Component) {
props.onSelect(selectedKeys, newSt); props.onSelect(selectedKeys, newSt);
}; };
Tree.prototype.onDoubleClick = function onDoubleClick(treeNode) {
var props = this.props;
var eventKey = treeNode.props.eventKey;
var newSt = {
event: 'dblclick',
node: treeNode
};
props.onDoubleClick(eventKey, newSt);
};
Tree.prototype.onMouseEnter = function onMouseEnter(e, treeNode) { Tree.prototype.onMouseEnter = function onMouseEnter(e, treeNode) {
this.props.onMouseEnter({ this.props.onMouseEnter({
event: e, event: e,
@ -528,6 +538,7 @@ var Tree = function (_React$Component) {
onMouseEnter: props.onMouseEnter, onMouseEnter: props.onMouseEnter,
onMouseLeave: props.onMouseLeave, onMouseLeave: props.onMouseLeave,
onRightClick: props.onRightClick, onRightClick: props.onRightClick,
onDoubleClick: props.onDoubleClick,
prefixCls: props.prefixCls, prefixCls: props.prefixCls,
showLine: props.showLine, showLine: props.showLine,
showIcon: props.showIcon, showIcon: props.showIcon,

View File

@ -53,7 +53,7 @@ var TreeNode = function (_React$Component) {
var _this2 = _possibleConstructorReturn(this, _React$Component.call(this, props)); var _this2 = _possibleConstructorReturn(this, _React$Component.call(this, props));
['onExpand', 'onCheck', 'onContextMenu', 'onMouseEnter', 'onMouseLeave', 'onDragStart', 'onDragEnter', 'onDragOver', 'onDragLeave', 'onDrop', 'onDragEnd'].forEach(function (m) { ['onExpand', 'onCheck', 'onContextMenu', 'onMouseEnter', 'onMouseLeave', 'onDragStart', 'onDragEnter', 'onDragOver', 'onDragLeave', 'onDrop', 'onDragEnd', 'onDoubleClick'].forEach(function (m) {
_this2[m] = _this2[m].bind(_this2); _this2[m] = _this2[m].bind(_this2);
}); });
_this2.state = { _this2.state = {
@ -77,11 +77,23 @@ var TreeNode = function (_React$Component) {
// } // }
TreeNode.prototype.onCheck = function onCheck() { TreeNode.prototype.onCheck = function onCheck() {
this.props.root.onCheck(this); this.props.root.onCheck(this);
}; };
TreeNode.prototype.onSelect = function onSelect() { TreeNode.prototype.onSelect = function onSelect() {
this.props.root.onSelect(this); clearTimeout(this.doubleClickFlag);
var _this = this;
//执行延时
this.doubleClickFlag = setTimeout(function () {
//do function在此处写单击事件要执行的代码
_this.props.root.onSelect(_this);
}, 300);
};
TreeNode.prototype.onDoubleClick = function onDoubleClick() {
clearTimeout(this.doubleClickFlag);
this.props.root.onDoubleClick(this);
}; };
TreeNode.prototype.onMouseEnter = function onMouseEnter(e) { TreeNode.prototype.onMouseEnter = function onMouseEnter(e) {
@ -360,6 +372,10 @@ var TreeNode = function (_React$Component) {
// } // }
}; };
if (props.onDoubleClick) {
domProps.onDoubleClick = _this4.onDoubleClick;
}
if (props.onRightClick) { if (props.onRightClick) {
domProps.onContextMenu = _this4.onContextMenu; domProps.onContextMenu = _this4.onContextMenu;
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "bee-tree", "name": "bee-tree",
"version": "1.1.0", "version": "1.1.1",
"description": "Tree ui component for react", "description": "Tree ui component for react",
"keywords": [ "keywords": [
"react", "react",