Skip to content

Commit a6a9c3b

Browse files
authored
Merge pull request #329 from lljj-x/feat/array-feature
Feat/array feature
2 parents 7e30389 + c5339c4 commit a6a9c3b

File tree

34 files changed

+1322
-815
lines changed

34 files changed

+1322
-815
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Created by Liu.Jun on 2019/12/4 15:06.
33
*/
44

5-
import propsSchema from './schema.json';
5+
import propsSchema from './schema.js';
66
import uiSchema from './uiSchema.js';
77

88
const View = () => import('./View.vue');
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
export default {
2+
$schema: 'http://json-schema.org/draft-07/schema#',
3+
type: 'object',
4+
definitions: {
5+
ImgItem: {
6+
type: 'object',
7+
properties: {
8+
imgUrl: {
9+
title: '图片地址',
10+
type: 'string',
11+
format: 'uri'
12+
},
13+
imgLink: {
14+
title: '链接地址',
15+
type: 'string',
16+
format: 'uri',
17+
default: 'https://www.jd.com'
18+
}
19+
},
20+
required: [
21+
'imgUrl',
22+
'imgLink'
23+
]
24+
}
25+
},
26+
properties: {
27+
startTime: {
28+
title: '配置秒杀开始时间',
29+
type: 'string',
30+
format: 'date-time'
31+
},
32+
seckillBrand: {
33+
$ref: '#/definitions/ImgItem'
34+
},
35+
goodsList: {
36+
type: 'array',
37+
minItems: 4,
38+
maxItems: 8,
39+
uniqueItems: true,
40+
'ui:afterArrayOperate': (formData, command, payload) => {
41+
debugger;
42+
},
43+
items: {
44+
$ref: '#/definitions/ImgItem'
45+
}
46+
}
47+
},
48+
required: [
49+
'startTime'
50+
],
51+
additionalProperties: false
52+
};

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

