import React from 'react'; import ReactDOM from 'react-dom'; import Dialog from './Modal'; import Icon from '../icon'; import Button from '../button'; import objectAssign from 'object-assign'; const defaultLocale = { okText: '确定', cancelText: '取消', justOkText: '知道了', }; let runtimeLocale = { ...defaultLocale }; export function changeConfirmLocale(newLocale) { if (newLocale) { objectAssign(runtimeLocale, newLocale); } else { runtimeLocale = { ...defaultLocale }; } } export default function confirm(config) { const props = objectAssign({}, config); let div = document.createElement('div'); document.body.appendChild(div); let d; props.iconClassName = props.iconClassName || 'question-circle'; let iconClassType = props.iconClassName; let width = props.width || 416; // 默认为 true,保持向下兼容 if (!('okCancel' in props)) { props.okCancel = true; } props.okText = props.okText || (props.okCancel ? runtimeLocale.okText : runtimeLocale.justOkText); props.cancelText = props.cancelText || runtimeLocale.cancelText; function close() { d.setState({ visible: false, }); ReactDOM.unmountComponentAtNode(div); div.parentNode.removeChild(div); } function onCancel() { let cancelFn = props.onCancel; if (cancelFn) { let ret; if (cancelFn.length) { ret = cancelFn(close); } else { ret = cancelFn(); if (!ret) { close(); } } if (ret && ret.then) { ret.then(close); } } else { close(); } } function onOk() { let okFn = props.onOk; if (okFn) { let ret; if (okFn.length) { ret = okFn(close); } else { ret = okFn(); if (!ret) { close(); } } if (ret && ret.then) { ret.then(close); } } else { close(); } } let body = (