kn-hooks 0.0.10 → 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.
@@ -0,0 +1,49 @@
1
+ <a id="module_useclipboard"></a>
2
+ ## <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
3
+
4
+ * [ useClipboard](#module_useclipboard)
5
+ * [ useClipboard([props])](#module_useclipboard__useclipboard) ⇒ <code>UseClipboardResult</code>
6
+ * [ FunCopy](#module_useclipboard__funcopy) : <code>callback</code>
7
+ * [ UseClipboardResult](#module_useclipboard__useclipboardresult) : <code>Object</code>
8
+
9
+ <a id="module_useclipboard__useclipboard"></a>
10
+ ### <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>
11
+ 剪贴板工具
12
+
13
+ [Demo - CodeSandBox](https://codesandbox.io/s/useclipboard-b4ryc?file=/index.js)
14
+
15
+
16
+ | Param | Type | Description |
17
+ | --- | --- | --- |
18
+ | [props] | <code>Object</code> | - |
19
+ | [props.onSuccess] | <code>callback</code> | 成功复制到剪贴板后的回调 ()=>void |
20
+
21
+ **Example**
22
+ ```js
23
+ const clipboard= useClipboard();
24
+ const onCopy=()=>{
25
+ clipboard.copy('text',()=>{console.log('success')})
26
+ }
27
+ ```
28
+ <a id="module_useclipboard__funcopy"></a>
29
+ ### <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>
30
+ 复制函数
31
+
32
+ **Properties**
33
+
34
+ | Name | Type | Description |
35
+ | --- | --- | --- |
36
+ | text | <code>string</code> | 需要被复制的字符串 |
37
+ | onCurSuccess | <code>callback</code> | 复制成功的回调 ()=>void |
38
+
39
+ <a id="module_useclipboard__useclipboardresult"></a>
40
+ ### <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>
41
+ UseClipboardResult返回的hook
42
+
43
+ **Properties**
44
+
45
+ | Name | Type | Description |
46
+ | --- | --- | --- |
47
+ | copy | <code>FunCopy</code> | 触发复制字符串的函数 |
48
+
49
+
@@ -0,0 +1,28 @@
1
+ <a id="module_usecounter"></a>
2
+ ## <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
3
+
4
+ * [ useCounter](#module_usecounter)
5
+ * [ useCounter()](#module_usecounter__usecounter) ⇒ <code>UseCounterResult</code>
6
+ * [ UseCounterResult](#module_usecounter__usecounterresult)
7
+
8
+ <a id="module_usecounter__usecounter"></a>
9
+ ### <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>
10
+ 加法计数器
11
+
12
+ **Example**
13
+ ```js
14
+ const counter= useCounter();
15
+ const onAdd=()=>{counter.addCount()}
16
+ return <span>当前计数器:{counter.count}</span>
17
+ ```
18
+ <a id="module_usecounter__usecounterresult"></a>
19
+ ### <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
20
+ **Properties**
21
+
22
+ | Name | Type | Description |
23
+ | --- | --- | --- |
24
+ | req | <code>Object</code> | |
25
+ | req.count | <code>number</code> | 当前计数器的值 |
26
+ | req.addCount | <code>function</code> | 计数器的值+1。 ()=>void |
27
+
28
+
@@ -0,0 +1,115 @@
1
+ <a id="module_usedictionary"></a>
2
+ ## <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
3
+
4
+ * [ useDictionary](#module_usedictionary)
5
+ * [ useDictionary(props)](#module_usedictionary__usedictionary) ⇒ <code>UseDictionaryResult</code>
6
+ * [ SET(params)](#module_usedictionary__set) ⇒ <code>void</code>
7
+ * [ Api](#module_usedictionary__api) ⇒ <code>Object</code>
8
+ * [ DictionaryItem](#module_usedictionary__dictionaryitem)
9
+ * [ UseDictionaryResult](#module_usedictionary__usedictionaryresult)
10
+
11
+ <a id="module_usedictionary__usedictionary"></a>
12
+ ### <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>
13
+ 字典管理
14
+
15
+ [Demo - CodeSandBox](https://codesandbox.io/s/usedictionary-j7cw8?file=/index.js)
16
+
17
+
18
+ | Param | Type | Default | Description |
19
+ | --- | --- | --- | --- |
20
+ | props | <code>Object</code> | | |
21
+ | props.api | <code>Api</code> | | 用于获取字典列表的接口 |
22
+ | [props.idKey] | <code>string</code> | <code>&quot;&#x27;id&#x27;&quot;</code> | 字段id的key键值 |
23
+ | [props.nameKey] | <code>string</code> | <code>&quot;&#x27;name&#x27;&quot;</code> | 字段name的key键值 |
24
+ | [props.labelKey] | <code>string</code> | <code>&quot;&#x27;label&#x27;&quot;</code> | 字段label的key键值 |
25
+ | [props.SelectOption] | <code>ReactDom</code> | | 指定\<Select.Option\>对象是谁 |
26
+ | [props.RadioOption] | <code>ReactDom</code> | | 指定\<Radio.Button\>对象是谁 |
27
+ | [props.beforeApi] | <code>callback</code> | | (request:object)=>object 接口调用前的参数拦截器 |
28
+ | [props.afterApi] | <code>callback</code> | | (reponse:object)=>object[] 接口调用后的拦截器 |
29
+
30
+ **Example**
31
+ ```js
32
+ import {Select,Radio} from 'antd';
33
+ import useDictionary from '@/useDictionary';
34
+ useDictionary.SET({SelectOption:Select.Option,RadioOption:Radio.Button});
35
+
36
+ const Index=()=>{
37
+
38
+ const emCity = useDictionary({
39
+ api:()=>{
40
+ return new Promise(resolve=>{
41
+ resolve({
42
+ code:0,
43
+ data:{
44
+ body:[
45
+ {id:1,name:'shanghai',label:'上海'},
46
+ {id:2,name:'beijing',label:'北京'},
47
+ {id:3,name:'guangzhou',label:'广州'}
48
+ ]
49
+ }
50
+ })
51
+ })
52
+ }
53
+ });
54
+
55
+ return (
56
+ <section >
57
+ <Select defaultValue={1}>
58
+ {
59
+ emCity.selectOptions
60
+ }
61
+ </Select>
62
+ <p>分割线</p>
63
+ <Radio.Group defaultValue={1}>
64
+ {
65
+ emCity.radioOptions
66
+ }
67
+ </Radio.Group>
68
+ </section>
69
+ )
70
+ }
71
+ ```
72
+ <a id="module_usedictionary__set"></a>
73
+ ### <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>
74
+ 全局设置SelectOption和RadioOption
75
+
76
+
77
+ | Param | Type | Description |
78
+ | --- | --- | --- |
79
+ | params | <code>Object</code> | |
80
+ | params.SelectOption | <code>ReactDom</code> | Antd的SelectOption组件 |
81
+ | params.RadioOption | <code>ReactDom</code> | Antd的SelectOption组件 |
82
+
83
+ <a id="module_usedictionary__api"></a>
84
+ ### <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>
85
+ **Properties**
86
+
87
+ | Name | Type | Description |
88
+ | --- | --- | --- |
89
+ | params | <code>Object</code> | 调用接口用到的参数 |
90
+
91
+ <a id="module_usedictionary__dictionaryitem"></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;">T</span> DictionaryItem
93
+ **Properties**
94
+
95
+ | Name | Type | Description |
96
+ | --- | --- | --- |
97
+ | id | <code>string</code> | 数据唯一ID |
98
+ | name | <code>string</code> | 数据唯一id对应的别名 |
99
+ | label | <code>string</code> | 展示给用户看的文字 |
100
+
101
+ <a id="module_usedictionary__usedictionaryresult"></a>
102
+ ### <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
103
+ **Properties**
104
+
105
+ | Name | Type | Description |
106
+ | --- | --- | --- |
107
+ | types | <code>Array.&lt;DictionaryItem&gt;</code> | 字典数据列表 |
108
+ | selectOptions | <code>Array.&lt;ReactDOM&gt;</code> | 供Antd渲染\<Select\>的列表 |
109
+ | radioOptions | <code>Array.&lt;ReactDOM&gt;</code> | 供Antd渲染\<Radio\>的列表 |
110
+ | getId | <code>function</code> | (labelOrName:string)=>string,搜索字典项中,label或name匹配labelOrName的项目,返回其id的值 |
111
+ | getName | <code>function</code> | (id:string)=>string,搜索字典项中,id匹配id的项目,返回其name的值 |
112
+ | getLabel | <code>function</code> | (id:string)=>string,搜索字典项中,id匹配id的项目,返回其label的值 |
113
+ | reload | <code>function</code> | ()=>void,重新调用字典接口刷新字典列表 |
114
+
115
+
@@ -0,0 +1,154 @@
1
+ <a id="module_usepagination"></a>
2
+ ## <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
3
+
4
+ * [ usePagination](#module_usepagination)
5
+ * [ usePagination(props)](#module_usepagination__usepagination) ⇒ <code>UsePaginationResult</code>
6
+ * [ Pagination](#module_usepagination__pagination) : <code>Object</code>
7
+ * [ PageDataResult](#module_usepagination__pagedataresult) : <code>Object</code>
8
+ * [ FunUpdate](#module_usepagination__funupdate) ⇒ <code>Promise.&lt;PageDataResult&gt;</code>
9
+ * [ UsePaginationResult](#module_usepagination__usepaginationresult) : <code>Object</code>
10
+ * [ FunListener](#module_usepagination__funlistener) ⇒ <code>Object</code> \| <code>Promise.&lt;Object&gt;</code>
11
+
12
+ <a id="module_usepagination__usepagination"></a>
13
+ ### <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>
14
+ 分页管理器
15
+
16
+ **Version**: 1.0.0
17
+
18
+ | Param | Type | Description |
19
+ | --- | --- | --- |
20
+ | props | <code>Object</code> | |
21
+ | props.service | <code>function</code> | 发送请求的方法,默认分页使用current和pageSize,如有特殊需求通过beforeService拦截处理 |
22
+ | [props.pagination] | <code>Pagination</code> | 默认分页信息 |
23
+
24
+ **Example**
25
+ ```js
26
+ // 移动端滚动加载案例
27
+ const page = usePagination({
28
+ service:GET_LIST,
29
+ pagination:{pageSize:10},
30
+
31
+ });
32
+
33
+ useEffect(()=>{
34
+ const fnFeforeService = (params)=>{
35
+ // 假如你这里需要变更接口字段名称的话
36
+ params.page=params.current;
37
+ params.keyword='abc';
38
+ return params;
39
+ }
40
+
41
+ const fnAfterService = (response)=>{
42
+ // 这里你可以翻译及二次处理你的接口字段
43
+ let req={
44
+ code:response.errorCode
45
+ data:response.list,
46
+ page:response.pageInfo
47
+ };
48
+ response.code=response;
49
+ return response;
50
+ },
51
+
52
+ page.addListener('beforeService',fnFeforeService);
53
+ page.addListener('afterService',fnAfterService);
54
+ return ()=>{
55
+ page.removeListener('beforeService',fnFeforeService);
56
+ page.removeListener('afterService',fnAfterService)
57
+ }
58
+ },[])
59
+
60
+ const onReset=()=>{page.reset();}
61
+
62
+ const onPageChange=()=>{
63
+ let value=document.querySelector('#inputPage').value;
64
+ page.update({pagination:{current:+value}})
65
+ }
66
+ const onNext=()=>{page.nextPage();}
67
+
68
+ const renderTable=()=>{
69
+ let renderData= [];
70
+ page?.data?.forEach(list=>{
71
+ renderData=[...renderData,...list];
72
+ })
73
+
74
+ return (
75
+ <ul>
76
+ {
77
+ renderData?.map((item,idx)=>{
78
+ return <li key={idx}>[{idx}]{item}</li>
79
+ })
80
+ }
81
+ </ul>
82
+ )
83
+
84
+ }
85
+ return (
86
+ <ul>
87
+ {renderTable()}
88
+ </ul>
89
+ )
90
+ ```
91
+ <a id="module_usepagination__pagination"></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;">T</span> Pagination : <code>Object</code>
93
+ 分页信息
94
+
95
+ **Properties**
96
+
97
+ | Name | Type | Default | Description |
98
+ | --- | --- | --- | --- |
99
+ | pageSize | <code>number</code> | <code>20</code> | 分页大小 |
100
+ | current | <code>number</code> | <code>1</code> | 当前页码 |
101
+ | total | <code>number</code> | <code>1</code> | 总记录数 |
102
+ | [startIdx] | <code>number</code> | <code>0</code> | 当前页面下第一条数据的序号 |
103
+ | [more] | <code>boolean</code> | | 是否还有下一页 |
104
+
105
+ <a id="module_usepagination__pagedataresult"></a>
106
+ ### <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>
107
+ 分页数据结果
108
+
109
+ **Properties**
110
+
111
+ | Name | Type | Description |
112
+ | --- | --- | --- |
113
+ | pagination | <code>Pagination</code> | 最新分页信息 |
114
+ | data | <code>Array.&lt;Array.&lt;Object&gt;&gt;</code> | 分页数据集合 |
115
+
116
+ <a id="module_usepagination__funupdate"></a>
117
+ ### <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>
118
+ 分页查询结果
119
+
120
+ **Returns**: <code>Promise.&lt;PageDataResult&gt;</code> - 最新的分页数据结果
121
+ **Properties**
122
+
123
+ | Name | Type | Description |
124
+ | --- | --- | --- |
125
+ | [pagination] | <code>Pagination</code> | 最新分页信息 |
126
+ | [clear] | <code>boolean</code> | 是否清空数据 |
127
+
128
+ <a id="module_usepagination__usepaginationresult"></a>
129
+ ### <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>
130
+ usePagination的返回对象
131
+
132
+ **Properties**
133
+
134
+ | Name | Type | Description |
135
+ | --- | --- | --- |
136
+ | data | <code>Array.&lt;Array.&lt;Object&gt;&gt;</code> | 分页数据集合 |
137
+ | paginnation | <code>Pagination</code> | 分页信息 |
138
+ | update | <code>FunUpdate</code> | 查询方法 |
139
+ | next | <code>FunUpdate</code> | 获取下一页数据 |
140
+ | addListener | <code>function</code> | 监听事件 (type='beforeService'|'afterService',fn:FunListener)=>object |
141
+ | removeListener | <code>function</code> | 移除监听事件 (type,fn:FunListener)=>void |
142
+
143
+ <a id="module_usepagination__funlistener"></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;">T</span> FunListener ⇒ <code>Object</code> \| <code>Promise.&lt;Object&gt;</code>
145
+ 事件监听方法
146
+
147
+ **Returns**: <code>Object</code> \| <code>Promise.&lt;Object&gt;</code> - 处理完毕的数据对象或者Promise
148
+ **Properties**
149
+
150
+ | Name | Type | Description |
151
+ | --- | --- | --- |
152
+ | params | <code>Object</code> | 被拦截的数据对象 |
153
+
154
+
@@ -0,0 +1,39 @@
1
+ <a id="module_usepaginationwithform"></a>
2
+ ## <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
3
+ <a id="module_usepaginationwithform__usepaginationwithform"></a>
4
+ ### <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)
5
+ 支持Antd-Form的usePagination
6
+ 作用是在查询接口前自动获取form表单内的字段,并作为接口查询参数进行查询
7
+ 使用方法及参数字段参考 [usePagination](usePagination.md)
8
+
9
+
10
+ | Param | Type | Description |
11
+ | --- | --- | --- |
12
+ | props | <code>Object</code> | |
13
+ | props.form | <code>Object</code> | Form表单的ref,在接口调用前会校验获取form表单内的数据,提交到接口参数内查询 |
14
+
15
+ **Example**
16
+ ```js
17
+ const [form] = Form.useForm();
18
+ const page = usePaginationWithForm({
19
+ service:GET_LIST,
20
+ pagination:{pageSize:10},
21
+ form:form
22
+ });
23
+
24
+ return(
25
+ <Form form={form} style={{width:'600px'}} layout="inline">
26
+ <Form.Item label='关键字' name='keyword' rules={[
27
+ {
28
+ max:5,
29
+ message:'最多5个字符'
30
+ }
31
+ ]}>
32
+ <Input />
33
+ </Form.Item>
34
+ <Button onClick={onSearch} type='primary'>查询</Button>
35
+ <Button onClick={onReset} type='primary'>重置</Button>
36
+ </Form>
37
+ )
38
+ ```
39
+
@@ -0,0 +1,35 @@
1
+ <a id="module_useswitch"></a>
2
+ ## <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
3
+ useSwitch
4
+
5
+
6
+ * [ useSwitch](#module_useswitch)
7
+ * [ useSwitch([props])](#module_useswitch__useswitch) ⇒ <code>UseSwitchResult</code>
8
+ * [ UseSwitchResult](#module_useswitch__useswitchresult) : <code>Object</code>
9
+
10
+ <a id="module_useswitch__useswitch"></a>
11
+ ### <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>
12
+ 控制开关
13
+
14
+ [Demo-CodeSandbox](https://codesandbox.io/s/useswitch-qd7dr?file=/index.js)
15
+
16
+
17
+ | Param | Type | Default | Description |
18
+ | --- | --- | --- | --- |
19
+ | [props] | <code>boolean</code> | <code>false</code> | 默认的开关状态 |
20
+
21
+ <a id="module_useswitch__useswitchresult"></a>
22
+ ### <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>
23
+ useSwitchHookResult
24
+
25
+ **Properties**
26
+
27
+ | Name | Type | Description |
28
+ | --- | --- | --- |
29
+ | state | <code>boolean</code> | 当前开关状态 |
30
+ | count | <code>number</code> | 当前开关计数器 |
31
+ | open | <code>function</code> | 切换至开模式 (force?:boolean)=>void |
32
+ | close | <code>function</code> | 切换至关模式 (force?:boolean)=>void |
33
+ | toggle | <code>function</code> | 切换至反向模式 ()=>void |
34
+
35
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kn-hooks",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
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",
@@ -56,7 +56,8 @@
56
56
  "files": [
57
57
  "test",
58
58
  "src",
59
- "lib"
59
+ "lib",
60
+ "md"
60
61
  ],
61
62
  "keywords": [],
62
63
  "description": "",
package/readme.md CHANGED
@@ -6,12 +6,12 @@
6
6
  * [按需打包](#package)
7
7
 
8
8
  * API
9
- * [useDictionary - 字典管理及下拉选项框渲染](md/useDictionary.md)
10
- * [useSwitch - 开关控制](md/useSwitch.md)
11
- * [useClipboard - 剪贴板](md/useClipboard.md)
12
- * [useCounter - 计数器](md/useCounter.md)
13
- * [usePagination - 分页管理](md/usePagination.md)
14
- * [usePaginationWithForm - 支持Antd-From的分页管理](md/usePaginationWithForm.md)
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>&quot;&#x27;id&#x27;&quot;</code> | 字段id的key键值 |
165
+ | [props.nameKey] | <code>string</code> | <code>&quot;&#x27;name&#x27;&quot;</code> | 字段name的key键值 |
166
+ | [props.labelKey] | <code>string</code> | <code>&quot;&#x27;label&#x27;&quot;</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.&lt;DictionaryItem&gt;</code> | 字典数据列表 |
250
+ | selectOptions | <code>Array.&lt;ReactDOM&gt;</code> | 供Antd渲染\<Select\>的列表 |
251
+ | radioOptions | <code>Array.&lt;ReactDOM&gt;</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.&lt;PageDataResult&gt;</code>
266
+ * [ UsePaginationResult](#module_usepagination__usepaginationresult) : <code>Object</code>
267
+ * [ FunListener](#module_usepagination__funlistener) ⇒ <code>Object</code> \| <code>Promise.&lt;Object&gt;</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.&lt;Array.&lt;Object&gt;&gt;</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.&lt;PageDataResult&gt;</code>
375
+ 分页查询结果
376
+
377
+ **Returns**: <code>Promise.&lt;PageDataResult&gt;</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.&lt;Array.&lt;Object&gt;&gt;</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.&lt;Object&gt;</code>
402
+ 事件监听方法
403
+
404
+ **Returns**: <code>Object</code> \| <code>Promise.&lt;Object&gt;</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
+