@reacted/bootstrap-react-component-examples
Version:
选择数据的树结构组件
87 lines (70 loc) • 2.23 kB
JavaScript
import "core-js/modules/es6.promise";
import "core-js/modules/web.dom.iterable";
import "core-js/modules/es6.array.iterator";
import "core-js/modules/es6.object.to-string";
import "core-js/modules/es6.string.iterator";
import "core-js/modules/es6.regexp.match";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import React from 'react';
var currentPage = '$$currentPage';
var df = 'default';
var PageProxy =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(PageProxy, _React$Component);
function PageProxy() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
_this.state = {
hasError: false
};
return _this;
}
var _proto = PageProxy.prototype;
_proto.getPagePath = function getPagePath() {
var url = this.props.match.url;
return url.substr(1) || 'default';
};
PageProxy.getDerivedStateFromError = function getDerivedStateFromError(error) {
return {
hasError: true,
error: error
};
};
_proto.render = function render() {
var state = this.state;
var Page = state[this.getPagePath()];
if (Page) {
return React.createElement(Page, this.props);
}
this.loadAsyncPages(this.getPagePath());
return React.createElement("div", null, "\u52A0\u8F7D\u4E2D");
};
_proto.loadAsyncPages = function loadAsyncPages(path) {
var _this2 = this;
Promise.all([import(
/* webpackMode: "lazy", webpackChunkName: "[request]" */
"_/examples/" + path + "/index")]).then(function (_ref) {
var loadedModule = _ref[0];
var needUpdate = false;
var updateData = {};
var PageComponent = loadedModule[df];
if (PageComponent) {
needUpdate = true;
updateData[path] = PageComponent;
}
if (_this2.state[currentPage] !== path) {
needUpdate = true;
updateData[currentPage] = path;
}
if (needUpdate) {
_this2.setState(updateData);
}
});
};
return PageProxy;
}(React.Component);
export { PageProxy as default };