feat: add prompt to save when closing the form
This commit is contained in:
parent
cbb95bfb6f
commit
7a4e047910
@ -1,6 +1,7 @@
|
|||||||
import React, { useState, useEffect, useImperativeHandle, forwardRef, useRef } from 'react';
|
import React, { useState, useEffect, useImperativeHandle, forwardRef, useRef } from 'react';
|
||||||
import { Button, Drawer } from 'antd';
|
import { Button, Drawer } from 'antd';
|
||||||
import { Tooltip, Input, Space } from 'antd';
|
import { Tooltip, Input, Space, Modal } from 'antd';
|
||||||
|
import isEqual from 'lodash/isEqual';
|
||||||
import {
|
import {
|
||||||
SchemaForm,
|
SchemaForm,
|
||||||
SchemaMarkupField as Field,
|
SchemaMarkupField as Field,
|
||||||
@ -18,6 +19,8 @@ import { useRequest } from 'umi';
|
|||||||
import api from '@/api-client';
|
import api from '@/api-client';
|
||||||
import { Spin } from '@nocobase/client';
|
import { Spin } from '@nocobase/client';
|
||||||
|
|
||||||
|
const actions = createFormActions();
|
||||||
|
|
||||||
export default forwardRef((props: any, ref) => {
|
export default forwardRef((props: any, ref) => {
|
||||||
console.log(props);
|
console.log(props);
|
||||||
const {
|
const {
|
||||||
@ -37,7 +40,6 @@ export default forwardRef((props: any, ref) => {
|
|||||||
setTitle,
|
setTitle,
|
||||||
setIndex,
|
setIndex,
|
||||||
}));
|
}));
|
||||||
const actions = createFormActions();
|
|
||||||
console.log({onFinish});
|
console.log({onFinish});
|
||||||
const { fields = {} } = schema;
|
const { fields = {} } = schema;
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@ -51,7 +53,18 @@ export default forwardRef((props: any, ref) => {
|
|||||||
className={'noco-drawer'}
|
className={'noco-drawer'}
|
||||||
width={'40%'}
|
width={'40%'}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
|
actions.getFormState(state => {
|
||||||
|
if (isEqual(state.initialValues, state.values)) {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Modal.confirm({
|
||||||
|
title: '表单内容发生变化,确定不保存吗?',
|
||||||
|
onOk() {
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
title={title}
|
title={title}
|
||||||
footer={(
|
footer={(
|
||||||
|
@ -4,6 +4,7 @@ import './style.less';
|
|||||||
import { history, Link, request, useModel } from 'umi';
|
import { history, Link, request, useModel } from 'umi';
|
||||||
import { ProfileOutlined, LogoutOutlined, UserOutlined, CodeOutlined } from '@ant-design/icons';
|
import { ProfileOutlined, LogoutOutlined, UserOutlined, CodeOutlined } from '@ant-design/icons';
|
||||||
import Icon from '@/components/icons';
|
import Icon from '@/components/icons';
|
||||||
|
import { useResponsive } from 'ahooks';
|
||||||
|
|
||||||
const overlay = (
|
const overlay = (
|
||||||
<Menu>
|
<Menu>
|
||||||
@ -21,9 +22,11 @@ const overlay = (
|
|||||||
|
|
||||||
export default (props: any) => {
|
export default (props: any) => {
|
||||||
const { initialState = {}, loading, error, refresh, setInitialState } = useModel('@@initialState');
|
const { initialState = {}, loading, error, refresh, setInitialState } = useModel('@@initialState');
|
||||||
|
const responsive = useResponsive();
|
||||||
|
const isMobile = responsive.small && !responsive.middle && !responsive.large;
|
||||||
return (
|
return (
|
||||||
<div className={'avatar-dropdown-wrapper'}>
|
<div className={'avatar-dropdown-wrapper'}>
|
||||||
<Dropdown overlay={overlay} placement="bottomRight">
|
<Dropdown trigger={isMobile ? ['click'] : ['hover']} overlay={overlay} placement="bottomRight">
|
||||||
<span style={{display: 'block'}} className="dropdown-link" onClick={e => e.preventDefault()}>
|
<span style={{display: 'block'}} className="dropdown-link" onClick={e => e.preventDefault()}>
|
||||||
<Avatar size={'small'} icon={<UserOutlined/>} style={{marginRight: 5}}/> {initialState.currentUser.nickname}
|
<Avatar size={'small'} icon={<UserOutlined/>} style={{marginRight: 5}}/> {initialState.currentUser.nickname}
|
||||||
</span>
|
</span>
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
.dropdown-link {
|
.dropdown-link {
|
||||||
padding-left: 20px;
|
padding-left: 20px;
|
||||||
padding-right: 20px;
|
padding-right: 20px;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect, useImperativeHandle, forwardRef, useRef } from 'react';
|
import React, { useState, useEffect, useImperativeHandle, forwardRef, useRef } from 'react';
|
||||||
import { Button, Drawer } from 'antd';
|
import { Button, Drawer, Modal } from 'antd';
|
||||||
import { Tooltip, Input } from 'antd';
|
import { Tooltip, Input } from 'antd';
|
||||||
import {
|
import {
|
||||||
SchemaForm,
|
SchemaForm,
|
||||||
@ -19,6 +19,7 @@ import { QuestionCircleOutlined } from '@ant-design/icons';
|
|||||||
import { useRequest } from 'umi';
|
import { useRequest } from 'umi';
|
||||||
import api from '@/api-client';
|
import api from '@/api-client';
|
||||||
import { Spin } from '@nocobase/client';
|
import { Spin } from '@nocobase/client';
|
||||||
|
import isEqual from 'lodash/isEqual';
|
||||||
|
|
||||||
const actions = createFormActions();
|
const actions = createFormActions();
|
||||||
|
|
||||||
@ -62,7 +63,18 @@ export const DrawerForm = forwardRef((props: any, ref) => {
|
|||||||
width={'40%'}
|
width={'40%'}
|
||||||
className={'noco-drawer'}
|
className={'noco-drawer'}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
|
actions.getFormState(state => {
|
||||||
|
if (isEqual(state.initialValues, state.values)) {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Modal.confirm({
|
||||||
|
title: '表单内容发生变化,确定不保存吗?',
|
||||||
|
onOk() {
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
title={title}
|
title={title}
|
||||||
footer={(
|
footer={(
|
||||||
|
Loading…
Reference in New Issue
Block a user