This commit is contained in:
dap
2024-09-30 07:59:26 +08:00
51 changed files with 195 additions and 79 deletions

View File

@@ -12,20 +12,13 @@ import { toRaw } from 'vue';
import { Store } from '@vben-core/shared/store';
import {
bindMethods,
createMerge,
isFunction,
mergeWithArrayOverride,
StateHandler,
} from '@vben-core/shared/utils';
import { objectPick } from '@vueuse/core';
const merge = createMerge((originObj, key, updates) => {
if (Array.isArray(originObj[key]) && Array.isArray(updates)) {
originObj[key] = updates;
return true;
}
});
function getDefaultState(): VbenFormProps {
return {
actionWrapperClass: '',
@@ -218,10 +211,10 @@ export class FormApi {
) {
if (isFunction(stateOrFn)) {
this.store.setState((prev) => {
return merge(stateOrFn(prev), prev);
return mergeWithArrayOverride(stateOrFn(prev), prev);
});
} else {
this.store.setState((prev) => merge(stateOrFn, prev));
this.store.setState((prev) => mergeWithArrayOverride(stateOrFn, prev));
}
}
@@ -287,7 +280,10 @@ export class FormApi {
currentSchema.forEach((schema, index) => {
const updatedData = updatedMap[schema.fieldName];
if (updatedData) {
currentSchema[index] = merge(updatedData, schema) as FormSchema;
currentSchema[index] = mergeWithArrayOverride(
updatedData,
schema,
) as FormSchema;
}
});
this.setState({ schema: currentSchema });