UNPKG

@doreamonjs/gate

Version:
191 lines (190 loc) 7.47 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_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 = __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 = __decorate([ dva_1.connect(mapState, mapActions) ], ZDialog); exports.default = ZDialog;