Lines changed: 0 additions & 49 deletions
This file was deleted.

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ export default {
1717
txt: {
1818
title: '文字',
1919
type: 'string',
20-
'ui:placeholder': '输入你的内容',
21-
'err:required': '必须输入标题文字内容'
20+
'err:required': '必须输入标题文字内容',
21+
'fui:placeholder': (parent, root, prop) => {
22+
console.log(parent, root, prop);
23+
return parent.txtColor;
24+
},
2225
},
2326
txtColor: {
2427
title: '选择文字颜色',

packages/demo/demo-v3/src/pages/index/views/Demo/index.vue

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,15 @@ import schemaTypes from 'demo-common/schemaTypes';
228228
const VueElementForm = defineAsyncComponent(() => import('@lljj/vue3-form-element'));
229229
230230
let installedAntdv = false;
231-
const VueAntForm = defineAsyncComponent(async () => {
231+
232+
const VueAntForms = (async () => {
232233
// eslint-disable-next-line no-unused-vars
233234
const [antdv, antForm] = await Promise.all([
234235
import('demo-common/components/Antdv/index.js'),
235236
import('@lljj/vue3-form-ant')
236237
]);
237238
238-
return {
239+
const antdFormGenerator = (formProperty = 'default') => ({
239240
name: 'antFormWrap',
240241
setup(props, { attrs, slots }) {
241242
// hack 动态install antDv,因为我不知其它地方如何获取 vue app
@@ -245,12 +246,20 @@ const VueAntForm = defineAsyncComponent(async () => {
245246
installedAntdv = true;
246247
}
247248
248-
return () => h(antForm.default, {
249+
return () => h(antForm[formProperty], {
249250
...attrs
250251
}, slots);
251252
}
253+
});
254+
255+
return {
256+
v3: antdFormGenerator('default'),
257+
v4: antdFormGenerator('JsonSchemaFormAntdV4')
252258
};
253-
});
259+
})();
260+
261+
const VueAntForm = defineAsyncComponent(() => VueAntForms.then(res => res.v3));
262+
const VueAntFormV4 = defineAsyncComponent(() => VueAntForms.then(res => res.v4));
254263
255264
let installedNaive = false;
256265
const VueNaiveForm = defineAsyncComponent(async () => {
@@ -285,6 +294,7 @@ export default {
285294
CodeEditor,
286295
VueElementForm,
287296
VueAntForm,
297+
VueAntFormV4,
288298
VueNaiveForm,
289299
EditorHeader
290300
},
@@ -299,6 +309,9 @@ export default {
299309
}, {
300310
name: 'Antdv',
301311
component: 'VueAntForm'
312+
}, {
313+
name: 'Antdv(特殊适配antd4,未完整测试)',
314+
component: 'VueAntFormV4'
302315
}, {
303316
name: 'Naive',
304317
component: 'VueNaiveForm'
@@ -315,7 +328,7 @@ export default {
315328
return this.$route.query.type;
316329
},
317330
isUseLabelWidth() {
318-
return this.curVueForm !== 'VueAntForm';
331+
return this.curVueForm !== 'VueAntForm' && this.curVueForm !== 'VueAntFormV4';
319332
},
320333
trueFormProps() {
321334
if (!this.formProps) return {};

packages/docs/docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pageClass: custom-page-home
44
heroImage: /logo.png
55
heroText: Vue JSON Schema Form
66
tagline: 基于 Vue 、JSON Schema 构建form表单,支持Vue3和多Ui框架
7-
footer: Apache2.0 Licensed | Copyright © 2020-2020 Jun
7+
footer: Apache2.0 Licensed | Copyright © 2020-2023 Jun
88
actionText: 快速开始 →
99
actionLink: /zh/guide/
1010
---

packages/docs/docs/en/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pageClass: custom-page-home
44
heroImage: /logo.png
55
heroText: Vue JSON Schema Form
66
tagline: Quickly building HTML form based on Vue and JSON Schema
7-
footer: Apache2.0 Licensed | Copyright © 2020-2020 Jun
7+
footer: Apache2.0 Licensed | Copyright © 2020-2023 Jun
88
# actionText: Quick start →
99
# actionLink: /en/guide/
1010
---

packages/lib/utils/formUtils.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,28 @@ export function getUserUiOptions({
121121

122122
// https://github.com/lljj-x/vue-json-schema-form/issues/170
123123
// ui:hidden需要作为内置属性使用,不能直接透传给widget组件,如果组件需要只能在ui:options 中使用hidden传递
124-
if (key !== 'ui:hidden' && key.indexOf('ui:') === 0) {
125-
// 只对 ui:xxx 配置形式支持表达式
126-
return {
127-
...options,
128-
[key.substring(3)]: curNodePath === undefined ? value : handleExpression(rootFormData, curNodePath, value, () => value)
129-
};
124+
if (key !== 'ui:hidden') {
125+
// 处理 ui:xxx 参数
126+
if (key.indexOf('ui:') === 0) {
127+
// 只对 ui:xxx 配置形式支持表达式
128+
return {
129+
...options,
130+
[key.substring(3)]: curNodePath === undefined ? value : handleExpression(rootFormData, curNodePath, value, () => value)
131+
};
132+
}
133+
134+
// 处理 fui:xxx 参数,支持所有的options 通过function配置
135+
if (key.indexOf('fui:') === 0) {
136+
return {
137+
...options,
138+
[key.substring(4)]: value.call(
139+
null,
140+
getPathVal(rootFormData, curNodePath, 1),
141+
rootFormData,
142+
curNodePath
143+
)
144+
};
145+
}
130146
}
131147

132148
return options;
@@ -233,6 +249,7 @@ export function getWidgetConfig({
233249
renderScopedSlots,
234250
renderChildren,
235251
onChange,
252+
required: uiRequired,
236253
...uiProps
237254
} = uiOptions;
238255

@@ -254,7 +271,8 @@ export function getWidgetConfig({
254271
renderChildren,
255272
onChange,
256273
widgetListeners,
257-
uiProps
274+
uiProps,
275+
uiRequired
258276
};
259277
}
260278

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ export default {
5050
type: [String, Function, Object],
5151
default: null
5252
},
53+
// 通过定义的 schema 计算出来的
5354
required: {
5455
type: Boolean,
5556
default: false
5657
},
58+
59+
// 通过ui schema 配置传递的props
60+
uiRequired: {
61+
type: Boolean
62+
},
5763
// 解决 JSON Schema和实际输入元素中空字符串 required 判定的差异性
5864
// 元素输入为 '' 使用 emptyValue 的值
5965
emptyValue: {
@@ -152,6 +158,9 @@ export default {
152158
this.$emit('onOtherDataChange', trueValue);
153159
}
154160
}
161+
},
162+
realRequired() {
163+
return this.uiRequired ?? this.required;
155164
}
156165
},
157166
created() {
@@ -164,7 +173,7 @@ export default {
164173
// array 渲染为多选框时默认为空数组
165174
if (this.schema.items) {
166175
this.value = [];
167-
} else if (this.required && this.formProps.defaultSelectFirstOption) {
176+
} else if (this.realRequired && this.formProps.defaultSelectFirstOption) {
168177
this.value = this.uiProps.enumOptions[0].value;
169178
}
170179
}
@@ -252,7 +261,7 @@ export default {
252261
uiSchema: self.$props.uiSchema,
253262
customFormats: self.$props.customFormats,
254263
errorSchema: self.errorSchema,
255-
required: self.required,
264+
required: self.realRequired,
256265
propPath: path2prop(curNodePath)
257266
});
258267
if (errors.length > 0) {
@@ -297,7 +306,7 @@ export default {
297306
slot: 'label',
298307
class: {
299308
genFormLabel: true,
300-
genFormItemRequired: self.required,
309+
genFormItemRequired: self.realRequired,
301310
},
302311
}, [
303312
`${label}`,

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

Lines changed: 17 additions & 1 deletion
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
}

0 commit comments

Comments
 (0)