@hzab/list-render 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +226 -63
- package/docs/form-linkage.md +203 -0
- package/docs/remote-data.md +72 -22
- package/docs/table.md +86 -0
- package/lib/data-model.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +2 -1
- package/src/data-model.js +2 -225
- package/src/index.js +1 -1
- package/src/list-render.jsx +0 -1
- package/src/pagination-render/index.jsx +2 -2
- package/src/table-render/index.jsx +10 -10
package/docs/remote-data.md
CHANGED
|
@@ -6,34 +6,67 @@
|
|
|
6
6
|
|
|
7
7
|
```JSX
|
|
8
8
|
// RemoteData
|
|
9
|
-
|
|
10
9
|
import listSchema from "./list.schema.json";
|
|
11
10
|
|
|
12
11
|
const schemaScope = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
// 动态获取 select 数据
|
|
13
|
+
fetchSelectOptions(field, query) {
|
|
14
|
+
field.loading = true;
|
|
15
|
+
fetch(
|
|
16
|
+
`//some.domain/getSomething?test=${query.test}`
|
|
17
|
+
)
|
|
18
|
+
.then((response) => response.json())
|
|
19
|
+
.then(
|
|
20
|
+
({ data }) => {
|
|
21
|
+
// field 目标组件的 配置参数
|
|
22
|
+
console.log("fetchSelectOptions field", field);
|
|
23
|
+
// 通过 select 可直接通过 field.dataSource 进行选项数据的配置
|
|
24
|
+
field.dataSource = data;
|
|
25
|
+
field.loading = false;
|
|
26
|
+
},
|
|
27
|
+
() => {
|
|
28
|
+
field.loading = false;
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
},
|
|
32
|
+
// 动态获取 treeSelect 数据
|
|
33
|
+
fetchMenuTree(field, query) {
|
|
34
|
+
field.loading = true;
|
|
35
|
+
fetch(
|
|
36
|
+
`//some.domain/getSomething?test=${query.test}`
|
|
37
|
+
)
|
|
38
|
+
.then((response) => response.json())
|
|
39
|
+
.then(
|
|
40
|
+
({ data }) => {
|
|
41
|
+
// field 目标组件的 配置参数
|
|
42
|
+
console.log("fetchMenuTree field", field);
|
|
43
|
+
// 通过 field.component[1] 可以动态配置目标组件的 props
|
|
44
|
+
console.log("fetchMenuTree field.component[1]", field.component[1]);
|
|
45
|
+
// 树选择器 数据源,需要通过 field.component[1] 进行配置
|
|
46
|
+
field.component[1].treeData = data;
|
|
47
|
+
field.loading = false;
|
|
48
|
+
},
|
|
49
|
+
() => {
|
|
50
|
+
field.loading = false;
|
|
51
|
+
}
|
|
52
|
+
);
|
|
20
53
|
},
|
|
21
54
|
};
|
|
22
55
|
|
|
23
|
-
function RemoteData
|
|
24
|
-
const listDM = useMemo(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
56
|
+
function RemoteData() {
|
|
57
|
+
const listDM = useMemo(
|
|
58
|
+
() =>
|
|
59
|
+
new DataModule({
|
|
60
|
+
getListApi: "/api/v1/user/list",
|
|
61
|
+
getApi: "/api/v1/user/list/:id",
|
|
62
|
+
createApi: "/api/v1/user/list",
|
|
63
|
+
updateApi: "/api/v1/user/list/:id",
|
|
64
|
+
deleteApi: "/api/v1/user/list/:id",
|
|
65
|
+
}),
|
|
66
|
+
[]
|
|
67
|
+
);
|
|
31
68
|
return (
|
|
32
|
-
|
|
33
|
-
model={listDM}
|
|
34
|
-
schema={listSchema}
|
|
35
|
-
schemaScope={schemaScope}
|
|
36
|
-
/>
|
|
69
|
+
<ListRender model={listDM} schema={listSchema} schemaScope={schemaScope} />
|
|
37
70
|
);
|
|
38
71
|
}
|
|
39
72
|
|
|
@@ -65,9 +98,26 @@ export default RemoteData;
|
|
|
65
98
|
"name": "parentId",
|
|
66
99
|
"x-designable-id": "i012z5nbd5z",
|
|
67
100
|
"x-index": 0
|
|
101
|
+
},
|
|
102
|
+
"select": {
|
|
103
|
+
"title": "select",
|
|
104
|
+
"x-decorator": "FormItem",
|
|
105
|
+
"x-component": "Select",
|
|
106
|
+
"x-validator": [],
|
|
107
|
+
"x-component-props": {},
|
|
108
|
+
"x-decorator-props": {},
|
|
109
|
+
"name": "select",
|
|
110
|
+
"x-designable-id": "jvjf7fkpke9",
|
|
111
|
+
"x-index": 1,
|
|
112
|
+
"x-reactions": {
|
|
113
|
+
"dependencies": [],
|
|
114
|
+
"fulfill": {
|
|
115
|
+
"run": "$effect(() => {\n try {\n fetchSelectOptions && fetchSelectOptions($self);\n } catch (e) {}\n}, [])\n"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
68
118
|
}
|
|
69
119
|
},
|
|
70
|
-
"x-designable-id": "
|
|
120
|
+
"x-designable-id": "ldzb3lu81dx"
|
|
71
121
|
}
|
|
72
122
|
}
|
|
73
123
|
|
package/docs/table.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# 表格相关
|
|
2
|
+
|
|
3
|
+
## query 相关
|
|
4
|
+
|
|
5
|
+
#### 设置过滤项
|
|
6
|
+
|
|
7
|
+
```JSX
|
|
8
|
+
<ListRender
|
|
9
|
+
schema={schema}
|
|
10
|
+
model={listDM}
|
|
11
|
+
// 字段为 search 的 query
|
|
12
|
+
search="模糊搜索"
|
|
13
|
+
// 传入 schema 中所需表单项的 name
|
|
14
|
+
filters={["userId"]}
|
|
15
|
+
/>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
#### 开启重置按钮
|
|
19
|
+
|
|
20
|
+
```JSX
|
|
21
|
+
<ListRender
|
|
22
|
+
schema={schema}
|
|
23
|
+
model={listDM}
|
|
24
|
+
// 字段为 search 的 query
|
|
25
|
+
search="模糊搜索"
|
|
26
|
+
// 传入 schema 中所需表单项的 name
|
|
27
|
+
filters={["userId"]}
|
|
28
|
+
queryConf={{
|
|
29
|
+
hasReset: true
|
|
30
|
+
}}
|
|
31
|
+
/>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 顶部操作栏(新增按钮附近)
|
|
35
|
+
|
|
36
|
+
#### 新增按钮右侧添加其他组件
|
|
37
|
+
|
|
38
|
+
- 使用 Slots 实现
|
|
39
|
+
|
|
40
|
+
```JSX
|
|
41
|
+
const Slots = {
|
|
42
|
+
headerActionSuffix() {
|
|
43
|
+
return (<div>headerActionPrefix</div>)
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
<ListRender schema={schema} model={listDM} Slots={Slots} />
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## table 相关
|
|
51
|
+
|
|
52
|
+
#### 手动发起请求
|
|
53
|
+
|
|
54
|
+
```JSX
|
|
55
|
+
|
|
56
|
+
// 手动发起请求
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
// 重置 pageNum 为1,并发起请求
|
|
59
|
+
listRef.current?.onSearch();
|
|
60
|
+
// 请求当前页数据
|
|
61
|
+
listRef.current?.getList();
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
<ListRender
|
|
65
|
+
ref={listRef}
|
|
66
|
+
schema={schema}
|
|
67
|
+
model={listDM}
|
|
68
|
+
// 关闭自动发起请求
|
|
69
|
+
closeAutoRequest={false}
|
|
70
|
+
/>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### 编辑按钮左侧添加组件
|
|
74
|
+
|
|
75
|
+
```JSX
|
|
76
|
+
const Slots = {
|
|
77
|
+
actionPrefixSlot(props) {
|
|
78
|
+
const { text, record, index, onEdit, onDel } = props;
|
|
79
|
+
return (<div>actionPrefixSlot</div>)
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
<ListRender schema={schema} model={listDM} Slots={Slots} />
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 新增、编辑表单相关
|
package/lib/data-model.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export*from"@hzab/data-model";import DataModel from"@hzab/data-model";export default DataModel;
|