Skip to content

Commit 955308d

Browse files
author
Jino Liu
committed
feat(lib): 支持配置 fui 自定义function
re #323
1 parent 84adc7f commit 955308d

File tree

7 files changed

+82
-60
lines changed

7 files changed

+82
-60
lines changed

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

+1-1
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');
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:onArrayOperate': (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

-49
This file was deleted.

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

+5-2
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/docs/docs/README.md

+1-1
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

+1-1
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

+22-6
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;

0 commit comments

Comments
 (0)