kn-hooks 0.0.24 → 0.0.25

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.
Files changed (2) hide show
  1. package/README.md +591 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1 +1,591 @@
1
- # tHIS IS README
1
+ # kn-hooks
2
+
3
+ ## 目录
4
+
5
+ * [使用方法](#start)
6
+ * [按需打包](#package)
7
+
8
+ * API
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
+
16
+
17
+
18
+ <a id='start'></a>
19
+
20
+ ## 使用方法
21
+
22
+ ```javascript
23
+ npm i kn-hooks
24
+ ```
25
+
26
+ ```javascript
27
+ // 务必使用 {指定模块名} 来引用触发tree-shake
28
+ import {useClipboard} from 'kn-hooks';
29
+
30
+ const Index=()=>{
31
+ const clip = useClipboard();
32
+ }
33
+
34
+ ```
35
+
36
+
37
+ <a id='package'></a>
38
+
39
+ ## 按需打包
40
+
41
+ > webpack4及以上版本无需下面配置
42
+
43
+ webpack增加`bable-plugin-import`插件,给babel plugins增加配置
44
+ ```javascript
45
+ // rules: [
46
+ // {
47
+ // test: /\.js[x]?$/,
48
+ // exclude: /node_modules/,
49
+ // use: {
50
+ // loader:'babel-loader',
51
+ // options:{
52
+ // plugins: [
53
+ [
54
+ import, {
55
+ libraryName: "kn-hooks" ,
56
+ camel2DashComponentName:false,
57
+ libraryDirectory:"src",
58
+ }
59
+ ]
60
+ // ]
61
+ // }
62
+ // }
63
+ // }
64
+ // ]
65
+
66
+ ```
67
+
68
+
69
+
70
+ ## API
71
+
72
+
73
+ <a id="module_useclipboard"></a>
74
+ ## <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
75
+
76
+ * [ useClipboard](#module_useclipboard)
77
+ * [ useClipboard([props])](#module_useclipboard__useclipboard) ⇒ <code>UseClipboardResult</code>
78
+ * [ FunCopy](#module_useclipboard__funcopy) : <code>callback</code>
79
+ * [ UseClipboardResult](#module_useclipboard__useclipboardresult) : <code>Object</code>
80
+
81
+ <a id="module_useclipboard__useclipboard"></a>
82
+ ### <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>
83
+ 剪贴板工具
84
+
85
+ [Demo - CodeSandBox](https://codesandbox.io/s/useclipboard-b4ryc?file=/index.js)
86
+
87
+
88
+ | Param | Type | Description |
89
+ | --- | --- | --- |
90
+ | [props] | <code>Object</code> | - |
91
+ | [props.onSuccess] | <code>callback</code> | 成功复制到剪贴板后的回调 ()=>void |
92
+
93
+ **Example**
94
+ ```js
95
+ const clipboard= useClipboard();
96
+ const onCopy=()=>{
97
+ clipboard.copy('text',()=>{console.log('success')})
98
+ }
99
+ ```
100
+ <a id="module_useclipboard__funcopy"></a>
101
+ ### <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>
102
+ 复制函数
103
+
104
+ **Properties**
105
+
106
+ | Name | Type | Description |
107
+ | --- | --- | --- |
108
+ | text | <code>string</code> | 需要被复制的字符串 |
109
+ | onCurSuccess | <code>callback</code> | 复制成功的回调 ()=>void |
110
+
111
+ <a id="module_useclipboard__useclipboardresult"></a>
112
+ ### <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>
113
+ UseClipboardResult返回的hook
114
+
115
+ **Properties**
116
+
117
+ | Name | Type | Description |
118
+ | --- | --- | --- |
119
+ | copy | <code>FunCopy</code> | 触发复制字符串的函数 |
120
+
121
+
122
+ <a id="module_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;">G</span> useCounter
124
+
125
+ * [ useCounter](#module_usecounter)
126
+ * [ useCounter()](#module_usecounter__usecounter) ⇒ <code>UseCounterResult</code>
127
+ * [ UseCounterResult](#module_usecounter__usecounterresult)
128
+
129
+ <a id="module_usecounter__usecounter"></a>
130
+ ### <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>
131
+ 加法计数器
132
+
133
+ **Example**
134
+ ```js
135
+ const counter= useCounter();
136
+ const onAdd=()=>{counter.addCount()}
137
+ return <span>当前计数器:{counter.count}</span>
138
+ ```
139
+ <a id="module_usecounter__usecounterresult"></a>
140
+ ### <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
141
+ **Properties**
142
+
143
+ | Name | Type | Description |
144
+ | --- | --- | --- |
145
+ | req | <code>Object</code> | |
146
+ | req.count | <code>number</code> | 当前计数器的值 |
147
+ | req.addCount | <code>function</code> | 计数器的值+1。 ()=>void |
148
+
149
+
150
+ <a id="module_usedictionary"></a>
151
+ ## <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
152
+
153
+ * [ useDictionary](#module_usedictionary)
154
+ * _static_
155
+ * [ SetConfig(params)](#module_usedictionary_setconfig) ⇒ <code>void</code>
156
+ * [ createDictionary(options)](#module_usedictionary_createdictionary) ⇒ <code>callback</code>
157
+ * _inner_
158
+ * [ useDictionary(props)](#module_usedictionary__usedictionary) ⇒ <code>UseDictionaryResult</code>
159
+ * [ Api](#module_usedictionary__api) ⇒ <code>Object</code>
160
+ * [ DictionaryItem](#module_usedictionary__dictionaryitem)
161
+ * [ UseDictionaryResult](#module_usedictionary__usedictionaryresult)
162
+
163
+ <a id="module_usedictionary_setconfig"></a>
164
+ ### <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> SetConfig(params) ⇒ <code>void</code>
165
+ 全局设置SelectOption和RadioOption
166
+
167
+
168
+ | Param | Type | Description |
169
+ | --- | --- | --- |
170
+ | params | <code>Object</code> | |
171
+ | params.SelectOption | <code>ReactDom</code> | Antd的SelectOption组件 |
172
+ | params.RadioOption | <code>ReactDom</code> | Antd的SelectOption组件 |
173
+
174
+ **Example**
175
+ ```js
176
+ import {useDictionary} from 'kn-hooks';
177
+ import {Select,Radio} from 'antd';
178
+ useDictionary.SetConfig(Select.Option,Radio.Option);
179
+ ```
180
+ <a id="module_usedictionary_createdictionary"></a>
181
+ ### <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> createDictionary(options) ⇒ <code>callback</code>
182
+ 创建字典hooks工具
183
+
184
+
185
+ | Param | Type | Default | Description |
186
+ | --- | --- | --- | --- |
187
+ | options | <code>Object</code> | | |
188
+ | options.api | <code>Api</code> | | 用于获取字典列表的接口 |
189
+ | [options.idKey] | <code>string</code> | <code>&quot;&#x27;id&#x27;&quot;</code> | 字段id的key键值 |
190
+ | [options.nameKey] | <code>string</code> | <code>&quot;&#x27;name&#x27;&quot;</code> | 字段name的key键值 |
191
+ | [options.labelKey] | <code>string</code> | <code>&quot;&#x27;label&#x27;&quot;</code> | 字段label的key键值 |
192
+ | [options.SelectOption] | <code>ReactDom</code> | | 指定\<Select.Option\>对象是谁 |
193
+ | [options.RadioOption] | <code>ReactDom</code> | | 指定\<Radio.Button\>对象是谁 |
194
+ | [options.beforeApi] | <code>callback</code> | | (request:object)=>object 接口调用前的参数拦截器 |
195
+ | [options.afterApi] | <code>callback</code> | | (reponse:object)=>object[] 接口调用后的拦截器 |
196
+ | [options.defaultTypes] | <code>Array.&lt;DictionaryItem&gt;</code> | | 如果字典不是通过api获取,可以在这里设置字典的内容 |
197
+
198
+ **Example**
199
+ ```js
200
+ // emUserType.jsx
201
+ import {useDictionary} from 'kn-hooks';
202
+ export const userType = useDictionary.createDictionary({
203
+ api:()=>Promise.resolve([{id:'1001',label:'项目1001',name:'pm1001'},]),
204
+ afterApi:(response)=>{
205
+ return response?.data;
206
+ }
207
+ });
208
+ // index.jsx
209
+ import {userType} from './emUserType.jsx'
210
+ const Page=()=>{
211
+ const emUserType = userType();
212
+ return (
213
+ <section>
214
+ <Select defaultValue={emUserType.getId('项目1001')}>
215
+ {emUserType.selectOptions}
216
+ </Select>
217
+ </section>
218
+ )
219
+ }
220
+ ```
221
+ <a id="module_usedictionary__usedictionary"></a>
222
+ ### <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>
223
+ 字典管理
224
+
225
+ [Demo - CodeSandBox](https://codesandbox.io/s/usedictionary-j7cw8?file=/index.js)
226
+
227
+
228
+ | Param | Type | Default | Description |
229
+ | --- | --- | --- | --- |
230
+ | props | <code>Object</code> | | |
231
+ | props.api | <code>Api</code> | | 用于获取字典列表的接口 |
232
+ | [props.idKey] | <code>string</code> | <code>&quot;&#x27;id&#x27;&quot;</code> | 字段id的key键值 |
233
+ | [props.nameKey] | <code>string</code> | <code>&quot;&#x27;name&#x27;&quot;</code> | 字段name的key键值 |
234
+ | [props.labelKey] | <code>string</code> | <code>&quot;&#x27;label&#x27;&quot;</code> | 字段label的key键值 |
235
+ | [props.SelectOption] | <code>ReactDom</code> | | 指定\<Select.Option\>对象是谁 |
236
+ | [props.RadioOption] | <code>ReactDom</code> | | 指定\<Radio.Button\>对象是谁 |
237
+ | [props.beforeApi] | <code>callback</code> | | (request:object)=>object 接口调用前的参数拦截器 |
238
+ | [props.afterApi] | <code>callback</code> | | (reponse:object)=>object[] 接口调用后的拦截器 |
239
+ | [props.defaultTypes] | <code>Array.&lt;DictionaryItem&gt;</code> | | 如果字典不是通过api获取,可以在这里设置字典的内容 |
240
+
241
+ **Example**
242
+ ```js
243
+ import {Select,Radio} from 'antd';
244
+ import useDictionary,{SetConfig} from '@/useDictionary';
245
+ SetConfig({SelectOption:Select.Option,RadioOption:Radio.Button});
246
+
247
+ const Index=()=>{
248
+
249
+ const emCity = useDictionary({
250
+ api:()=>{
251
+ return new Promise(resolve=>{
252
+ resolve({
253
+ code:0,
254
+ data:{
255
+ body:[
256
+ {id:1,name:'shanghai',label:'上海'},
257
+ {id:2,name:'beijing',label:'北京'},
258
+ {id:3,name:'guangzhou',label:'广州'}
259
+ ]
260
+ }
261
+ })
262
+ })
263
+ }
264
+ });
265
+
266
+ return (
267
+ <section >
268
+ <Select defaultValue={1}>
269
+ {
270
+ emCity.selectOptions
271
+ }
272
+ </Select>
273
+ <p>分割线</p>
274
+ <Radio.Group defaultValue={1}>
275
+ {
276
+ emCity.radioOptions
277
+ }
278
+ </Radio.Group>
279
+ </section>
280
+ )
281
+ }
282
+ ```
283
+ <a id="module_usedictionary__api"></a>
284
+ ### <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>
285
+ **Properties**
286
+
287
+ | Name | Type | Description |
288
+ | --- | --- | --- |
289
+ | params | <code>Object</code> | 调用接口用到的参数 |
290
+
291
+ <a id="module_usedictionary__dictionaryitem"></a>
292
+ ### <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
293
+ **Properties**
294
+
295
+ | Name | Type | Description |
296
+ | --- | --- | --- |
297
+ | id | <code>string</code> | 数据唯一ID |
298
+ | name | <code>string</code> | 数据唯一id对应的别名 |
299
+ | label | <code>string</code> | 展示给用户看的文字 |
300
+
301
+ <a id="module_usedictionary__usedictionaryresult"></a>
302
+ ### <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
303
+ **Properties**
304
+
305
+ | Name | Type | Description |
306
+ | --- | --- | --- |
307
+ | types | <code>Array.&lt;DictionaryItem&gt;</code> | 字典数据列表 |
308
+ | selectOptions | <code>Array.&lt;ReactDOM&gt;</code> | 供Antd渲染\<Select\>的列表 |
309
+ | radioOptions | <code>Array.&lt;ReactDOM&gt;</code> | 供Antd渲染\<Radio\>的列表 |
310
+ | getId | <code>function</code> | (labelOrName:string)=>string,搜索字典项中,label或name匹配labelOrName的项目,返回其id的值 |
311
+ | getName | <code>function</code> | (id:string)=>string,搜索字典项中,id匹配id的项目,返回其name的值 |
312
+ | getLabel | <code>function</code> | (id:string)=>string,搜索字典项中,id匹配id的项目,返回其label的值 |
313
+ | reload | <code>function</code> | ()=>void,重新调用字典接口刷新字典列表 |
314
+
315
+
316
+ <a id="module_usepagination"></a>
317
+ ## <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
318
+
319
+ * [ usePagination](#module_usepagination)
320
+ * [ usePagination(props)](#module_usepagination__usepagination) ⇒ <code>UsePaginationResult</code>
321
+ * [ FunServices()](#module_usepagination__funservices) ⇒ <code>FunServicesCallback</code>
322
+ * [ FunServicesCallback](#module_usepagination__funservicescallback) : <code>Object</code>
323
+ * [ Pagination](#module_usepagination__pagination) : <code>Object</code>
324
+ * [ PageDataResult](#module_usepagination__pagedataresult) : <code>Object</code>
325
+ * [ FunUpdate](#module_usepagination__funupdate) ⇒ <code>Promise.&lt;PageDataResult&gt;</code>
326
+ * [ UsePaginationResult](#module_usepagination__usepaginationresult) : <code>Object</code>
327
+ * [ FunListener](#module_usepagination__funlistener) ⇒ <code>Object</code> \| <code>Promise.&lt;Object&gt;</code>
328
+
329
+ <a id="module_usepagination__usepagination"></a>
330
+ ### <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>
331
+ 分页管理器
332
+
333
+ **Version**: 1.0.0
334
+
335
+ | Param | Type | Description |
336
+ | --- | --- | --- |
337
+ | props | <code>Object</code> | |
338
+ | props.service | <code>FunServices</code> | 发送请求的方法 |
339
+ | [props.pagination] | <code>Pagination</code> | 默认分页信息 |
340
+
341
+ **Example**
342
+ ```js
343
+ // 移动端滚动加载案例
344
+ const page = usePagination({
345
+ service:GET_LIST,
346
+ pagination:{pageSize:10},
347
+ });
348
+
349
+ useEffect(()=>{
350
+ const fnFeforeService = (params)=>{
351
+ // 假如你这里需要变更接口字段名称的话
352
+ params.page=params.current;
353
+ params.keyword='abc';
354
+ return params;
355
+ }
356
+
357
+ const fnAfterService = (response)=>{
358
+ // 这里你可以翻译及二次处理你的接口字段
359
+ let req={
360
+ code:response.errorCode
361
+ data:response.list,
362
+ page:response.pageInfo
363
+ };
364
+ return req;
365
+ },
366
+
367
+ page.addListener('beforeService',fnFeforeService);
368
+ page.addListener('afterService',fnAfterService);
369
+ return ()=>{
370
+ page.removeListener('beforeService',fnFeforeService);
371
+ page.removeListener('afterService',fnAfterService)
372
+ }
373
+ },[])
374
+
375
+ const onReset=()=>{page.reset();}
376
+
377
+ const onPageChange=()=>{
378
+ let value=document.querySelector('#inputPage').value;
379
+ page.update({pagination:{current:+value}})
380
+ }
381
+ const onNext=()=>{page.nextPage();}
382
+
383
+ const renderTable=()=>{
384
+ let renderData= [];
385
+ page?.data?.forEach(list=>{
386
+ renderData=[...renderData,...list];
387
+ })
388
+
389
+ return (
390
+ <ul>
391
+ {
392
+ renderData?.map((item,idx)=>{
393
+ return <li key={idx}>[{idx}]{item}</li>
394
+ })
395
+ }
396
+ </ul>
397
+ )
398
+
399
+ }
400
+ return (
401
+ <ul>
402
+ {renderTable()}
403
+ </ul>
404
+ )
405
+ ```
406
+ <a id="module_usepagination__funservices"></a>
407
+ ### <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> FunServices() ⇒ <code>FunServicesCallback</code>
408
+ 分页请求接口格式要求
409
+
410
+ **Properties**
411
+
412
+ | Name | Type | Default | Description |
413
+ | --- | --- | --- | --- |
414
+ | current | <code>number</code> | <code>1</code> | 页码 |
415
+ | pageSize | <code>number</code> | <code>10</code> | 分页大小 |
416
+ | ...others | <code>any</code> | | 其它接口附带参数 |
417
+
418
+ <a id="module_usepagination__funservicescallback"></a>
419
+ ### <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> FunServicesCallback : <code>Object</code>
420
+ 分页接口请求结果
421
+
422
+ **Properties**
423
+
424
+ | Name | Type | Default | Description |
425
+ | --- | --- | --- | --- |
426
+ | code | <code>number</code> | <code>0</code> | 接口调用结果,0为成功 |
427
+ | data | <code>Array.&lt;Object&gt;</code> | | 分页数据 |
428
+ | page | <code>Object</code> | | 分页信息 |
429
+ | page.current | <code>number</code> | | 页码 |
430
+ | page.pageSize | <code>number</code> | | 分页大小 |
431
+ | page.total | <code>number</code> | | 数据总量 |
432
+
433
+ <a id="module_usepagination__pagination"></a>
434
+ ### <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>
435
+ 分页信息
436
+
437
+ **Properties**
438
+
439
+ | Name | Type | Default | Description |
440
+ | --- | --- | --- | --- |
441
+ | pageSize | <code>number</code> | <code>20</code> | 分页大小 |
442
+ | current | <code>number</code> | <code>1</code> | 当前页码 |
443
+ | total | <code>number</code> | <code>1</code> | 总记录数 |
444
+ | [startIdx] | <code>number</code> | <code>0</code> | 当前页面下第一条数据的序号 |
445
+ | [more] | <code>boolean</code> | | 是否还有下一页 |
446
+
447
+ <a id="module_usepagination__pagedataresult"></a>
448
+ ### <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>
449
+ 分页数据结果
450
+
451
+ **Properties**
452
+
453
+ | Name | Type | Description |
454
+ | --- | --- | --- |
455
+ | pagination | <code>Pagination</code> | 最新分页信息 |
456
+ | data | <code>Array.&lt;Array.&lt;Object&gt;&gt;</code> | 分页数据集合 |
457
+
458
+ <a id="module_usepagination__funupdate"></a>
459
+ ### <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.&lt;PageDataResult&gt;</code>
460
+ 分页查询结果
461
+
462
+ **Returns**: <code>Promise.&lt;PageDataResult&gt;</code> - 最新的分页数据结果
463
+ **Properties**
464
+
465
+ | Name | Type | Description |
466
+ | --- | --- | --- |
467
+ | [pagination] | <code>Pagination</code> | 最新分页信息 |
468
+ | [clear] | <code>boolean</code> | 是否清空数据 |
469
+
470
+ <a id="module_usepagination__usepaginationresult"></a>
471
+ ### <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>
472
+ usePagination的返回对象
473
+
474
+ **Properties**
475
+
476
+ | Name | Type | Description |
477
+ | --- | --- | --- |
478
+ | data | <code>Array.&lt;Array.&lt;Object&gt;&gt;</code> | 分页数据集合 |
479
+ | paginnation | <code>Pagination</code> | 分页信息 |
480
+ | update | <code>FunUpdate</code> | 查询方法 |
481
+ | next | <code>FunUpdate</code> | 获取下一页数据 |
482
+ | addListener | <code>function</code> | 监听事件 (type='beforeService'|'afterService',fn:FunListener)=>object |
483
+ | removeListener | <code>function</code> | 移除监听事件 (type,fn:FunListener)=>void |
484
+
485
+ <a id="module_usepagination__funlistener"></a>
486
+ ### <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.&lt;Object&gt;</code>
487
+ 事件监听方法
488
+
489
+ **Returns**: <code>Object</code> \| <code>Promise.&lt;Object&gt;</code> - 处理完毕的数据对象或者Promise
490
+ **Properties**
491
+
492
+ | Name | Type | Description |
493
+ | --- | --- | --- |
494
+ | params | <code>Object</code> | 被拦截的数据对象 |
495
+
496
+
497
+ <a id="module_usepaginationwithform"></a>
498
+ ## <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
499
+
500
+ * [ usePaginationWithForm](#module_usepaginationwithform)
501
+ * [ usePaginationWithForm(props)](#module_usepaginationwithform__usepaginationwithform) ⇒ <code>UsePaginationWithFormResult</code>
502
+ * [ UsePaginationWithFormResult](#module_usepaginationwithform__usepaginationwithformresult) : <code>Object</code>
503
+
504
+ <a id="module_usepaginationwithform__usepaginationwithform"></a>
505
+ ### <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) ⇒ <code>UsePaginationWithFormResult</code>
506
+ 支持Antd-Form的usePagination
507
+ 作用是在查询接口前自动获取form表单内的字段,并作为接口查询参数进行查询
508
+ 使用方法及参数字段参考 [usePagination](usePagination.md)
509
+
510
+
511
+ | Param | Type | Description |
512
+ | --- | --- | --- |
513
+ | props | <code>Object</code> | |
514
+ | props.form | <code>Object</code> | Form表单的ref,在接口调用前会校验获取form表单内的数据,提交到接口参数内查询 |
515
+
516
+ **Example**
517
+ ```js
518
+ const [form] = Form.useForm();
519
+ const page = usePaginationWithForm({
520
+ service:GET_LIST,
521
+ pagination:{pageSize:10},
522
+ form:form
523
+ });
524
+
525
+ const onSearch=()=>{
526
+ page.update();
527
+ }
528
+ const onReset=()=>{
529
+ page.reset();
530
+ }
531
+ return(
532
+ <Form form={form} style={{width:'600px'}} layout="inline">
533
+ <Form.Item label='关键字' name='keyword' rules={[
534
+ {
535
+ max:5,
536
+ message:'最多5个字符'
537
+ }
538
+ ]}>
539
+ <Input />
540
+ </Form.Item>
541
+ <Button onClick={onSearch} type='primary'>查询</Button>
542
+ <Button onClick={onReset} type='primary'>重置</Button>
543
+ </Form>
544
+ )
545
+ ```
546
+ <a id="module_usepaginationwithform__usepaginationwithformresult"></a>
547
+ ### <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> UsePaginationWithFormResult : <code>Object</code>
548
+ usePaginationWithForm的返回对象
549
+
550
+ **Properties**
551
+
552
+ | Name | Type | Description |
553
+ | --- | --- | --- |
554
+ | reset | <code>function</code> | 重置方法 |
555
+
556
+
557
+ <a id="module_useswitch"></a>
558
+ ## <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
559
+ useSwitch
560
+
561
+
562
+ * [ useSwitch](#module_useswitch)
563
+ * [ useSwitch([props])](#module_useswitch__useswitch) ⇒ <code>UseSwitchResult</code>
564
+ * [ UseSwitchResult](#module_useswitch__useswitchresult) : <code>Object</code>
565
+
566
+ <a id="module_useswitch__useswitch"></a>
567
+ ### <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>
568
+ 控制开关
569
+
570
+ [Demo-CodeSandbox](https://codesandbox.io/s/useswitch-qd7dr?file=/index.js)
571
+
572
+
573
+ | Param | Type | Default | Description |
574
+ | --- | --- | --- | --- |
575
+ | [props] | <code>boolean</code> | <code>false</code> | 默认的开关状态 |
576
+
577
+ <a id="module_useswitch__useswitchresult"></a>
578
+ ### <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>
579
+ useSwitchHookResult
580
+
581
+ **Properties**
582
+
583
+ | Name | Type | Description |
584
+ | --- | --- | --- |
585
+ | state | <code>boolean</code> | 当前开关状态 |
586
+ | count | <code>number</code> | 当前开关计数器 |
587
+ | open | <code>function</code> | 切换至开模式 (force?:boolean)=>void |
588
+ | close | <code>function</code> | 切换至关模式 (force?:boolean)=>void |
589
+ | toggle | <code>function</code> | 切换至反向模式 ()=>void |
590
+
591
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kn-hooks",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "scripts": {
5
5
  "dev": "cross-env env_api=dev env_package=dev webpack-dev-server --progress",
6
6
  "build": "cross-env env_api=prod env_package=prod webpack --config webpack.config.js",