1. import React from 'react';
    2. import {Modal} from 'antd';
    3. import hint2 from '../../../images/hint2.png';
    4. import style from './style';
    5. /**
    6. * 直接在点击事件调用这个方法
    7. *
    8. *
    9. const data = {
    10. title: '提示',
    11. content: '您还未保存页面内容,确定需要离开吗?',
    12. okText: '保存离开',
    13. cancelText: '不保存离开'
    14. };
    15. ConfirmModal(
    16. data,
    17. close => {
    18. console.log(1);
    19. close();
    20. },
    21. close => {
    22. console.log(2);
    23. close();
    24. }
    25. );
    26. * */
    27. export default function ConfirmModal(props, ok, no) {
    28. const ModalCon = Modal.confirm({
    29. ...props,
    30. title: props?.title || '标题',
    31. icon: <img src={hint2} className="icon" />,
    32. content: props?.content || '内容',
    33. okText: props?.okText || '确定',
    34. className: style.ConfirmModal,
    35. cancelText: props?.cancelText || '取消',
    36. onOk: close => {
    37. ModalCon.update({
    38. okButtonProps: {loading: true}
    39. });
    40. ok ? ok(() => close()) : close();
    41. },
    42. onCancel: close => {
    43. no ? no(() => close()) : close();
    44. }
    45. });
    46. return ModalCon;
    47. }
    1. .ConfirmModal {
    2. :global {
    3. .ant-modal-content {
    4. width: 384px;
    5. height: 178px;
    6. }
    7. .ant-modal-body {
    8. padding: 42px 24px 20px 40px;
    9. }
    10. .ant-modal-confirm-btns {
    11. margin-top: 13px;
    12. }
    13. .ant-modal-confirm-title {
    14. margin-left: 10px;
    15. display: inline-block !important;
    16. vertical-align: bottom;
    17. font-size: 14px !important;
    18. font-weight: bold !important;
    19. color: rgba(0, 0, 0, 0.85) !important;
    20. }
    21. .ant-modal-confirm-content {
    22. font-size: 13px !important;
    23. font-weight: 400 !important;
    24. color: rgba(0, 0, 0, 0.65) !important;
    25. margin-left: 26px;
    26. }
    27. .ant-checkbox-checked::after {
    28. position: absolute;
    29. top: 0;
    30. left: -1px;
    31. width: 100%;
    32. height: 100%;
    33. border: 1px solid #1890ff;
    34. border-radius: 2px;
    35. visibility: hidden;
    36. animation: antCheckboxEffect 0.36s ease-in-out;
    37. animation-fill-mode: backwards;
    38. content: '';
    39. }
    40. }
    41. }
    1. import ConfirmModal from '../....'
    2. const data = {
    3. title: '提示',
    4. content: '您还未保存页面内容,确定需要离开吗?',
    5. okText: '保存离开',
    6. cancelText: '不保存离开'
    7. };
    8. ConfirmModal(
    9. data,
    10. close => {
    11. close();
    12. },
    13. close => {
    14. close();
    15. }
    16. );