drawer closeWithConfirm props

This commit is contained in:
chenos 2021-05-26 09:10:20 +08:00
parent 60862736ea
commit 8fc5be634e
2 changed files with 12 additions and 11 deletions

View File

@ -11,7 +11,7 @@ group:
# Drawer - 抽屉 # Drawer - 抽屉
通过 `Drawer.open(props)` 方法打开抽屉,无需预渲染,可在任意触发事件中使用,多层抽屉的实现也更为巧妙 通过 `Drawer.open(props)` 方法打开抽屉,无需预渲染,可在触发事件中使用。
### 基础抽屉 ### 基础抽屉

View File

@ -5,6 +5,7 @@ import { DrawerProps } from 'antd/lib/drawer';
import { useContext } from 'react'; import { useContext } from 'react';
import { ConfigProvider } from 'antd'; import { ConfigProvider } from 'antd';
import zhCN from 'antd/lib/locale/zh_CN'; import zhCN from 'antd/lib/locale/zh_CN';
import { ModalFuncProps } from 'antd/lib/modal/Modal'
import isNum from 'lodash/isNumber'; import isNum from 'lodash/isNumber';
import isBool from 'lodash/isBoolean'; import isBool from 'lodash/isBoolean';
import isStr from 'lodash/isString'; import isStr from 'lodash/isString';
@ -89,7 +90,7 @@ export function Drawer(title: any, content: any): IDrawer {
render( render(
false, false,
() => { () => {
drawer.closeWithConfirm = false; drawer.closeWithConfirm = null;
drawer.close(); drawer.close();
}, },
() => { () => {
@ -100,7 +101,7 @@ export function Drawer(title: any, content: any): IDrawer {
render( render(
true, true,
() => { () => {
drawer.closeWithConfirm = false; drawer.closeWithConfirm = null;
drawer.close(); drawer.close();
}, },
() => { () => {
@ -113,11 +114,11 @@ export function Drawer(title: any, content: any): IDrawer {
if (!env.root) return; if (!env.root) return;
if (drawer.closeWithConfirm) { if (drawer.closeWithConfirm) {
Modal.confirm({ Modal.confirm({
title: drawer.closeWithConfirm === true ? '表单内容发生变化,确定不保存吗?' : drawer.closeWithConfirm.title,
okText: '确定', okText: '确定',
cancelText: '取消', cancelText: '取消',
...drawer.closeWithConfirm,
onOk() { onOk() {
drawer.closeWithConfirm = false; drawer.closeWithConfirm = null;
const els = document.querySelectorAll('.env-root-push'); const els = document.querySelectorAll('.env-root-push');
if (els.length) { if (els.length) {
const last = els[els.length - 1]; const last = els[els.length - 1];
@ -135,11 +136,11 @@ export function Drawer(title: any, content: any): IDrawer {
render(false); render(false);
} }
}, },
closeWithConfirm: false, closeWithConfirm: null,
}; };
const closeWithConfirm = (bool) => { const closeWithConfirm = (props) => {
drawer.closeWithConfirm = bool; drawer.closeWithConfirm = props;
}; };
const render = (visible = true, resolve?: () => any, reject?: () => any) => { const render = (visible = true, resolve?: () => any, reject?: () => any) => {
@ -192,12 +193,12 @@ const DrawerFooter: React.FC = (props) => {
interface ContentPorps { interface ContentPorps {
resolve?: () => any; resolve?: () => any;
closeWithConfirm?: (bool: boolean) => any; closeWithConfirm?: (props: ModalFuncProps) => any;
} }
Drawer.open = (props: DrawerProps & { content: (contentPorps?: ContentPorps) => any }) => { Drawer.open = (props: DrawerProps & { content: (contentPorps?: ContentPorps) => any }) => {
const { content, visible, ...rest } = props; const { content, visible, ...others } = props;
return Drawer(rest, content).open({ visible }); return Drawer(others, content).open({ visible });
}; };
Drawer.Footer = DrawerFooter; Drawer.Footer = DrawerFooter;