解决 quickEdit 初始值无效问题

This commit is contained in:
liaoxuezhi 2019-09-06 10:20:55 +08:00
parent ff19124bc4
commit ba136dd56c
6 changed files with 28 additions and 14 deletions

View File

@ -85,9 +85,9 @@ export class Card extends React.Component<CardProps> {
onAction && onAction(e, action, ctx || item.data);
}
handleQuickChange(values: object, saveImmediately?: boolean, saveSlient?: boolean) {
handleQuickChange(values: object, saveImmediately?: boolean, savePristine?: boolean) {
const {onQuickChange, item} = this.props;
onQuickChange && onQuickChange(item, values, saveImmediately, saveSlient);
onQuickChange && onQuickChange(item, values, saveImmediately, savePristine);
}
getPopOverContainer() {

View File

@ -312,11 +312,12 @@ export default class Form extends React.Component<FormProps, object> {
submitOnInit
} = this.props;
const data = store.data;
store.setInited(true);
const hooks:Array<(data:any) => Promise<any>> = this.hooks['init'] || [];
await Promise.all(hooks.map(hook => hook(store.data)));
await Promise.all(hooks.map(hook => hook(data)));
onInit && onInit(store.data);
onInit && onInit(data);
submitOnInit && this.handleAction(undefined, {
type: 'submit'

View File

@ -270,10 +270,10 @@ export default class List extends React.Component<ListProps, object> {
onSelect && onSelect(store.selectedItems.map(item => item.data), store.unSelectedItems.map(item => item.data));
}
handleQuickChange(item: IItem, values: object, saveImmediately?: boolean | any, saveSilent?: boolean) {
item.change(values, saveSilent);
handleQuickChange(item: IItem, values: object, saveImmediately?: boolean | any, savePristine?: boolean) {
item.change(values, savePristine);
if (!saveImmediately || saveSilent) {
if (!saveImmediately || savePristine) {
return;
}
@ -790,9 +790,9 @@ export class ListItem extends React.Component<ListItemProps> {
onAction && onAction(e, action, ctx || item.data);
}
handleQuickChange(values: object, saveImmediately?: boolean, saveSilent?: boolean) {
handleQuickChange(values: object, saveImmediately?: boolean, savePristine?: boolean) {
const {onQuickChange, item} = this.props;
onQuickChange && onQuickChange(item, values, saveImmediately, saveSilent);
onQuickChange && onQuickChange(item, values, saveImmediately, savePristine);
}
renderLeft() {

View File

@ -63,6 +63,8 @@ export const HocQuickEdit = (config: Partial<QuickEditConfig> = {}) => (Componen
this.handleWindowKeyPress = this.handleWindowKeyPress.bind(this);
this.handleWindowKeyDown = this.handleWindowKeyDown.bind(this);
this.formRef = this.formRef.bind(this);
this.handleInit = this.handleInit.bind(this);
this.handleChange = this.handleChange.bind(this);
this.state = {
isOpened: false,
@ -241,6 +243,17 @@ export const HocQuickEdit = (config: Partial<QuickEditConfig> = {}) => (Componen
onQuickChange(values, (quickEdit as QuickEditConfig).saveImmediately);
}
handleInit(values: object) {
const {onQuickChange} = this.props;
onQuickChange(values, false, true);
}
handleChange(values: object) {
const {onQuickChange, quickEdit} = this.props;
onQuickChange(values, (quickEdit as QuickEditConfig).saveImmediately);
}
openQuickEdit() {
currentOpened = this;
this.setState({
@ -405,8 +418,8 @@ export const HocQuickEdit = (config: Partial<QuickEditConfig> = {}) => (Componen
wrapperComponent: 'div',
className: cx('Form--quickEdit'),
ref: this.formRef,
onChange: (values: object) =>
onQuickChange(values, (quickEdit as QuickEditConfig).saveImmediately),
onInit: this.handleInit,
onChange: this.handleChange,
})}
</Component>
);

View File

@ -1604,9 +1604,9 @@ class TableRow extends React.Component<TableRowProps> {
onAction && onAction(e, action, ctx || item.data);
}
handleQuickChange(values: object, saveImmediately?: boolean, saveSilent?: boolean) {
handleQuickChange(values: object, saveImmediately?: boolean, savePristine?: boolean) {
const {onQuickChange, item} = this.props;
onQuickChange && onQuickChange(item, values, saveImmediately, saveSilent);
onQuickChange && onQuickChange(item, values, saveImmediately, savePristine);
}
render() {

View File

@ -267,7 +267,7 @@ export const FormItemStore = types
rules && (self.rules = rules);
if (
typeof value !== void 0 && self.value === void 0
value !== void 0 && self.value === void 0
) {
form.setValueByName(self.name, value, true);
}