kn-hooks 0.0.11 → 0.0.12
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/md/useClipboard.md +0 -1
- package/md/useCounter.md +0 -1
- package/md/useDictionary.md +0 -1
- package/md/usePagination.md +0 -1
- package/md/usePaginationWithForm.md +0 -1
- package/md/useSwitch.md +0 -1
- package/package.json +1 -1
- package/readme.md +426 -7
package/md/useClipboard.md
CHANGED
package/md/useCounter.md
CHANGED
package/md/useDictionary.md
CHANGED
package/md/usePagination.md
CHANGED
package/md/useSwitch.md
CHANGED
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* [按需打包](#package)
|
|
7
7
|
|
|
8
8
|
* API
|
|
9
|
-
* [useDictionary - 字典管理及下拉选项框渲染](
|
|
10
|
-
* [useSwitch - 开关控制](
|
|
11
|
-
* [useClipboard - 剪贴板](
|
|
12
|
-
* [useCounter - 计数器](
|
|
13
|
-
* [usePagination - 分页管理](
|
|
14
|
-
* [usePaginationWithForm - 支持Antd-From的分页管理](
|
|
9
|
+
* [useDictionary - 字典管理及下拉选项框渲染](#module_usedictionary)
|
|
10
|
+
* [useSwitch - 开关控制](#module_useswitch)
|
|
11
|
+
* [useClipboard - 剪贴板](#module_useclipboard)
|
|
12
|
+
* [useCounter - 计数器](#module_usecounter)
|
|
13
|
+
* [usePagination - 分页管理](#module_usepagination)
|
|
14
|
+
* [usePaginationWithForm - 支持Antd-From的分页管理](#module_usepaginationwithform)
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -63,4 +63,423 @@ webpack增加`bable-plugin-import`插件,给babel plugins增加配置
|
|
|
63
63
|
// }
|
|
64
64
|
// ]
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
```<a id="module_useclipboard"></a>
|
|
67
|
+
## <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">G</span> useClipboard
|
|
68
|
+
|
|
69
|
+
* [ useClipboard](#module_useclipboard)
|
|
70
|
+
* [ useClipboard([props])](#module_useclipboard__useclipboard) ⇒ <code>UseClipboardResult</code>
|
|
71
|
+
* [ FunCopy](#module_useclipboard__funcopy) : <code>callback</code>
|
|
72
|
+
* [ UseClipboardResult](#module_useclipboard__useclipboardresult) : <code>Object</code>
|
|
73
|
+
|
|
74
|
+
<a id="module_useclipboard__useclipboard"></a>
|
|
75
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">M</span> useClipboard([props]) ⇒ <code>UseClipboardResult</code>
|
|
76
|
+
剪贴板工具
|
|
77
|
+
|
|
78
|
+
[Demo - CodeSandBox](https://codesandbox.io/s/useclipboard-b4ryc?file=/index.js)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
| Param | Type | Description |
|
|
82
|
+
| --- | --- | --- |
|
|
83
|
+
| [props] | <code>Object</code> | - |
|
|
84
|
+
| [props.onSuccess] | <code>callback</code> | 成功复制到剪贴板后的回调 ()=>void |
|
|
85
|
+
|
|
86
|
+
**Example**
|
|
87
|
+
```js
|
|
88
|
+
const clipboard= useClipboard();
|
|
89
|
+
const onCopy=()=>{
|
|
90
|
+
clipboard.copy('text',()=>{console.log('success')})
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
<a id="module_useclipboard__funcopy"></a>
|
|
94
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> FunCopy : <code>callback</code>
|
|
95
|
+
复制函数
|
|
96
|
+
|
|
97
|
+
**Properties**
|
|
98
|
+
|
|
99
|
+
| Name | Type | Description |
|
|
100
|
+
| --- | --- | --- |
|
|
101
|
+
| text | <code>string</code> | 需要被复制的字符串 |
|
|
102
|
+
| onCurSuccess | <code>callback</code> | 复制成功的回调 ()=>void |
|
|
103
|
+
|
|
104
|
+
<a id="module_useclipboard__useclipboardresult"></a>
|
|
105
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> UseClipboardResult : <code>Object</code>
|
|
106
|
+
UseClipboardResult返回的hook
|
|
107
|
+
|
|
108
|
+
**Properties**
|
|
109
|
+
|
|
110
|
+
| Name | Type | Description |
|
|
111
|
+
| --- | --- | --- |
|
|
112
|
+
| copy | <code>FunCopy</code> | 触发复制字符串的函数 |
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
<a id="module_usecounter"></a>
|
|
116
|
+
## <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">G</span> useCounter
|
|
117
|
+
|
|
118
|
+
* [ useCounter](#module_usecounter)
|
|
119
|
+
* [ useCounter()](#module_usecounter__usecounter) ⇒ <code>UseCounterResult</code>
|
|
120
|
+
* [ UseCounterResult](#module_usecounter__usecounterresult)
|
|
121
|
+
|
|
122
|
+
<a id="module_usecounter__usecounter"></a>
|
|
123
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">M</span> useCounter() ⇒ <code>UseCounterResult</code>
|
|
124
|
+
加法计数器
|
|
125
|
+
|
|
126
|
+
**Example**
|
|
127
|
+
```js
|
|
128
|
+
const counter= useCounter();
|
|
129
|
+
const onAdd=()=>{counter.addCount()}
|
|
130
|
+
return <span>当前计数器:{counter.count}</span>
|
|
131
|
+
```
|
|
132
|
+
<a id="module_usecounter__usecounterresult"></a>
|
|
133
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> UseCounterResult
|
|
134
|
+
**Properties**
|
|
135
|
+
|
|
136
|
+
| Name | Type | Description |
|
|
137
|
+
| --- | --- | --- |
|
|
138
|
+
| req | <code>Object</code> | |
|
|
139
|
+
| req.count | <code>number</code> | 当前计数器的值 |
|
|
140
|
+
| req.addCount | <code>function</code> | 计数器的值+1。 ()=>void |
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
<a id="module_usedictionary"></a>
|
|
144
|
+
## <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">G</span> useDictionary
|
|
145
|
+
|
|
146
|
+
* [ useDictionary](#module_usedictionary)
|
|
147
|
+
* [ useDictionary(props)](#module_usedictionary__usedictionary) ⇒ <code>UseDictionaryResult</code>
|
|
148
|
+
* [ SET(params)](#module_usedictionary__set) ⇒ <code>void</code>
|
|
149
|
+
* [ Api](#module_usedictionary__api) ⇒ <code>Object</code>
|
|
150
|
+
* [ DictionaryItem](#module_usedictionary__dictionaryitem)
|
|
151
|
+
* [ UseDictionaryResult](#module_usedictionary__usedictionaryresult)
|
|
152
|
+
|
|
153
|
+
<a id="module_usedictionary__usedictionary"></a>
|
|
154
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">M</span> useDictionary(props) ⇒ <code>UseDictionaryResult</code>
|
|
155
|
+
字典管理
|
|
156
|
+
|
|
157
|
+
[Demo - CodeSandBox](https://codesandbox.io/s/usedictionary-j7cw8?file=/index.js)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
| Param | Type | Default | Description |
|
|
161
|
+
| --- | --- | --- | --- |
|
|
162
|
+
| props | <code>Object</code> | | |
|
|
163
|
+
| props.api | <code>Api</code> | | 用于获取字典列表的接口 |
|
|
164
|
+
| [props.idKey] | <code>string</code> | <code>"'id'"</code> | 字段id的key键值 |
|
|
165
|
+
| [props.nameKey] | <code>string</code> | <code>"'name'"</code> | 字段name的key键值 |
|
|
166
|
+
| [props.labelKey] | <code>string</code> | <code>"'label'"</code> | 字段label的key键值 |
|
|
167
|
+
| [props.SelectOption] | <code>ReactDom</code> | | 指定\<Select.Option\>对象是谁 |
|
|
168
|
+
| [props.RadioOption] | <code>ReactDom</code> | | 指定\<Radio.Button\>对象是谁 |
|
|
169
|
+
| [props.beforeApi] | <code>callback</code> | | (request:object)=>object 接口调用前的参数拦截器 |
|
|
170
|
+
| [props.afterApi] | <code>callback</code> | | (reponse:object)=>object[] 接口调用后的拦截器 |
|
|
171
|
+
|
|
172
|
+
**Example**
|
|
173
|
+
```js
|
|
174
|
+
import {Select,Radio} from 'antd';
|
|
175
|
+
import useDictionary from '@/useDictionary';
|
|
176
|
+
useDictionary.SET({SelectOption:Select.Option,RadioOption:Radio.Button});
|
|
177
|
+
|
|
178
|
+
const Index=()=>{
|
|
179
|
+
|
|
180
|
+
const emCity = useDictionary({
|
|
181
|
+
api:()=>{
|
|
182
|
+
return new Promise(resolve=>{
|
|
183
|
+
resolve({
|
|
184
|
+
code:0,
|
|
185
|
+
data:{
|
|
186
|
+
body:[
|
|
187
|
+
{id:1,name:'shanghai',label:'上海'},
|
|
188
|
+
{id:2,name:'beijing',label:'北京'},
|
|
189
|
+
{id:3,name:'guangzhou',label:'广州'}
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<section >
|
|
199
|
+
<Select defaultValue={1}>
|
|
200
|
+
{
|
|
201
|
+
emCity.selectOptions
|
|
202
|
+
}
|
|
203
|
+
</Select>
|
|
204
|
+
<p>分割线</p>
|
|
205
|
+
<Radio.Group defaultValue={1}>
|
|
206
|
+
{
|
|
207
|
+
emCity.radioOptions
|
|
208
|
+
}
|
|
209
|
+
</Radio.Group>
|
|
210
|
+
</section>
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
<a id="module_usedictionary__set"></a>
|
|
215
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">M</span> SET(params) ⇒ <code>void</code>
|
|
216
|
+
全局设置SelectOption和RadioOption
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
| Param | Type | Description |
|
|
220
|
+
| --- | --- | --- |
|
|
221
|
+
| params | <code>Object</code> | |
|
|
222
|
+
| params.SelectOption | <code>ReactDom</code> | Antd的SelectOption组件 |
|
|
223
|
+
| params.RadioOption | <code>ReactDom</code> | Antd的SelectOption组件 |
|
|
224
|
+
|
|
225
|
+
<a id="module_usedictionary__api"></a>
|
|
226
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> Api ⇒ <code>Object</code>
|
|
227
|
+
**Properties**
|
|
228
|
+
|
|
229
|
+
| Name | Type | Description |
|
|
230
|
+
| --- | --- | --- |
|
|
231
|
+
| params | <code>Object</code> | 调用接口用到的参数 |
|
|
232
|
+
|
|
233
|
+
<a id="module_usedictionary__dictionaryitem"></a>
|
|
234
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> DictionaryItem
|
|
235
|
+
**Properties**
|
|
236
|
+
|
|
237
|
+
| Name | Type | Description |
|
|
238
|
+
| --- | --- | --- |
|
|
239
|
+
| id | <code>string</code> | 数据唯一ID |
|
|
240
|
+
| name | <code>string</code> | 数据唯一id对应的别名 |
|
|
241
|
+
| label | <code>string</code> | 展示给用户看的文字 |
|
|
242
|
+
|
|
243
|
+
<a id="module_usedictionary__usedictionaryresult"></a>
|
|
244
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> UseDictionaryResult
|
|
245
|
+
**Properties**
|
|
246
|
+
|
|
247
|
+
| Name | Type | Description |
|
|
248
|
+
| --- | --- | --- |
|
|
249
|
+
| types | <code>Array.<DictionaryItem></code> | 字典数据列表 |
|
|
250
|
+
| selectOptions | <code>Array.<ReactDOM></code> | 供Antd渲染\<Select\>的列表 |
|
|
251
|
+
| radioOptions | <code>Array.<ReactDOM></code> | 供Antd渲染\<Radio\>的列表 |
|
|
252
|
+
| getId | <code>function</code> | (labelOrName:string)=>string,搜索字典项中,label或name匹配labelOrName的项目,返回其id的值 |
|
|
253
|
+
| getName | <code>function</code> | (id:string)=>string,搜索字典项中,id匹配id的项目,返回其name的值 |
|
|
254
|
+
| getLabel | <code>function</code> | (id:string)=>string,搜索字典项中,id匹配id的项目,返回其label的值 |
|
|
255
|
+
| reload | <code>function</code> | ()=>void,重新调用字典接口刷新字典列表 |
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
<a id="module_usepagination"></a>
|
|
259
|
+
## <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">G</span> usePagination
|
|
260
|
+
|
|
261
|
+
* [ usePagination](#module_usepagination)
|
|
262
|
+
* [ usePagination(props)](#module_usepagination__usepagination) ⇒ <code>UsePaginationResult</code>
|
|
263
|
+
* [ Pagination](#module_usepagination__pagination) : <code>Object</code>
|
|
264
|
+
* [ PageDataResult](#module_usepagination__pagedataresult) : <code>Object</code>
|
|
265
|
+
* [ FunUpdate](#module_usepagination__funupdate) ⇒ <code>Promise.<PageDataResult></code>
|
|
266
|
+
* [ UsePaginationResult](#module_usepagination__usepaginationresult) : <code>Object</code>
|
|
267
|
+
* [ FunListener](#module_usepagination__funlistener) ⇒ <code>Object</code> \| <code>Promise.<Object></code>
|
|
268
|
+
|
|
269
|
+
<a id="module_usepagination__usepagination"></a>
|
|
270
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">M</span> usePagination(props) ⇒ <code>UsePaginationResult</code>
|
|
271
|
+
分页管理器
|
|
272
|
+
|
|
273
|
+
**Version**: 1.0.0
|
|
274
|
+
|
|
275
|
+
| Param | Type | Description |
|
|
276
|
+
| --- | --- | --- |
|
|
277
|
+
| props | <code>Object</code> | |
|
|
278
|
+
| props.service | <code>function</code> | 发送请求的方法,默认分页使用current和pageSize,如有特殊需求通过beforeService拦截处理 |
|
|
279
|
+
| [props.pagination] | <code>Pagination</code> | 默认分页信息 |
|
|
280
|
+
|
|
281
|
+
**Example**
|
|
282
|
+
```js
|
|
283
|
+
// 移动端滚动加载案例
|
|
284
|
+
const page = usePagination({
|
|
285
|
+
service:GET_LIST,
|
|
286
|
+
pagination:{pageSize:10},
|
|
287
|
+
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
useEffect(()=>{
|
|
291
|
+
const fnFeforeService = (params)=>{
|
|
292
|
+
// 假如你这里需要变更接口字段名称的话
|
|
293
|
+
params.page=params.current;
|
|
294
|
+
params.keyword='abc';
|
|
295
|
+
return params;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const fnAfterService = (response)=>{
|
|
299
|
+
// 这里你可以翻译及二次处理你的接口字段
|
|
300
|
+
let req={
|
|
301
|
+
code:response.errorCode
|
|
302
|
+
data:response.list,
|
|
303
|
+
page:response.pageInfo
|
|
304
|
+
};
|
|
305
|
+
response.code=response;
|
|
306
|
+
return response;
|
|
307
|
+
},
|
|
308
|
+
|
|
309
|
+
page.addListener('beforeService',fnFeforeService);
|
|
310
|
+
page.addListener('afterService',fnAfterService);
|
|
311
|
+
return ()=>{
|
|
312
|
+
page.removeListener('beforeService',fnFeforeService);
|
|
313
|
+
page.removeListener('afterService',fnAfterService)
|
|
314
|
+
}
|
|
315
|
+
},[])
|
|
316
|
+
|
|
317
|
+
const onReset=()=>{page.reset();}
|
|
318
|
+
|
|
319
|
+
const onPageChange=()=>{
|
|
320
|
+
let value=document.querySelector('#inputPage').value;
|
|
321
|
+
page.update({pagination:{current:+value}})
|
|
322
|
+
}
|
|
323
|
+
const onNext=()=>{page.nextPage();}
|
|
324
|
+
|
|
325
|
+
const renderTable=()=>{
|
|
326
|
+
let renderData= [];
|
|
327
|
+
page?.data?.forEach(list=>{
|
|
328
|
+
renderData=[...renderData,...list];
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
return (
|
|
332
|
+
<ul>
|
|
333
|
+
{
|
|
334
|
+
renderData?.map((item,idx)=>{
|
|
335
|
+
return <li key={idx}>[{idx}]{item}</li>
|
|
336
|
+
})
|
|
337
|
+
}
|
|
338
|
+
</ul>
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
}
|
|
342
|
+
return (
|
|
343
|
+
<ul>
|
|
344
|
+
{renderTable()}
|
|
345
|
+
</ul>
|
|
346
|
+
)
|
|
347
|
+
```
|
|
348
|
+
<a id="module_usepagination__pagination"></a>
|
|
349
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> Pagination : <code>Object</code>
|
|
350
|
+
分页信息
|
|
351
|
+
|
|
352
|
+
**Properties**
|
|
353
|
+
|
|
354
|
+
| Name | Type | Default | Description |
|
|
355
|
+
| --- | --- | --- | --- |
|
|
356
|
+
| pageSize | <code>number</code> | <code>20</code> | 分页大小 |
|
|
357
|
+
| current | <code>number</code> | <code>1</code> | 当前页码 |
|
|
358
|
+
| total | <code>number</code> | <code>1</code> | 总记录数 |
|
|
359
|
+
| [startIdx] | <code>number</code> | <code>0</code> | 当前页面下第一条数据的序号 |
|
|
360
|
+
| [more] | <code>boolean</code> | | 是否还有下一页 |
|
|
361
|
+
|
|
362
|
+
<a id="module_usepagination__pagedataresult"></a>
|
|
363
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> PageDataResult : <code>Object</code>
|
|
364
|
+
分页数据结果
|
|
365
|
+
|
|
366
|
+
**Properties**
|
|
367
|
+
|
|
368
|
+
| Name | Type | Description |
|
|
369
|
+
| --- | --- | --- |
|
|
370
|
+
| pagination | <code>Pagination</code> | 最新分页信息 |
|
|
371
|
+
| data | <code>Array.<Array.<Object>></code> | 分页数据集合 |
|
|
372
|
+
|
|
373
|
+
<a id="module_usepagination__funupdate"></a>
|
|
374
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> FunUpdate ⇒ <code>Promise.<PageDataResult></code>
|
|
375
|
+
分页查询结果
|
|
376
|
+
|
|
377
|
+
**Returns**: <code>Promise.<PageDataResult></code> - 最新的分页数据结果
|
|
378
|
+
**Properties**
|
|
379
|
+
|
|
380
|
+
| Name | Type | Description |
|
|
381
|
+
| --- | --- | --- |
|
|
382
|
+
| [pagination] | <code>Pagination</code> | 最新分页信息 |
|
|
383
|
+
| [clear] | <code>boolean</code> | 是否清空数据 |
|
|
384
|
+
|
|
385
|
+
<a id="module_usepagination__usepaginationresult"></a>
|
|
386
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> UsePaginationResult : <code>Object</code>
|
|
387
|
+
usePagination的返回对象
|
|
388
|
+
|
|
389
|
+
**Properties**
|
|
390
|
+
|
|
391
|
+
| Name | Type | Description |
|
|
392
|
+
| --- | --- | --- |
|
|
393
|
+
| data | <code>Array.<Array.<Object>></code> | 分页数据集合 |
|
|
394
|
+
| paginnation | <code>Pagination</code> | 分页信息 |
|
|
395
|
+
| update | <code>FunUpdate</code> | 查询方法 |
|
|
396
|
+
| next | <code>FunUpdate</code> | 获取下一页数据 |
|
|
397
|
+
| addListener | <code>function</code> | 监听事件 (type='beforeService'|'afterService',fn:FunListener)=>object |
|
|
398
|
+
| removeListener | <code>function</code> | 移除监听事件 (type,fn:FunListener)=>void |
|
|
399
|
+
|
|
400
|
+
<a id="module_usepagination__funlistener"></a>
|
|
401
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> FunListener ⇒ <code>Object</code> \| <code>Promise.<Object></code>
|
|
402
|
+
事件监听方法
|
|
403
|
+
|
|
404
|
+
**Returns**: <code>Object</code> \| <code>Promise.<Object></code> - 处理完毕的数据对象或者Promise
|
|
405
|
+
**Properties**
|
|
406
|
+
|
|
407
|
+
| Name | Type | Description |
|
|
408
|
+
| --- | --- | --- |
|
|
409
|
+
| params | <code>Object</code> | 被拦截的数据对象 |
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
<a id="module_usepaginationwithform"></a>
|
|
413
|
+
## <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">G</span> usePaginationWithForm
|
|
414
|
+
<a id="module_usepaginationwithform__usepaginationwithform"></a>
|
|
415
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">M</span> usePaginationWithForm(props)
|
|
416
|
+
支持Antd-Form的usePagination
|
|
417
|
+
作用是在查询接口前自动获取form表单内的字段,并作为接口查询参数进行查询
|
|
418
|
+
使用方法及参数字段参考 [usePagination](usePagination.md)
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
| Param | Type | Description |
|
|
422
|
+
| --- | --- | --- |
|
|
423
|
+
| props | <code>Object</code> | |
|
|
424
|
+
| props.form | <code>Object</code> | Form表单的ref,在接口调用前会校验获取form表单内的数据,提交到接口参数内查询 |
|
|
425
|
+
|
|
426
|
+
**Example**
|
|
427
|
+
```js
|
|
428
|
+
const [form] = Form.useForm();
|
|
429
|
+
const page = usePaginationWithForm({
|
|
430
|
+
service:GET_LIST,
|
|
431
|
+
pagination:{pageSize:10},
|
|
432
|
+
form:form
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
return(
|
|
436
|
+
<Form form={form} style={{width:'600px'}} layout="inline">
|
|
437
|
+
<Form.Item label='关键字' name='keyword' rules={[
|
|
438
|
+
{
|
|
439
|
+
max:5,
|
|
440
|
+
message:'最多5个字符'
|
|
441
|
+
}
|
|
442
|
+
]}>
|
|
443
|
+
<Input />
|
|
444
|
+
</Form.Item>
|
|
445
|
+
<Button onClick={onSearch} type='primary'>查询</Button>
|
|
446
|
+
<Button onClick={onReset} type='primary'>重置</Button>
|
|
447
|
+
</Form>
|
|
448
|
+
)
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
<a id="module_useswitch"></a>
|
|
452
|
+
## <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">G</span> useSwitch
|
|
453
|
+
useSwitch
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
* [ useSwitch](#module_useswitch)
|
|
457
|
+
* [ useSwitch([props])](#module_useswitch__useswitch) ⇒ <code>UseSwitchResult</code>
|
|
458
|
+
* [ UseSwitchResult](#module_useswitch__useswitchresult) : <code>Object</code>
|
|
459
|
+
|
|
460
|
+
<a id="module_useswitch__useswitch"></a>
|
|
461
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">M</span> useSwitch([props]) ⇒ <code>UseSwitchResult</code>
|
|
462
|
+
控制开关
|
|
463
|
+
|
|
464
|
+
[Demo-CodeSandbox](https://codesandbox.io/s/useswitch-qd7dr?file=/index.js)
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
| Param | Type | Default | Description |
|
|
468
|
+
| --- | --- | --- | --- |
|
|
469
|
+
| [props] | <code>boolean</code> | <code>false</code> | 默认的开关状态 |
|
|
470
|
+
|
|
471
|
+
<a id="module_useswitch__useswitchresult"></a>
|
|
472
|
+
### <span style="display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:4px;color:rgb(71, 128, 227);background:#ede6e6;">T</span> UseSwitchResult : <code>Object</code>
|
|
473
|
+
useSwitchHookResult
|
|
474
|
+
|
|
475
|
+
**Properties**
|
|
476
|
+
|
|
477
|
+
| Name | Type | Description |
|
|
478
|
+
| --- | --- | --- |
|
|
479
|
+
| state | <code>boolean</code> | 当前开关状态 |
|
|
480
|
+
| count | <code>number</code> | 当前开关计数器 |
|
|
481
|
+
| open | <code>function</code> | 切换至开模式 (force?:boolean)=>void |
|
|
482
|
+
| close | <code>function</code> | 切换至关模式 (force?:boolean)=>void |
|
|
483
|
+
| toggle | <code>function</code> | 切换至反向模式 ()=>void |
|
|
484
|
+
|
|
485
|
+
|