kn-hooks 0.0.26 → 0.0.27
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 +18 -5
- package/md/useDictionary.md +12 -3
- package/md/usePagination.md +6 -2
- package/package.json +1 -1
- package/src/useDictionary/index.js +12 -3
- package/src/usePagination/index.js +9 -5
package/README.md
CHANGED
|
@@ -175,7 +175,7 @@ return <span>当前计数器:{counter.count}</span>
|
|
|
175
175
|
```js
|
|
176
176
|
import {useDictionary} from 'kn-hooks';
|
|
177
177
|
import {Select,Radio} from 'antd';
|
|
178
|
-
useDictionary.SetConfig(Select.Option,Radio.Option);
|
|
178
|
+
useDictionary.SetConfig({SelectOption:Select.Option,RadioOption:Radio.Option});
|
|
179
179
|
```
|
|
180
180
|
<a id="module_usedictionary_createdictionary"></a>
|
|
181
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>
|
|
@@ -200,9 +200,18 @@ import {useDictionary} from 'kn-hooks';
|
|
|
200
200
|
// emUserType.jsx
|
|
201
201
|
import {useDictionary} from 'kn-hooks';
|
|
202
202
|
export const userType = useDictionary.createDictionary({
|
|
203
|
-
api:()=>Promise.resolve(
|
|
203
|
+
api:()=>Promise.resolve({
|
|
204
|
+
code:0,
|
|
205
|
+
data:{
|
|
206
|
+
body:[{id:'1001',label:'项目1001',name:'pm1001'},],
|
|
207
|
+
}
|
|
208
|
+
}),
|
|
204
209
|
afterApi:(response)=>{
|
|
205
|
-
|
|
210
|
+
let list;
|
|
211
|
+
if(response?.code==0){
|
|
212
|
+
list= response?.data?.body?.map(item=>{...})
|
|
213
|
+
}
|
|
214
|
+
return list;
|
|
206
215
|
}
|
|
207
216
|
});
|
|
208
217
|
// index.jsx
|
|
@@ -330,13 +339,15 @@ const Index=()=>{
|
|
|
330
339
|
### <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
340
|
分页管理器
|
|
332
341
|
|
|
333
|
-
**Version**: 1.0.
|
|
342
|
+
**Version**: 1.0.1
|
|
334
343
|
|
|
335
344
|
| Param | Type | Description |
|
|
336
345
|
| --- | --- | --- |
|
|
337
346
|
| props | <code>Object</code> | |
|
|
338
347
|
| props.service | <code>FunServices</code> | 发送请求的方法 |
|
|
339
348
|
| [props.pagination] | <code>Pagination</code> | 默认分页信息 |
|
|
349
|
+
| [props.beforeService] | <code>Array.<function()></code> | api调用前监听方法列表 |
|
|
350
|
+
| [props.afterService] | <code>Array.<function()></code> | api调用后监听方法列表 |
|
|
340
351
|
|
|
341
352
|
**Example**
|
|
342
353
|
```js
|
|
@@ -347,6 +358,8 @@ const Index=()=>{
|
|
|
347
358
|
});
|
|
348
359
|
|
|
349
360
|
useEffect(()=>{
|
|
361
|
+
// beforeService和afterService监听方法也可以直接设置在props内
|
|
362
|
+
|
|
350
363
|
const fnFeforeService = (params)=>{
|
|
351
364
|
// 假如你这里需要变更接口字段名称的话
|
|
352
365
|
params.page=params.current;
|
|
@@ -476,7 +489,7 @@ usePagination的返回对象
|
|
|
476
489
|
| Name | Type | Description |
|
|
477
490
|
| --- | --- | --- |
|
|
478
491
|
| data | <code>Array.<Array.<Object>></code> | 分页数据集合 |
|
|
479
|
-
|
|
|
492
|
+
| pagination | <code>Pagination</code> | 分页信息 |
|
|
480
493
|
| update | <code>FunUpdate</code> | 查询方法 |
|
|
481
494
|
| next | <code>FunUpdate</code> | 获取下一页数据 |
|
|
482
495
|
| addListener | <code>function</code> | 监听事件 (type='beforeService'|'afterService',fn:FunListener)=>object |
|
package/md/useDictionary.md
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
```js
|
|
27
27
|
import {useDictionary} from 'kn-hooks';
|
|
28
28
|
import {Select,Radio} from 'antd';
|
|
29
|
-
useDictionary.SetConfig(Select.Option,Radio.Option);
|
|
29
|
+
useDictionary.SetConfig({SelectOption:Select.Option,RadioOption:Radio.Option});
|
|
30
30
|
```
|
|
31
31
|
<a id="module_usedictionary_createdictionary"></a>
|
|
32
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>
|
|
@@ -51,9 +51,18 @@ import {useDictionary} from 'kn-hooks';
|
|
|
51
51
|
// emUserType.jsx
|
|
52
52
|
import {useDictionary} from 'kn-hooks';
|
|
53
53
|
export const userType = useDictionary.createDictionary({
|
|
54
|
-
api:()=>Promise.resolve(
|
|
54
|
+
api:()=>Promise.resolve({
|
|
55
|
+
code:0,
|
|
56
|
+
data:{
|
|
57
|
+
body:[{id:'1001',label:'项目1001',name:'pm1001'},],
|
|
58
|
+
}
|
|
59
|
+
}),
|
|
55
60
|
afterApi:(response)=>{
|
|
56
|
-
|
|
61
|
+
let list;
|
|
62
|
+
if(response?.code==0){
|
|
63
|
+
list= response?.data?.body?.map(item=>{...})
|
|
64
|
+
}
|
|
65
|
+
return list;
|
|
57
66
|
}
|
|
58
67
|
});
|
|
59
68
|
// index.jsx
|
package/md/usePagination.md
CHANGED
|
@@ -15,13 +15,15 @@
|
|
|
15
15
|
### <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>
|
|
16
16
|
分页管理器
|
|
17
17
|
|
|
18
|
-
**Version**: 1.0.
|
|
18
|
+
**Version**: 1.0.1
|
|
19
19
|
|
|
20
20
|
| Param | Type | Description |
|
|
21
21
|
| --- | --- | --- |
|
|
22
22
|
| props | <code>Object</code> | |
|
|
23
23
|
| props.service | <code>FunServices</code> | 发送请求的方法 |
|
|
24
24
|
| [props.pagination] | <code>Pagination</code> | 默认分页信息 |
|
|
25
|
+
| [props.beforeService] | <code>Array.<function()></code> | api调用前监听方法列表 |
|
|
26
|
+
| [props.afterService] | <code>Array.<function()></code> | api调用后监听方法列表 |
|
|
25
27
|
|
|
26
28
|
**Example**
|
|
27
29
|
```js
|
|
@@ -32,6 +34,8 @@
|
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
useEffect(()=>{
|
|
37
|
+
// beforeService和afterService监听方法也可以直接设置在props内
|
|
38
|
+
|
|
35
39
|
const fnFeforeService = (params)=>{
|
|
36
40
|
// 假如你这里需要变更接口字段名称的话
|
|
37
41
|
params.page=params.current;
|
|
@@ -161,7 +165,7 @@ usePagination的返回对象
|
|
|
161
165
|
| Name | Type | Description |
|
|
162
166
|
| --- | --- | --- |
|
|
163
167
|
| data | <code>Array.<Array.<Object>></code> | 分页数据集合 |
|
|
164
|
-
|
|
|
168
|
+
| pagination | <code>Pagination</code> | 分页信息 |
|
|
165
169
|
| update | <code>FunUpdate</code> | 查询方法 |
|
|
166
170
|
| next | <code>FunUpdate</code> | 获取下一页数据 |
|
|
167
171
|
| addListener | <code>function</code> | 监听事件 (type='beforeService'|'afterService',fn:FunListener)=>object |
|
package/package.json
CHANGED
|
@@ -189,7 +189,7 @@ const useDictionary=(props)=>{
|
|
|
189
189
|
* @example
|
|
190
190
|
import {useDictionary} from 'kn-hooks';
|
|
191
191
|
import {Select,Radio} from 'antd';
|
|
192
|
-
useDictionary.SetConfig(Select.Option,Radio.Option);
|
|
192
|
+
useDictionary.SetConfig({SelectOption:Select.Option,RadioOption:Radio.Option});
|
|
193
193
|
*/
|
|
194
194
|
export const SetConfig = ({SelectOption,RadioOption})=>{
|
|
195
195
|
if(SelectOption)DEFAULT_CONFIG.SelectOption = SelectOption;
|
|
@@ -216,9 +216,18 @@ export const SetConfig = ({SelectOption,RadioOption})=>{
|
|
|
216
216
|
// emUserType.jsx
|
|
217
217
|
import {useDictionary} from 'kn-hooks';
|
|
218
218
|
export const userType = useDictionary.createDictionary({
|
|
219
|
-
api:()=>Promise.resolve(
|
|
219
|
+
api:()=>Promise.resolve({
|
|
220
|
+
code:0,
|
|
221
|
+
data:{
|
|
222
|
+
body:[{id:'1001',label:'项目1001',name:'pm1001'},],
|
|
223
|
+
}
|
|
224
|
+
}),
|
|
220
225
|
afterApi:(response)=>{
|
|
221
|
-
|
|
226
|
+
let list;
|
|
227
|
+
if(response?.code==0){
|
|
228
|
+
list= response?.data?.body?.map(item=>{...})
|
|
229
|
+
}
|
|
230
|
+
return list;
|
|
222
231
|
}
|
|
223
232
|
});
|
|
224
233
|
// index.jsx
|
|
@@ -11,8 +11,10 @@ import { useState,useMemo,useRef } from 'react';
|
|
|
11
11
|
* @param {Object} props
|
|
12
12
|
* @param {FunServices} props.service - 发送请求的方法
|
|
13
13
|
* @param {Pagination} [props.pagination] - 默认分页信息
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
14
|
+
* @param {Array<Function>} [props.beforeService] - api调用前监听方法列表
|
|
15
|
+
* @param {Array<Function>} [props.afterService] - api调用后监听方法列表
|
|
16
|
+
*
|
|
17
|
+
* @version 1.0.1
|
|
16
18
|
*
|
|
17
19
|
* @example
|
|
18
20
|
// 移动端滚动加载案例
|
|
@@ -22,6 +24,8 @@ import { useState,useMemo,useRef } from 'react';
|
|
|
22
24
|
});
|
|
23
25
|
|
|
24
26
|
useEffect(()=>{
|
|
27
|
+
// beforeService和afterService监听方法也可以直接设置在props内
|
|
28
|
+
|
|
25
29
|
const fnFeforeService = (params)=>{
|
|
26
30
|
// 假如你这里需要变更接口字段名称的话
|
|
27
31
|
params.page=params.current;
|
|
@@ -92,8 +96,8 @@ const usePagination=(props)=>{
|
|
|
92
96
|
});
|
|
93
97
|
const [data,setData] = useState(null);
|
|
94
98
|
const refListener= useRef({
|
|
95
|
-
beforeService:[],
|
|
96
|
-
afterService:[]
|
|
99
|
+
beforeService:props?.beforeService??[],
|
|
100
|
+
afterService:props?.afterService??[]
|
|
97
101
|
});
|
|
98
102
|
|
|
99
103
|
const update= async ({pagination:_pagination,clear=false}={})=>{
|
|
@@ -270,7 +274,7 @@ const usePagination=(props)=>{
|
|
|
270
274
|
* usePagination的返回对象
|
|
271
275
|
* @typedef {Object} UsePaginationResult
|
|
272
276
|
* @property {Object[][]} data - 分页数据集合
|
|
273
|
-
* @property {Pagination}
|
|
277
|
+
* @property {Pagination} pagination - 分页信息
|
|
274
278
|
* @property {FunUpdate} update - 查询方法
|
|
275
279
|
* @property {FunUpdate} next - 获取下一页数据
|
|
276
280
|
* @property {function} addListener - 监听事件 (type='beforeService'|'afterService',fn:FunListener)=>object
|