tntd 1.3.65 → 1.4.1
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/.eslintignore +2 -1
- package/babel.config.js +2 -2
- package/dist/0645cf743e4e44ca9da321d689897f07.png +0 -0
- package/dist/09db77de0c24fa0f45f8a5cf299a3d11.png +0 -0
- package/dist/1.tntd.js +12 -0
- package/dist/1d0b52448de217857b270af807e9360d.png +0 -0
- package/dist/25d78d77c9c2f0d403e5d899ceb5b1ef.png +0 -0
- package/dist/27fa44ff0c98e1594d79b73045aabedf.png +0 -0
- package/dist/2c95075adb68d6131b59cae9fa554ec2.png +0 -0
- package/dist/377c871d922a25c773a9e7c2f42ed7c0.png +0 -0
- package/dist/3d901589b40bd56ff1fde2bbb700bfe1.png +0 -0
- package/dist/4abe481e130d7be0574e45573de8beb7.png +0 -0
- package/dist/95ee2260a509cd630d89c5367ed1973b.png +0 -0
- package/dist/b9dd5ff3622296fbee51ed68f4bca1bf.png +0 -0
- package/dist/bd2921989f9296089ba58efb7a76f3ef.png +0 -0
- package/dist/stats.json +45855 -0
- package/dist/tntd.css +1 -0
- package/dist/tntd.js +15 -0
- package/es/ArrayInput/README.md +129 -0
- package/es/ArrayInput/icon.js +24 -0
- package/es/ArrayInput/index.js +274 -0
- package/es/ArrayInput/index.less +20 -0
- package/es/AuthContext.js +4 -0
- package/es/Columns/README.md +149 -0
- package/es/Columns/index.js +82 -0
- package/es/Columns/index.less +75 -0
- package/es/DevelopmentLogin/LoginModal.js +117 -0
- package/es/DevelopmentLogin/README.md +49 -0
- package/es/DevelopmentLogin/index.js +40 -0
- package/es/Ellipsis/README.md +104 -0
- package/es/Ellipsis/Svg/CopySVG.js +63 -0
- package/es/Ellipsis/Svg/TickSVG.js +41 -0
- package/es/Ellipsis/index.js +139 -0
- package/es/Ellipsis/index.less +56 -0
- package/es/Handle/README.md +104 -0
- package/es/Handle/index.js +86 -0
- package/es/Handle/index.less +9 -0
- package/es/Icon/README.md +119 -0
- package/es/Icon/fonts/demo.css +539 -0
- package/es/Icon/fonts/demo_index.html +3345 -0
- package/es/Icon/fonts/iconfont.css +569 -0
- package/es/Icon/fonts/iconfont.eot +0 -0
- package/es/Icon/fonts/iconfont.js +41 -0
- package/es/Icon/fonts/iconfont.json +975 -0
- package/es/Icon/fonts/iconfont.svg +440 -0
- package/es/Icon/fonts/iconfont.ttf +0 -0
- package/es/Icon/fonts/iconfont.woff +0 -0
- package/es/Icon/fonts/iconfont.woff2 +0 -0
- package/es/Icon/iconList.js +1 -0
- package/es/Icon/index.js +26 -0
- package/es/Icon/index.less +9 -0
- package/es/Img/Contain.js +69 -0
- package/es/Img/Cover.js +126 -0
- package/es/Img/README.md +131 -0
- package/es/Img/index.js +76 -0
- package/es/Layout/ActionsContext.js +3 -0
- package/es/Layout/AppList.js +223 -0
- package/es/Layout/Application.js +113 -0
- package/es/Layout/Avatar.js +112 -0
- package/es/Layout/CompatibleLanguage.js +177 -0
- package/es/Layout/EnterpriseLayout/Avatar.js +138 -0
- package/es/Layout/EnterpriseLayout/Language.js +81 -0
- package/es/Layout/EnterpriseLayout/Theme.js +75 -0
- package/es/Layout/EnterpriseLayout/index.js +31 -0
- package/es/Layout/GlobalNavigation/NavigationPopup.js +396 -0
- package/es/Layout/GlobalNavigation/index.js +137 -0
- package/es/Layout/Header.js +95 -0
- package/es/Layout/HeaderActions.js +105 -0
- package/es/Layout/HeaderNavs.js +93 -0
- package/es/Layout/HeaderTabs.js +264 -0
- package/es/Layout/Iconfont.js +4 -0
- package/es/Layout/Language.js +81 -0
- package/es/Layout/Layout.js +232 -0
- package/es/Layout/Logo.js +86 -0
- package/es/Layout/OrgAppList.js +304 -0
- package/es/Layout/README.md +783 -0
- package/es/Layout/SideMenu.js +338 -0
- package/es/Layout/Theme.js +105 -0
- package/es/Layout/checkAuth.js +29 -0
- package/es/Layout/createActions.js +39 -0
- package/es/Layout/images/avatar/empty.png +0 -0
- package/es/Layout/images/avatar/female1.png +0 -0
- package/es/Layout/images/avatar/female2.png +0 -0
- package/es/Layout/images/avatar/female3.png +0 -0
- package/es/Layout/images/avatar/female4.png +0 -0
- package/es/Layout/images/avatar/female5.png +0 -0
- package/es/Layout/images/avatar/female6.png +0 -0
- package/es/Layout/images/avatar/male1.png +0 -0
- package/es/Layout/images/avatar/male2.png +0 -0
- package/es/Layout/images/avatar/male3.png +0 -0
- package/es/Layout/images/avatar/male4.png +0 -0
- package/es/Layout/images/avatar/male5.png +0 -0
- package/es/Layout/images/avatar/male6.png +0 -0
- package/es/Layout/images/index.js +35 -0
- package/es/Layout/images/logo/baldur.svg +14 -0
- package/es/Layout/images/logo/bi.svg +14 -0
- package/es/Layout/images/logo/bridge.svg +15 -0
- package/es/Layout/images/logo/convert.svg +18 -0
- package/es/Layout/images/logo/dataocean.svg +31 -0
- package/es/Layout/images/logo/default.svg +19 -0
- package/es/Layout/images/logo/dispatch.svg +14 -0
- package/es/Layout/images/logo/graph.svg +26 -0
- package/es/Layout/images/logo/handle.svg +10 -0
- package/es/Layout/images/logo/indicator.svg +41 -0
- package/es/Layout/images/logo/kafka.svg +12 -0
- package/es/Layout/images/logo/logo-custom.svg +13 -0
- package/es/Layout/images/logo/model.svg +17 -0
- package/es/Layout/images/logo/mysql.svg +15 -0
- package/es/Layout/images/logo/orion.svg +24 -0
- package/es/Layout/images/logo/salaxy.svg +11 -0
- package/es/Layout/images/logo/storage.svg +16 -0
- package/es/Layout/images/logo/tnt_cli_identify.svg +19 -0
- package/es/Layout/images/logo/turing.svg +35 -0
- package/es/Layout/images/theme/theme1.svg +35 -0
- package/es/Layout/images/theme/theme2.svg +33 -0
- package/es/Layout/index.js +122 -0
- package/es/Layout/paaslayout/CompactSideMenu.js +167 -0
- package/es/Layout/paaslayout/Header.js +77 -0
- package/es/Layout/paaslayout/Logo.js +22 -0
- package/es/Layout/paaslayout/SideMenu.js +168 -0
- package/es/Layout/paaslayout/index.js +233 -0
- package/es/Layout/storage.js +47 -0
- package/es/Layout/utils.js +136 -0
- package/es/LoadingButton/README.md +75 -0
- package/es/LoadingButton/index.js +43 -0
- package/es/Modal/README.md +59 -0
- package/es/Modal/index.js +94 -0
- package/es/Modal/index.less +86 -0
- package/es/Page/Box.js +72 -0
- package/es/Page/README.md +180 -0
- package/es/Page/index.js +165 -0
- package/es/Page/index.less +144 -0
- package/es/Page/utils.js +23 -0
- package/es/QueryForm/Field/Checkbox.js +19 -0
- package/es/QueryForm/Field/Select.js +78 -0
- package/es/QueryForm/Field/SelectInput.js +88 -0
- package/es/QueryForm/Field/fieldsMap.js +27 -0
- package/es/QueryForm/Field/index.js +155 -0
- package/es/QueryForm/README.md +512 -0
- package/es/QueryForm/createActions.js +53 -0
- package/es/QueryForm/index.js +376 -0
- package/es/QueryForm/index.less +133 -0
- package/es/QueryForm/useForm.js +7 -0
- package/es/QueryListScene/List.js +376 -0
- package/es/QueryListScene/QueryForm.js +166 -0
- package/es/QueryListScene/QueryListScene.js +76 -0
- package/es/QueryListScene/README.md +790 -0
- package/es/QueryListScene/Title.js +12 -0
- package/es/QueryListScene/Toolbar.js +20 -0
- package/es/QueryListScene/createActions.js +72 -0
- package/es/QueryListScene/index.js +19 -0
- package/es/QueryListScene/index.less +97 -0
- package/es/QueryListScene/useActions.js +7 -0
- package/es/Select/DropDownWrap.js +116 -0
- package/es/Select/README.md +68 -0
- package/es/Select/index.js +618 -0
- package/es/Table/README.md +109 -0
- package/es/Table/ResizableTable/index.js +108 -0
- package/es/Table/ResizableTable/index.less +36 -0
- package/es/Table/index.js +33 -0
- package/es/Title/README.md +106 -0
- package/es/Title/index.js +40 -0
- package/es/Title/index.less +170 -0
- package/es/index.js +19 -0
- package/es/locale.js +60 -0
- package/package.json +1 -1
- package/doc-scripts.config.js +0 -37
- package/doc-scripts.renderer.js +0 -11
- package/docs/README.md +0 -1643
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
,## QueryForm
|
|
2
|
+
查询表单
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### 安装
|
|
6
|
+
```
|
|
7
|
+
npm install tntd --save
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
### 代码演示
|
|
11
|
+
|
|
12
|
+
### 展开/收起查询条件
|
|
13
|
+
```jsx
|
|
14
|
+
import React, { useState, Fragment } from 'react';
|
|
15
|
+
import ReactDOM from 'react-dom';
|
|
16
|
+
import { Button, Popconfirm, Divider, ButtonGroup, TreeSelect, Cascader, Checkbox } from 'antd';
|
|
17
|
+
import { QueryForm } from 'tntd';
|
|
18
|
+
import 'antd/dist/antd.css';
|
|
19
|
+
|
|
20
|
+
const { Field } = QueryForm;
|
|
21
|
+
const ExtraActions = (
|
|
22
|
+
<Button.Group>
|
|
23
|
+
<Button icon="cloud-upload" />
|
|
24
|
+
<Button icon="cloud-download" />
|
|
25
|
+
<Button icon="setting" />
|
|
26
|
+
</Button.Group>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
ReactDOM.render(
|
|
30
|
+
<QueryForm
|
|
31
|
+
extraActions={ExtraActions}
|
|
32
|
+
initialValues={{
|
|
33
|
+
name: 'zhangsan',
|
|
34
|
+
status: 'initial'
|
|
35
|
+
}}
|
|
36
|
+
onChange={console.log}
|
|
37
|
+
onSearch={console.log}
|
|
38
|
+
onReset={console.log}
|
|
39
|
+
onToggleExpand={console.log}
|
|
40
|
+
>
|
|
41
|
+
<Field
|
|
42
|
+
name="tree"
|
|
43
|
+
component={TreeSelect}
|
|
44
|
+
props={{
|
|
45
|
+
placeholder: "树形选择",
|
|
46
|
+
dropdownStyle:{
|
|
47
|
+
maxHeight: 400,
|
|
48
|
+
overflow: 'auto'
|
|
49
|
+
},
|
|
50
|
+
treeData: [
|
|
51
|
+
{
|
|
52
|
+
title: 'Node1',
|
|
53
|
+
value: '0-0',
|
|
54
|
+
key: '0-0',
|
|
55
|
+
children: [
|
|
56
|
+
{
|
|
57
|
+
title: 'Child Node1',
|
|
58
|
+
value: '0-0-1',
|
|
59
|
+
key: '0-0-1',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
title: 'Child Node2',
|
|
63
|
+
value: '0-0-2',
|
|
64
|
+
key: '0-0-2',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
title: 'Node2',
|
|
70
|
+
value: '0-1',
|
|
71
|
+
key: '0-1',
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
<Field
|
|
77
|
+
type="input"
|
|
78
|
+
name="name"
|
|
79
|
+
props={{
|
|
80
|
+
placeholder: "名称"
|
|
81
|
+
}}
|
|
82
|
+
/>
|
|
83
|
+
<Field
|
|
84
|
+
type="select"
|
|
85
|
+
name="status"
|
|
86
|
+
props={{
|
|
87
|
+
placeholder: '状态',
|
|
88
|
+
options: [
|
|
89
|
+
{ label: '初始化', value: 'initial' },
|
|
90
|
+
{ label: '运行中', value: 'running' },
|
|
91
|
+
{ label: '成功', value: 'success', disabled: true },
|
|
92
|
+
{ label: '失败', value: 'fail' }
|
|
93
|
+
]
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
<Field
|
|
97
|
+
type="select"
|
|
98
|
+
name="select1"
|
|
99
|
+
props={{
|
|
100
|
+
placeholder: '状态',
|
|
101
|
+
loadData: () => new Promise(resolve => resolve(['初始化', '运行中', '成功', '失败']))
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
<Field
|
|
105
|
+
type="input"
|
|
106
|
+
name="name2"
|
|
107
|
+
props={{ placeholder: "名称" }}
|
|
108
|
+
/>
|
|
109
|
+
<Field
|
|
110
|
+
type="search"
|
|
111
|
+
name="search"
|
|
112
|
+
props={{
|
|
113
|
+
placeholder: '搜索'
|
|
114
|
+
}}
|
|
115
|
+
/>
|
|
116
|
+
<Field
|
|
117
|
+
type="select"
|
|
118
|
+
name="select2"
|
|
119
|
+
props={{
|
|
120
|
+
placeholder: '状态',
|
|
121
|
+
options: ['初始化', '运行中', '成功', '失败']
|
|
122
|
+
}}
|
|
123
|
+
/>
|
|
124
|
+
<Field type="date" name="date3" />
|
|
125
|
+
<Field type="input" name="field1" />
|
|
126
|
+
<Field type="input" name="field2" />
|
|
127
|
+
<Field type="dateRange" name="date2" />
|
|
128
|
+
<Field type="checkbox" name="checkbox" />
|
|
129
|
+
</QueryForm>,
|
|
130
|
+
document.getElementById('root')
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 类组件示例
|
|
135
|
+
```jsx
|
|
136
|
+
import React from 'react';
|
|
137
|
+
import { Button } from 'antd';
|
|
138
|
+
import { QueryForm } from 'tntd';
|
|
139
|
+
|
|
140
|
+
const { Field, createForm } = QueryForm;
|
|
141
|
+
|
|
142
|
+
class QueryFormDemo extends React.Component {
|
|
143
|
+
form = createForm();
|
|
144
|
+
|
|
145
|
+
render() {
|
|
146
|
+
return (
|
|
147
|
+
<QueryForm
|
|
148
|
+
form={this.form}
|
|
149
|
+
initialValues={{ name: 'Hello', job: 'Developer', status: 'init' }}
|
|
150
|
+
extraActions={(
|
|
151
|
+
<Button.Group>
|
|
152
|
+
<Button onClick={() => this.form.setValues({ name: 'World', status: 'running' })}>设置值</Button>
|
|
153
|
+
<Button onClick={() => this.form.setValue('job', 'Designer')}>设置单个值</Button>
|
|
154
|
+
<Button onClick={() => alert(JSON.stringify(this.form.getValues(), null, 4))}>获取值</Button>
|
|
155
|
+
</Button.Group>
|
|
156
|
+
)}
|
|
157
|
+
>
|
|
158
|
+
<Field type="input" name="name" />
|
|
159
|
+
<Field type="input" name="job" />
|
|
160
|
+
<Field type="select" name="status" props={{ options: ['init', 'running', 'error', 'success']}} />
|
|
161
|
+
</QueryForm>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
componentDidMount() {
|
|
166
|
+
console.log('form:', this.form);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
ReactDOM.render(
|
|
171
|
+
<QueryFormDemo />,
|
|
172
|
+
document.getElementById('root')
|
|
173
|
+
)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
### 抽屉显示更多条件
|
|
178
|
+
```jsx
|
|
179
|
+
import React, { useState, Fragment } from 'react';
|
|
180
|
+
import ReactDOM from 'react-dom';
|
|
181
|
+
import { Button, Popconfirm, Divider, ButtonGroup, TreeSelect, Cascader, Icon } from 'antd';
|
|
182
|
+
import { QueryForm } from 'tntd';
|
|
183
|
+
import { createGlobalStyle } from 'styled-components';
|
|
184
|
+
import 'antd/dist/antd.css';
|
|
185
|
+
|
|
186
|
+
const GlobalStyle = createGlobalStyle`
|
|
187
|
+
.site-body {
|
|
188
|
+
.ichYgh {
|
|
189
|
+
overflow: visible;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
`;
|
|
193
|
+
|
|
194
|
+
const { useForm, Field } = QueryForm;
|
|
195
|
+
|
|
196
|
+
const QueryFormDemo = () => {
|
|
197
|
+
const [form] = useForm();
|
|
198
|
+
|
|
199
|
+
const ExtraActions = (
|
|
200
|
+
<Button.Group>
|
|
201
|
+
<Button icon="cloud-upload" onClick={() => form.setValues({ tree: '0-0', name: '张三', obj: { id: '1000' }})}/>
|
|
202
|
+
<Button icon="cloud-upload" onClick={() => form.setValue('name', '')} />
|
|
203
|
+
<Button icon="cloud-download" onClick={() => form.resetValues()}/>
|
|
204
|
+
<Button icon="setting" onClick={() => console.log('form values:', form.getValues())}/>
|
|
205
|
+
</Button.Group>
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<QueryForm
|
|
210
|
+
form={form}
|
|
211
|
+
extraActions={ExtraActions}
|
|
212
|
+
// 设置showFieldCount时,则使用抽屉显示更多否则使用展开/收起交互
|
|
213
|
+
showFieldCount={2}
|
|
214
|
+
initialValues={{
|
|
215
|
+
name: 'Jim Green',
|
|
216
|
+
status: 'initial',
|
|
217
|
+
obj: {
|
|
218
|
+
name: 'zhangsan'
|
|
219
|
+
}
|
|
220
|
+
}}
|
|
221
|
+
onChange={console.log}
|
|
222
|
+
onSearch={console.log}
|
|
223
|
+
onReset={console.log}
|
|
224
|
+
onToggleExpand={console.log}
|
|
225
|
+
>
|
|
226
|
+
<Field
|
|
227
|
+
type="selectInput"
|
|
228
|
+
name="obj"
|
|
229
|
+
props={{
|
|
230
|
+
placeholder: "名称",
|
|
231
|
+
options: [
|
|
232
|
+
{ label: '名称', value: 'name' },
|
|
233
|
+
{ label: 'ID', value: 'id' }
|
|
234
|
+
],
|
|
235
|
+
addonBeforeStyle: { width: '100px' }
|
|
236
|
+
}}
|
|
237
|
+
/>
|
|
238
|
+
<Field
|
|
239
|
+
name="tree"
|
|
240
|
+
component={TreeSelect}
|
|
241
|
+
props={{
|
|
242
|
+
placeholder: "名称222",
|
|
243
|
+
dropdownStyle:{
|
|
244
|
+
maxHeight: 400,
|
|
245
|
+
overflow: 'auto'
|
|
246
|
+
},
|
|
247
|
+
treeData: [
|
|
248
|
+
{
|
|
249
|
+
title: 'Node1',
|
|
250
|
+
value: '0-0',
|
|
251
|
+
key: '0-0',
|
|
252
|
+
children: [
|
|
253
|
+
{
|
|
254
|
+
title: 'Child Node1',
|
|
255
|
+
value: '0-0-1',
|
|
256
|
+
key: '0-0-1',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
title: 'Child Node2',
|
|
260
|
+
value: '0-0-2',
|
|
261
|
+
key: '0-0-2',
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
title: 'Node2',
|
|
267
|
+
value: '0-1',
|
|
268
|
+
key: '0-1',
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
}}
|
|
272
|
+
/>
|
|
273
|
+
<Field
|
|
274
|
+
type="input"
|
|
275
|
+
name="name"
|
|
276
|
+
props={{
|
|
277
|
+
placeholder: "名称"
|
|
278
|
+
}}
|
|
279
|
+
/>
|
|
280
|
+
<Field
|
|
281
|
+
name="cascader"
|
|
282
|
+
component={Cascader}
|
|
283
|
+
props={{
|
|
284
|
+
options: [
|
|
285
|
+
{
|
|
286
|
+
value: 'zhejiang',
|
|
287
|
+
label: 'Zhejiang',
|
|
288
|
+
children: [
|
|
289
|
+
{
|
|
290
|
+
value: 'hangzhou',
|
|
291
|
+
label: 'Hangzhou',
|
|
292
|
+
children: [
|
|
293
|
+
{
|
|
294
|
+
value: 'xihu',
|
|
295
|
+
label: 'West Lake'
|
|
296
|
+
}
|
|
297
|
+
]
|
|
298
|
+
}
|
|
299
|
+
]
|
|
300
|
+
}
|
|
301
|
+
]
|
|
302
|
+
}}
|
|
303
|
+
/>
|
|
304
|
+
<Field
|
|
305
|
+
type="date"
|
|
306
|
+
name="date1"
|
|
307
|
+
/>
|
|
308
|
+
<Field
|
|
309
|
+
title="状态"
|
|
310
|
+
type="select"
|
|
311
|
+
name="status2"
|
|
312
|
+
props={{
|
|
313
|
+
placeholder: '状态',
|
|
314
|
+
options: [
|
|
315
|
+
{ label: '初始化', value: 'initial' },
|
|
316
|
+
{ label: '运行中', value: 'running' },
|
|
317
|
+
{ label: '成功', value: 'success', disabled: true },
|
|
318
|
+
{ label: '失败', value: 'fail' }
|
|
319
|
+
]
|
|
320
|
+
}}
|
|
321
|
+
/>
|
|
322
|
+
<Field title="日期" type="date" name="date" />
|
|
323
|
+
<Field
|
|
324
|
+
title="日期范围"
|
|
325
|
+
type="dateRange"
|
|
326
|
+
name="date2"
|
|
327
|
+
/>
|
|
328
|
+
<Field
|
|
329
|
+
title="状态"
|
|
330
|
+
type="select"
|
|
331
|
+
name="select1"
|
|
332
|
+
props={{
|
|
333
|
+
placeholder: '状态',
|
|
334
|
+
fieldNames: {
|
|
335
|
+
label: 'displayName',
|
|
336
|
+
value: 'name'
|
|
337
|
+
},
|
|
338
|
+
loadData: () => new Promise(
|
|
339
|
+
resolve => resolve([
|
|
340
|
+
{ name: 'success', displayName: '成功' },
|
|
341
|
+
{ name: 'fail', displayName: '失败' }
|
|
342
|
+
])
|
|
343
|
+
)
|
|
344
|
+
}}
|
|
345
|
+
/>
|
|
346
|
+
<Field
|
|
347
|
+
title="名称"
|
|
348
|
+
type="input"
|
|
349
|
+
name="name2"
|
|
350
|
+
props={{ placeholder: "名称" }}
|
|
351
|
+
/>
|
|
352
|
+
<Field
|
|
353
|
+
title="状态2"
|
|
354
|
+
type="select"
|
|
355
|
+
name="select2"
|
|
356
|
+
props={{
|
|
357
|
+
placeholder: '状态',
|
|
358
|
+
options: ['初始化', '运行中', '成功', '失败']
|
|
359
|
+
}}
|
|
360
|
+
/>
|
|
361
|
+
</QueryForm>
|
|
362
|
+
);
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
ReactDOM.render(
|
|
366
|
+
<Fragment>
|
|
367
|
+
<QueryFormDemo />
|
|
368
|
+
<GlobalStyle />
|
|
369
|
+
</Fragment>,
|
|
370
|
+
document.getElementById('root')
|
|
371
|
+
)
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### API
|
|
375
|
+
#### QueryForm
|
|
376
|
+
| 属性名称 | 属性说明 | 类型 | 默认值 | 是否必须 |
|
|
377
|
+
| :------------- | :-------------------------------------------------------- | :-------- | :----- | :------- |
|
|
378
|
+
| initialValues | 表单初始值对象 | object | 无 | 否 |
|
|
379
|
+
| showFieldCount | 显示在外面的表单数量(尽在“更多条件”在Drawer交互时使用) | number | 无 | 否 |
|
|
380
|
+
| showExpand | 展开/收起功能配置,默认开启 | boolean | true | 否 |
|
|
381
|
+
| showSearch | 搜索按钮显示配置,默认开启 | boolean | true | 否 |
|
|
382
|
+
| showReset | 重置按钮显示配置,默认开启 | boolean | true | 否 |
|
|
383
|
+
| drawerProps | Drawer props(参见antd,设置样式宽度时可用) | Object | 无 | 否 |
|
|
384
|
+
| extraActions | 额外操作 | ReactNode | 无 | 否 |
|
|
385
|
+
| renderActions | 表单操作, 自定义操作按钮,默认是查询、重置 | Function | 无 | 否 |
|
|
386
|
+
| onChange | 表单变化事件,onChange(values, { name, value, preValue }) | Function | 无 | 否 |
|
|
387
|
+
| onSearch | 搜索事件,onSearch(values) | Function | 无 | 否 |
|
|
388
|
+
| onReset | 重置表单事件,onReset(values) | Function | 无 | 否 |
|
|
389
|
+
|
|
390
|
+
#### Field
|
|
391
|
+
| 属性名称 | 属性说明 | 类型 | 默认值 | 是否必须 |
|
|
392
|
+
| :-------- | :------------------------------------------------------------- | :----- | :----- | :------- |
|
|
393
|
+
| name | 表单项名,保证唯一 | string | 无 | 是 |
|
|
394
|
+
| title | 表单label | string | 无 | 否 |
|
|
395
|
+
| type | 表单类型input、search, number、select、selectInput、 date、 dateRange | 无 | 否 |
|
|
396
|
+
| component | 表单组件,如果内置的type表单组件不满足需求的话,可以直接传ReactNode类型的表单组件,其优先级高于type,如 antd TreeSelect、Cascader等,也可以完全自定义表单组件 | 无 | 否 |
|
|
397
|
+
| props | 表单元素属性,参照antd, Input, InputNumber, Select, DatePicker | Object | 无 | 否 |
|
|
398
|
+
| className | 添加样式class | string | 无 | 否 |
|
|
399
|
+
|
|
400
|
+
type="select", props 扩展了 options, fieldNames, loadData用法如下:
|
|
401
|
+
```js
|
|
402
|
+
<Field
|
|
403
|
+
type="select"
|
|
404
|
+
name="status"
|
|
405
|
+
props={{
|
|
406
|
+
options: [
|
|
407
|
+
{ name: 'success', displayName: '成功' },
|
|
408
|
+
{ name: 'fail', displayName: '失败' }
|
|
409
|
+
],
|
|
410
|
+
fieldNames: {
|
|
411
|
+
label: 'displayName',
|
|
412
|
+
value: 'name'
|
|
413
|
+
}
|
|
414
|
+
}}
|
|
415
|
+
/>
|
|
416
|
+
```
|
|
417
|
+
loadData 是一个function 返回一个promise, 用于异步加载options的场景
|
|
418
|
+
```js
|
|
419
|
+
<Field
|
|
420
|
+
type="select"
|
|
421
|
+
name="status"
|
|
422
|
+
props={{
|
|
423
|
+
loadData: () => new Promise(
|
|
424
|
+
resolve => resolve([
|
|
425
|
+
{ name: 'success', displayName: '成功' },
|
|
426
|
+
{ name: 'fail', displayName: '失败' }
|
|
427
|
+
])
|
|
428
|
+
),
|
|
429
|
+
fieldNames: {
|
|
430
|
+
label: 'displayName',
|
|
431
|
+
value: 'name'
|
|
432
|
+
}
|
|
433
|
+
}}
|
|
434
|
+
/>
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
type="selectInput", 扩展了addonBeforeStyle属性,用来设置前面Select的样式
|
|
438
|
+
```js
|
|
439
|
+
<Field
|
|
440
|
+
type="selectInput"
|
|
441
|
+
props={{
|
|
442
|
+
addonBeforeStyle: {
|
|
443
|
+
width: '160px'
|
|
444
|
+
}
|
|
445
|
+
}}
|
|
446
|
+
/>
|
|
447
|
+
```
|
|
448
|
+
#### form
|
|
449
|
+
form是QueryForm组件数据管理的对象,里面包含了数据相关的setter 和 getter方法。
|
|
450
|
+
```js
|
|
451
|
+
{
|
|
452
|
+
// 设置form表单值
|
|
453
|
+
setValues(values: object): void,
|
|
454
|
+
|
|
455
|
+
// 设置单个field表单项值
|
|
456
|
+
setValue(name: string, value): void,
|
|
457
|
+
|
|
458
|
+
// 重置form表单值
|
|
459
|
+
resetValues(): void,
|
|
460
|
+
|
|
461
|
+
// 获取form表单值
|
|
462
|
+
getValues(): object,
|
|
463
|
+
|
|
464
|
+
// 获取单个field值
|
|
465
|
+
getValue(name): any
|
|
466
|
+
}
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
#### useForm
|
|
470
|
+
hooks函数组件中使用,返回一个[form]用法如下:
|
|
471
|
+
```js
|
|
472
|
+
import { QueryForm } from 'tntd';
|
|
473
|
+
|
|
474
|
+
const { Field, useForm } = QueryForm;
|
|
475
|
+
|
|
476
|
+
const Demo = () => {
|
|
477
|
+
const [form] = useForm();
|
|
478
|
+
|
|
479
|
+
return (
|
|
480
|
+
<>
|
|
481
|
+
<Button onClick={() => form.setValues({ name: 'Hello World' })}>设置值</Button>
|
|
482
|
+
<QueryForm form={form}>
|
|
483
|
+
<Field
|
|
484
|
+
type="input"
|
|
485
|
+
name="name"
|
|
486
|
+
/>
|
|
487
|
+
</QueryForm>
|
|
488
|
+
<>
|
|
489
|
+
);
|
|
490
|
+
};
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
#### createForm
|
|
494
|
+
主要用在class 组件的场景,用法如下:
|
|
495
|
+
```js
|
|
496
|
+
import React from 'react';
|
|
497
|
+
import { QueryForm } from 'tntd';
|
|
498
|
+
|
|
499
|
+
const { Field, createForm } = QueryForm;
|
|
500
|
+
|
|
501
|
+
class Demo extends React.Component {
|
|
502
|
+
form = createForm();
|
|
503
|
+
|
|
504
|
+
render() {
|
|
505
|
+
return (
|
|
506
|
+
<QueryForm form={this.form}>
|
|
507
|
+
<Field type="input" name="name" />
|
|
508
|
+
</QueryForm>
|
|
509
|
+
)
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
```
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
import EventEmitter from 'eventemitter3';
|
|
8
|
+
import { get, set } from 'lodash';
|
|
9
|
+
export default (function () {
|
|
10
|
+
var eventEmitter = new EventEmitter();
|
|
11
|
+
var data = {
|
|
12
|
+
initialValues: {},
|
|
13
|
+
values: {}
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
setData: function setData(key, value) {
|
|
17
|
+
set(data, key, value);
|
|
18
|
+
},
|
|
19
|
+
getData: function getData(key) {
|
|
20
|
+
get(data, key);
|
|
21
|
+
},
|
|
22
|
+
setValues: function setValues(values) {
|
|
23
|
+
data.values = values;
|
|
24
|
+
eventEmitter.emit('setValues', values);
|
|
25
|
+
},
|
|
26
|
+
getValues: function getValues() {
|
|
27
|
+
return data.values;
|
|
28
|
+
},
|
|
29
|
+
resetValues: function resetValues() {
|
|
30
|
+
data.values = _objectSpread({}, data.initialValues);
|
|
31
|
+
eventEmitter.emit('setValues', data.values);
|
|
32
|
+
},
|
|
33
|
+
setValue: function setValue(name, value) {
|
|
34
|
+
data.values = data.values || {};
|
|
35
|
+
data.values[name] = value;
|
|
36
|
+
eventEmitter.emit('setValue', name, value);
|
|
37
|
+
},
|
|
38
|
+
getValue: function getValue(name) {
|
|
39
|
+
var _data$values;
|
|
40
|
+
|
|
41
|
+
return (_data$values = data.values) == null ? void 0 : _data$values[name];
|
|
42
|
+
},
|
|
43
|
+
on: function on(eventName, callback) {
|
|
44
|
+
eventEmitter.on(eventName, callback);
|
|
45
|
+
},
|
|
46
|
+
emit: function emit() {
|
|
47
|
+
eventEmitter.emit.apply(eventEmitter, arguments);
|
|
48
|
+
},
|
|
49
|
+
off: function off() {
|
|
50
|
+
eventEmitter.removeListener.apply(eventEmitter, arguments);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
});
|