@kne/super-select 0.1.31 → 0.1.33
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 +1146 -368
- package/dist/index.css +22 -6
- package/dist/index.css.map +1 -1
- package/dist/index.js +51 -41
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +33 -8
- package/dist/index.modern.js.map +1 -1
- package/package.json +16 -4
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
### 描述
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
React 复杂信息选择组件库,提供列表、表格、树形等多种选择模式,支持单选/多选、搜索、全选等功能
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
### 安装
|
|
@@ -79,135 +79,358 @@ npm i --save @kne/super-select
|
|
|
79
79
|
|
|
80
80
|
#### 示例代码
|
|
81
81
|
|
|
82
|
-
-
|
|
83
|
-
-
|
|
82
|
+
- SelectInput 基础组件
|
|
83
|
+
- 基础选择输入组件,展示尺寸、多选、弹窗模式、前后缀等核心功能
|
|
84
84
|
- _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
|
|
85
85
|
|
|
86
86
|
```jsx
|
|
87
87
|
const { SelectInput } = _SuperSelect;
|
|
88
|
-
const { Space, Flex } = antd;
|
|
88
|
+
const { Space, Flex, Divider, Button, Tag, Switch } = antd;
|
|
89
|
+
const { useState } = React;
|
|
90
|
+
|
|
91
|
+
// 基础示例:展示基本使用和尺寸
|
|
92
|
+
const BasicExample = ({ isPopup }) => {
|
|
93
|
+
return (
|
|
94
|
+
<Flex vertical gap={12}>
|
|
95
|
+
<Flex gap={8} align="center">
|
|
96
|
+
<span>基础使用:</span>
|
|
97
|
+
<SelectInput isPopup={isPopup} placeholder="请选择" style={{ width: 200 }} />
|
|
98
|
+
<SelectInput isPopup={isPopup} placeholder="禁用状态" disabled style={{ width: 200 }} />
|
|
99
|
+
</Flex>
|
|
100
|
+
<Flex gap={8} align="center">
|
|
101
|
+
<span>尺寸:</span>
|
|
102
|
+
<SelectInput isPopup={isPopup} size="small" placeholder="小尺寸" style={{ width: 120 }} />
|
|
103
|
+
<SelectInput isPopup={isPopup} size="default" placeholder="默认尺寸" style={{ width: 140 }} />
|
|
104
|
+
<SelectInput isPopup={isPopup} size="large" placeholder="大尺寸" style={{ width: 160 }} />
|
|
105
|
+
</Flex>
|
|
106
|
+
</Flex>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// 多选示例:展示多选和标签显示
|
|
111
|
+
const MultiSelectExample = ({ isPopup }) => {
|
|
112
|
+
const [value, setValue] = useState([
|
|
113
|
+
{ value: 'react', label: 'React' },
|
|
114
|
+
{ value: 'vue', label: 'Vue' }
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<Flex vertical gap={12}>
|
|
119
|
+
<Flex gap={8} align="center">
|
|
120
|
+
<span>多选模式:</span>
|
|
121
|
+
<SelectInput
|
|
122
|
+
value={value}
|
|
123
|
+
onChange={setValue}
|
|
124
|
+
isPopup={isPopup}
|
|
125
|
+
placeholder="请选择技术栈"
|
|
126
|
+
style={{ width: 300 }}
|
|
127
|
+
/>
|
|
128
|
+
</Flex>
|
|
129
|
+
<Flex gap={8} align="center">
|
|
130
|
+
<span>带数量限制:</span>
|
|
131
|
+
<SelectInput
|
|
132
|
+
defaultValue={[
|
|
133
|
+
{ value: 1, label: '选项一' },
|
|
134
|
+
{ value: 2, label: '选项二' }
|
|
135
|
+
]}
|
|
136
|
+
isPopup={isPopup}
|
|
137
|
+
maxLength={3}
|
|
138
|
+
placeholder="最多选择3项"
|
|
139
|
+
style={{ width: 300 }}
|
|
140
|
+
/>
|
|
141
|
+
</Flex>
|
|
142
|
+
</Flex>
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// 自定义前后缀示例
|
|
147
|
+
const PrefixSuffixExample = ({ isPopup }) => {
|
|
148
|
+
const [value, setValue] = useState([
|
|
149
|
+
{ value: 'tech', label: '技术研发部' }
|
|
150
|
+
]);
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<Flex vertical gap={12}>
|
|
154
|
+
<Flex gap={12} align="center">
|
|
155
|
+
<SelectInput
|
|
156
|
+
value={value}
|
|
157
|
+
onChange={setValue}
|
|
158
|
+
isPopup={isPopup}
|
|
159
|
+
prefix={
|
|
160
|
+
<Tag color="blue" style={{ margin: 0, borderRadius: 4 }}>
|
|
161
|
+
部门
|
|
162
|
+
</Tag>
|
|
163
|
+
}
|
|
164
|
+
placeholder="请选择部门"
|
|
165
|
+
style={{ width: 240 }}
|
|
166
|
+
/>
|
|
167
|
+
<SelectInput
|
|
168
|
+
defaultValue={[{ value: 'project', label: '项目A' }]}
|
|
169
|
+
isPopup={isPopup}
|
|
170
|
+
suffix={
|
|
171
|
+
<Button type="primary" size="small" style={{ fontSize: 12 }}>
|
|
172
|
+
详情
|
|
173
|
+
</Button>
|
|
174
|
+
}
|
|
175
|
+
placeholder="请选择项目"
|
|
176
|
+
style={{ width: 240 }}
|
|
177
|
+
/>
|
|
178
|
+
</Flex>
|
|
179
|
+
<Flex gap={12} align="center">
|
|
180
|
+
<SelectInput
|
|
181
|
+
defaultValue={[{ value: 'user1', label: '张三' }]}
|
|
182
|
+
isPopup={isPopup}
|
|
183
|
+
prefix={
|
|
184
|
+
<span style={{
|
|
185
|
+
color: '#1677ff',
|
|
186
|
+
fontWeight: 500,
|
|
187
|
+
fontSize: 13
|
|
188
|
+
}}>
|
|
189
|
+
负责人:
|
|
190
|
+
</span>
|
|
191
|
+
}
|
|
192
|
+
placeholder="请选择负责人"
|
|
193
|
+
style={{ width: 220 }}
|
|
194
|
+
/>
|
|
195
|
+
<SelectInput
|
|
196
|
+
size="large"
|
|
197
|
+
isPopup={isPopup}
|
|
198
|
+
defaultValue={[{ value: 'pending', label: '待处理' }]}
|
|
199
|
+
suffix={
|
|
200
|
+
<Tag color="orange" style={{ margin: 0 }}>
|
|
201
|
+
3条待办
|
|
202
|
+
</Tag>
|
|
203
|
+
}
|
|
204
|
+
placeholder="请选择状态"
|
|
205
|
+
style={{ width: 260 }}
|
|
206
|
+
/>
|
|
207
|
+
</Flex>
|
|
208
|
+
</Flex>
|
|
209
|
+
);
|
|
210
|
+
};
|
|
89
211
|
|
|
90
212
|
const BaseExample = () => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
213
|
+
const [isPopup, setIsPopup] = useState(true);
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<Flex vertical gap={24}>
|
|
217
|
+
<Flex align="center" gap={12}>
|
|
218
|
+
<span>展示模式:</span>
|
|
219
|
+
<Switch
|
|
220
|
+
checked={isPopup}
|
|
221
|
+
onChange={setIsPopup}
|
|
222
|
+
checkedChildren="下拉"
|
|
223
|
+
unCheckedChildren="弹窗"
|
|
224
|
+
/>
|
|
225
|
+
<span style={{ color: '#666', fontSize: 12 }}>
|
|
226
|
+
{isPopup ? '点击输入框展开下拉菜单' : '点击输入框打开弹窗'}
|
|
227
|
+
</span>
|
|
228
|
+
</Flex>
|
|
229
|
+
<Divider />
|
|
230
|
+
<BasicExample isPopup={isPopup} />
|
|
231
|
+
<Divider />
|
|
232
|
+
<MultiSelectExample isPopup={isPopup} />
|
|
233
|
+
<Divider />
|
|
234
|
+
<PrefixSuffixExample isPopup={isPopup} />
|
|
235
|
+
</Flex>
|
|
236
|
+
);
|
|
105
237
|
};
|
|
106
238
|
|
|
107
239
|
render(<BaseExample />);
|
|
108
240
|
|
|
109
241
|
```
|
|
110
242
|
|
|
111
|
-
-
|
|
112
|
-
-
|
|
243
|
+
- SuperSelect 列表选择
|
|
244
|
+
- 通用列表选择组件,支持单选/多选、搜索、全选、数量限制、弹窗模式等功能
|
|
113
245
|
- _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
|
|
114
246
|
|
|
115
247
|
```jsx
|
|
116
248
|
const { default: SuperSelect } = _SuperSelect;
|
|
117
|
-
const { Space, Button } = antd;
|
|
249
|
+
const { Space, Button, Flex, Divider, Tag, Switch } = antd;
|
|
250
|
+
const { useState } = React;
|
|
251
|
+
|
|
252
|
+
// 模拟部门数据
|
|
253
|
+
const departmentOptions = [
|
|
254
|
+
{ value: 'tech', label: '技术研发部', disabled: false },
|
|
255
|
+
{ value: 'product', label: '产品设计部', disabled: false },
|
|
256
|
+
{ value: 'operation', label: '运营管理部', disabled: false },
|
|
257
|
+
{ value: 'hr', label: '人力资源部', disabled: false },
|
|
258
|
+
{ value: 'finance', label: '财务部', disabled: true },
|
|
259
|
+
{ value: 'marketing', label: '市场营销部', disabled: false }
|
|
260
|
+
];
|
|
118
261
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
262
|
+
// 模拟用户数据
|
|
263
|
+
const userOptions = Array.from({ length: 30 }).map((_, index) => ({
|
|
264
|
+
value: `user_${index + 1}`,
|
|
265
|
+
label: `用户${index + 1}`,
|
|
266
|
+
email: `user${index + 1}@company.com`,
|
|
267
|
+
department: departmentOptions[index % departmentOptions.length].label,
|
|
268
|
+
disabled: index === 5
|
|
269
|
+
}));
|
|
270
|
+
|
|
271
|
+
// 基础列表选择
|
|
272
|
+
const BasicListExample = ({ isPopup }) => {
|
|
273
|
+
const [value, setValue] = useState([]);
|
|
126
274
|
|
|
127
|
-
const BaseExample = () => {
|
|
128
275
|
return (
|
|
129
|
-
<
|
|
130
|
-
<
|
|
276
|
+
<Flex vertical gap={8}>
|
|
277
|
+
<span>多选列表:</span>
|
|
131
278
|
<SuperSelect
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
]}
|
|
279
|
+
options={departmentOptions}
|
|
280
|
+
value={value}
|
|
281
|
+
onChange={setValue}
|
|
282
|
+
isPopup={isPopup}
|
|
283
|
+
placeholder="请选择部门"
|
|
284
|
+
style={{ width: 280 }}
|
|
140
285
|
/>
|
|
286
|
+
{value.length > 0 && (
|
|
287
|
+
<div>已选:{value.map(item => item.label).join('、')}</div>
|
|
288
|
+
)}
|
|
289
|
+
</Flex>
|
|
290
|
+
);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// 单选列表
|
|
294
|
+
const SingleSelectExample = ({ isPopup }) => {
|
|
295
|
+
const [value, setValue] = useState(null);
|
|
296
|
+
|
|
297
|
+
return (
|
|
298
|
+
<Flex vertical gap={8}>
|
|
299
|
+
<span>单选列表:</span>
|
|
141
300
|
<SuperSelect
|
|
142
|
-
|
|
143
|
-
options={
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
301
|
+
single
|
|
302
|
+
options={userOptions.slice(0, 10)}
|
|
303
|
+
value={value}
|
|
304
|
+
onChange={setValue}
|
|
305
|
+
isPopup={isPopup}
|
|
306
|
+
placeholder="请选择负责人"
|
|
307
|
+
style={{ width: 280 }}
|
|
148
308
|
/>
|
|
309
|
+
{value && <div>已选:{value.label}</div>}
|
|
310
|
+
</Flex>
|
|
311
|
+
);
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// 带搜索的选择
|
|
315
|
+
const SearchableExample = ({ isPopup }) => {
|
|
316
|
+
const [value, setValue] = useState([]);
|
|
317
|
+
|
|
318
|
+
return (
|
|
319
|
+
<Flex vertical gap={8}>
|
|
320
|
+
<span>带搜索功能:</span>
|
|
149
321
|
<SuperSelect
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
322
|
+
options={userOptions}
|
|
323
|
+
value={value}
|
|
324
|
+
onChange={setValue}
|
|
325
|
+
isPopup={isPopup}
|
|
326
|
+
placeholder="搜索并选择用户"
|
|
153
327
|
getSearchCallback={({ searchText }, item) => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
loader: ({ data }) => {
|
|
161
|
-
const searchText = data.searchProps && data.searchProps.searchText;
|
|
162
|
-
if (!searchText) {
|
|
163
|
-
return {
|
|
164
|
-
pageData: optionList,
|
|
165
|
-
totalCount: optionList.length
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
const newOptionList = optionList.filter(item => !searchText || item.label.indexOf(searchText) > -1);
|
|
169
|
-
return {
|
|
170
|
-
pageData: newOptionList,
|
|
171
|
-
totalCount: newOptionList.length
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
}}
|
|
175
|
-
isPopup={false}
|
|
176
|
-
getSearchProps={({ searchText }) => {
|
|
177
|
-
return { searchText };
|
|
328
|
+
if (!searchText) return true;
|
|
329
|
+
const keyword = searchText.toLowerCase();
|
|
330
|
+
return (
|
|
331
|
+
item.label.toLowerCase().includes(keyword) ||
|
|
332
|
+
item.email.toLowerCase().includes(keyword)
|
|
333
|
+
);
|
|
178
334
|
}}
|
|
335
|
+
style={{ width: 320 }}
|
|
179
336
|
/>
|
|
337
|
+
</Flex>
|
|
338
|
+
);
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// 全选功能
|
|
342
|
+
const SelectAllExample = ({ isPopup }) => {
|
|
343
|
+
const [value, setValue] = useState([]);
|
|
180
344
|
|
|
345
|
+
return (
|
|
346
|
+
<Flex vertical gap={8}>
|
|
347
|
+
<span>支持全选:</span>
|
|
181
348
|
<SuperSelect
|
|
182
|
-
|
|
183
|
-
options={
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
349
|
+
allowSelectedAll
|
|
350
|
+
options={departmentOptions.filter(item => !item.disabled)}
|
|
351
|
+
value={value}
|
|
352
|
+
onChange={setValue}
|
|
353
|
+
isPopup={isPopup}
|
|
354
|
+
placeholder="请选择部门(支持全选)"
|
|
355
|
+
style={{ width: 280 }}
|
|
187
356
|
/>
|
|
357
|
+
</Flex>
|
|
358
|
+
);
|
|
359
|
+
};
|
|
188
360
|
|
|
361
|
+
// 带数量限制
|
|
362
|
+
const MaxLimitExample = ({ isPopup }) => {
|
|
363
|
+
const [value, setValue] = useState([]);
|
|
364
|
+
|
|
365
|
+
return (
|
|
366
|
+
<Flex vertical gap={8}>
|
|
367
|
+
<span>最多选择3项:</span>
|
|
189
368
|
<SuperSelect
|
|
190
|
-
options={
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}}
|
|
369
|
+
options={userOptions.slice(0, 10)}
|
|
370
|
+
value={value}
|
|
371
|
+
onChange={setValue}
|
|
372
|
+
isPopup={isPopup}
|
|
373
|
+
maxLength={3}
|
|
374
|
+
placeholder="请选择(最多3项)"
|
|
375
|
+
style={{ width: 320 }}
|
|
198
376
|
/>
|
|
377
|
+
<Tag color={value.length >= 3 ? 'red' : 'blue'}>
|
|
378
|
+
已选择 {value.length}/3 项
|
|
379
|
+
</Tag>
|
|
380
|
+
</Flex>
|
|
381
|
+
);
|
|
382
|
+
};
|
|
199
383
|
|
|
384
|
+
// 自定义渲染
|
|
385
|
+
const CustomRenderExample = () => {
|
|
386
|
+
return (
|
|
387
|
+
<Flex vertical gap={8}>
|
|
388
|
+
<span>自定义输入框渲染:</span>
|
|
200
389
|
<SuperSelect
|
|
201
|
-
options={
|
|
202
|
-
|
|
390
|
+
options={departmentOptions}
|
|
391
|
+
inputRender={(props, context) => {
|
|
392
|
+
const { value } = context;
|
|
203
393
|
return (
|
|
204
|
-
<Button type="
|
|
205
|
-
|
|
394
|
+
<Button type="primary" {...props}>
|
|
395
|
+
{value.length > 0 ? `已选择 ${value.length} 项` : '点击选择部门'}
|
|
206
396
|
</Button>
|
|
207
397
|
);
|
|
208
398
|
}}
|
|
209
399
|
/>
|
|
210
|
-
</
|
|
400
|
+
</Flex>
|
|
401
|
+
);
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
const BaseExample = () => {
|
|
405
|
+
const [isPopup, setIsPopup] = useState(true);
|
|
406
|
+
|
|
407
|
+
return (
|
|
408
|
+
<Flex vertical gap={24}>
|
|
409
|
+
<Flex align="center" gap={12}>
|
|
410
|
+
<span>展示模式:</span>
|
|
411
|
+
<Switch
|
|
412
|
+
checked={isPopup}
|
|
413
|
+
onChange={setIsPopup}
|
|
414
|
+
checkedChildren="下拉"
|
|
415
|
+
unCheckedChildren="弹窗"
|
|
416
|
+
/>
|
|
417
|
+
<span style={{ color: '#666', fontSize: 12 }}>
|
|
418
|
+
{isPopup ? '点击输入框展开下拉菜单' : '点击输入框打开弹窗'}
|
|
419
|
+
</span>
|
|
420
|
+
</Flex>
|
|
421
|
+
<Divider />
|
|
422
|
+
<BasicListExample isPopup={isPopup} />
|
|
423
|
+
<Divider />
|
|
424
|
+
<SingleSelectExample isPopup={isPopup} />
|
|
425
|
+
<Divider />
|
|
426
|
+
<SearchableExample isPopup={isPopup} />
|
|
427
|
+
<Divider />
|
|
428
|
+
<SelectAllExample isPopup={isPopup} />
|
|
429
|
+
<Divider />
|
|
430
|
+
<MaxLimitExample isPopup={isPopup} />
|
|
431
|
+
<Divider />
|
|
432
|
+
<CustomRenderExample />
|
|
433
|
+
</Flex>
|
|
211
434
|
);
|
|
212
435
|
};
|
|
213
436
|
|
|
@@ -215,306 +438,710 @@ render(<BaseExample />);
|
|
|
215
438
|
|
|
216
439
|
```
|
|
217
440
|
|
|
218
|
-
-
|
|
219
|
-
-
|
|
441
|
+
- SelectTableList 表格选择
|
|
442
|
+
- 表格形式的选择组件,适合复杂数据的展示和选择,支持自定义列、搜索、单选/多选等
|
|
220
443
|
- _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
|
|
221
444
|
|
|
222
445
|
```jsx
|
|
223
446
|
const { SelectTableList } = _SuperSelect;
|
|
224
|
-
const { Space, Button, Divider } = antd;
|
|
447
|
+
const { Space, Button, Flex, Divider, Tag, Avatar, Switch } = antd;
|
|
448
|
+
const { useState } = React;
|
|
449
|
+
|
|
450
|
+
// 模拟员工数据
|
|
451
|
+
const employeeOptions = Array.from({ length: 25 }).map((_, index) => ({
|
|
452
|
+
id: `emp_${index + 1}`,
|
|
453
|
+
name: `员工${index + 1}`,
|
|
454
|
+
email: `employee${index + 1}@company.com`,
|
|
455
|
+
department: ['技术研发部', '产品设计部', '运营部', '市场部'][index % 4],
|
|
456
|
+
position: ['工程师', '设计师', '经理', '专员'][index % 4],
|
|
457
|
+
status: index === 3 ? 'inactive' : 'active',
|
|
458
|
+
joinDate: `2023-${String((index % 12) + 1).padStart(2, '0')}-15`
|
|
459
|
+
}));
|
|
460
|
+
|
|
461
|
+
// 员工列表列配置
|
|
462
|
+
const employeeColumns = [
|
|
463
|
+
{
|
|
464
|
+
name: 'name',
|
|
465
|
+
title: '姓名',
|
|
466
|
+
span: 6,
|
|
467
|
+
getValueOf: (item) => (
|
|
468
|
+
<Flex align="center" gap={8}>
|
|
469
|
+
<Avatar size="small" style={{ backgroundColor: '#1677ff' }}>
|
|
470
|
+
{item.name.slice(-2)}
|
|
471
|
+
</Avatar>
|
|
472
|
+
<span>{item.name}</span>
|
|
473
|
+
</Flex>
|
|
474
|
+
)
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
name: 'department',
|
|
478
|
+
title: '部门',
|
|
479
|
+
span: 6
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: 'position',
|
|
483
|
+
title: '职位',
|
|
484
|
+
span: 4
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
name: 'email',
|
|
488
|
+
title: '邮箱',
|
|
489
|
+
span: 6,
|
|
490
|
+
getValueOf: (item) => (
|
|
491
|
+
<span style={{ color: '#666', fontSize: 12 }}>{item.email}</span>
|
|
492
|
+
)
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
name: 'options',
|
|
496
|
+
title: '操作',
|
|
497
|
+
span: 2,
|
|
498
|
+
getValueOf: (item, { context }) => {
|
|
499
|
+
return (
|
|
500
|
+
<Button
|
|
501
|
+
type="link"
|
|
502
|
+
size="small"
|
|
503
|
+
danger
|
|
504
|
+
disabled={item.status === 'inactive'}
|
|
505
|
+
onClick={(e) => {
|
|
506
|
+
e.stopPropagation();
|
|
507
|
+
console.log('删除员工:', item.name);
|
|
508
|
+
}}
|
|
509
|
+
>
|
|
510
|
+
移除
|
|
511
|
+
</Button>
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
];
|
|
225
516
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
517
|
+
// 产品数据
|
|
518
|
+
const productOptions = Array.from({ length: 20 }).map((_, index) => ({
|
|
519
|
+
id: `prod_${index + 1}`,
|
|
520
|
+
productName: `产品${index + 1}`,
|
|
521
|
+
category: ['电子产品', '服装', '食品', '家居'][index % 4],
|
|
522
|
+
price: Math.floor(Math.random() * 1000) + 100,
|
|
523
|
+
stock: Math.floor(Math.random() * 500),
|
|
524
|
+
status: index === 5 ? '下架' : '在售'
|
|
525
|
+
}));
|
|
526
|
+
|
|
527
|
+
const productColumns = [
|
|
528
|
+
{
|
|
529
|
+
name: 'productName',
|
|
530
|
+
title: '产品名称',
|
|
531
|
+
span: 6
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
name: 'category',
|
|
535
|
+
title: '分类',
|
|
536
|
+
span: 4,
|
|
537
|
+
getValueOf: (item) => (
|
|
538
|
+
<Tag color="blue">{item.category}</Tag>
|
|
539
|
+
)
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
name: 'price',
|
|
543
|
+
title: '价格',
|
|
544
|
+
span: 4,
|
|
545
|
+
getValueOf: (item) => `¥${item.price}`
|
|
546
|
+
},
|
|
547
|
+
{
|
|
548
|
+
name: 'stock',
|
|
549
|
+
title: '库存',
|
|
550
|
+
span: 4,
|
|
551
|
+
getValueOf: (item) => (
|
|
552
|
+
<span style={{ color: item.stock < 50 ? 'red' : 'green' }}>
|
|
553
|
+
{item.stock}
|
|
554
|
+
</span>
|
|
555
|
+
)
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
name: 'status',
|
|
559
|
+
title: '状态',
|
|
560
|
+
span: 4,
|
|
561
|
+
getValueOf: (item) => (
|
|
562
|
+
<Tag color={item.status === '在售' ? 'success' : 'default'}>
|
|
563
|
+
{item.status}
|
|
564
|
+
</Tag>
|
|
565
|
+
)
|
|
259
566
|
}
|
|
260
|
-
|
|
567
|
+
];
|
|
568
|
+
|
|
569
|
+
// 基础表格选择
|
|
570
|
+
const BasicTableExample = ({ isPopup }) => {
|
|
571
|
+
const [value, setValue] = useState([]);
|
|
572
|
+
|
|
573
|
+
return (
|
|
574
|
+
<Flex vertical gap={8}>
|
|
575
|
+
<span>多选表格:</span>
|
|
576
|
+
<SelectTableList
|
|
577
|
+
options={employeeOptions}
|
|
578
|
+
columns={employeeColumns}
|
|
579
|
+
valueKey="id"
|
|
580
|
+
labelKey="name"
|
|
581
|
+
value={value}
|
|
582
|
+
onChange={setValue}
|
|
583
|
+
isPopup={isPopup}
|
|
584
|
+
placeholder="请选择员工"
|
|
585
|
+
style={{ width: 600 }}
|
|
586
|
+
/>
|
|
587
|
+
{value.length > 0 && (
|
|
588
|
+
<div>已选 {value.length} 人:{value.map(item => item.name).join('、')}</div>
|
|
589
|
+
)}
|
|
590
|
+
</Flex>
|
|
591
|
+
);
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// 单选表格
|
|
595
|
+
const SingleTableExample = ({ isPopup }) => {
|
|
596
|
+
const [value, setValue] = useState(null);
|
|
597
|
+
|
|
598
|
+
return (
|
|
599
|
+
<Flex vertical gap={8}>
|
|
600
|
+
<span>单选表格:</span>
|
|
601
|
+
<SelectTableList
|
|
602
|
+
single
|
|
603
|
+
options={productOptions}
|
|
604
|
+
columns={productColumns}
|
|
605
|
+
valueKey="id"
|
|
606
|
+
labelKey="productName"
|
|
607
|
+
value={value}
|
|
608
|
+
onChange={setValue}
|
|
609
|
+
isPopup={isPopup}
|
|
610
|
+
placeholder="请选择产品"
|
|
611
|
+
style={{ width: 600 }}
|
|
612
|
+
/>
|
|
613
|
+
{value && <div>已选:{value.productName}</div>}
|
|
614
|
+
</Flex>
|
|
615
|
+
);
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
// 带搜索的表格选择
|
|
619
|
+
const SearchableTableExample = ({ isPopup }) => {
|
|
620
|
+
const [value, setValue] = useState([]);
|
|
621
|
+
|
|
622
|
+
return (
|
|
623
|
+
<Flex vertical gap={8}>
|
|
624
|
+
<span>带搜索功能:</span>
|
|
625
|
+
<SelectTableList
|
|
626
|
+
options={employeeOptions}
|
|
627
|
+
columns={employeeColumns}
|
|
628
|
+
valueKey="id"
|
|
629
|
+
labelKey="name"
|
|
630
|
+
value={value}
|
|
631
|
+
onChange={setValue}
|
|
632
|
+
isPopup={isPopup}
|
|
633
|
+
placeholder="搜索姓名、邮箱或部门"
|
|
634
|
+
getSearchCallback={({ searchText }, item) => {
|
|
635
|
+
if (!searchText) return true;
|
|
636
|
+
const keyword = searchText.toLowerCase();
|
|
637
|
+
return (
|
|
638
|
+
item.name.toLowerCase().includes(keyword) ||
|
|
639
|
+
item.email.toLowerCase().includes(keyword) ||
|
|
640
|
+
item.department.toLowerCase().includes(keyword)
|
|
641
|
+
);
|
|
642
|
+
}}
|
|
643
|
+
style={{ width: 600 }}
|
|
644
|
+
/>
|
|
645
|
+
</Flex>
|
|
646
|
+
);
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
// 全选功能
|
|
650
|
+
const SelectAllTableExample = ({ isPopup }) => {
|
|
651
|
+
const [value, setValue] = useState([]);
|
|
652
|
+
|
|
653
|
+
return (
|
|
654
|
+
<Flex vertical gap={8}>
|
|
655
|
+
<span>支持全选:</span>
|
|
656
|
+
<SelectTableList
|
|
657
|
+
allowSelectedAll
|
|
658
|
+
options={productOptions.filter(item => item.status === '在售')}
|
|
659
|
+
columns={productColumns}
|
|
660
|
+
valueKey="id"
|
|
661
|
+
labelKey="productName"
|
|
662
|
+
value={value}
|
|
663
|
+
onChange={setValue}
|
|
664
|
+
isPopup={isPopup}
|
|
665
|
+
placeholder="请选择在售产品"
|
|
666
|
+
style={{ width: 600 }}
|
|
667
|
+
/>
|
|
668
|
+
</Flex>
|
|
669
|
+
);
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
// 自定义底部
|
|
673
|
+
const CustomFooterExample = ({ isPopup }) => {
|
|
674
|
+
const [value, setValue] = useState([]);
|
|
675
|
+
|
|
676
|
+
return (
|
|
677
|
+
<Flex vertical gap={8}>
|
|
678
|
+
<span>自定义底部操作:</span>
|
|
679
|
+
<SelectTableList
|
|
680
|
+
options={employeeOptions}
|
|
681
|
+
columns={employeeColumns}
|
|
682
|
+
valueKey="id"
|
|
683
|
+
labelKey="name"
|
|
684
|
+
value={value}
|
|
685
|
+
onChange={setValue}
|
|
686
|
+
isPopup={isPopup}
|
|
687
|
+
placeholder="请选择员工"
|
|
688
|
+
footer={({ close, reload }) => (
|
|
689
|
+
<Flex justify="space-between" align="center">
|
|
690
|
+
<Button type="link" onClick={reload}>
|
|
691
|
+
刷新数据
|
|
692
|
+
</Button>
|
|
693
|
+
<Button type="primary" onClick={close}>
|
|
694
|
+
确认选择
|
|
695
|
+
</Button>
|
|
696
|
+
</Flex>
|
|
697
|
+
)}
|
|
698
|
+
style={{ width: 600 }}
|
|
699
|
+
/>
|
|
700
|
+
</Flex>
|
|
701
|
+
);
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
// 直接展示在页面上(无触发器)
|
|
705
|
+
const DirectRenderExample = () => {
|
|
706
|
+
const [value, setValue] = useState([]);
|
|
707
|
+
|
|
708
|
+
return (
|
|
709
|
+
<Flex vertical gap={8}>
|
|
710
|
+
<span>直接展示在页面(嵌入模式):</span>
|
|
711
|
+
<SelectTableList
|
|
712
|
+
options={employeeOptions}
|
|
713
|
+
columns={employeeColumns}
|
|
714
|
+
valueKey="id"
|
|
715
|
+
labelKey="name"
|
|
716
|
+
value={value}
|
|
717
|
+
onChange={setValue}
|
|
718
|
+
placeholder="请选择员工"
|
|
719
|
+
getSearchCallback={({ searchText }, item) => {
|
|
720
|
+
if (!searchText) return true;
|
|
721
|
+
const keyword = searchText.toLowerCase();
|
|
722
|
+
return (
|
|
723
|
+
item.name.toLowerCase().includes(keyword) ||
|
|
724
|
+
item.email.toLowerCase().includes(keyword) ||
|
|
725
|
+
item.department.toLowerCase().includes(keyword)
|
|
726
|
+
);
|
|
727
|
+
}}
|
|
728
|
+
style={{ width: '100%' }}
|
|
729
|
+
renderContent={(content) => (
|
|
730
|
+
<div style={{
|
|
731
|
+
border: '1px solid #d9d9d9',
|
|
732
|
+
borderRadius: 6,
|
|
733
|
+
padding: 16,
|
|
734
|
+
backgroundColor: '#fafafa'
|
|
735
|
+
}}>
|
|
736
|
+
{content}
|
|
737
|
+
</div>
|
|
738
|
+
)}
|
|
739
|
+
/>
|
|
740
|
+
{value.length > 0 && (
|
|
741
|
+
<div style={{ padding: '8px 12px', backgroundColor: '#e6f4ff', borderRadius: 4 }}>
|
|
742
|
+
已选择 {value.length} 人:{value.map(item => item.name).join('、')}
|
|
743
|
+
</div>
|
|
744
|
+
)}
|
|
745
|
+
</Flex>
|
|
746
|
+
);
|
|
747
|
+
};
|
|
261
748
|
|
|
262
749
|
const BaseExample = () => {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
<SelectTableList single options={[]} columns={columns} isPopup={false} valueKey="id"
|
|
280
|
-
footer={<Button type="link">预览</Button>} />
|
|
281
|
-
<div>
|
|
750
|
+
const [isPopup, setIsPopup] = useState(true);
|
|
751
|
+
|
|
752
|
+
return (
|
|
753
|
+
<Flex vertical gap={24}>
|
|
754
|
+
<Flex align="center" gap={12}>
|
|
755
|
+
<span>展示模式:</span>
|
|
756
|
+
<Switch
|
|
757
|
+
checked={isPopup}
|
|
758
|
+
onChange={setIsPopup}
|
|
759
|
+
checkedChildren="下拉"
|
|
760
|
+
unCheckedChildren="弹窗"
|
|
761
|
+
/>
|
|
762
|
+
<span style={{ color: '#666', fontSize: 12 }}>
|
|
763
|
+
{isPopup ? '点击输入框展开下拉菜单' : '点击输入框打开弹窗'}
|
|
764
|
+
</span>
|
|
765
|
+
</Flex>
|
|
282
766
|
<Divider />
|
|
283
|
-
<
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
767
|
+
<BasicTableExample isPopup={isPopup} />
|
|
768
|
+
<Divider />
|
|
769
|
+
<SingleTableExample isPopup={isPopup} />
|
|
770
|
+
<Divider />
|
|
771
|
+
<SearchableTableExample isPopup={isPopup} />
|
|
772
|
+
<Divider />
|
|
773
|
+
<SelectAllTableExample isPopup={isPopup} />
|
|
774
|
+
<Divider />
|
|
775
|
+
<CustomFooterExample isPopup={isPopup} />
|
|
776
|
+
<Divider />
|
|
777
|
+
<DirectRenderExample />
|
|
778
|
+
</Flex>
|
|
779
|
+
);
|
|
291
780
|
};
|
|
292
781
|
|
|
293
782
|
render(<BaseExample />);
|
|
294
783
|
|
|
295
784
|
```
|
|
296
785
|
|
|
297
|
-
-
|
|
298
|
-
-
|
|
786
|
+
- SelectTree 树形选择
|
|
787
|
+
- 树形结构的选择组件,适用于组织架构、地区、分类等层级数据的选择
|
|
299
788
|
- _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
|
|
300
789
|
|
|
301
790
|
```jsx
|
|
302
791
|
const { SelectTree } = _SuperSelect;
|
|
303
|
-
const { Space, Button } = antd;
|
|
792
|
+
const { Space, Button, Flex, Divider, Tag, Switch } = antd;
|
|
793
|
+
const { useState } = React;
|
|
304
794
|
|
|
305
|
-
|
|
795
|
+
// 组织架构数据
|
|
796
|
+
const organizationTree = [
|
|
797
|
+
{
|
|
798
|
+
id: 'root',
|
|
799
|
+
parentId: null,
|
|
800
|
+
name: '集团总部',
|
|
801
|
+
code: 'HQ',
|
|
802
|
+
employeeCount: 500
|
|
803
|
+
},
|
|
804
|
+
{
|
|
805
|
+
id: 'tech',
|
|
806
|
+
parentId: 'root',
|
|
807
|
+
name: '技术中心',
|
|
808
|
+
code: 'TECH',
|
|
809
|
+
employeeCount: 200
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
id: 'tech-fe',
|
|
813
|
+
parentId: 'tech',
|
|
814
|
+
name: '前端开发组',
|
|
815
|
+
code: 'FE',
|
|
816
|
+
employeeCount: 50
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
id: 'tech-be',
|
|
820
|
+
parentId: 'tech',
|
|
821
|
+
name: '后端开发组',
|
|
822
|
+
code: 'BE',
|
|
823
|
+
employeeCount: 80
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
id: 'tech-qa',
|
|
827
|
+
parentId: 'tech',
|
|
828
|
+
name: '质量保障组',
|
|
829
|
+
code: 'QA',
|
|
830
|
+
employeeCount: 30
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
id: 'tech-devops',
|
|
834
|
+
parentId: 'tech',
|
|
835
|
+
name: '运维组',
|
|
836
|
+
code: 'DEVOPS',
|
|
837
|
+
employeeCount: 20
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
id: 'product',
|
|
841
|
+
parentId: 'root',
|
|
842
|
+
name: '产品中心',
|
|
843
|
+
code: 'PRODUCT',
|
|
844
|
+
employeeCount: 100
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
id: 'product-design',
|
|
848
|
+
parentId: 'product',
|
|
849
|
+
name: '产品设计组',
|
|
850
|
+
code: 'DESIGN',
|
|
851
|
+
employeeCount: 40
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
id: 'product-pm',
|
|
855
|
+
parentId: 'product',
|
|
856
|
+
name: '项目管理组',
|
|
857
|
+
code: 'PM',
|
|
858
|
+
employeeCount: 30
|
|
859
|
+
},
|
|
860
|
+
{
|
|
861
|
+
id: 'operation',
|
|
862
|
+
parentId: 'root',
|
|
863
|
+
name: '运营中心',
|
|
864
|
+
code: 'OP',
|
|
865
|
+
employeeCount: 80
|
|
866
|
+
},
|
|
306
867
|
{
|
|
307
|
-
id: '
|
|
308
|
-
parentId: '
|
|
309
|
-
name: '
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
createdAt: '2025-08-21T07:35:20.346Z',
|
|
313
|
-
updatedAt: '2025-08-21T07:35:20.346Z',
|
|
314
|
-
deletedAt: null,
|
|
315
|
-
tenantId: '216429049541559296'
|
|
868
|
+
id: 'operation-marketing',
|
|
869
|
+
parentId: 'operation',
|
|
870
|
+
name: '市场营销组',
|
|
871
|
+
code: 'MARKETING',
|
|
872
|
+
employeeCount: 50
|
|
316
873
|
},
|
|
317
874
|
{
|
|
318
|
-
id: '
|
|
319
|
-
parentId: '
|
|
320
|
-
name: '
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
createdAt: '2025-08-21T07:55:25.508Z',
|
|
324
|
-
updatedAt: '2025-08-21T07:55:25.508Z',
|
|
325
|
-
deletedAt: null,
|
|
326
|
-
tenantId: '216429049541559296'
|
|
875
|
+
id: 'operation-cs',
|
|
876
|
+
parentId: 'operation',
|
|
877
|
+
name: '客户服务组',
|
|
878
|
+
code: 'CS',
|
|
879
|
+
employeeCount: 30
|
|
327
880
|
},
|
|
328
881
|
{
|
|
329
|
-
id: '
|
|
882
|
+
id: 'hr',
|
|
883
|
+
parentId: 'root',
|
|
884
|
+
name: '人力资源部',
|
|
885
|
+
code: 'HR',
|
|
886
|
+
employeeCount: 40
|
|
887
|
+
},
|
|
888
|
+
{
|
|
889
|
+
id: 'finance',
|
|
890
|
+
parentId: 'root',
|
|
891
|
+
name: '财务部',
|
|
892
|
+
code: 'FINANCE',
|
|
893
|
+
employeeCount: 30
|
|
894
|
+
}
|
|
895
|
+
];
|
|
896
|
+
|
|
897
|
+
// 地区数据
|
|
898
|
+
const regionTree = [
|
|
899
|
+
{
|
|
900
|
+
id: 'china',
|
|
330
901
|
parentId: null,
|
|
331
|
-
name: '
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
902
|
+
name: '中国',
|
|
903
|
+
code: 'CN'
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
id: 'beijing',
|
|
907
|
+
parentId: 'china',
|
|
908
|
+
name: '北京市',
|
|
909
|
+
code: 'BJ'
|
|
910
|
+
},
|
|
911
|
+
{
|
|
912
|
+
id: 'shanghai',
|
|
913
|
+
parentId: 'china',
|
|
914
|
+
name: '上海市',
|
|
915
|
+
code: 'SH'
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
id: 'guangdong',
|
|
919
|
+
parentId: 'china',
|
|
920
|
+
name: '广东省',
|
|
921
|
+
code: 'GD'
|
|
922
|
+
},
|
|
923
|
+
{
|
|
924
|
+
id: 'guangzhou',
|
|
925
|
+
parentId: 'guangdong',
|
|
926
|
+
name: '广州市',
|
|
927
|
+
code: 'GZ'
|
|
928
|
+
},
|
|
929
|
+
{
|
|
930
|
+
id: 'shenzhen',
|
|
931
|
+
parentId: 'guangdong',
|
|
932
|
+
name: '深圳市',
|
|
933
|
+
code: 'SZ'
|
|
934
|
+
},
|
|
935
|
+
{
|
|
936
|
+
id: 'zhejiang',
|
|
937
|
+
parentId: 'china',
|
|
938
|
+
name: '浙江省',
|
|
939
|
+
code: 'ZJ'
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
id: 'hangzhou',
|
|
943
|
+
parentId: 'zhejiang',
|
|
944
|
+
name: '杭州市',
|
|
945
|
+
code: 'HZ'
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
id: 'jiangsu',
|
|
949
|
+
parentId: 'china',
|
|
950
|
+
name: '江苏省',
|
|
951
|
+
code: 'JS'
|
|
952
|
+
},
|
|
953
|
+
{
|
|
954
|
+
id: 'nanjing',
|
|
955
|
+
parentId: 'jiangsu',
|
|
956
|
+
name: '南京市',
|
|
957
|
+
code: 'NJ'
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
id: 'usa',
|
|
374
961
|
parentId: null,
|
|
375
|
-
name: '
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
{
|
|
395
|
-
id: '
|
|
396
|
-
parentId: '216843395140682752',
|
|
397
|
-
name: '水电费水电费',
|
|
398
|
-
description: '水电费水电费水电费水电费水电费',
|
|
399
|
-
index: 0,
|
|
400
|
-
createdAt: '2025-08-21T09:01:58.488Z',
|
|
401
|
-
updatedAt: '2025-08-21T09:01:58.488Z',
|
|
402
|
-
deletedAt: null,
|
|
403
|
-
tenantId: '216429049541559296'
|
|
404
|
-
},
|
|
405
|
-
{
|
|
406
|
-
id: '216844365669073920',
|
|
407
|
-
parentId: '216844313588401152',
|
|
408
|
-
name: '水电费水电费',
|
|
409
|
-
description: '水电费水电费水电费水电费发大水',
|
|
410
|
-
index: 0,
|
|
411
|
-
createdAt: '2025-08-21T09:02:05.548Z',
|
|
412
|
-
updatedAt: '2025-08-21T09:02:05.548Z',
|
|
413
|
-
deletedAt: null,
|
|
414
|
-
tenantId: '216429049541559296'
|
|
415
|
-
},
|
|
416
|
-
{
|
|
417
|
-
id: '216844381611623424',
|
|
418
|
-
parentId: '216844336053093376',
|
|
419
|
-
name: '的身份水电费是的',
|
|
420
|
-
description: null,
|
|
421
|
-
index: 0,
|
|
422
|
-
createdAt: '2025-08-21T09:02:09.349Z',
|
|
423
|
-
updatedAt: '2025-08-21T09:02:09.349Z',
|
|
424
|
-
deletedAt: null,
|
|
425
|
-
tenantId: '216429049541559296'
|
|
426
|
-
},
|
|
427
|
-
{
|
|
428
|
-
id: '216844403434587136',
|
|
429
|
-
parentId: '216843395140682752',
|
|
430
|
-
name: '水电费水电费水电费是的',
|
|
431
|
-
description: null,
|
|
432
|
-
index: 0,
|
|
433
|
-
createdAt: '2025-08-21T09:02:14.553Z',
|
|
434
|
-
updatedAt: '2025-08-21T09:02:14.553Z',
|
|
435
|
-
deletedAt: null,
|
|
436
|
-
tenantId: '216429049541559296'
|
|
437
|
-
},
|
|
438
|
-
{
|
|
439
|
-
id: '216822162877580288',
|
|
440
|
-
parentId: '216820469385397248',
|
|
441
|
-
name: '水电费是的',
|
|
442
|
-
description: '水电费水电费的身份水电费11111',
|
|
443
|
-
index: 0,
|
|
444
|
-
createdAt: '2025-08-21T07:33:51.990Z',
|
|
445
|
-
updatedAt: '2025-08-21T09:09:38.933Z',
|
|
446
|
-
deletedAt: null,
|
|
447
|
-
tenantId: '216429049541559296'
|
|
448
|
-
},
|
|
449
|
-
{
|
|
450
|
-
id: '216847218563351552',
|
|
962
|
+
name: '美国',
|
|
963
|
+
code: 'US'
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
id: 'newyork',
|
|
967
|
+
parentId: 'usa',
|
|
968
|
+
name: '纽约州',
|
|
969
|
+
code: 'NY'
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
id: 'california',
|
|
973
|
+
parentId: 'usa',
|
|
974
|
+
name: '加利福尼亚州',
|
|
975
|
+
code: 'CA'
|
|
976
|
+
}
|
|
977
|
+
];
|
|
978
|
+
|
|
979
|
+
// 分类数据
|
|
980
|
+
const categoryTree = [
|
|
981
|
+
{
|
|
982
|
+
id: 'electronics',
|
|
451
983
|
parentId: null,
|
|
452
|
-
name: '
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
index: 0,
|
|
477
|
-
createdAt: '2025-08-21T09:41:08.936Z',
|
|
478
|
-
updatedAt: '2025-08-21T09:41:08.936Z',
|
|
479
|
-
deletedAt: null,
|
|
480
|
-
tenantId: '216429049541559296'
|
|
481
|
-
},
|
|
482
|
-
{
|
|
483
|
-
id: '216856947163399168',
|
|
984
|
+
name: '电子产品'
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
id: 'phone',
|
|
988
|
+
parentId: 'electronics',
|
|
989
|
+
name: '手机'
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
id: 'computer',
|
|
993
|
+
parentId: 'electronics',
|
|
994
|
+
name: '电脑'
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
id: 'laptop',
|
|
998
|
+
parentId: 'computer',
|
|
999
|
+
name: '笔记本'
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
id: 'desktop',
|
|
1003
|
+
parentId: 'computer',
|
|
1004
|
+
name: '台式机'
|
|
1005
|
+
},
|
|
1006
|
+
{
|
|
1007
|
+
id: 'clothing',
|
|
484
1008
|
parentId: null,
|
|
485
|
-
name: '
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
1009
|
+
name: '服装'
|
|
1010
|
+
},
|
|
1011
|
+
{
|
|
1012
|
+
id: 'mens',
|
|
1013
|
+
parentId: 'clothing',
|
|
1014
|
+
name: '男装'
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
id: 'womens',
|
|
1018
|
+
parentId: 'clothing',
|
|
1019
|
+
name: '女装'
|
|
492
1020
|
}
|
|
493
1021
|
];
|
|
494
1022
|
|
|
495
|
-
|
|
1023
|
+
// 基础树选择
|
|
1024
|
+
const BasicTreeExample = ({ isPopup }) => {
|
|
1025
|
+
const [value, setValue] = useState([]);
|
|
1026
|
+
|
|
496
1027
|
return (
|
|
497
|
-
<
|
|
498
|
-
<
|
|
1028
|
+
<Flex vertical gap={8}>
|
|
1029
|
+
<span>组织架构多选:</span>
|
|
1030
|
+
<SelectTree
|
|
1031
|
+
options={organizationTree}
|
|
1032
|
+
valueKey="id"
|
|
1033
|
+
labelKey="name"
|
|
1034
|
+
value={value}
|
|
1035
|
+
onChange={setValue}
|
|
1036
|
+
isPopup={isPopup}
|
|
1037
|
+
placeholder="请选择部门"
|
|
1038
|
+
style={{ width: 320 }}
|
|
1039
|
+
/>
|
|
1040
|
+
{value.length > 0 && (
|
|
1041
|
+
<Flex wrap gap={4}>
|
|
1042
|
+
{value.map(item => (
|
|
1043
|
+
<Tag key={item.id} color="blue">{item.name}</Tag>
|
|
1044
|
+
))}
|
|
1045
|
+
</Flex>
|
|
1046
|
+
)}
|
|
1047
|
+
</Flex>
|
|
1048
|
+
);
|
|
1049
|
+
};
|
|
499
1050
|
|
|
500
|
-
|
|
1051
|
+
// 单选树
|
|
1052
|
+
const SingleTreeExample = ({ isPopup }) => {
|
|
1053
|
+
const [value, setValue] = useState(null);
|
|
501
1054
|
|
|
1055
|
+
return (
|
|
1056
|
+
<Flex vertical gap={8}>
|
|
1057
|
+
<span>地区单选:</span>
|
|
502
1058
|
<SelectTree
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
1059
|
+
single
|
|
1060
|
+
options={regionTree}
|
|
1061
|
+
valueKey="id"
|
|
1062
|
+
labelKey="name"
|
|
1063
|
+
value={value}
|
|
1064
|
+
onChange={setValue}
|
|
1065
|
+
isPopup={isPopup}
|
|
1066
|
+
placeholder="请选择地区"
|
|
1067
|
+
style={{ width: 320 }}
|
|
1068
|
+
/>
|
|
1069
|
+
{value && <Tag color="green">已选:{value.name} ({value.code})</Tag>}
|
|
1070
|
+
</Flex>
|
|
1071
|
+
);
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
// 带搜索的树选择
|
|
1075
|
+
const SearchableTreeExample = ({ isPopup }) => {
|
|
1076
|
+
const [value, setValue] = useState([]);
|
|
1077
|
+
|
|
1078
|
+
return (
|
|
1079
|
+
<Flex vertical gap={8}>
|
|
1080
|
+
<span>带搜索功能:</span>
|
|
1081
|
+
<SelectTree
|
|
1082
|
+
options={organizationTree}
|
|
1083
|
+
valueKey="id"
|
|
1084
|
+
labelKey="name"
|
|
1085
|
+
value={value}
|
|
1086
|
+
onChange={setValue}
|
|
1087
|
+
isPopup={isPopup}
|
|
1088
|
+
placeholder="搜索部门名称或编码"
|
|
1089
|
+
style={{ width: 320 }}
|
|
516
1090
|
/>
|
|
517
|
-
</
|
|
1091
|
+
</Flex>
|
|
1092
|
+
);
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
// 分类选择
|
|
1096
|
+
const CategoryTreeExample = ({ isPopup }) => {
|
|
1097
|
+
const [value, setValue] = useState([]);
|
|
1098
|
+
|
|
1099
|
+
return (
|
|
1100
|
+
<Flex vertical gap={8}>
|
|
1101
|
+
<span>商品分类选择:</span>
|
|
1102
|
+
<SelectTree
|
|
1103
|
+
options={categoryTree}
|
|
1104
|
+
valueKey="id"
|
|
1105
|
+
labelKey="name"
|
|
1106
|
+
value={value}
|
|
1107
|
+
onChange={setValue}
|
|
1108
|
+
isPopup={isPopup}
|
|
1109
|
+
placeholder="请选择分类"
|
|
1110
|
+
style={{ width: 320 }}
|
|
1111
|
+
/>
|
|
1112
|
+
{value.length > 0 && (
|
|
1113
|
+
<div>已选分类:{value.map(item => item.name).join(' > ')}</div>
|
|
1114
|
+
)}
|
|
1115
|
+
</Flex>
|
|
1116
|
+
);
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
const BaseExample = () => {
|
|
1120
|
+
const [isPopup, setIsPopup] = useState(true);
|
|
1121
|
+
|
|
1122
|
+
return (
|
|
1123
|
+
<Flex vertical gap={24}>
|
|
1124
|
+
<Flex align="center" gap={12}>
|
|
1125
|
+
<span>展示模式:</span>
|
|
1126
|
+
<Switch
|
|
1127
|
+
checked={isPopup}
|
|
1128
|
+
onChange={setIsPopup}
|
|
1129
|
+
checkedChildren="下拉"
|
|
1130
|
+
unCheckedChildren="弹窗"
|
|
1131
|
+
/>
|
|
1132
|
+
<span style={{ color: '#666', fontSize: 12 }}>
|
|
1133
|
+
{isPopup ? '点击输入框展开下拉菜单' : '点击输入框打开弹窗'}
|
|
1134
|
+
</span>
|
|
1135
|
+
</Flex>
|
|
1136
|
+
<Divider />
|
|
1137
|
+
<BasicTreeExample isPopup={isPopup} />
|
|
1138
|
+
<Divider />
|
|
1139
|
+
<SingleTreeExample isPopup={isPopup} />
|
|
1140
|
+
<Divider />
|
|
1141
|
+
<SearchableTreeExample isPopup={isPopup} />
|
|
1142
|
+
<Divider />
|
|
1143
|
+
<CategoryTreeExample isPopup={isPopup} />
|
|
1144
|
+
</Flex>
|
|
518
1145
|
);
|
|
519
1146
|
};
|
|
520
1147
|
|
|
@@ -522,29 +1149,179 @@ render(<BaseExample />);
|
|
|
522
1149
|
|
|
523
1150
|
```
|
|
524
1151
|
|
|
525
|
-
-
|
|
526
|
-
-
|
|
1152
|
+
- Ref 使用方法
|
|
1153
|
+
- 展示如何通过 ref 控制选择器的打开/关闭、获取/设置值、程序化选择等操作
|
|
527
1154
|
- _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
|
|
528
1155
|
|
|
529
1156
|
```jsx
|
|
530
1157
|
const { default: SuperSelect } = _SuperSelect;
|
|
531
|
-
const { Space, Button } = antd;
|
|
532
|
-
const { useRef } = React;
|
|
1158
|
+
const { Space, Button, Flex, Divider, message } = antd;
|
|
1159
|
+
const { useRef, useState } = React;
|
|
1160
|
+
|
|
1161
|
+
// 基础 ref 操作示例
|
|
1162
|
+
const BasicRefExample = () => {
|
|
1163
|
+
const selectRef = useRef();
|
|
1164
|
+
const [value, setValue] = useState([]);
|
|
1165
|
+
|
|
1166
|
+
const departmentOptions = [
|
|
1167
|
+
{ value: 'tech', label: '技术研发部' },
|
|
1168
|
+
{ value: 'product', label: '产品设计部' },
|
|
1169
|
+
{ value: 'operation', label: '运营管理部' },
|
|
1170
|
+
{ value: 'hr', label: '人力资源部' }
|
|
1171
|
+
];
|
|
1172
|
+
|
|
1173
|
+
return (
|
|
1174
|
+
<Flex vertical gap={12}>
|
|
1175
|
+
<span>通过 ref 控制选择器:</span>
|
|
1176
|
+
<Flex gap={8}>
|
|
1177
|
+
<SuperSelect
|
|
1178
|
+
ref={selectRef}
|
|
1179
|
+
options={departmentOptions}
|
|
1180
|
+
value={value}
|
|
1181
|
+
onChange={setValue}
|
|
1182
|
+
placeholder="请选择部门"
|
|
1183
|
+
style={{ width: 240 }}
|
|
1184
|
+
/>
|
|
1185
|
+
<Button type="primary" onClick={() => selectRef.current?.onOpenChange(true)}>
|
|
1186
|
+
打开
|
|
1187
|
+
</Button>
|
|
1188
|
+
<Button onClick={() => selectRef.current?.onOpenChange(false)}>
|
|
1189
|
+
关闭
|
|
1190
|
+
</Button>
|
|
1191
|
+
</Flex>
|
|
1192
|
+
</Flex>
|
|
1193
|
+
);
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
// 完整 ref 属性展示
|
|
1197
|
+
const FullRefExample = () => {
|
|
1198
|
+
const selectRef = useRef();
|
|
1199
|
+
const [value, setValue] = useState([]);
|
|
1200
|
+
const [log, setLog] = useState([]);
|
|
1201
|
+
|
|
1202
|
+
const addLog = (msg) => {
|
|
1203
|
+
setLog(prev => [...prev, `[${new Date().toLocaleTimeString()}] ${msg}`]);
|
|
1204
|
+
};
|
|
1205
|
+
|
|
1206
|
+
const userOptions = Array.from({ length: 15 }).map((_, i) => ({
|
|
1207
|
+
value: `user_${i + 1}`,
|
|
1208
|
+
label: `用户${i + 1}`
|
|
1209
|
+
}));
|
|
533
1210
|
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
1211
|
+
const handleGetValue = () => {
|
|
1212
|
+
const currentValue = selectRef.current?.value || [];
|
|
1213
|
+
addLog(`当前值: ${JSON.stringify(currentValue.map(v => v.label))}`);
|
|
1214
|
+
message.info(`已选 ${currentValue.length} 项`);
|
|
537
1215
|
};
|
|
538
|
-
|
|
1216
|
+
|
|
1217
|
+
const handleClear = () => {
|
|
1218
|
+
selectRef.current?.setValue([]);
|
|
1219
|
+
addLog('已清空选择');
|
|
1220
|
+
};
|
|
1221
|
+
|
|
1222
|
+
const handleSelectFirst = () => {
|
|
1223
|
+
const firstOption = userOptions[0];
|
|
1224
|
+
if (firstOption) {
|
|
1225
|
+
selectRef.current?.onSelect(firstOption);
|
|
1226
|
+
addLog(`已选择: ${firstOption.label}`);
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
return (
|
|
1231
|
+
<Flex vertical gap={12}>
|
|
1232
|
+
<span>ref 完整功能展示:</span>
|
|
1233
|
+
<Flex gap={8} wrap>
|
|
1234
|
+
<SuperSelect
|
|
1235
|
+
ref={selectRef}
|
|
1236
|
+
options={userOptions}
|
|
1237
|
+
value={value}
|
|
1238
|
+
onChange={setValue}
|
|
1239
|
+
placeholder="请选择用户"
|
|
1240
|
+
style={{ width: 240 }}
|
|
1241
|
+
/>
|
|
1242
|
+
</Flex>
|
|
1243
|
+
<Flex gap={8} wrap>
|
|
1244
|
+
<Button type="primary" onClick={() => selectRef.current?.onOpenChange(true)}>
|
|
1245
|
+
打开下拉
|
|
1246
|
+
</Button>
|
|
1247
|
+
<Button onClick={() => selectRef.current?.onOpenChange(false)}>
|
|
1248
|
+
关闭下拉
|
|
1249
|
+
</Button>
|
|
1250
|
+
<Button onClick={handleGetValue}>
|
|
1251
|
+
获取当前值
|
|
1252
|
+
</Button>
|
|
1253
|
+
<Button onClick={handleClear}>
|
|
1254
|
+
清空选择
|
|
1255
|
+
</Button>
|
|
1256
|
+
<Button onClick={handleSelectFirst}>
|
|
1257
|
+
选择第一项
|
|
1258
|
+
</Button>
|
|
1259
|
+
</Flex>
|
|
1260
|
+
<div style={{
|
|
1261
|
+
background: '#f5f5f5',
|
|
1262
|
+
padding: 12,
|
|
1263
|
+
borderRadius: 4,
|
|
1264
|
+
maxHeight: 120,
|
|
1265
|
+
overflow: 'auto',
|
|
1266
|
+
fontSize: 12
|
|
1267
|
+
}}>
|
|
1268
|
+
<div style={{ marginBottom: 4, fontWeight: 'bold' }}>操作日志:</div>
|
|
1269
|
+
{log.length === 0 ? (
|
|
1270
|
+
<div style={{ color: '#999' }}>暂无操作</div>
|
|
1271
|
+
) : (
|
|
1272
|
+
log.map((item, index) => <div key={index}>{item}</div>)
|
|
1273
|
+
)}
|
|
1274
|
+
</div>
|
|
1275
|
+
</Flex>
|
|
1276
|
+
);
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1279
|
+
// ref 常见场景
|
|
1280
|
+
const CommonScenariosExample = () => {
|
|
1281
|
+
const selectRef = useRef();
|
|
1282
|
+
|
|
1283
|
+
const options = [
|
|
1284
|
+
{ value: 1, label: '选项一' },
|
|
1285
|
+
{ value: 2, label: '选项二' },
|
|
1286
|
+
{ value: 3, label: '选项三' }
|
|
1287
|
+
];
|
|
1288
|
+
|
|
1289
|
+
return (
|
|
1290
|
+
<Flex vertical gap={12}>
|
|
1291
|
+
<span>常见使用场景:</span>
|
|
1292
|
+
<Flex gap={8} align="center">
|
|
1293
|
+
<SuperSelect
|
|
1294
|
+
ref={selectRef}
|
|
1295
|
+
options={options}
|
|
1296
|
+
placeholder="请选择"
|
|
1297
|
+
style={{ width: 200 }}
|
|
1298
|
+
/>
|
|
1299
|
+
<Button
|
|
1300
|
+
type="primary"
|
|
1301
|
+
onClick={() => {
|
|
1302
|
+
selectRef.current?.onOpenChange(true);
|
|
1303
|
+
}}
|
|
1304
|
+
>
|
|
1305
|
+
外部触发打开
|
|
1306
|
+
</Button>
|
|
1307
|
+
</Flex>
|
|
1308
|
+
<div style={{ color: '#666', fontSize: 12 }}>
|
|
1309
|
+
提示:ref 可用于表单联动、外部控制弹窗、程序化操作等场景
|
|
1310
|
+
</div>
|
|
1311
|
+
</Flex>
|
|
1312
|
+
);
|
|
1313
|
+
};
|
|
539
1314
|
|
|
540
1315
|
const BaseExample = () => {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
1316
|
+
return (
|
|
1317
|
+
<Flex vertical gap={24}>
|
|
1318
|
+
<BasicRefExample />
|
|
1319
|
+
<Divider />
|
|
1320
|
+
<FullRefExample />
|
|
1321
|
+
<Divider />
|
|
1322
|
+
<CommonScenariosExample />
|
|
1323
|
+
</Flex>
|
|
1324
|
+
);
|
|
548
1325
|
};
|
|
549
1326
|
|
|
550
1327
|
render(<BaseExample />);
|
|
@@ -568,6 +1345,7 @@ render(<BaseExample />);
|
|
|
568
1345
|
| max | 最多可选数量 | number | - |
|
|
569
1346
|
| disabled | 是否禁用 | boolean | false |
|
|
570
1347
|
| readOnly | 是否只读 | boolean | false |
|
|
1348
|
+
| size | 选择框尺寸 | 'small' \| 'default' \| 'large' | 'default' |
|
|
571
1349
|
| className | 自定义类名 | string | - |
|
|
572
1350
|
| style | 自定义样式 | object | - |
|
|
573
1351
|
| children | 自定义渲染内容 | function(props) | - |
|