form reload 逻辑优化

This commit is contained in:
liaoxuezhi 2019-08-29 15:56:14 +08:00
parent 32e364e997
commit 10b203f415
6 changed files with 63 additions and 25 deletions

View File

@ -248,10 +248,10 @@ body {
@include media-breakpoint-up(md) {
.#{$ns}Layout {
&--boxed {
width: px2rem(750px);
width: px2rem(760px);
&.#{$ns}Layout--headerFixed .#{$ns}Layout-header {
width: px2rem(750px);
width: px2rem(760px);
}
}
@ -488,10 +488,10 @@ body {
@include media-breakpoint-up(lg) {
.#{$ns}Layout {
&--boxed {
width: px2rem(970px);
width: px2rem(980px);
&.#{$ns}Layout--headerFixed .#{$ns}Layout-header {
width: px2rem(970px);
width: px2rem(980px);
}
}
}
@ -500,10 +500,10 @@ body {
@include media-breakpoint-up(xl) {
.#{$ns}Layout {
&--boxed {
width: px2rem(1170px);
width: px2rem(1180px);
&.#{$ns}Layout--headerFixed .#{$ns}Layout-header {
width: px2rem(1170px);
width: px2rem(1180px);
}
}
}

View File

@ -127,7 +127,8 @@ export default class ComboControl extends React.Component<ComboProps> {
store,
value,
minLength,
maxLength
maxLength,
formItem
} = this.props;
store.config({
@ -135,6 +136,8 @@ export default class ComboControl extends React.Component<ComboProps> {
maxLength,
length: this.getValueAsArray().length
});
formItem && formItem.setSubStore(store);
}
componentWillReceiveProps(nextProps:ComboProps) {
@ -155,6 +158,14 @@ export default class ComboControl extends React.Component<ComboProps> {
}
}
componentWillUnmount() {
const {
formItem
} = this.props;
formItem && formItem.setSubStore(null);
}
getValueAsArray(props = this.props) {
const {
flat,

View File

@ -293,6 +293,12 @@ export default class Form extends React.Component<FormProps, object> {
(this.handleChange as any).cancel();
this.asyncCancel && this.asyncCancel();
this.disposeOnValidate && this.disposeOnValidate();
const store = this.props.store;
if (store && store.parentStore && store.parentStore.storeType === 'ComboStore') {
const combo = store.parentStore as IComboStore;
combo.removeForm(store);
}
}
async onInit() {
@ -334,21 +340,24 @@ export default class Form extends React.Component<FormProps, object> {
[initFinishedField || 'finished']: false
});
isEffectiveApi(initApi, store.data) &&
store.fetchData(initApi, store.data, {
successMessage: fetchSuccess,
errorMessage: fetchFailed,
silent,
onSuccess: () => {
if (!isEffectiveApi(initAsyncApi, store.data) || store.data[initFinishedField || 'finished']) {
return;
}
isEffectiveApi(initApi, store.data)
? store.fetchInitData(initApi, store.data, {
successMessage: fetchSuccess,
errorMessage: fetchFailed,
silent,
onSuccess: () => {
if (!isEffectiveApi(initAsyncApi, store.data) || store.data[initFinishedField || 'finished']) {
return;
}
return until(() => store.checkRemote(initAsyncApi, store.data)
, (ret:any) => ret && ret[initFinishedField || 'finished']
, (cancel) => this.asyncCancel = cancel);
}
}).then(this.initInterval);
return until(() => store.checkRemote(initAsyncApi, store.data)
, (ret:any) => ret && ret[initFinishedField || 'finished']
, (cancel) => this.asyncCancel = cancel);
}
})
.then(this.initInterval)
.then(() => store.reset(undefined, false))
: store.reset();
}
receive(values:object) {
@ -599,7 +608,9 @@ export default class Form extends React.Component<FormProps, object> {
})
.then(async (response) => {
response && onChange && onChange(store.data, difference(store.data, store.pristine));
store.validated && this.validate(true);
if (store.validated) {
await this.validate(true);
}
if (action.feedback && isVisible(action.feedback, store.data)) {
await this.openFeedback(action.feedback, store.data);

View File

@ -705,7 +705,7 @@ export default class Table extends React.Component<TableProps, object> {
}
@autobind
handleDragOver(e: DragEvent) {
handleDragOver(e: any) {
if (!e.target) {
return;
}

View File

@ -336,11 +336,14 @@ export const FormStore = ServiceStore
items.forEach(item => item.reset());
}
function reset(cb?: (data:any) => void) {
self.data = self.pristine;
function reset(cb?: (data:any) => void, resetData: boolean = true) {
if (resetData) {
self.data = self.pristine;
}
// 值可能变了,重新验证一次。
self.validated = false;
self.submited = false;
self.items.forEach(item => item.reset());
cb && cb(self.data);
}

View File

@ -31,6 +31,7 @@ import {
import { IRendererStore } from ".";
import { normalizeOptions } from "../components/Select";
import find = require('lodash/find');
import { iRendererStore } from './iRenderer';
interface IOption {
value?: string | number | null;
@ -486,8 +487,19 @@ export const FormItemStore = types
self.loading = value;
}
let subStore:any;
function setSubStore(store:any) {
subStore = store;
}
function reset() {
self.validated = false;
if (subStore && subStore.storeType === 'ComboStore') {
const combo = subStore as IComboStore;
combo.forms.forEach(form => form.reset());
}
clearError();
}
@ -502,6 +514,7 @@ export const FormItemStore = types
loadOptions,
syncOptions,
setLoading,
setSubStore,
reset
}
});