kn-hooks 0.0.13 → 0.0.14
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 +62 -18
- package/package.json +1 -1
- package/readme.md +62 -18
- package/src/.DS_Store +0 -0
- package/src/useDictionary/index.js +162 -12
- package/test/.DS_Store +0 -0
package/md/useDictionary.md
CHANGED
|
@@ -2,12 +2,66 @@
|
|
|
2
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
3
|
|
|
4
4
|
* [ useDictionary](#module_usedictionary)
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
|
|
5
|
+
* _static_
|
|
6
|
+
* [ SetConfig(params)](#module_usedictionary_setconfig) ⇒ <code>void</code>
|
|
7
|
+
* [ createDictionary(options)](#module_usedictionary_createdictionary) ⇒ <code>callback</code>
|
|
8
|
+
* _inner_
|
|
9
|
+
* [ useDictionary(props)](#module_usedictionary__usedictionary) ⇒ <code>UseDictionaryResult</code>
|
|
10
|
+
* [ Api](#module_usedictionary__api) ⇒ <code>Object</code>
|
|
11
|
+
* [ DictionaryItem](#module_usedictionary__dictionaryitem)
|
|
12
|
+
* [ UseDictionaryResult](#module_usedictionary__usedictionaryresult)
|
|
13
|
+
|
|
14
|
+
<a id="module_usedictionary_setconfig"></a>
|
|
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> SetConfig(params) ⇒ <code>void</code>
|
|
16
|
+
全局设置SelectOption和RadioOption
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
| Param | Type | Description |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| params | <code>Object</code> | |
|
|
22
|
+
| params.SelectOption | <code>ReactDom</code> | Antd的SelectOption组件 |
|
|
23
|
+
| params.RadioOption | <code>ReactDom</code> | Antd的SelectOption组件 |
|
|
24
|
+
|
|
25
|
+
<a id="module_usedictionary_createdictionary"></a>
|
|
26
|
+
### <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
|
+
创建字典hooks工具
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
| Param | Type | Default | Description |
|
|
31
|
+
| --- | --- | --- | --- |
|
|
32
|
+
| options | <code>Object</code> | | |
|
|
33
|
+
| options.api | <code>Api</code> | | 用于获取字典列表的接口 |
|
|
34
|
+
| [options.idKey] | <code>string</code> | <code>"'id'"</code> | 字段id的key键值 |
|
|
35
|
+
| [options.nameKey] | <code>string</code> | <code>"'name'"</code> | 字段name的key键值 |
|
|
36
|
+
| [options.labelKey] | <code>string</code> | <code>"'label'"</code> | 字段label的key键值 |
|
|
37
|
+
| [options.SelectOption] | <code>ReactDom</code> | | 指定\<Select.Option\>对象是谁 |
|
|
38
|
+
| [options.RadioOption] | <code>ReactDom</code> | | 指定\<Radio.Button\>对象是谁 |
|
|
39
|
+
| [options.beforeApi] | <code>callback</code> | | (request:object)=>object 接口调用前的参数拦截器 |
|
|
40
|
+
| [options.afterApi] | <code>callback</code> | | (reponse:object)=>object[] 接口调用后的拦截器 |
|
|
41
|
+
| [options.defaultTypes] | <code>Array.<DictionaryItem></code> | | 如果字典不是通过api获取,可以在这里设置字典的内容 |
|
|
10
42
|
|
|
43
|
+
**Example**
|
|
44
|
+
```js
|
|
45
|
+
// emUserType.jsx
|
|
46
|
+
export const userType = createDictionary({
|
|
47
|
+
api:()=>Promise.resolve([{id:'1001',label:'项目1001',name:'pm1001'},]),
|
|
48
|
+
afterApi:(response)=>{
|
|
49
|
+
return response?.data;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
// index.jsx
|
|
53
|
+
import {userType} from './emUserType.jsx'
|
|
54
|
+
const Page=()=>{
|
|
55
|
+
const emUserType = userType();
|
|
56
|
+
return (
|
|
57
|
+
<section>
|
|
58
|
+
<Select defaultValue={emUserType.getId('项目1001')}>
|
|
59
|
+
{emUserType.selectOptions}
|
|
60
|
+
</Select>
|
|
61
|
+
</section>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
```
|
|
11
65
|
<a id="module_usedictionary__usedictionary"></a>
|
|
12
66
|
### <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
67
|
字典管理
|
|
@@ -26,12 +80,13 @@
|
|
|
26
80
|
| [props.RadioOption] | <code>ReactDom</code> | | 指定\<Radio.Button\>对象是谁 |
|
|
27
81
|
| [props.beforeApi] | <code>callback</code> | | (request:object)=>object 接口调用前的参数拦截器 |
|
|
28
82
|
| [props.afterApi] | <code>callback</code> | | (reponse:object)=>object[] 接口调用后的拦截器 |
|
|
83
|
+
| [props.defaultTypes] | <code>Array.<DictionaryItem></code> | | 如果字典不是通过api获取,可以在这里设置字典的内容 |
|
|
29
84
|
|
|
30
85
|
**Example**
|
|
31
86
|
```js
|
|
32
87
|
import {Select,Radio} from 'antd';
|
|
33
|
-
import useDictionary from '@/useDictionary';
|
|
34
|
-
|
|
88
|
+
import useDictionary,{SetConfig} from '@/useDictionary';
|
|
89
|
+
SetConfig({SelectOption:Select.Option,RadioOption:Radio.Button});
|
|
35
90
|
|
|
36
91
|
const Index=()=>{
|
|
37
92
|
|
|
@@ -69,17 +124,6 @@ const Index=()=>{
|
|
|
69
124
|
)
|
|
70
125
|
}
|
|
71
126
|
```
|
|
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
127
|
<a id="module_usedictionary__api"></a>
|
|
84
128
|
### <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
129
|
**Properties**
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -151,12 +151,66 @@ return <span>当前计数器:{counter.count}</span>
|
|
|
151
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
152
|
|
|
153
153
|
* [ useDictionary](#module_usedictionary)
|
|
154
|
-
*
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
*
|
|
158
|
-
|
|
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组件 |
|
|
159
173
|
|
|
174
|
+
<a id="module_usedictionary_createdictionary"></a>
|
|
175
|
+
### <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
|
+
创建字典hooks工具
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
| Param | Type | Default | Description |
|
|
180
|
+
| --- | --- | --- | --- |
|
|
181
|
+
| options | <code>Object</code> | | |
|
|
182
|
+
| options.api | <code>Api</code> | | 用于获取字典列表的接口 |
|
|
183
|
+
| [options.idKey] | <code>string</code> | <code>"'id'"</code> | 字段id的key键值 |
|
|
184
|
+
| [options.nameKey] | <code>string</code> | <code>"'name'"</code> | 字段name的key键值 |
|
|
185
|
+
| [options.labelKey] | <code>string</code> | <code>"'label'"</code> | 字段label的key键值 |
|
|
186
|
+
| [options.SelectOption] | <code>ReactDom</code> | | 指定\<Select.Option\>对象是谁 |
|
|
187
|
+
| [options.RadioOption] | <code>ReactDom</code> | | 指定\<Radio.Button\>对象是谁 |
|
|
188
|
+
| [options.beforeApi] | <code>callback</code> | | (request:object)=>object 接口调用前的参数拦截器 |
|
|
189
|
+
| [options.afterApi] | <code>callback</code> | | (reponse:object)=>object[] 接口调用后的拦截器 |
|
|
190
|
+
| [options.defaultTypes] | <code>Array.<DictionaryItem></code> | | 如果字典不是通过api获取,可以在这里设置字典的内容 |
|
|
191
|
+
|
|
192
|
+
**Example**
|
|
193
|
+
```js
|
|
194
|
+
// emUserType.jsx
|
|
195
|
+
export const userType = createDictionary({
|
|
196
|
+
api:()=>Promise.resolve([{id:'1001',label:'项目1001',name:'pm1001'},]),
|
|
197
|
+
afterApi:(response)=>{
|
|
198
|
+
return response?.data;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
// index.jsx
|
|
202
|
+
import {userType} from './emUserType.jsx'
|
|
203
|
+
const Page=()=>{
|
|
204
|
+
const emUserType = userType();
|
|
205
|
+
return (
|
|
206
|
+
<section>
|
|
207
|
+
<Select defaultValue={emUserType.getId('项目1001')}>
|
|
208
|
+
{emUserType.selectOptions}
|
|
209
|
+
</Select>
|
|
210
|
+
</section>
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
```
|
|
160
214
|
<a id="module_usedictionary__usedictionary"></a>
|
|
161
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> useDictionary(props) ⇒ <code>UseDictionaryResult</code>
|
|
162
216
|
字典管理
|
|
@@ -175,12 +229,13 @@ return <span>当前计数器:{counter.count}</span>
|
|
|
175
229
|
| [props.RadioOption] | <code>ReactDom</code> | | 指定\<Radio.Button\>对象是谁 |
|
|
176
230
|
| [props.beforeApi] | <code>callback</code> | | (request:object)=>object 接口调用前的参数拦截器 |
|
|
177
231
|
| [props.afterApi] | <code>callback</code> | | (reponse:object)=>object[] 接口调用后的拦截器 |
|
|
232
|
+
| [props.defaultTypes] | <code>Array.<DictionaryItem></code> | | 如果字典不是通过api获取,可以在这里设置字典的内容 |
|
|
178
233
|
|
|
179
234
|
**Example**
|
|
180
235
|
```js
|
|
181
236
|
import {Select,Radio} from 'antd';
|
|
182
|
-
import useDictionary from '@/useDictionary';
|
|
183
|
-
|
|
237
|
+
import useDictionary,{SetConfig} from '@/useDictionary';
|
|
238
|
+
SetConfig({SelectOption:Select.Option,RadioOption:Radio.Button});
|
|
184
239
|
|
|
185
240
|
const Index=()=>{
|
|
186
241
|
|
|
@@ -218,17 +273,6 @@ const Index=()=>{
|
|
|
218
273
|
)
|
|
219
274
|
}
|
|
220
275
|
```
|
|
221
|
-
<a id="module_usedictionary__set"></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> SET(params) ⇒ <code>void</code>
|
|
223
|
-
全局设置SelectOption和RadioOption
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
| Param | Type | Description |
|
|
227
|
-
| --- | --- | --- |
|
|
228
|
-
| params | <code>Object</code> | |
|
|
229
|
-
| params.SelectOption | <code>ReactDom</code> | Antd的SelectOption组件 |
|
|
230
|
-
| params.RadioOption | <code>ReactDom</code> | Antd的SelectOption组件 |
|
|
231
|
-
|
|
232
276
|
<a id="module_usedictionary__api"></a>
|
|
233
277
|
### <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>
|
|
234
278
|
**Properties**
|
package/src/.DS_Store
CHANGED
|
Binary file
|
|
@@ -22,14 +22,15 @@ const DEFAULT_CONFIG={
|
|
|
22
22
|
* @param {ReactDom} [props.RadioOption] - 指定\<Radio.Button\>对象是谁
|
|
23
23
|
* @param {callback} [props.beforeApi] - (request:object)=>object 接口调用前的参数拦截器
|
|
24
24
|
* @param {callback} [props.afterApi] - (reponse:object)=>object[] 接口调用后的拦截器
|
|
25
|
+
* @param {DictionaryItem[]} [props.defaultTypes] - 如果字典不是通过api获取,可以在这里设置字典的内容
|
|
25
26
|
*
|
|
26
27
|
*
|
|
27
28
|
* @return {UseDictionaryResult}
|
|
28
29
|
*
|
|
29
30
|
* @example
|
|
30
31
|
import {Select,Radio} from 'antd';
|
|
31
|
-
import useDictionary from '@/useDictionary';
|
|
32
|
-
|
|
32
|
+
import useDictionary,{SetConfig} from '@/useDictionary';
|
|
33
|
+
SetConfig({SelectOption:Select.Option,RadioOption:Radio.Button});
|
|
33
34
|
|
|
34
35
|
const Index=()=>{
|
|
35
36
|
|
|
@@ -76,12 +77,14 @@ const useDictionary=(props)=>{
|
|
|
76
77
|
labelKey = 'label',
|
|
77
78
|
beforeApi,
|
|
78
79
|
afterApi,
|
|
80
|
+
defaultTypes,
|
|
79
81
|
SelectOption= DEFAULT_CONFIG.SelectOption,
|
|
80
82
|
RadioOption= DEFAULT_CONFIG.RadioOption } = props;
|
|
81
83
|
|
|
82
|
-
const [types, setTypes] = useState(null);
|
|
84
|
+
const [types, setTypes] = useState(defaultTypes||null);
|
|
83
85
|
|
|
84
86
|
const init = async () => {
|
|
87
|
+
if(!api)return;
|
|
85
88
|
let params={};
|
|
86
89
|
if(beforeApi){
|
|
87
90
|
params = beforeApi();
|
|
@@ -176,11 +179,166 @@ const useDictionary=(props)=>{
|
|
|
176
179
|
|
|
177
180
|
}
|
|
178
181
|
|
|
182
|
+
/**
|
|
183
|
+
* @function
|
|
184
|
+
* @description 全局设置SelectOption和RadioOption
|
|
185
|
+
* @param {Object} params
|
|
186
|
+
* @param {ReactDom} params.SelectOption - Antd的SelectOption组件
|
|
187
|
+
* @param {ReactDom} params.RadioOption - Antd的SelectOption组件
|
|
188
|
+
* @returns {void}
|
|
189
|
+
*/
|
|
179
190
|
export const SetConfig = ({SelectOption,RadioOption})=>{
|
|
180
191
|
if(SelectOption)DEFAULT_CONFIG.SelectOption = SelectOption;
|
|
181
192
|
if(RadioOption)DEFAULT_CONFIG.RadioOption = RadioOption;
|
|
182
193
|
};
|
|
183
194
|
|
|
195
|
+
/**
|
|
196
|
+
* @function
|
|
197
|
+
* @description 创建字典hooks工具
|
|
198
|
+
* @param {Object} options
|
|
199
|
+
* @param {Api} options.api - 用于获取字典列表的接口
|
|
200
|
+
* @param {string} [options.idKey='id'] - 字段id的key键值
|
|
201
|
+
* @param {string} [options.nameKey='name'] - 字段name的key键值
|
|
202
|
+
* @param {string} [options.labelKey='label'] - 字段label的key键值
|
|
203
|
+
* @param {ReactDom} [options.SelectOption] - 指定\<Select.Option\>对象是谁
|
|
204
|
+
* @param {ReactDom} [options.RadioOption] - 指定\<Radio.Button\>对象是谁
|
|
205
|
+
* @param {callback} [options.beforeApi] - (request:object)=>object 接口调用前的参数拦截器
|
|
206
|
+
* @param {callback} [options.afterApi] - (reponse:object)=>object[] 接口调用后的拦截器
|
|
207
|
+
* @param {DictionaryItem[]} [options.defaultTypes] - 如果字典不是通过api获取,可以在这里设置字典的内容
|
|
208
|
+
*
|
|
209
|
+
* @returns {callback}
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
// emUserType.jsx
|
|
213
|
+
export const userType = createDictionary({
|
|
214
|
+
api:()=>Promise.resolve([{id:'1001',label:'项目1001',name:'pm1001'},]),
|
|
215
|
+
afterApi:(response)=>{
|
|
216
|
+
return response?.data;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
// index.jsx
|
|
220
|
+
import {userType} from './emUserType.jsx'
|
|
221
|
+
const Page=()=>{
|
|
222
|
+
const emUserType = userType();
|
|
223
|
+
return (
|
|
224
|
+
<section>
|
|
225
|
+
<Select defaultValue={emUserType.getId('项目1001')}>
|
|
226
|
+
{emUserType.selectOptions}
|
|
227
|
+
</Select>
|
|
228
|
+
</section>
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
*/
|
|
232
|
+
export const createDictionary=options=>{
|
|
233
|
+
const {
|
|
234
|
+
api,
|
|
235
|
+
idKey = 'id',
|
|
236
|
+
nameKey = 'name',
|
|
237
|
+
labelKey = 'label',
|
|
238
|
+
beforeApi,
|
|
239
|
+
afterApi,
|
|
240
|
+
defaultTypes=null,
|
|
241
|
+
SelectOption= DEFAULT_CONFIG.SelectOption,
|
|
242
|
+
RadioOption= DEFAULT_CONFIG.RadioOption } = options;
|
|
243
|
+
|
|
244
|
+
return (props)=>{
|
|
245
|
+
const [types, setTypes] = useState(defaultTypes||null);
|
|
246
|
+
|
|
247
|
+
const init = async () => {
|
|
248
|
+
if(!api)return;
|
|
249
|
+
let params={};
|
|
250
|
+
if(beforeApi){
|
|
251
|
+
params = beforeApi();
|
|
252
|
+
}
|
|
253
|
+
const ret = await api(params);
|
|
254
|
+
if(afterApi){
|
|
255
|
+
ret = afterApi(ret);
|
|
256
|
+
setTypes(ret||[]);
|
|
257
|
+
}else{
|
|
258
|
+
if (+ret?.code === 0) {
|
|
259
|
+
setTypes(ret.data.body || []);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
init();
|
|
266
|
+
}, []);
|
|
267
|
+
|
|
268
|
+
const getLabel = (id) => {
|
|
269
|
+
if (types) {
|
|
270
|
+
for (let i = 0; i < types.length; i++) {
|
|
271
|
+
if ('' + types[i][idKey] === '' + id) {
|
|
272
|
+
return types[i][labelKey];
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return '';
|
|
277
|
+
};
|
|
278
|
+
const getName = (id) => {
|
|
279
|
+
if (types) {
|
|
280
|
+
for (let i = 0; i < types.length; i++) {
|
|
281
|
+
if ('' + types[i][idKey] === '' + id) {
|
|
282
|
+
return types[i][nameKey];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return '';
|
|
287
|
+
};
|
|
288
|
+
const getId = (labelOrName) => {
|
|
289
|
+
if (types) {
|
|
290
|
+
for (let i = 0; i < types.length; i++) {
|
|
291
|
+
const label = '' + types[i][labelKey];
|
|
292
|
+
const name = '' + types[i][nameKey];
|
|
293
|
+
const txt = '' + labelOrName;
|
|
294
|
+
if (label === txt || name === txt) {
|
|
295
|
+
return types[i][idKey];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return '';
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const selectOptions = useMemo(() => {
|
|
303
|
+
if(!SelectOption)return <>SelectOption未指定</>;
|
|
304
|
+
return (
|
|
305
|
+
types?.map((item) => {
|
|
306
|
+
return (
|
|
307
|
+
<SelectOption key={item[idKey]} value={item[idKey]} data-keyname={item[nameKey]}>
|
|
308
|
+
{item[labelKey]}
|
|
309
|
+
</SelectOption>
|
|
310
|
+
);
|
|
311
|
+
}) || ''
|
|
312
|
+
);
|
|
313
|
+
}, [types,SelectOption]);
|
|
314
|
+
|
|
315
|
+
const radioOptions = useMemo(() => {
|
|
316
|
+
if(!RadioOption)return <>RadioOption没指定</>;
|
|
317
|
+
return (
|
|
318
|
+
types?.map((item) => {
|
|
319
|
+
return (
|
|
320
|
+
<RadioOption key={item[idKey]} value={item[idKey]} data-keyname={item[nameKey]}>
|
|
321
|
+
{item[labelKey]}
|
|
322
|
+
</RadioOption>
|
|
323
|
+
);
|
|
324
|
+
}) || ''
|
|
325
|
+
);
|
|
326
|
+
}, [types,RadioOption]);
|
|
327
|
+
|
|
328
|
+
const isReady = () => {
|
|
329
|
+
return types !== null;
|
|
330
|
+
};
|
|
331
|
+
const reload = () => {
|
|
332
|
+
init();
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
const actions = useMemo(() => {
|
|
336
|
+
return { types, getLabel, getId, getName, selectOptions, isReady, reload, radioOptions };
|
|
337
|
+
}, [types]);
|
|
338
|
+
|
|
339
|
+
return actions;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
184
342
|
|
|
185
343
|
|
|
186
344
|
/**
|
|
@@ -212,15 +370,7 @@ export const SetConfig = ({SelectOption,RadioOption})=>{
|
|
|
212
370
|
*
|
|
213
371
|
*/
|
|
214
372
|
|
|
215
|
-
|
|
216
|
-
* @function SET
|
|
217
|
-
* @description 全局设置SelectOption和RadioOption
|
|
218
|
-
*
|
|
219
|
-
* @param {Object} params
|
|
220
|
-
* @param {ReactDom} params.SelectOption - Antd的SelectOption组件
|
|
221
|
-
* @param {ReactDom} params.RadioOption - Antd的SelectOption组件
|
|
222
|
-
* @returns {void}
|
|
223
|
-
*/
|
|
373
|
+
|
|
224
374
|
|
|
225
375
|
|
|
226
376
|
export default useDictionary
|
package/test/.DS_Store
CHANGED
|
Binary file
|