Skip to content

Commit 2d2264b

Browse files
committed
feat(core): widget 节点直接配置onChange
build(build): lib build release
1 parent 4dd046b commit 2d2264b

File tree

21 files changed

+188
-61
lines changed

21 files changed

+188
-61
lines changed

packages/demo/demo-v2/src/pages/vue-editor/views/editor/viewComponents/Text/uiSchema.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export default {
77
'ui:options': {
88
getWidget(widgetVm) {
99
console.log(widgetVm);
10+
},
11+
onChange(newVal, oldVal) {
12+
console.log('change:', newVal, oldVal);
1013
}
1114
}
1215
}

packages/docs/docs/zh/guide/basic-config.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ uiSchema = {
169169
console.log(widgetVm);
170170
},
171171

172+
// onChange
173+
// 支持版本 1.3
174+
onChange(newVal, oldVal) {
175+
console.log('change:', newVal, oldVal);
176+
},
177+
172178
// 显示标题?只对 type为`object`、`array` 类型有效
173179
showTitle: true,
174180

packages/lib/utils/formUtils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export function getWidgetConfig({
227227
emptyValue,
228228
width,
229229
getWidget,
230+
onChange,
230231
...uiProps
231232
} = uiOptions;
232233

@@ -244,6 +245,7 @@ export function getWidgetConfig({
244245
fieldClass,
245246
emptyValue,
246247
getWidget,
248+
onChange,
247249
uiProps
248250
};
249251
}

packages/lib/vue2/vue2-core/src/components/Widget.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ export default {
129129
},
130130
formProps: null,
131131
getWidget: null,
132-
globalOptions: null // 全局配置
132+
globalOptions: null, // 全局配置
133+
onChange: null
133134
},
134135
computed: {
135136
value: {
@@ -320,8 +321,12 @@ export default {
320321
// 为了兼容 number 小数点后0结尾的数据场景
321322
// 比如 1. 1.010 这类特殊数据输入是不需要触发 新值的设置,否则会导致schema校验为非数字
322323
// 但由于element为了解另外的问题,会在nextTick时强制同步dom的值等于vm的值所以无法通过这种方式来hack,这里旧的这份逻辑依旧保留 不过update一直为true
323-
if (formatValue.update && self.value !== formatValue.value) {
324+
const preVal = self.value;
325+
if (formatValue.update && preVal !== formatValue.value) {
324326
self.value = formatValue.value;
327+
if (self.onChange) {
328+
self.onChange(formatValue.value, preVal);
329+
}
325330
}
326331
}
327332
}

packages/lib/vue2/vue2-form-element/dist/vueJsonSchemaForm.esm.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8619,7 +8619,8 @@ function getWidgetConfig(_ref6) {
86198619
emptyValue = uiOptions.emptyValue,
86208620
width = uiOptions.width,
86218621
getWidget = uiOptions.getWidget,
8622-
uiProps = _objectWithoutProperties(uiOptions, ["widget", "title", "labelWidth", "description", "attrs", "class", "style", "fieldAttrs", "fieldStyle", "fieldClass", "emptyValue", "width", "getWidget"]);
8622+
onChange = uiOptions.onChange,
8623+
uiProps = _objectWithoutProperties(uiOptions, ["widget", "title", "labelWidth", "description", "attrs", "class", "style", "fieldAttrs", "fieldStyle", "fieldClass", "emptyValue", "width", "getWidget", "onChange"]);
86238624

86248625
return {
86258626
widget: widget,
@@ -8635,6 +8636,7 @@ function getWidgetConfig(_ref6) {
86358636
fieldClass: fieldClass,
86368637
emptyValue: emptyValue,
86378638
getWidget: getWidget,
8639+
onChange: onChange,
86388640
uiProps: uiProps
86398641
};
86408642
} // 解析用户配置的 errorSchema options
@@ -9081,13 +9083,16 @@ function getMatchingOption(formData, options, rootSchema) {
90819083
if (option.properties) {
90829084
// Create an "anyOf" schema that requires at least one of the keys in the
90839085
// "properties" object
9084-
var requiresAnyOf = {
9086+
var requiresAnyOf = _objectSpread2(_objectSpread2({}, rootSchema.definitions ? {
9087+
definitions: rootSchema.definitions
9088+
} : {}), {}, {
90859089
anyOf: Object.keys(option.properties).map(function (key) {
90869090
return {
90879091
required: [key]
90889092
};
90899093
})
9090-
};
9094+
});
9095+
90919096
var augmentedSchema = void 0; // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
90929097

90939098
if (option.anyOf) {
@@ -10147,8 +10152,9 @@ var Widget = {
1014710152
},
1014810153
formProps: null,
1014910154
getWidget: null,
10150-
globalOptions: null // 全局配置
10151-
10155+
globalOptions: null,
10156+
// 全局配置
10157+
onChange: null
1015210158
},
1015310159
computed: {
1015410160
value: {
@@ -10304,8 +10310,14 @@ var Widget = {
1030410310
// 比如 1. 1.010 这类特殊数据输入是不需要触发 新值的设置,否则会导致schema校验为非数字
1030510311
// 但由于element为了解另外的问题,会在nextTick时强制同步dom的值等于vm的值所以无法通过这种方式来hack,这里旧的这份逻辑依旧保留 不过update一直为true
1030610312

10307-
if (formatValue.update && self.value !== formatValue.value) {
10313+
var preVal = self.value;
10314+
10315+
if (formatValue.update && preVal !== formatValue.value) {
1030810316
self.value = formatValue.value;
10317+
10318+
if (self.onChange) {
10319+
self.onChange(formatValue.value, preVal);
10320+
}
1030910321
}
1031010322
}
1031110323
}

packages/lib/vue2/vue2-form-element/dist/vueJsonSchemaForm.esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/lib/vue2/vue2-form-element/dist/vueJsonSchemaForm.umd.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8627,7 +8627,8 @@
86278627
emptyValue = uiOptions.emptyValue,
86288628
width = uiOptions.width,
86298629
getWidget = uiOptions.getWidget,
8630-
uiProps = _objectWithoutProperties(uiOptions, ["widget", "title", "labelWidth", "description", "attrs", "class", "style", "fieldAttrs", "fieldStyle", "fieldClass", "emptyValue", "width", "getWidget"]);
8630+
onChange = uiOptions.onChange,
8631+
uiProps = _objectWithoutProperties(uiOptions, ["widget", "title", "labelWidth", "description", "attrs", "class", "style", "fieldAttrs", "fieldStyle", "fieldClass", "emptyValue", "width", "getWidget", "onChange"]);
86318632

86328633
return {
86338634
widget: widget,
@@ -8643,6 +8644,7 @@
86438644
fieldClass: fieldClass,
86448645
emptyValue: emptyValue,
86458646
getWidget: getWidget,
8647+
onChange: onChange,
86468648
uiProps: uiProps
86478649
};
86488650
} // 解析用户配置的 errorSchema options
@@ -9089,13 +9091,16 @@
90899091
if (option.properties) {
90909092
// Create an "anyOf" schema that requires at least one of the keys in the
90919093
// "properties" object
9092-
var requiresAnyOf = {
9094+
var requiresAnyOf = _objectSpread2(_objectSpread2({}, rootSchema.definitions ? {
9095+
definitions: rootSchema.definitions
9096+
} : {}), {}, {
90939097
anyOf: Object.keys(option.properties).map(function (key) {
90949098
return {
90959099
required: [key]
90969100
};
90979101
})
9098-
};
9102+
});
9103+
90999104
var augmentedSchema = void 0; // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
91009105

91019106
if (option.anyOf) {
@@ -10155,8 +10160,9 @@
1015510160
},
1015610161
formProps: null,
1015710162
getWidget: null,
10158-
globalOptions: null // 全局配置
10159-
10163+
globalOptions: null,
10164+
// 全局配置
10165+
onChange: null
1016010166
},
1016110167
computed: {
1016210168
value: {
@@ -10312,8 +10318,14 @@
1031210318
// 比如 1. 1.010 这类特殊数据输入是不需要触发 新值的设置,否则会导致schema校验为非数字
1031310319
// 但由于element为了解另外的问题,会在nextTick时强制同步dom的值等于vm的值所以无法通过这种方式来hack,这里旧的这份逻辑依旧保留 不过update一直为true
1031410320

10315-
if (formatValue.update && self.value !== formatValue.value) {
10321+
var preVal = self.value;
10322+
10323+
if (formatValue.update && preVal !== formatValue.value) {
1031610324
self.value = formatValue.value;
10325+
10326+
if (self.onChange) {
10327+
self.onChange(formatValue.value, preVal);
10328+
}
1031710329
}
1031810330
}
1031910331
}

packages/lib/vue2/vue2-form-element/dist/vueJsonSchemaForm.umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/lib/vue2/vue2-form-iview3/dist/vue2-form-iview3.esm.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8619,7 +8619,8 @@ function getWidgetConfig(_ref6) {
86198619
emptyValue = uiOptions.emptyValue,
86208620
width = uiOptions.width,
86218621
getWidget = uiOptions.getWidget,
8622-
uiProps = _objectWithoutProperties(uiOptions, ["widget", "title", "labelWidth", "description", "attrs", "class", "style", "fieldAttrs", "fieldStyle", "fieldClass", "emptyValue", "width", "getWidget"]);
8622+
onChange = uiOptions.onChange,
8623+
uiProps = _objectWithoutProperties(uiOptions, ["widget", "title", "labelWidth", "description", "attrs", "class", "style", "fieldAttrs", "fieldStyle", "fieldClass", "emptyValue", "width", "getWidget", "onChange"]);
86238624

86248625
return {
86258626
widget: widget,
@@ -8635,6 +8636,7 @@ function getWidgetConfig(_ref6) {
86358636
fieldClass: fieldClass,
86368637
emptyValue: emptyValue,
86378638
getWidget: getWidget,
8639+
onChange: onChange,
86388640
uiProps: uiProps
86398641
};
86408642
} // 解析用户配置的 errorSchema options
@@ -9081,13 +9083,16 @@ function getMatchingOption(formData, options, rootSchema) {
90819083
if (option.properties) {
90829084
// Create an "anyOf" schema that requires at least one of the keys in the
90839085
// "properties" object
9084-
var requiresAnyOf = {
9086+
var requiresAnyOf = _objectSpread2(_objectSpread2({}, rootSchema.definitions ? {
9087+
definitions: rootSchema.definitions
9088+
} : {}), {}, {
90859089
anyOf: Object.keys(option.properties).map(function (key) {
90869090
return {
90879091
required: [key]
90889092
};
90899093
})
9090-
};
9094+
});
9095+
90919096
var augmentedSchema = void 0; // If the "anyOf" keyword already exists, wrap the augmentation in an "allOf"
90929097

90939098
if (option.anyOf) {
@@ -10147,8 +10152,9 @@ var Widget = {
1014710152
},
1014810153
formProps: null,
1014910154
getWidget: null,
10150-
globalOptions: null // 全局配置
10151-
10155+
globalOptions: null,
10156+
// 全局配置
10157+
onChange: null
1015210158
},
1015310159
computed: {
1015410160
value: {
@@ -10304,8 +10310,14 @@ var Widget = {
1030410310
// 比如 1. 1.010 这类特殊数据输入是不需要触发 新值的设置,否则会导致schema校验为非数字
1030510311
// 但由于element为了解另外的问题,会在nextTick时强制同步dom的值等于vm的值所以无法通过这种方式来hack,这里旧的这份逻辑依旧保留 不过update一直为true
1030610312

10307-
if (formatValue.update && self.value !== formatValue.value) {
10313+
var preVal = self.value;
10314+
10315+
if (formatValue.update && preVal !== formatValue.value) {
1030810316
self.value = formatValue.value;
10317+
10318+
if (self.onChange) {
10319+
self.onChange(formatValue.value, preVal);
10320+
}
1030910321
}
1031010322
}
1031110323
}

packages/lib/vue2/vue2-form-iview3/dist/vue2-form-iview3.esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)