123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- import React, { Component } from 'react';
- import styles from './index.less';
- import NewPortal from './NewPortal'
- import PropTypes from 'prop-types';
- import close from "../../images/close1.png";
- import icon1 from '../../images/icon.png'
- /***
- * 弹窗组件
- * author:zxc@2018-11-19
- * 接收参数:
- * visible: Boolean,对话框是否可见
- * title: 弹窗标题, String
- * titleBg: 标题背景颜色
- * children: 包含的子组件
- * noFooter: 是否包含底部,Boolean, 默认为false
- * confirm: 点击确认回调
- * close:点击遮罩层或右上角叉
- * cancel: 点击取消按钮的回调
- * closable: 是否显示右上角的关闭按钮, Boolean, 默认为true
- * mask:是否显示遮罩, Boolean, 默认为true
- * maskClosable: 点击蒙层是否允许关闭, Boolean, 默认为false
- * okText: 确认按钮文字,String,默认为确认
- * okColor: 确认按钮文字颜色
- * okBorderColor: 确认按钮边框颜色
- * oKBg: 确认按钮背景颜色
- * cancelText: 取消按钮文字, String,默认为取消
- * cancelColor: 取消按钮文字颜色
- * cancelBorderColor:取消按钮边框颜色
- * cancelBg: 取消按钮背景颜色
- * width: 宽度, string|number, 默认为300
- * height: 弹窗高度, string|number, 默认为200
- ***/
- const propTypes = {
- visible: PropTypes.bool,
- confirm: PropTypes.func,
- cancel: PropTypes.func,
- close: PropTypes.func,
- title: PropTypes.string,
- titleBg: PropTypes.string,
- noFooter: PropTypes.bool,
- okText: PropTypes.string,
- okType:PropTypes.string,
- cancelText: PropTypes.string,
- }
- const defaultProps = {
- titleBg: '#fff',
- noFooter: false,
- mask: true,
- maskClosable: true,
- closable: true,
- okText: '确认',
- okType:'normal', //normal蓝色,danger红色
- cancelText: '取消',
- width: '400px',
- height: '204px',
- };
- class ConfirmModal extends Component {
- constructor(props) {
- super(props);
- this.confirm = this.confirm.bind(this);
- this.cancel = this.cancel.bind(this);
- this.maskClick = this.maskClick.bind(this);
- this.closeModal = this.closeModal.bind(this)
- }
-
-
- closeModal() {
- const { close } = this.props
- close && close()
- }
- confirm() {
- const { confirm } = this.props
- confirm && confirm()
- }
- cancel() {
- const { cancel } = this.props
- cancel && cancel()
- }
- maskClick() {
- const { close } = this.props
- close && close()
- }
- render() {
- const {
- visible,
- title,
- titleBg,
- children,
- mask,
- maskClosable,
- okText,
- okType,
- cancelText,
- width,
- height,
- closable,
- noFooter,
- icon,
- } = this.props;
- const marginLeft = -parseInt(width)/2
- const marginTop = -parseInt(height)/2
- return (
- <NewPortal visible={visible}>
- <div className={styles['modal-wrapper']} id='confirm'>
- <div className={styles[['modal']]} style = {{width: width, marginLeft:marginLeft, minHeight:height, marginTop:marginTop}}>
- <div className={styles['modal-title']} style={{background: titleBg}}>
- {icon?<img src={icon} className={styles['icon']}/>:''}
- {title ? title : ''}
- {closable ? <img onClick={this.closeModal} className={styles['modal-close']} src = {close}/> : false}
- </div>
- <div className={styles['modal-content']}><img src={icon1}/>{children}</div>
- {noFooter ? '' : <div className={styles['modal-operator']+' clearfix'}>
- <div className={styles['modal-btn-box']}>
- <div
- onClick={this.confirm}
- className={styles['modal-operator-confirm']+" "+styles[okType]}>
- { okText}
- </div>
- </div>
- <div className={styles['modal-btn-box']}>
- <div
- onClick={this.cancel}
- className={styles['modal-operator-close']}>
- { cancelText}
- </div>
- </div>
- </div>}
- </div>
- {mask ? <div className={styles['mask']}
- onClick = {maskClosable === true ? this.maskClick : ()=>{}}
- ></div> : ''}
- </div>
- </NewPortal>
- )
- }
- }
- ConfirmModal.propTypes = propTypes;
- ConfirmModal.defaultProps = defaultProps;
- export default ConfirmModal;
|