kn-hooks 0.0.17 → 0.0.19
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/useDictionary.md +8 -1
- package/md/usePagination.md +31 -4
- package/package.json +1 -1
- package/readme.md +39 -5
- package/src/usePagination/index.js +29 -4
package/md/useDictionary.md
CHANGED
|
@@ -22,6 +22,12 @@
|
|
|
22
22
|
| params.SelectOption | <code>ReactDom</code> | Antd的SelectOption组件 |
|
|
23
23
|
| params.RadioOption | <code>ReactDom</code> | Antd的SelectOption组件 |
|
|
24
24
|
|
|
25
|
+
**Example**
|
|
26
|
+
```js
|
|
27
|
+
import {useDictionary} from 'kn-hooks';
|
|
28
|
+
import {Select,Radio} from 'antd';
|
|
29
|
+
useDictionary.SetConfig(Select.Option,Radio.Option);
|
|
30
|
+
```
|
|
25
31
|
<a id="module_usedictionary_createdictionary"></a>
|
|
26
32
|
### <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>
|
|
27
33
|
创建字典hooks工具
|
|
@@ -43,7 +49,8 @@
|
|
|
43
49
|
**Example**
|
|
44
50
|
```js
|
|
45
51
|
// emUserType.jsx
|
|
46
|
-
|
|
52
|
+
import {useDictionary} from 'kn-hooks';
|
|
53
|
+
export const userType = useDictionary.createDictionary({
|
|
47
54
|
api:()=>Promise.resolve([{id:'1001',label:'项目1001',name:'pm1001'},]),
|
|
48
55
|
afterApi:(response)=>{
|
|
49
56
|
return response?.data;
|
package/md/usePagination.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
* [ usePagination](#module_usepagination)
|
|
5
5
|
* [ usePagination(props)](#module_usepagination__usepagination) ⇒ <code>UsePaginationResult</code>
|
|
6
|
+
* [ FunServices()](#module_usepagination__funservices) ⇒ <code>FunServicesCallback</code>
|
|
7
|
+
* [ FunServicesCallback](#module_usepagination__funservicescallback) : <code>Object</code>
|
|
6
8
|
* [ Pagination](#module_usepagination__pagination) : <code>Object</code>
|
|
7
9
|
* [ PageDataResult](#module_usepagination__pagedataresult) : <code>Object</code>
|
|
8
10
|
* [ FunUpdate](#module_usepagination__funupdate) ⇒ <code>Promise.<PageDataResult></code>
|
|
@@ -18,7 +20,7 @@
|
|
|
18
20
|
| Param | Type | Description |
|
|
19
21
|
| --- | --- | --- |
|
|
20
22
|
| props | <code>Object</code> | |
|
|
21
|
-
| props.service | <code>
|
|
23
|
+
| props.service | <code>FunServices</code> | 发送请求的方法 |
|
|
22
24
|
| [props.pagination] | <code>Pagination</code> | 默认分页信息 |
|
|
23
25
|
|
|
24
26
|
**Example**
|
|
@@ -27,7 +29,6 @@
|
|
|
27
29
|
const page = usePagination({
|
|
28
30
|
service:GET_LIST,
|
|
29
31
|
pagination:{pageSize:10},
|
|
30
|
-
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
useEffect(()=>{
|
|
@@ -45,8 +46,7 @@
|
|
|
45
46
|
data:response.list,
|
|
46
47
|
page:response.pageInfo
|
|
47
48
|
};
|
|
48
|
-
|
|
49
|
-
return response;
|
|
49
|
+
return req;
|
|
50
50
|
},
|
|
51
51
|
|
|
52
52
|
page.addListener('beforeService',fnFeforeService);
|
|
@@ -88,6 +88,33 @@
|
|
|
88
88
|
</ul>
|
|
89
89
|
)
|
|
90
90
|
```
|
|
91
|
+
<a id="module_usepagination__funservices"></a>
|
|
92
|
+
### <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>
|
|
93
|
+
分页请求接口格式要求
|
|
94
|
+
|
|
95
|
+
**Properties**
|
|
96
|
+
|
|
97
|
+
| Name | Type | Default | Description |
|
|
98
|
+
| --- | --- | --- | --- |
|
|
99
|
+
| current | <code>number</code> | <code>1</code> | 页码 |
|
|
100
|
+
| pageSize | <code>number</code> | <code>10</code> | 分页大小 |
|
|
101
|
+
| ...others | <code>any</code> | | 其它接口附带参数 |
|
|
102
|
+
|
|
103
|
+
<a id="module_usepagination__funservicescallback"></a>
|
|
104
|
+
### <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>
|
|
105
|
+
分页接口请求结果
|
|
106
|
+
|
|
107
|
+
**Properties**
|
|
108
|
+
|
|
109
|
+
| Name | Type | Default | Description |
|
|
110
|
+
| --- | --- | --- | --- |
|
|
111
|
+
| code | <code>number</code> | <code>0</code> | 接口调用结果,0为成功 |
|
|
112
|
+
| data | <code>Array.<Object></code> | | 分页数据 |
|
|
113
|
+
| page | <code>Object</code> | | 分页信息 |
|
|
114
|
+
| page.current | <code>number</code> | | 页码 |
|
|
115
|
+
| page.pageSize | <code>number</code> | | 分页大小 |
|
|
116
|
+
| page.total | <code>number</code> | | 数据总量 |
|
|
117
|
+
|
|
91
118
|
<a id="module_usepagination__pagination"></a>
|
|
92
119
|
### <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>
|
|
93
120
|
分页信息
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -171,6 +171,12 @@ return <span>当前计数器:{counter.count}</span>
|
|
|
171
171
|
| params.SelectOption | <code>ReactDom</code> | Antd的SelectOption组件 |
|
|
172
172
|
| params.RadioOption | <code>ReactDom</code> | Antd的SelectOption组件 |
|
|
173
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
|
+
```
|
|
174
180
|
<a id="module_usedictionary_createdictionary"></a>
|
|
175
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>
|
|
176
182
|
创建字典hooks工具
|
|
@@ -192,7 +198,8 @@ return <span>当前计数器:{counter.count}</span>
|
|
|
192
198
|
**Example**
|
|
193
199
|
```js
|
|
194
200
|
// emUserType.jsx
|
|
195
|
-
|
|
201
|
+
import {useDictionary} from 'kn-hooks';
|
|
202
|
+
export const userType = useDictionary.createDictionary({
|
|
196
203
|
api:()=>Promise.resolve([{id:'1001',label:'项目1001',name:'pm1001'},]),
|
|
197
204
|
afterApi:(response)=>{
|
|
198
205
|
return response?.data;
|
|
@@ -311,6 +318,8 @@ const Index=()=>{
|
|
|
311
318
|
|
|
312
319
|
* [ usePagination](#module_usepagination)
|
|
313
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>
|
|
314
323
|
* [ Pagination](#module_usepagination__pagination) : <code>Object</code>
|
|
315
324
|
* [ PageDataResult](#module_usepagination__pagedataresult) : <code>Object</code>
|
|
316
325
|
* [ FunUpdate](#module_usepagination__funupdate) ⇒ <code>Promise.<PageDataResult></code>
|
|
@@ -326,7 +335,7 @@ const Index=()=>{
|
|
|
326
335
|
| Param | Type | Description |
|
|
327
336
|
| --- | --- | --- |
|
|
328
337
|
| props | <code>Object</code> | |
|
|
329
|
-
| props.service | <code>
|
|
338
|
+
| props.service | <code>FunServices</code> | 发送请求的方法 |
|
|
330
339
|
| [props.pagination] | <code>Pagination</code> | 默认分页信息 |
|
|
331
340
|
|
|
332
341
|
**Example**
|
|
@@ -335,7 +344,6 @@ const Index=()=>{
|
|
|
335
344
|
const page = usePagination({
|
|
336
345
|
service:GET_LIST,
|
|
337
346
|
pagination:{pageSize:10},
|
|
338
|
-
|
|
339
347
|
});
|
|
340
348
|
|
|
341
349
|
useEffect(()=>{
|
|
@@ -353,8 +361,7 @@ const Index=()=>{
|
|
|
353
361
|
data:response.list,
|
|
354
362
|
page:response.pageInfo
|
|
355
363
|
};
|
|
356
|
-
|
|
357
|
-
return response;
|
|
364
|
+
return req;
|
|
358
365
|
},
|
|
359
366
|
|
|
360
367
|
page.addListener('beforeService',fnFeforeService);
|
|
@@ -396,6 +403,33 @@ const Index=()=>{
|
|
|
396
403
|
</ul>
|
|
397
404
|
)
|
|
398
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.<Object></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
|
+
|
|
399
433
|
<a id="module_usepagination__pagination"></a>
|
|
400
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>
|
|
401
435
|
分页信息
|
|
@@ -6,9 +6,12 @@ import { useState,useMemo,useRef } from 'react';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 分页管理器
|
|
9
|
+
*
|
|
10
|
+
*
|
|
9
11
|
* @param {Object} props
|
|
10
|
-
* @param {
|
|
12
|
+
* @param {FunServices} props.service - 发送请求的方法
|
|
11
13
|
* @param {Pagination} [props.pagination] - 默认分页信息
|
|
14
|
+
*
|
|
12
15
|
* @version 1.0.0
|
|
13
16
|
*
|
|
14
17
|
* @example
|
|
@@ -16,7 +19,6 @@ import { useState,useMemo,useRef } from 'react';
|
|
|
16
19
|
const page = usePagination({
|
|
17
20
|
service:GET_LIST,
|
|
18
21
|
pagination:{pageSize:10},
|
|
19
|
-
|
|
20
22
|
});
|
|
21
23
|
|
|
22
24
|
useEffect(()=>{
|
|
@@ -34,8 +36,7 @@ import { useState,useMemo,useRef } from 'react';
|
|
|
34
36
|
data:response.list,
|
|
35
37
|
page:response.pageInfo
|
|
36
38
|
};
|
|
37
|
-
|
|
38
|
-
return response;
|
|
39
|
+
return req;
|
|
39
40
|
},
|
|
40
41
|
|
|
41
42
|
page.addListener('beforeService',fnFeforeService);
|
|
@@ -211,6 +212,30 @@ const usePagination=(props)=>{
|
|
|
211
212
|
|
|
212
213
|
|
|
213
214
|
|
|
215
|
+
/**
|
|
216
|
+
* 分页接口请求结果
|
|
217
|
+
* @typedef {Object} FunServicesCallback
|
|
218
|
+
* @property {number} code=0 - 接口调用结果,0为成功
|
|
219
|
+
* @property {Object[]} data - 分页数据
|
|
220
|
+
* @property {Object} page - 分页信息
|
|
221
|
+
* @property {number} page.current - 页码
|
|
222
|
+
* @property {number} page.pageSize - 分页大小
|
|
223
|
+
* @property {number} page.total - 数据总量
|
|
224
|
+
*
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @function
|
|
230
|
+
* @name FunServices
|
|
231
|
+
* @description 分页请求接口格式要求
|
|
232
|
+
* @property {number} current=1 - 页码
|
|
233
|
+
* @property {number} pageSize=10 - 分页大小
|
|
234
|
+
* @property {...any} others - 其它接口附带参数
|
|
235
|
+
* @return {FunServicesCallback}
|
|
236
|
+
*/
|
|
237
|
+
|
|
238
|
+
|
|
214
239
|
/**
|
|
215
240
|
* 分页信息
|
|
216
241
|
* @typedef {Object} Pagination
|