modal.jsx 1.19 KB
/*eslint-disable*/
import React, { PureComponent } from 'react';
import { Modal } from 'antd-mobile';

export default class ModalBase extends PureComponent {
    state = {
        visible: this.props.visible,
    }

    closeModal = () => {
        this.setState({ visible: false });
    }

    openModal = () => {
        this.setState({ visible: true });
    }

    render() {
        const { title, submitAction, content, cancelAction, ...others } = this.props;
        return <>
            <Modal
                bodyStyle={{
                    height: '60vh',
                }}
                transparent
                maskClosable={false}
                destroyOnClose
                title={title || ''}
                footer={[
                    { text: '取消', onPress: () => { typeof cancelAction === 'function' && cancelAction() } },
                    { text: '确认', onPress: () => { typeof submitAction === 'function' && submitAction() } },
                ]}
                { ...others }
            >
                <div style={{ height: '100%' }}>
                    {
                        content
                    }
                </div>
            </Modal>
        </>
    }
}