Skip to content

Commit 267582c

Browse files
committed
refactor(vjsf dependencies): 移除对schema dependencies 的相关逻辑,暂不支持
1 parent 67dffba commit 267582c

File tree

6 files changed

+91
-53
lines changed

6 files changed

+91
-53
lines changed

packages/demo/src/index/views/Demo/schemaTypes/91.Object-Dependencies/index.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Created by Liu.Jun on 2020/5/19 15:41.
3+
*/
4+
5+
export default {
6+
schema: {
7+
title: 'Property dependencies',
8+
description: 'These samples are best viewed without live validation.',
9+
type: 'object',
10+
properties: {
11+
unidirectional: {
12+
title: 'Unidirectional',
13+
src: 'https://spacetelescope.github.io/understanding-json-schema/reference/object.html#dependencies',
14+
type: 'object',
15+
properties: {
16+
name: {
17+
type: 'string'
18+
},
19+
credit_card: {
20+
type: 'number'
21+
},
22+
billing_address: {
23+
type: 'string'
24+
}
25+
},
26+
required: [
27+
'name'
28+
],
29+
dependencies: {
30+
credit_card: [
31+
'billing_address'
32+
]
33+
}
34+
}
35+
}
36+
}
37+
};

packages/docs/docs/zh/guide/todo.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
- [x] custom-rule 参数 支持
2121
- [x] 逐步开源发布
2222
- [x] 优化源码 不需要this的组件调整为 functional
23+
- [x] 数组支持配置是否显示序号
24+
- [x] 数组渲染样式微调优化(控制条下间距等)
25+
- [ ] 支持属性依赖 [属性依赖](https://json-schema.org/understanding-json-schema/reference/object.html#property-dependencies)
26+
- [ ] 支持Schema依赖 [Schema依赖](https://json-schema.org/understanding-json-schema/reference/object.html#schema-dependencies)
2327

24-
- [ ] 数组 title 和 description支持配置 $index 通配符 渲染时替换为 1 2 3
25-
- [ ] 数组渲染样式微调优化(控制条下间距,)
2628
- [ ] 添加代码测试
27-
- [ ] Ui配置,支持函数表达式配置,hidden title description placeholder等
2829
- [ ] 对照react schema from适配更多规则支持
2930
- [ ] 解耦elementUi 重新开发form 和formItem组件,通过配置化实现适配elementUi iView 等常用ui组件

packages/lib/src/JsonSchemaForm/common/schema/getDefaultFormState.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import findSchemaDefinition from './findSchemaDefinition';
99
import { getMatchingOption } from './validate';
1010
import { fillObj } from '../arrayUtils';
1111
import { isFixedItems, isMultiSelect } from '../formUtils';
12-
import retrieveSchema, { resolveDependencies, resolveAllOf } from './retriev';
12+
import retrieveSchema, { /* resolveDependencies, */ resolveAllOf } from './retriev';
1313

1414
/**
1515
* When merging defaults and form data, we want to merge in this specific way:
@@ -78,7 +78,7 @@ function computeDefaults(
7878
formData,
7979
includeUndefinedValues
8080
);
81-
} else if ('dependencies' in schema) {
81+
} else if /* ('dependencies' in schema) {
8282
const resolvedSchema = resolveDependencies(schema, rootSchema, formData);
8383
return computeDefaults(
8484
resolvedSchema,
@@ -87,7 +87,7 @@ function computeDefaults(
8787
formData,
8888
includeUndefinedValues
8989
);
90-
} else if (isFixedItems(schema)) {
90+
} else if */ (isFixedItems(schema)) {
9191
defaults = schema.items.map((itemSchema, idx) => computeDefaults(
9292
itemSchema,
9393
Array.isArray(parentDefaults) ? parentDefaults[idx] : undefined,

packages/lib/src/JsonSchemaForm/common/schema/retriev.js

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,18 @@ import findSchemaDefinition from './findSchemaDefinition';
1414
import { intersection } from '../arrayUtils';
1515

1616
import {
17-
isObject,
18-
guessType,
19-
mergeSchemas,
20-
scm
17+
/* guessType, mergeSchemas, */ isObject, scm
2118
} from '../utils';
2219

23-
import { isValid, getMatchingOption } from './validate';
20+
// import { getMatchingOption, isValid } from './validate';
2421

2522
// 自动添加分割线
2623

27-
export const ADDITIONAL_PROPERTY_FLAG = '__additional_property';
24+
// export const ADDITIONAL_PROPERTY_FLAG = '__additional_property';
2825

2926
// resolve Schema - dependencies
3027
// https://json-schema.org/understanding-json-schema/reference/object.html#dependencies
28+
/*
3129
export function resolveDependencies(schema, rootSchema, formData) {
3230
// 从源模式中删除依赖项。
3331
const { dependencies = {} } = schema;
@@ -48,9 +46,12 @@ export function resolveDependencies(schema, rootSchema, formData) {
4846
formData
4947
);
5048
}
49+
*/
5150

5251
// 处理依赖关系 dependencies
5352
// https://json-schema.org/understanding-json-schema/reference/object.html#dependencies
53+
/*
54+
5455
function processDependencies(
5556
dependencies,
5657
resolvedSchema,
@@ -96,9 +97,12 @@ function processDependencies(
9697
}
9798
return resolvedSchema;
9899
}
100+
*/
99101

100102
// 属性依赖
101103
// https://json-schema.org/understanding-json-schema/reference/object.html#property-dependencies
104+
105+
/*
102106
function withDependentProperties(schema, additionallyRequired) {
103107
if (!additionallyRequired) {
104108
return schema;
@@ -108,9 +112,11 @@ function withDependentProperties(schema, additionallyRequired) {
108112
: additionallyRequired;
109113
return { ...schema, required };
110114
}
115+
*/
111116

112117
// schema 依赖
113118
// https://json-schema.org/understanding-json-schema/reference/object.html#schema-dependencies
119+
/*
114120
function withDependentSchema(
115121
schema,
116122
rootSchema,
@@ -185,6 +191,7 @@ function withExactlyOneSubschema(
185191
retrieveSchema(dependentSchema, rootSchema, formData)
186192
);
187193
}
194+
*/
188195

189196
// resolve Schema - $ref
190197
// https://json-schema.org/understanding-json-schema/structuring.html#using-id-with-ref
@@ -332,27 +339,43 @@ export function resolveAllOf(schema, rootSchema, formData) {
332339
// resolve Schema
333340
function resolveSchema(schema, rootSchema = {}, formData = {}) {
334341
// allOf 、$ref、dependencies 可能被同时配置
335-
// 按优先级处理
342+
343+
// allOf
336344
if (schema.hasOwnProperty('allOf')) {
337-
// 配置了 allOf属性合并数据
338345
schema = resolveAllOf(schema, rootSchema, formData);
339346
}
340347

348+
// $ref
341349
if (schema.hasOwnProperty('$ref')) {
342350
schema = resolveReference(schema, rootSchema, formData);
343351
}
344352

353+
// dependencies
354+
/*
345355
if (schema.hasOwnProperty('dependencies')) {
346356
const resolvedSchema = resolveDependencies(schema, rootSchema, formData);
347357
schema = retrieveSchema(resolvedSchema, rootSchema, formData);
348358
}
359+
*/
360+
361+
// additionalProperties
362+
/*
363+
const hasAdditionalProperties = schema.hasOwnProperty('additionalProperties') && schema.additionalProperties !== false;
364+
if (hasAdditionalProperties) {
365+
return stubExistingAdditionalProperties(
366+
schema,
367+
rootSchema,
368+
formData
369+
);
370+
}
371+
*/
349372

350373
return schema;
351374
}
352375

353376
// 这个函数将为formData中的每个键创建新的“属性”项
354377
// 查找到附加属性统一到properties[key]格式 并且打上标准
355-
function stubExistingAdditionalProperties(
378+
/* function stubExistingAdditionalProperties(
356379
schema,
357380
rootSchema = {},
358381
formData = {}
@@ -390,25 +413,13 @@ function stubExistingAdditionalProperties(
390413
});
391414
392415
return schema;
393-
}
416+
} */
394417

395418
// 索引当前节点
396419
export default function retrieveSchema(schema, rootSchema = {}, formData = {}) {
397420
if (!isObject(schema)) {
398421
return {};
399422
}
400423

401-
const resolvedSchema = resolveSchema(schema, rootSchema, formData);
402-
403-
// 配置了 additionalProperties 属性
404-
const hasAdditionalProperties = resolvedSchema.hasOwnProperty('additionalProperties') && resolvedSchema.additionalProperties !== false;
405-
if (hasAdditionalProperties) {
406-
return stubExistingAdditionalProperties(
407-
resolvedSchema,
408-
rootSchema,
409-
formData
410-
);
411-
}
412-
413-
return resolvedSchema;
424+
return resolveSchema(schema, rootSchema, formData);
414425
}

packages/lib/src/JsonSchemaForm/fields/ObjectField/index.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import vueProps from '../props';
66

77
import { orderProperties, getUiOptions } from '../../common/formUtils';
8-
import { ADDITIONAL_PROPERTY_FLAG } from '../../common/schema/retriev';
98
import { computedCurPath } from '../../common/vueUtils';
109

1110
import FieldGroupWrap from '../../fieldComponents/FieldGroupWrap';
@@ -44,24 +43,20 @@ export default {
4443
const properties = Object.keys(schema.properties || {});
4544
const orderedProperties = orderProperties(properties, order);
4645

47-
const propertiesVNodeList = orderedProperties.map((name) => {
48-
const addedByAdditionalProperties = schema.properties[name].hasOwnProperty(ADDITIONAL_PROPERTY_FLAG);
49-
50-
// 递归参数
51-
return h(
52-
SchemaField,
53-
{
54-
props: {
55-
...props,
56-
schema: schema.properties[name],
57-
uiSchema: addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name],
58-
errorSchema: errorSchema[name],
59-
required: self.isRequired(name),
60-
curNodePath: computedCurPath(props.curNodePath, name)
61-
}
46+
// 递归参数
47+
const propertiesVNodeList = orderedProperties.map(name => h(
48+
SchemaField,
49+
{
50+
props: {
51+
...props,
52+
schema: schema.properties[name],
53+
uiSchema: uiSchema[name],
54+
errorSchema: errorSchema[name],
55+
required: self.isRequired(name),
56+
curNodePath: computedCurPath(props.curNodePath, name)
6257
}
63-
);
64-
});
58+
}
59+
));
6560

6661
return h(
6762
FieldGroupWrap,

0 commit comments

Comments
 (0)