UNPKG

micro-ui-y

Version:

139 lines (104 loc) 6.22 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); require('./test.css'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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) : subClass.__proto__ = superClass; } // 在拖动目标上触发事件 (源元素) // ondragstart - 用户开始拖动元素时触发 // ondrag - 元素正在拖动时触发 // ondragend - 用户完成元素拖动后触发 // 释放目标时触发的事件: // ondragenter - 当被鼠标拖动的对象进入其容器范围内时触发此事件 // ondragover - 当某被拖动的对象在另一对象容器范围内拖动时触发此事件 // ondragleave - 当被鼠标拖动的对象离开其容器范围内时触发此事件 // ondrop - 在一个拖动过程中,释放鼠标键时触发此事件 // const list = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"]; var list = ["IDE", "毕生云编辑器", "3MS知识云", "安全自助平台", "ERP", "IT管理部"]; var Test = function (_React$Component) { _inherits(Test, _React$Component); function Test() { var _ref; var _temp, _this, _ret; _classCallCheck(this, Test); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Test.__proto__ || Object.getPrototypeOf(Test)).call.apply(_ref, [this].concat(args))), _this), _this.state = { dragElement: "" }, _this.onDragStartFn = function (item, e) { console.log('ondragstartFn', e); _this.setState({ dragElement: item }); }, _this.onDragEndFn = function (item, e) { console.log('ondragend', e); if (_this.state.dragElement != _this.state.moveElement) { var indexDrag = list.indexOf(_this.state.dragElement); list.splice(indexDrag, 1); var indexMove = list.indexOf(_this.state.moveElement); list.splice(indexMove, 0, _this.state.dragElement); } _this.setState({ dragElement: "", moveElement: "" }); }, _this.onDragEnterFn = function (item, e) { console.log('ondragenter', e); _this.setState({ moveElement: item }); }, _this.onDragOverFn = function (item, e) { console.log('ondragover', e); }, _this.onDragLeaveFn = function (item, e) { console.log('ondragleave', e); }, _this.onDragFn = function (item, e) { console.log('ondrop', e); }, _temp), _possibleConstructorReturn(_this, _ret); } //用户开始拖动元素时触发 //用户完成元素拖动后触发 // 当被鼠标拖动的对象进入其容器范围内时触发此事件 //当某被拖动的对象在另一对象容器范围内拖动时触发此事件 //当被鼠标拖动的对象离开其容器范围内时触发此事件 //在一个拖动过程中,释放鼠标键时触发此事件 _createClass(Test, [{ key: 'render', value: function render() { var _this2 = this; return _react2.default.createElement( 'div', { className: 'task-wrapper' }, _react2.default.createElement( 'div', { className: 't-box' }, list.map(function (item, index) { return _react2.default.createElement( 'div', { key: index, className: _this2.state.dragElement == item ? "t-item drag" : _this2.state.moveElement == item ? "t-item move" : "t-item", onDragStart: _this2.onDragStartFn.bind(_this2, item), onDragEnd: _this2.onDragEndFn.bind(_this2, item), onDragEnter: _this2.onDragEnterFn.bind(_this2, item) // onDragOver={this.onDragOverFn.bind(this, item)} // onDragLeave={this.onDragLeaveFn.bind(this, item)} // onDrag={this.onDragFn.bind(this, item)} , draggable: 'true' }, item ); }) ) ); } }]); return Test; }(_react2.default.Component); exports.default = Test; //# sourceMappingURL=index.js.map