UNPKG

@doreamonjs/gate

Version:
118 lines (117 loc) 4.63 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 antd_1 = require("antd"); const antd_2 = require("antd"); const popup = __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 = __decorate([ dva_1.connect(mapState, mapActions) ], ZPopup); exports.default = ZPopup;