@doreamonjs/gate
Version:
gate for doreamonjs
167 lines • 6.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
const dva_1 = require("dva");
const icons_1 = require("@ant-design/icons");
const antd_1 = require("antd");
const antd_2 = require("antd");
const dialog = tslib_1.__importStar(require("@doreamonjs/plugin-dialog"));
const mapState = (states) => {
const { visible, attributes, datasets } = states[dialog.NAMESPACE];
const { target = {} } = attributes;
const nextEffect = `${target.namespace}/${target.effect}`;
const loading = states.loading.effects[nextEffect];
return {
...attributes,
...datasets,
//
visible,
loading,
//
values: datasets.values,
};
};
const mapActions = (dispatch) => ({
// onValueChange: (name: string, value: any) => dispatch({ type: `${dialog.NAMESPACE}/value/change`, payload: { [name]: value } }),
onCancel: () => dispatch({ type: `${dialog.NAMESPACE}/cancel` }),
onSubmit: (values, lastValues) => dispatch({
type: `${dialog.NAMESPACE}/submit`,
payload: { values, lastValues },
}),
});
let ZDialog = class ZDialog extends react_1.PureComponent {
constructor() {
super(...arguments);
this.state = {};
this.ref = react_1.createRef();
this.onSubmit = () => {
var _a, _b;
const { values, onSubmit } = this.props;
// validate
if ((_b = (_a = this.ref) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.validateFields) {
this.ref.current.validateFields((err, values) => {
if (err) {
return;
}
onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit({
...values,
...this.state,
}, values);
});
return;
}
onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit({
...values,
...this.state,
}, values);
};
this.onChange = (values) => {
this.setState(values);
};
}
get modalProps() {
var _a, _b;
const props = this.props;
const _props = {
confirmLoading: props.loading,
width: (_a = props === null || props === void 0 ? void 0 : props.width) !== null && _a !== void 0 ? _a : 700,
bodyStyle: {
height: (_b = props === null || props === void 0 ? void 0 : props.height) !== null && _b !== void 0 ? _b : 500,
overflow: 'hidden',
overflowY: 'auto',
},
title: props.title,
visible: props.visible,
onOk: this.onSubmit,
onCancel: props.onCancel,
cancelText: props.cancelText,
okText: props.submitText,
// title: props.hideHeader ? null : undefined,
// footer: props.hideFooter ? null : undefined,
maskClosable: props.maskClosable,
};
if (props.hideHeader) {
_props.title = null;
}
if (props.hideFooter) {
_props.footer = null;
}
if (props.hideClose) {
_props.closable = false;
}
if (!!props.alwaysRecreate) {
_props.key = String(Math.random());
}
return _props;
}
get renderOptions() {
return {
ref: this.ref,
};
}
get drawerProps() {
var _a;
const props = this.props;
const _props = {
placement: props.placement,
confirmLoading: props.loading,
visible: props.visible,
width: (_a = props === null || props === void 0 ? void 0 : props.width) !== null && _a !== void 0 ? _a : 900,
title: props.title,
onOk: this.onSubmit,
onClose: props.onCancel,
cancelText: props.cancelText,
okText: props.submitText,
bodyStyle: {
position: 'relative',
},
//
maskClosable: props.maskClosable,
};
if (!!props.noPadding) {
_props.bodyStyle.padding = 0;
}
if (!!props.alwaysRecreate) {
_props.key = String(Math.random());
}
return _props;
}
render() {
const { visible, type, values, fullscreen, render } = this.props;
if (!!fullscreen) {
if (!visible) {
return null;
}
return (react_1.default.createElement("div", { style: {
position: 'fixed',
top: 0,
left: 0,
width: '100vw',
height: '100vh',
zIndex: 9999,
} },
react_1.default.createElement(icons_1.CloseOutlined, { style: {
position: 'absolute',
right: 17,
top: 17,
zIndex: 1,
cursor: 'pointer',
color: '#000',
}, title: "close", onClick: this.props.onCancel }), render === null || render === void 0 ? void 0 :
render(values, this.onChange, this.renderOptions)));
}
if (type === 'drawer') {
return (react_1.default.createElement(antd_2.Drawer, { ...this.drawerProps }, render === null || render === void 0 ? void 0 : render(values, this.onChange, this.renderOptions)));
}
return (react_1.default.createElement(antd_1.Modal, { ...this.modalProps }, render === null || render === void 0 ? void 0 : render(values, this.onChange, this.renderOptions)));
}
};
ZDialog.defaultProps = {
type: 'modal',
};
ZDialog = tslib_1.__decorate([
dva_1.connect(mapState, mapActions)
], ZDialog);
exports.default = ZDialog;
//# sourceMappingURL=index.js.map