Skip to content

Commit de1068f

Browse files
author
Jino Liu
committed
feat(lib): 添加 afterArrayOperate 配置,支持数组操作回调
re #323
1 parent 955308d commit de1068f

File tree

3 files changed

+32
-3
lines changed
  • packages
    • demo/demo-v2/src/pages/vue-editor/views/editor/viewComponents/FlashSaleGoodsList
    • lib
      • vue2/vue2-core/src/fields/ArrayField
      • vue3/vue3-core/src/fields/ArrayField

3 files changed

+32
-3
lines changed

packages/demo/demo-v2/src/pages/vue-editor/views/editor/viewComponents/FlashSaleGoodsList/schema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default {
3737
minItems: 4,
3838
maxItems: 8,
3939
uniqueItems: true,
40-
'ui:onArrayOperate': (formData, command, payload) => {
40+
'ui:afterArrayOperate': (formData, command, payload) => {
4141
debugger;
4242
},
4343
items: {

packages/lib/vue2/vue2-core/src/fields/ArrayField/index.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import getDefaultFormState from '@lljj/vjsf-utils/schema/getDefaultFormState';
77

88
import {
9-
allowAdditionalItems, isFixedItems, isMultiSelect
9+
allowAdditionalItems, isFixedItems, isMultiSelect, getUserUiOptions
1010
} from '@lljj/vjsf-utils/formUtils';
1111
import { getPathVal, setPathVal } from '@lljj/vjsf-utils/vueUtils';
1212
import { genId, lowerCase } from '@lljj/vjsf-utils/utils';
@@ -31,6 +31,17 @@ export default {
3131
};
3232
},
3333
computed: {
34+
uiOptions() {
35+
const {
36+
schema, uiSchema, rootFormData, curNodePath
37+
} = this.$props;
38+
return getUserUiOptions({
39+
schema,
40+
uiSchema,
41+
curNodePath,
42+
rootFormData
43+
});
44+
},
3445
itemsFormData() {
3546
const formKeys = this.$data.formKeys;
3647
return this.curFormData.map((item, index) => ({
@@ -137,6 +148,11 @@ export default {
137148

138149
// 修改formData数据
139150
curStrategy.apply(this, [this.curFormData, formDataPrams]);
151+
152+
// onArrayOperate
153+
if (this.uiOptions.afterArrayOperate) {
154+
this.uiOptions.afterArrayOperate.call(null, this.curFormData, command, data);
155+
}
140156
} else {
141157
throw new Error(`错误 - 未知的操作:[${command}]`);
142158
}

packages/lib/vue3/vue3-core/src/fields/ArrayField/index.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import getDefaultFormState from '@lljj/vjsf-utils/schema/getDefaultFormState';
1111

1212
import {
13-
allowAdditionalItems, isFixedItems, isMultiSelect
13+
allowAdditionalItems, isFixedItems, isMultiSelect, getUserUiOptions
1414
} from '@lljj/vjsf-utils/formUtils';
1515
import { getPathVal, setPathVal } from '@lljj/vjsf-utils/vue3Utils';
1616
import { genId, lowerCase } from '@lljj/vjsf-utils/utils';
@@ -62,6 +62,14 @@ export default {
6262
value: item
6363
})));
6464

65+
// 当前节点的ui配置
66+
const uiOptions = computed(() => getUserUiOptions({
67+
schema: props.schema,
68+
uiSchema: props.uiSchema,
69+
curNodePath: props.curNodePath,
70+
rootFormData: props.rootFormData
71+
}));
72+
6573
// 获取一个新item
6674
const getNewFormDataRow = () => {
6775
const { schema, rootSchema } = props;
@@ -136,6 +144,11 @@ export default {
136144

137145
// 修改formData数据
138146
curStrategy.apply(null, [curFormData.value, formDataPrams]);
147+
148+
// onArrayOperate
149+
if (uiOptions.value.afterArrayOperate) {
150+
this.uiOptions.afterArrayOperate.call(null, curFormData.value, command, data);
151+
}
139152
} else {
140153
throw new Error(`错误 - 未知的操作:[${command}]`);
141154
}

0 commit comments

Comments
 (0)