UNPKG

qm-ui

Version:

千米公有云管理端UI基础组件库

167 lines (135 loc) 6.45 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = undefined; var _icon = require('antd/lib/icon'); var _icon2 = _interopRequireDefault(_icon); 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 _class, _temp2; var _react = require('react'); var _react2 = _interopRequireDefault(_react); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } 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; } /** * QMModal */ var QMModal = (_temp2 = _class = function (_Component) { _inherits(QMModal, _Component); function QMModal() { var _ref, _this2 = this; var _temp, _this, _ret; _classCallCheck(this, QMModal); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = QMModal.__proto__ || Object.getPrototypeOf(QMModal)).call.apply(_ref, [this].concat(args))), _this), _this.close = function (e, key) { var _this$props = _this.props, index = _this$props.index, nodes = _this$props.nodes; if (key == 'all') { // 关闭所有 Object.getOwnPropertyNames(nodes).forEach(function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(k) { return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return _this.move(nodes[k], 'close'); case 2: case 'end': return _context.stop(); } } }, _callee, _this2); })); return function (_x) { return _ref2.apply(this, arguments); }; }()); setTimeout(function () { return _this.props.close(e, 'all'); }, 382); } else { // 默认关闭当前;为防止越权,暂时不开放关闭其他弹层 _this.move(nodes[index], 'close'); setTimeout(function () { return _this.props.close(e, index); }, 382); } }, _this.move = function (node, flag) { node.setAttribute('class', 'qm-modal ' + (flag == 'open' ? 'show-modal' : '')); }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(QMModal, [{ key: 'componentDidMount', value: function componentDidMount() { var _this3 = this; var _props = this.props, index = _props.index, nodes = _props.nodes; setTimeout(function () { _this3.move(nodes[index], 'open'); }, 10); } }, { key: 'render', value: function render() { var _this4 = this; var _props2 = this.props, index = _props2.index, bottom = _props2.bottom, style = _props2.style, fail = _props2.fail, maskClosable = _props2.maskClosable, _props2$WrapperClassN = _props2.WrapperClassName, WrapperClassName = _props2$WrapperClassN === undefined ? '' : _props2$WrapperClassN; return _react2.default.createElement( 'div', { id: index, className: 'qm-modal ' + WrapperClassName, style: style }, bottom ? _react2.default.createElement('div', { className: 'qm-modal-mask', onClick: function onClick(e) { maskClosable ? _this4.close(e, 'all') : void 0; } }) : null, _react2.default.createElement( 'div', { className: 'qm-modal-main' }, _react2.default.createElement( 'button', { className: 'qm-modal-close', onClick: this.close }, _react2.default.createElement(_icon2.default, { type: bottom ? 'close' : 'left' }) ), _react2.default.createElement( 'div', { className: 'qm-modal-body' }, _react2.default.cloneElement(this.props.children, { close: this.close, fail: fail }) ) ) ); } /** * 关闭弹窗 * @param e any */ /** * @param node * @param flag "open" || "close" */ }]); return QMModal; }(_react.Component), _class.defaultProps = { index: '', nodes: {}, bottom: true, // 低层 maskClosable: true, //点击蒙层是否允许关闭 fail: function fail() {}, // fail close: function close() {} // close }, _temp2); exports.default = QMModal;