2020-08-31 16:53:19 +08:00
|
|
|
|
import classNames from '../_util/classNames';
|
2021-06-26 09:35:40 +08:00
|
|
|
|
import type { ModalFuncProps } from './Modal';
|
|
|
|
|
import Dialog from './Modal';
|
2019-01-12 11:33:27 +08:00
|
|
|
|
import ActionButton from './ActionButton';
|
|
|
|
|
import { getConfirmLocale } from './locale';
|
2021-09-08 17:12:11 +08:00
|
|
|
|
import { FunctionalComponent } from 'vue';
|
2018-03-06 19:14:41 +08:00
|
|
|
|
|
2020-10-19 23:09:36 +08:00
|
|
|
|
interface ConfirmDialogProps extends ModalFuncProps {
|
|
|
|
|
afterClose?: () => void;
|
2021-09-08 17:12:11 +08:00
|
|
|
|
close?: (...args: any[]) => void;
|
2020-10-19 23:09:36 +08:00
|
|
|
|
autoFocusButton?: null | 'ok' | 'cancel';
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 17:12:11 +08:00
|
|
|
|
function renderSomeContent(_name, someContent) {
|
|
|
|
|
if (typeof someContent === 'function') {
|
|
|
|
|
return someContent();
|
|
|
|
|
}
|
|
|
|
|
return someContent;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-19 23:09:36 +08:00
|
|
|
|
const ConfirmDialog: FunctionalComponent<ConfirmDialogProps> = props => {
|
2020-06-15 23:47:49 +08:00
|
|
|
|
const {
|
|
|
|
|
icon,
|
|
|
|
|
onCancel,
|
|
|
|
|
onOk,
|
|
|
|
|
close,
|
2021-03-27 22:03:23 +08:00
|
|
|
|
closable = false,
|
2020-06-15 23:47:49 +08:00
|
|
|
|
zIndex,
|
|
|
|
|
afterClose,
|
|
|
|
|
visible,
|
|
|
|
|
keyboard,
|
|
|
|
|
centered,
|
|
|
|
|
getContainer,
|
|
|
|
|
maskStyle,
|
|
|
|
|
okButtonProps,
|
|
|
|
|
cancelButtonProps,
|
2020-10-19 23:09:36 +08:00
|
|
|
|
// closable = false,
|
|
|
|
|
} = props;
|
|
|
|
|
const okType = props.okType || 'primary';
|
|
|
|
|
const prefixCls = props.prefixCls || 'ant-modal';
|
2020-06-15 23:47:49 +08:00
|
|
|
|
const contentPrefixCls = `${prefixCls}-confirm`;
|
|
|
|
|
// 默认为 true,保持向下兼容
|
2020-10-19 23:09:36 +08:00
|
|
|
|
const okCancel = 'okCancel' in props ? props.okCancel : true;
|
|
|
|
|
const width = props.width || 416;
|
|
|
|
|
const style = props.style || {};
|
|
|
|
|
const mask = props.mask === undefined ? true : props.mask;
|
2020-06-15 23:47:49 +08:00
|
|
|
|
// 默认为 false,保持旧版默认行为
|
2020-10-19 23:09:36 +08:00
|
|
|
|
const maskClosable = props.maskClosable === undefined ? false : props.maskClosable;
|
2020-06-15 23:47:49 +08:00
|
|
|
|
const runtimeLocale = getConfirmLocale();
|
2021-09-08 17:12:11 +08:00
|
|
|
|
const okText =
|
|
|
|
|
renderSomeContent('okText', props.okText) ||
|
|
|
|
|
(okCancel ? runtimeLocale.okText : runtimeLocale.justOkText);
|
|
|
|
|
const cancelText = renderSomeContent('cancelText', props.cancelText) || runtimeLocale.cancelText;
|
2020-10-19 23:09:36 +08:00
|
|
|
|
const autoFocusButton = props.autoFocusButton === null ? false : props.autoFocusButton || 'ok';
|
|
|
|
|
const transitionName = props.transitionName || 'zoom';
|
|
|
|
|
const maskTransitionName = props.maskTransitionName || 'fade';
|
2018-03-06 19:14:41 +08:00
|
|
|
|
|
2020-06-15 23:47:49 +08:00
|
|
|
|
const classString = classNames(
|
|
|
|
|
contentPrefixCls,
|
2020-10-19 23:09:36 +08:00
|
|
|
|
`${contentPrefixCls}-${props.type}`,
|
|
|
|
|
`${prefixCls}-${props.type}`,
|
|
|
|
|
props.class,
|
2020-06-15 23:47:49 +08:00
|
|
|
|
);
|
2018-03-06 19:14:41 +08:00
|
|
|
|
|
2020-06-15 23:47:49 +08:00
|
|
|
|
const cancelButton = okCancel && (
|
|
|
|
|
<ActionButton
|
|
|
|
|
actionFn={onCancel}
|
|
|
|
|
closeModal={close}
|
2020-07-17 17:36:58 +08:00
|
|
|
|
autofocus={autoFocusButton === 'cancel'}
|
2020-06-15 23:47:49 +08:00
|
|
|
|
buttonProps={cancelButtonProps}
|
|
|
|
|
>
|
|
|
|
|
{cancelText}
|
|
|
|
|
</ActionButton>
|
|
|
|
|
);
|
2018-03-06 19:14:41 +08:00
|
|
|
|
|
2020-06-15 23:47:49 +08:00
|
|
|
|
return (
|
|
|
|
|
<Dialog
|
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
|
class={classString}
|
|
|
|
|
wrapClassName={classNames({ [`${contentPrefixCls}-centered`]: !!centered })}
|
|
|
|
|
onCancel={e => close({ triggerCancel: true }, e)}
|
|
|
|
|
visible={visible}
|
|
|
|
|
title=""
|
|
|
|
|
transitionName={transitionName}
|
|
|
|
|
footer=""
|
|
|
|
|
maskTransitionName={maskTransitionName}
|
|
|
|
|
mask={mask}
|
|
|
|
|
maskClosable={maskClosable}
|
|
|
|
|
maskStyle={maskStyle}
|
|
|
|
|
style={style}
|
|
|
|
|
width={width}
|
|
|
|
|
zIndex={zIndex}
|
|
|
|
|
afterClose={afterClose}
|
|
|
|
|
keyboard={keyboard}
|
|
|
|
|
centered={centered}
|
|
|
|
|
getContainer={getContainer}
|
2021-03-27 22:03:23 +08:00
|
|
|
|
closable={closable}
|
2020-06-15 23:47:49 +08:00
|
|
|
|
>
|
|
|
|
|
<div class={`${contentPrefixCls}-body-wrapper`}>
|
|
|
|
|
<div class={`${contentPrefixCls}-body`}>
|
2021-09-08 17:12:11 +08:00
|
|
|
|
{renderSomeContent('icon', icon)}
|
2020-10-19 23:09:36 +08:00
|
|
|
|
{props.title === undefined ? null : (
|
2021-09-08 17:12:11 +08:00
|
|
|
|
<span class={`${contentPrefixCls}-title`}>
|
|
|
|
|
{renderSomeContent('title', props.title)}
|
|
|
|
|
</span>
|
2020-06-15 23:47:49 +08:00
|
|
|
|
)}
|
2021-09-08 17:12:11 +08:00
|
|
|
|
<div class={`${contentPrefixCls}-content`}>
|
|
|
|
|
{renderSomeContent('content', props.content)}
|
|
|
|
|
</div>
|
2018-03-06 19:14:41 +08:00
|
|
|
|
</div>
|
2020-06-15 23:47:49 +08:00
|
|
|
|
<div class={`${contentPrefixCls}-btns`}>
|
|
|
|
|
{cancelButton}
|
|
|
|
|
<ActionButton
|
|
|
|
|
type={okType}
|
|
|
|
|
actionFn={onOk}
|
|
|
|
|
closeModal={close}
|
2020-07-17 17:36:58 +08:00
|
|
|
|
autofocus={autoFocusButton === 'ok'}
|
2020-06-15 23:47:49 +08:00
|
|
|
|
buttonProps={okButtonProps}
|
|
|
|
|
>
|
|
|
|
|
{okText}
|
|
|
|
|
</ActionButton>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2020-10-19 23:09:36 +08:00
|
|
|
|
|
2020-06-15 23:47:49 +08:00
|
|
|
|
ConfirmDialog.inheritAttrs = false;
|
2020-10-19 23:09:36 +08:00
|
|
|
|
|
2020-06-15 23:47:49 +08:00
|
|
|
|
export default ConfirmDialog;
|