Skip to content
This repository was archived by the owner on Oct 10, 2018. It is now read-only.

Commit cbea99f

Browse files
committed
releases: 0.1.0, Happy Lantern Festival
1 parent 9bddc94 commit cbea99f

File tree

6 files changed

+110
-1
lines changed

6 files changed

+110
-1
lines changed

docs/changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ title: 更新日志
44
type: Basic
55
---
66

7+
### 0.1.0
8+
9+
`2018-3-2`
10+
11+
- `nz-sf` 组件
12+
- 新增 `refreshSchema()` 方法,用于需要动态修改 Schema 某个值时可以方便调用
13+
- 修复 `model` 参数双向绑定无效问题
14+
- Schema
15+
- `visibleIf`:支持复杂表达式
16+
- Widgets
17+
- `button`:新增 `popconfirm` 参数,允许设置按钮确认框
18+
- `number`:修复 `default` 值无效问题
19+
720
### 0.0.1
821

922
`2018-2-27`

docs/qa.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
order: 4
3+
title: 常见问题
4+
type: Basic
5+
---
6+
7+
## 隐藏字段的用处?
8+
9+
当你需要一些必填字段但又无需任何呈现时非常有用,例如 `parent_id` 父编号可能来自已知信息。
10+
11+
或一些条件表单中,例如:
12+
13+
```ts
14+
schema: SFSchema = {
15+
properties: {
16+
parent_id: {
17+
type: 'string',
18+
widget: 'hidden'
19+
},
20+
remark: {
21+
type: 'string',
22+
title: '描述',
23+
widget: 'textarea',
24+
visibleIf: {
25+
parent_id: (value: number) => value > 0
26+
}
27+
}
28+
}
29+
}
30+
```
31+
32+
其中 `parent_id` 必须定义为隐藏字段,这样在条件 `visibleIf` 中才能访问到你希望的属性值。
33+
34+
## 如何动态使用 Schema?
35+
36+
一般分为两种情形:
37+
38+
**1、Scheam 定义后可能受限于某个数据来自远程**
39+
40+
```ts
41+
@ViewChild('sf') sf: FormComponent;
42+
schema: SFSchema = {
43+
properties: {
44+
app: {
45+
type: 'string',
46+
title: '附属应用',
47+
widget: 'select',
48+
enum: []
49+
}
50+
}
51+
};
52+
53+
ngOnInit() {
54+
this.http.get('/apps').subscribe((res: any) => {
55+
this.schema.properties.app.enum = res;
56+
this.sf.refreshSchema();
57+
});
58+
}
59+
```
60+
61+
**2、远程 Schema**
62+
63+
```ts
64+
schema: SFSchema = {
65+
properties: {}
66+
};
67+
68+
ngOnInit() {
69+
this.http.get('/schema').subscribe((res: any) => {
70+
this.schema = res;
71+
});
72+
}
73+
```
74+
75+
## Schema 中 `enum``widget.data` 有什么区别?
76+
77+
二者是兼容的,`enum` 属性 Json Schema 标准之一;后者是为了使小部件属性的完整性;本质上应该尽可能使用 `enum` 标准。
78+
79+
## 什么时候使用 `default`
80+
81+
Schema 的 `default` 用于设置初始化,一般情况下当修改表单时是需要提供 `model` 参数,但对于增加表单来说,应该依靠 `default` 提供一个更友好的表单给用户。

docs/schema.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ disabled | 是否禁用状态 | `boolean` | -
3131
class | 自定义类,等同 `[ngClass]` 值 | `string,string[]` | -
3232
style | 自定义样式,等同 `[ngStyle]` 值 | `object` | -
3333
grid | 响应式属性 | `SFGrid` | -
34+
visibleIf | 条件表单 | `{ [key: string]: any[] | ((value: any) => boolean) }` | -
35+
36+
**visibleIf**
37+
38+
指定条件时才显示,例如:
39+
40+
- `visibleIf: { shown: [ true ] }`:当 `shown: true` 时才显示当前属性
41+
- `visibleIf: { shown: [ '$ANY$' ] }`:当 `shown` 包括任意值时
42+
- `visibleIf: { shown: (value: any) => value > 0 }`:复杂表达式
3443

3544
## 小部件Schema
3645

lib/src/schema/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export interface SFSchema extends ErrorSchema, SFHorizontalLayoutSchema, SFRende
157157
* 指定条件时才显示,例如:
158158
*
159159
* - `visibleIf: { shown: [ true ] }`:当 `shown: true` 时才显示当前属性
160+
* - `visibleIf: { shown: [ '$ANY$' ] }`:当 `shown` 包括任意值时
160161
* - `visibleIf: { shown: (value: any) => value > 0 }`:复杂表达式
161162
*/
162163
visibleIf?: { [key: string]: any[] | ((value: any) => boolean) };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nz-schema-form",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"license": "MIT",
55
"description": "ng-zorro-antd form generation based on JSON-Schema",
66
"main": "./bundles/index.js",

src/app/document/data.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export const DATA = {
2626
title: '自定义错误格式',
2727
content: getMd(require('!!raw-loader!../../../docs/error.md'))
2828
},
29+
{
30+
id: 'qa',
31+
title: '常见问题',
32+
content: getMd(require('!!raw-loader!../../../docs/qa.md'))
33+
},
2934
{
3035
id: 'changelog',
3136
title: '更新日志',

0 commit comments

Comments
 (0)