@doreamonjs/gate
Version:
gate for doreamonjs
94 lines • 3.29 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 antd_1 = require("antd");
const antd_2 = require("antd");
const popup = tslib_1.__importStar(require("@doreamonjs/plugin-popup"));
const mapState = (states) => {
const { visible, attributes, datasets } = states[popup.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: `${popup.NAMESPACE}/value/change`, payload: { [name]: value } }),
onClose: () => dispatch({ type: `${popup.NAMESPACE}/close` }),
onSubmit: (values, lastValues) => dispatch({
type: `${popup.NAMESPACE}/submit`,
payload: { values, lastValues },
}),
});
let ZPopup = class ZPopup extends react_1.PureComponent {
constructor() {
super(...arguments);
this.state = {};
this.onSubmit = () => {
const { values, onSubmit } = this.props;
onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit({
...values,
...this.state,
}, values);
};
this.onChange = (values) => {
this.setState(values);
};
}
get modalProps() {
var _a;
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: 'auto',
overflow: 'hidden',
overflowY: 'auto',
},
visible: props.visible,
onOk: this.onSubmit,
onCancel: props.onClose,
title: null,
footer: null,
closable: false,
};
return _props;
}
get drawerProps() {
var _a;
const props = this.props;
return {
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.onClose,
};
}
render() {
const { type, values, render } = this.props;
if (type === 'drawer') {
return (react_1.default.createElement(antd_2.Drawer, { ...this.drawerProps }, render === null || render === void 0 ? void 0 : render(values, this.onChange)));
}
return (react_1.default.createElement(antd_1.Modal, { ...this.modalProps }, render === null || render === void 0 ? void 0 : render(values, this.onChange)));
}
};
ZPopup.defaultProps = {
type: 'modal',
};
ZPopup = tslib_1.__decorate([
dva_1.connect(mapState, mapActions)
], ZPopup);
exports.default = ZPopup;
//# sourceMappingURL=index.js.map