@flatbiz/antd
Version:
93 lines (89 loc) • 3.12 kB
JavaScript
/*! @flatjs/forge MIT @flatbiz/antd */
import { e as _inherits, f as _createClass, g as _classCallCheck, h as _callSuper, i as _defineProperty } from './_rollupPluginBabelHelpers-BYm17lo8.js';
import * as React from 'react';
import { Alert, Button } from 'antd';
import { isUndefinedOrNull } from '@flatbiz/utils';
import { F as FlexLayout } from './flex-layout-BaDncU_Z.js';
import { jsx, jsxs } from 'react/jsx-runtime';
var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
function ErrorBoundary() {
var _this;
_classCallCheck(this, ErrorBoundary);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, ErrorBoundary, [].concat(args));
_defineProperty(_this, "state", {
error: undefined,
info: {
componentStack: ''
}
});
return _this;
}
_inherits(ErrorBoundary, _React$Component);
return _createClass(ErrorBoundary, [{
key: "componentDidCatch",
value: function componentDidCatch(error, info) {
this.setState({
error: error,
info: info
});
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
message = _this$props.message,
description = _this$props.description,
children = _this$props.children,
onRenderReset = _this$props.onRenderReset;
var _this$state = this.state,
error = _this$state.error,
info = _this$state.info;
var componentStack = info && info.componentStack ? info.componentStack : null;
var errorMessage = typeof message === 'undefined' ? (error || '').toString() : message;
var errorDescription = typeof description === 'undefined' ? componentStack : description;
var stackMaxHeight = isUndefinedOrNull(this.props.stackMaxHeight) ? 200 : this.props.stackMaxHeight;
if (error) {
return /*#__PURE__*/jsx(Alert, {
type: "error",
message: /*#__PURE__*/jsxs(FlexLayout, {
fullIndex: 0,
direction: "horizontal",
children: [/*#__PURE__*/jsx("span", {
children: errorMessage
}), /*#__PURE__*/jsx(Button, {
type: "primary",
ghost: true,
size: "small",
onClick: onRenderReset,
children: "\u91CD\u7F6E"
})]
}),
description: /*#__PURE__*/jsx(React.Fragment, {
children: /*#__PURE__*/jsx("div", {
style: {
maxHeight: stackMaxHeight,
overflow: 'auto'
},
children: /*#__PURE__*/jsx("pre", {
style: {
fontSize: '0.9em'
},
children: errorDescription
})
})
})
});
}
return children;
}
}]);
}(React.Component);
/**
* react 异常拦截
*/
var ErrorBoundaryWrapper = ErrorBoundary;
export { ErrorBoundaryWrapper as E };
//# sourceMappingURL=error-boundary-DtShAEtQ.js.map