@kne/super-select 0.1.32 → 0.1.34

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 CHANGED
@@ -1,11 +1,8 @@
1
-
2
1
  # super-select
3
2
 
4
-
5
3
  ### 描述
6
4
 
7
- 用于复杂信息选择.
8
-
5
+ React 复杂信息选择组件库,提供列表、表格、树形等多种选择模式,支持单选/多选、搜索、全选等功能
9
6
 
10
7
  ### 安装
11
8
 
@@ -13,201 +10,552 @@
13
10
  npm i --save @kne/super-select
14
11
  ```
15
12
 
16
-
17
13
  ### 概述
18
14
 
19
- @kne/super-select 是一个功能强大的 React 组件库,专门用于处理复杂的信息选择场景。它提供了一系列灵活且可组合的组件,使得在 React 应用中实现复杂的选择功能变得简单直观。
15
+ 一个功能强大的 React 组件库,专门用于处理复杂的信息选择场景。提供了一系列灵活且可组合的组件,使得在 React
16
+ 应用中实现复杂的选择功能变得简单直观。
20
17
 
21
- ### 主要功能
18
+ #### 主要功能
22
19
 
23
20
  - 支持多种选择模式(单选、多选)
21
+ - 支持下拉框和弹窗两种展示模式
24
22
  - 提供灵活的列表和表格展示方式
25
23
  - 内置标签式选中项展示
26
24
  - 支持全选/反选功能
27
25
  - 内置国际化支持(中文和英文)
28
- - 自定义样式支持(基于CSS Modules)
26
+ - 自定义样式支持(基于 CSS Modules)
27
+ - 标签溢出处理:单选文本省略、多选标签自动折叠显示 +N
28
+
29
+ #### 组件列表
30
+
31
+ | 组件名称 | 功能描述 |
32
+ |-----------------|-----------------------------|
33
+ | SelectInput | 基础选择输入组件,用于自定义构建其他选择组件的核心基础 |
34
+ | SelectList | 列表选择组件,适用于常规列表选择场景 |
35
+ | SelectTableList | 表格形式选择组件,支持多列数据展示 |
36
+ | SelectedAll | 全选功能组件,提供一键选择/取消选择 |
37
+ | SelectTree | 树形选择组件,适用于层级数据 |
38
+ | SelectedTagList | 已选项标签列表组件 |
39
+ | SelectCascader | 级联选择组件,支持父子关联、搜索过滤 |
40
+
41
+ #### 快速选择指南
42
+
43
+ | 需求 | 推荐组件 |
44
+ |----------|-----------------------------|
45
+ | 自定义选择组件 | SelectInput |
46
+ | 简单列表选择 | SelectList |
47
+ | 需要展示多列数据 | SelectTableList |
48
+ | 层级数据选择 | SelectTree 或 SelectCascader |
49
+ | 全选/反选功能 | SelectedAll |
50
+ | 已选项标签展示 | SelectedTagList |
51
+
52
+ #### 快速开始
29
53
 
30
- ### 组件概述
54
+ ```jsx
55
+ import { SelectInput, SelectList, SelectCascader } from '@kne/super-select';
31
56
 
32
- #### SelectInput
33
- 基础选择输入组件,提供核心的选择功能和状态管理。可以独立使用,也可以作为其他选择组件的基础。
57
+ // 自定义选择组件
58
+ <SelectInput placeholder="请选择" onChange={handleChange}>
59
+ {(props) => <CustomDropdown {...props} />}
60
+ </SelectInput>
34
61
 
35
- #### SelectList
36
- 基于 SelectInput 的列表选择组件,适用于常规的列表选择场景。提供了简洁的列表界面和直观的选择交互。
62
+ // 级联选择
63
+ <SelectCascader options={cascadeData} onChange={handleChange} />
64
+ ```
37
65
 
38
- #### SelectTableList
39
- 表格形式的选择组件,适用于需要展示多列数据的选择场景。支持自定义列配置和表格样式。
40
66
 
41
- #### SelectedAll
42
- 全选功能组件,提供一键选择/取消选择所有项的功能。可以与其他选择组件配合使用。
67
+ ### 示例
43
68
 
44
- #### SelectTree
45
- 树形选择组件,适用于层级数据的展示和选择。支持展开/折叠节点,并提供灵活的节点渲染方式。
69
+ #### 示例样式
46
70
 
47
- #### SelectedTagList
48
- 已选项标签列表组件,以标签形式展示已选中的项目。支持单个标签删除和清空所有已选项。
71
+ ```scss
72
+ .max-width-150 {
73
+ max-width: 150px;
74
+ }
75
+ ```
49
76
 
50
- ### 使用场景
77
+ #### 示例代码
51
78
 
52
- - 复杂的数据筛选和选择
53
- - 多条件组合查询
54
- - 批量操作数据
55
- - 表格数据的多选处理
56
- - 带标签展示的数据选择
57
- - 需要全选/反选功能的列表操作
79
+ - SelectInput 基础组件
80
+ - 基础选择输入组件,展示尺寸、多选、弹窗模式、前后缀等核心功能
81
+ - _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
58
82
 
59
- ### 技术特点
83
+ ```jsx
84
+ const { SelectInput } = _SuperSelect;
85
+ const { Space, Flex, Divider, Button, Tag, Switch } = antd;
86
+ const { useState } = React;
60
87
 
61
- - 基于 React 开发
62
- - 使用 CSS Modules 进行样式隔离
63
- - 支持 ES6+ 语法
64
- - 模块化设计,组件可独立使用
65
- - 支持主题定制
66
- - 完善的类型定义支持
88
+ // 基础示例:展示基本使用和尺寸
89
+ const BasicExample = ({ isPopup }) => {
90
+ return (
91
+ <Flex vertical gap={12}>
92
+ <Flex gap={8} align="center">
93
+ <span>基础使用:</span>
94
+ <SelectInput isPopup={isPopup} placeholder="请选择" style={{ width: 200 }} />
95
+ <SelectInput isPopup={isPopup} placeholder="禁用状态" disabled style={{ width: 200 }} />
96
+ </Flex>
97
+ <Flex gap={8} align="center">
98
+ <span>尺寸:</span>
99
+ <SelectInput isPopup={isPopup} size="small" placeholder="小尺寸" style={{ width: 120 }} />
100
+ <SelectInput isPopup={isPopup} size="default" placeholder="默认尺寸" style={{ width: 140 }} />
101
+ <SelectInput isPopup={isPopup} size="large" placeholder="大尺寸" style={{ width: 160 }} />
102
+ </Flex>
103
+ </Flex>
104
+ );
105
+ };
67
106
 
107
+ // 多选示例:展示多选和标签显示
108
+ const MultiSelectExample = ({ isPopup }) => {
109
+ const [value, setValue] = useState([
110
+ { value: 'react', label: 'React' },
111
+ { value: 'vue', label: 'Vue' }
112
+ ]);
68
113
 
69
- ### 示例
114
+ return (
115
+ <Flex vertical gap={12}>
116
+ <Flex gap={8} align="center">
117
+ <span>多选模式:</span>
118
+ <SelectInput
119
+ value={value}
120
+ onChange={setValue}
121
+ isPopup={isPopup}
122
+ placeholder="请选择技术栈"
123
+ style={{ width: 300 }}
124
+ />
125
+ </Flex>
126
+ <Flex gap={8} align="center">
127
+ <span>带数量限制:</span>
128
+ <SelectInput
129
+ defaultValue={[
130
+ { value: 1, label: '选项一' },
131
+ { value: 2, label: '选项二' }
132
+ ]}
133
+ isPopup={isPopup}
134
+ maxLength={3}
135
+ placeholder="最多选择3项"
136
+ style={{ width: 300 }}
137
+ />
138
+ </Flex>
139
+ </Flex>
140
+ );
141
+ };
70
142
 
143
+ // 自定义前后缀示例
144
+ const PrefixSuffixExample = ({ isPopup }) => {
145
+ const [value, setValue] = useState([
146
+ { value: 'tech', label: '技术研发部' }
147
+ ]);
71
148
 
72
- #### 示例样式
149
+ return (
150
+ <Flex vertical gap={12}>
151
+ <Flex gap={12} align="center">
152
+ <SelectInput
153
+ value={value}
154
+ onChange={setValue}
155
+ isPopup={isPopup}
156
+ prefix={
157
+ <Tag color="blue" style={{ margin: 0, borderRadius: 4 }}>
158
+ 部门
159
+ </Tag>
160
+ }
161
+ placeholder="请选择部门"
162
+ style={{ width: 240 }}
163
+ />
164
+ <SelectInput
165
+ defaultValue={[{ value: 'project', label: '项目A' }]}
166
+ isPopup={isPopup}
167
+ suffix={
168
+ <Button type="primary" size="small" style={{ fontSize: 12 }}>
169
+ 详情
170
+ </Button>
171
+ }
172
+ placeholder="请选择项目"
173
+ style={{ width: 240 }}
174
+ />
175
+ </Flex>
176
+ <Flex gap={12} align="center">
177
+ <SelectInput
178
+ defaultValue={[{ value: 'user1', label: '张三' }]}
179
+ isPopup={isPopup}
180
+ prefix={
181
+ <span style={{
182
+ color: '#1677ff',
183
+ fontWeight: 500,
184
+ fontSize: 13
185
+ }}>
186
+ 负责人:
187
+ </span>
188
+ }
189
+ placeholder="请选择负责人"
190
+ style={{ width: 220 }}
191
+ />
192
+ <SelectInput
193
+ size="large"
194
+ isPopup={isPopup}
195
+ defaultValue={[{ value: 'pending', label: '待处理' }]}
196
+ suffix={
197
+ <Tag color="orange" style={{ margin: 0 }}>
198
+ 3条待办
199
+ </Tag>
200
+ }
201
+ placeholder="请选择状态"
202
+ style={{ width: 260 }}
203
+ />
204
+ </Flex>
205
+ </Flex>
206
+ );
207
+ };
73
208
 
74
- ```scss
75
- .max-width-150 {
76
- max-width: 150px;
77
- }
78
- ```
209
+ const BaseExample = () => {
210
+ const [isPopup, setIsPopup] = useState(true);
79
211
 
80
- #### 示例代码
212
+ return (
213
+ <Flex vertical gap={24}>
214
+ <Flex align="center" gap={12}>
215
+ <span>展示模式:</span>
216
+ <Switch
217
+ checked={isPopup}
218
+ onChange={setIsPopup}
219
+ checkedChildren="下拉"
220
+ unCheckedChildren="弹窗"
221
+ />
222
+ <span style={{ color: '#666', fontSize: 12 }}>
223
+ {isPopup ? '点击输入框展开下拉菜单' : '点击输入框打开弹窗'}
224
+ </span>
225
+ </Flex>
226
+ <Divider />
227
+ <BasicExample isPopup={isPopup} />
228
+ <Divider />
229
+ <MultiSelectExample isPopup={isPopup} />
230
+ <Divider />
231
+ <PrefixSuffixExample isPopup={isPopup} />
232
+ </Flex>
233
+ );
234
+ };
235
+
236
+ render(<BaseExample />);
81
237
 
82
- - select-input
83
- - 用于显示一个选择框,可以下拉展开选项或者以modal展示选项
238
+ ```
239
+
240
+ - SelectInput 边界情况测试
241
+ - 测试超多选项(100项)、超长Label文本、大量已选项展示等边界场景
84
242
  - _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
85
243
 
86
244
  ```jsx
87
245
  const { SelectInput } = _SuperSelect;
88
- const { Space, Flex } = antd;
246
+ const { Flex, Tag } = antd;
247
+ const { useState } = React;
248
+
249
+ // 超多选项测试示例(100项)
250
+ const ManyOptionsExample = () => {
251
+ const manyOptions = Array.from({ length: 100 }, (_, i) => ({
252
+ value: &#96;user_${i + 1}&#96;,
253
+ label: &#96;用户${i + 1}&#96;
254
+ }));
255
+
256
+ // 直接预选10项测试
257
+ const [value, setValue] = useState(manyOptions.slice(0, 10));
258
+
259
+ return (
260
+ <Flex vertical gap={12}>
261
+ <span>超多选项显示测试(已选10项):</span>
262
+ <SelectInput
263
+ value={value}
264
+ onChange={setValue}
265
+ placeholder="请选择用户"
266
+ style={{ width: 400 }}
267
+ >
268
+ {() => <div style={{ padding: 12 }}>下拉内容</div>}
269
+ </SelectInput>
270
+ <Tag color="blue">已选择 {value.length} 项</Tag>
271
+ </Flex>
272
+ );
273
+ };
274
+
275
+ // 超长Label测试示例
276
+ const LongLabelExample = () => {
277
+ const longLabelOptions = [
278
+ { value: 'dept-1', label: '人工智能与机器学习应用技术研发中心' },
279
+ { value: 'dept-2', label: '自然语言处理与智能对话系统研发组' },
280
+ { value: 'dept-3', label: '大语言模型训练与优化专项小组' },
281
+ { value: 'dept-4', label: '云计算与大数据平台架构设计及实施运维中心' },
282
+ { value: 'dept-5', label: '网络安全与数据隐私保护技术保障中心' },
283
+ { value: 'dept-6', label: '物联网设备智能互联与边缘计算技术研发中心' },
284
+ { value: 'dept-7', label: '智能客服机器人产品研发团队-多模态交互技术组' },
285
+ { value: 'dept-8', label: '金融科技创新应用与区块链技术研发实验室' }
286
+ ];
287
+
288
+ const [value, setValue] = useState(longLabelOptions);
289
+
290
+ return (
291
+ <Flex vertical gap={12}>
292
+ <span>超长Label文本省略测试:</span>
293
+ <SelectInput
294
+ value={value}
295
+ onChange={setValue}
296
+ placeholder="请选择部门"
297
+ style={{ width: 280 }}
298
+ >
299
+ {() => <div style={{ padding: 12 }}>下拉内容</div>}
300
+ </SelectInput>
301
+ </Flex>
302
+ );
303
+ };
304
+
305
+ // 单选模式下超长Label测试
306
+ const SingleLongLabelExample = () => {
307
+ const [value, setValue] = useState({
308
+ value: 1,
309
+ label: '人工智能与机器学习应用技术研发中心-自然语言处理与智能对话系统研发组-大语言模型训练与优化专项小组'
310
+ });
311
+
312
+ return (
313
+ <Flex vertical gap={12}>
314
+ <span>单选模式 - 超长Label:</span>
315
+ <SelectInput
316
+ single
317
+ value={value}
318
+ onChange={setValue}
319
+ placeholder="请选择部门"
320
+ style={{ width: 240 }}
321
+ >
322
+ {() => <div style={{ padding: 12 }}>下拉内容</div>}
323
+ </SelectInput>
324
+ {value && <Tag color="green">已选:{value.label}</Tag>}
325
+ </Flex>
326
+ );
327
+ };
328
+
329
+ // 大量已选项展示测试
330
+ const ManySelectedExample = () => {
331
+ const [value, setValue] = useState(
332
+ Array.from({ length: 20 }, (_, i) => ({
333
+ value: &#96;item_${i + 1}&#96;,
334
+ label: &#96;选项${i + 1}&#96;
335
+ }))
336
+ );
337
+
338
+ return (
339
+ <Flex vertical gap={12}>
340
+ <span>大量已选项展示(默认已选20项):</span>
341
+ <SelectInput
342
+ value={value}
343
+ onChange={setValue}
344
+ placeholder="请选择"
345
+ style={{ width: 400 }}
346
+ >
347
+ {() => <div style={{ padding: 12 }}>下拉内容</div>}
348
+ </SelectInput>
349
+ </Flex>
350
+ );
351
+ };
89
352
 
90
353
  const BaseExample = () => {
91
- return <Flex vertical gap={8}>
92
- <Space>
93
- <SelectInput />
94
- <SelectInput defaultValue={[{ value: 0, label: '第一项' }, { value: 1, label: '第二项' }]} />
95
- <SelectInput defaultValue={[{ value: 'all', label: '全选' }]} />
96
- <SelectInput className="max-width-150" defaultValue={Array.from({ length: 10 }).map((value, index) => {
97
- return { value: index, label: `第${index}项` };
98
- })} />
99
- <SelectInput defaultValue={[{ value: 0, label: '第一项' }, { value: 1, label: '第二项' }]} disabled />
100
- </Space>
101
- <Space>
102
- <SelectInput isPopup={false}/>
103
- </Space>
104
- </Flex>;
354
+ return (
355
+ <Flex vertical gap={24}>
356
+ <ManyOptionsExample />
357
+ <LongLabelExample />
358
+ <SingleLongLabelExample />
359
+ <ManySelectedExample />
360
+ </Flex>
361
+ );
105
362
  };
106
363
 
107
364
  render(<BaseExample />);
108
365
 
109
366
  ```
110
367
 
111
- - select-list
112
- - 列表选择
368
+ - SuperSelect 列表选择
369
+ - 通用列表选择组件,支持单选/多选、搜索、全选、数量限制、弹窗模式等功能
113
370
  - _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
114
371
 
115
372
  ```jsx
116
373
  const { default: SuperSelect } = _SuperSelect;
117
- const { Space, Button } = antd;
374
+ const { Space, Button, Flex, Divider, Tag, Switch } = antd;
375
+ const { useState } = React;
376
+
377
+ // 模拟部门数据
378
+ const departmentOptions = [
379
+ { value: 'tech', label: '技术研发部', disabled: false },
380
+ { value: 'product', label: '产品设计部', disabled: false },
381
+ { value: 'operation', label: '运营管理部', disabled: false },
382
+ { value: 'hr', label: '人力资源部', disabled: false },
383
+ { value: 'finance', label: '财务部', disabled: true },
384
+ { value: 'marketing', label: '市场营销部', disabled: false }
385
+ ];
118
386
 
119
- const optionList = Array.from({ length: 20 }).map((item, key) => {
120
- return {
121
- label: `第${key + 1}项`,
122
- value: key + 1,
123
- disabled: key === 1
124
- };
125
- });
387
+ // 模拟用户数据
388
+ const userOptions = Array.from({ length: 30 }).map((_, index) => ({
389
+ value: &#96;user_${index + 1}&#96;,
390
+ label: &#96;用户${index + 1}&#96;,
391
+ email: &#96;user${index + 1}@company.com&#96;,
392
+ department: departmentOptions[index % departmentOptions.length].label,
393
+ disabled: index === 5
394
+ }));
395
+
396
+ // 基础列表选择
397
+ const BasicListExample = ({ isPopup }) => {
398
+ const [value, setValue] = useState([]);
126
399
 
127
- const BaseExample = () => {
128
400
  return (
129
- <Space wrap>
130
- <SuperSelect options={optionList} suffix={<Button type="text">预览</Button>} prefix={<Button type="text">查看</Button>} />
401
+ <Flex vertical gap={8}>
402
+ <span>多选列表:</span>
131
403
  <SuperSelect
132
- single
133
- options={[
134
- ...optionList,
135
- {
136
- value: 'other',
137
- label: '超长label项超长label项超长label项超长label项超长label项超长label项超长label项超长label项'
138
- }
139
- ]}
404
+ options={departmentOptions}
405
+ value={value}
406
+ onChange={setValue}
407
+ isPopup={isPopup}
408
+ placeholder="请选择部门"
409
+ style={{ width: 280 }}
140
410
  />
411
+ {value.length > 0 && (
412
+ <div>已选:{value.map(item => item.label).join('、')}</div>
413
+ )}
414
+ </Flex>
415
+ );
416
+ };
417
+
418
+ // 单选列表
419
+ const SingleSelectExample = ({ isPopup }) => {
420
+ const [value, setValue] = useState(null);
421
+
422
+ return (
423
+ <Flex vertical gap={8}>
424
+ <span>单选列表:</span>
141
425
  <SuperSelect
142
- allowSelectedAll
143
- options={optionList}
144
- maxLength={10}
145
- getSearchCallback={({ searchText }, item) => {
146
- return !searchText || item.label.indexOf(searchText) > -1;
147
- }}
426
+ single
427
+ options={userOptions.slice(0, 10)}
428
+ value={value}
429
+ onChange={setValue}
430
+ isPopup={isPopup}
431
+ placeholder="请选择负责人"
432
+ style={{ width: 280 }}
148
433
  />
434
+ {value && <div>已选:{value.label}</div>}
435
+ </Flex>
436
+ );
437
+ };
438
+
439
+ // 带搜索的选择
440
+ const SearchableExample = ({ isPopup }) => {
441
+ const [value, setValue] = useState([]);
442
+
443
+ return (
444
+ <Flex vertical gap={8}>
445
+ <span>带搜索功能:</span>
149
446
  <SuperSelect
150
- allowSelectedAll
151
- options={optionList}
152
- isPopup={false}
447
+ options={userOptions}
448
+ value={value}
449
+ onChange={setValue}
450
+ isPopup={isPopup}
451
+ placeholder="搜索并选择用户"
153
452
  getSearchCallback={({ searchText }, item) => {
154
- return !searchText || item.label.indexOf(searchText) > -1;
155
- }}
156
- />
157
- <SuperSelect
158
- api={{
159
- data: {},
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 };
453
+ if (!searchText) return true;
454
+ const keyword = searchText.toLowerCase();
455
+ return (
456
+ item.label.toLowerCase().includes(keyword) ||
457
+ item.email.toLowerCase().includes(keyword)
458
+ );
178
459
  }}
460
+ style={{ width: 320 }}
179
461
  />
462
+ </Flex>
463
+ );
464
+ };
180
465
 
466
+ // 全选功能
467
+ const SelectAllExample = ({ isPopup }) => {
468
+ const [value, setValue] = useState([]);
469
+
470
+ return (
471
+ <Flex vertical gap={8}>
472
+ <span>支持全选:</span>
181
473
  <SuperSelect
182
- defaultOpen
183
- options={optionList}
184
- inputRender={({ value }) => {
185
- return <Button type="link">编辑</Button>;
186
- }}
474
+ allowSelectedAll
475
+ options={departmentOptions.filter(item => !item.disabled)}
476
+ value={value}
477
+ onChange={setValue}
478
+ isPopup={isPopup}
479
+ placeholder="请选择部门(支持全选)"
480
+ style={{ width: 280 }}
187
481
  />
482
+ </Flex>
483
+ );
484
+ };
188
485
 
486
+ // 带数量限制
487
+ const MaxLimitExample = ({ isPopup }) => {
488
+ const [value, setValue] = useState([]);
489
+
490
+ return (
491
+ <Flex vertical gap={8}>
492
+ <span>最多选择3项:</span>
189
493
  <SuperSelect
190
- options={optionList}
191
- footer={({ close, reload }) => {
192
- return (
193
- <Button type="link" onClick={reload}>
194
- 添加
195
- </Button>
196
- );
197
- }}
494
+ options={userOptions.slice(0, 10)}
495
+ value={value}
496
+ onChange={setValue}
497
+ isPopup={isPopup}
498
+ maxLength={3}
499
+ placeholder="请选择(最多3项)"
500
+ style={{ width: 320 }}
198
501
  />
502
+ <Tag color={value.length >= 3 ? 'red' : 'blue'}>
503
+ 已选择 {value.length}/3 项
504
+ </Tag>
505
+ </Flex>
506
+ );
507
+ };
199
508
 
509
+ // 自定义渲染
510
+ const CustomRenderExample = () => {
511
+ return (
512
+ <Flex vertical gap={8}>
513
+ <span>自定义输入框渲染:</span>
200
514
  <SuperSelect
201
- options={[]}
202
- footer={({ close, reload }) => {
515
+ options={departmentOptions}
516
+ inputRender={(props, context) => {
517
+ const { value } = context;
203
518
  return (
204
- <Button type="link" onClick={reload}>
205
- 添加
519
+ <Button type="primary" {...props}>
520
+ {value.length > 0 ? &#96;已选择 ${value.length} 项&#96; : '点击选择部门'}
206
521
  </Button>
207
522
  );
208
523
  }}
209
524
  />
210
- </Space>
525
+ </Flex>
526
+ );
527
+ };
528
+
529
+ const BaseExample = () => {
530
+ const [isPopup, setIsPopup] = useState(true);
531
+
532
+ return (
533
+ <Flex vertical gap={24}>
534
+ <Flex align="center" gap={12}>
535
+ <span>展示模式:</span>
536
+ <Switch
537
+ checked={isPopup}
538
+ onChange={setIsPopup}
539
+ checkedChildren="下拉"
540
+ unCheckedChildren="弹窗"
541
+ />
542
+ <span style={{ color: '#666', fontSize: 12 }}>
543
+ {isPopup ? '点击输入框展开下拉菜单' : '点击输入框打开弹窗'}
544
+ </span>
545
+ </Flex>
546
+ <Divider />
547
+ <BasicListExample isPopup={isPopup} />
548
+ <Divider />
549
+ <SingleSelectExample isPopup={isPopup} />
550
+ <Divider />
551
+ <SearchableExample isPopup={isPopup} />
552
+ <Divider />
553
+ <SelectAllExample isPopup={isPopup} />
554
+ <Divider />
555
+ <MaxLimitExample isPopup={isPopup} />
556
+ <Divider />
557
+ <CustomRenderExample />
558
+ </Flex>
211
559
  );
212
560
  };
213
561
 
@@ -215,306 +563,709 @@ render(<BaseExample />);
215
563
 
216
564
  ```
217
565
 
218
- - select--table-list
219
- - 表格列表选择,适合更加复杂的数据选择
566
+ - SelectTableList 表格选择
567
+ - 表格形式的选择组件,适合复杂数据的展示和选择,支持自定义列、搜索、单选/多选等
220
568
  - _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
221
569
 
222
570
  ```jsx
223
571
  const { SelectTableList } = _SuperSelect;
224
- const { Space, Button, Divider } = antd;
572
+ const { Space, Button, Flex, Divider, Tag, Avatar, Switch } = antd;
573
+ const { useState } = React;
574
+
575
+ // 模拟员工数据
576
+ const employeeOptions = Array.from({ length: 25 }).map((_, index) => ({
577
+ id: &#96;emp_${index + 1}&#96;,
578
+ name: &#96;员工${index + 1}&#96;,
579
+ email: &#96;employee${index + 1}@company.com&#96;,
580
+ department: ['技术研发部', '产品设计部', '运营部', '市场部'][index % 4],
581
+ position: ['工程师', '设计师', '经理', '专员'][index % 4],
582
+ status: index === 3 ? 'inactive' : 'active',
583
+ joinDate: &#96;2023-${String((index % 12) + 1).padStart(2, '0')}-15&#96;
584
+ }));
585
+
586
+ // 员工列表列配置
587
+ const employeeColumns = [
588
+ {
589
+ name: 'name',
590
+ title: '姓名',
591
+ span: 6,
592
+ getValueOf: (item) => (
593
+ <Flex align="center" gap={8}>
594
+ <Avatar size="small" style={{ backgroundColor: '#1677ff' }}>
595
+ {item.name.slice(-2)}
596
+ </Avatar>
597
+ <span>{item.name}</span>
598
+ </Flex>
599
+ )
600
+ },
601
+ {
602
+ name: 'department',
603
+ title: '部门',
604
+ span: 6
605
+ },
606
+ {
607
+ name: 'position',
608
+ title: '职位',
609
+ span: 4
610
+ },
611
+ {
612
+ name: 'email',
613
+ title: '邮箱',
614
+ span: 6,
615
+ getValueOf: (item) => (
616
+ <span style={{ color: '#666', fontSize: 12 }}>{item.email}</span>
617
+ )
618
+ },
619
+ {
620
+ name: 'options',
621
+ title: '操作',
622
+ span: 2,
623
+ getValueOf: (item, { context }) => {
624
+ return (
625
+ <Button
626
+ type="link"
627
+ size="small"
628
+ danger
629
+ disabled={item.status === 'inactive'}
630
+ onClick={(e) => {
631
+ e.stopPropagation();
632
+ console.log('删除员工:', item.name);
633
+ }}
634
+ >
635
+ 移除
636
+ </Button>
637
+ );
638
+ }
639
+ }
640
+ ];
225
641
 
226
- const optionList = Array.from({ length: 20 }).map((item, key) => {
227
- return {
228
- id: key + 1, label: `名称${key + 1}`, count: key + 1, description: `描述${key + 1}`, disabled: key === 1
229
- };
230
- });
231
-
232
- const columns = [{
233
- name: 'label', title: '名称', span: 8
234
- }, {
235
- name: 'count', title: '数量', span: 4
236
- }, {
237
- name: 'description', title: '描述', span: 8
238
- }, {
239
- name: 'options', title: '操作', span: 4, getValueOf: (item, { column, context }) => {
240
- return <Button type="link" danger disabled={!!item.disabled} className="btn-no-padding" onClick={(e) => {
241
- e.stopPropagation();
242
- const { data, setData } = context.fetchApi;
243
- if (context.value) {
244
- //如果已选数据中还有该项,需要同时删除
245
- const index = context.value.findIndex((target) => target.id === item.id);
246
- if (index > -1) {
247
- const newValue = context.value.slice(0);
248
- newValue.splice(index, 1);
249
- context.setValue(newValue);
250
- }
251
- }
252
- const index = data.pageData.findIndex((target) => target.id === item.id);
253
- const newPageData = data.pageData.slice(0);
254
- newPageData.splice(index, 1);
255
- setData(Object.assign({}, data, {
256
- pageData: newPageData
257
- }));
258
- }}>删除</Button>;
642
+ // 产品数据
643
+ const productOptions = Array.from({ length: 20 }).map((_, index) => ({
644
+ id: &#96;prod_${index + 1}&#96;,
645
+ productName: &#96;产品${index + 1}&#96;,
646
+ category: ['电子产品', '服装', '食品', '家居'][index % 4],
647
+ price: Math.floor(Math.random() * 1000) + 100,
648
+ stock: Math.floor(Math.random() * 500),
649
+ status: index === 5 ? '下架' : '在售'
650
+ }));
651
+
652
+ const productColumns = [
653
+ {
654
+ name: 'productName',
655
+ title: '产品名称',
656
+ span: 6
657
+ },
658
+ {
659
+ name: 'category',
660
+ title: '分类',
661
+ span: 4,
662
+ getValueOf: (item) => (
663
+ <Tag color="blue">{item.category}</Tag>
664
+ )
665
+ },
666
+ {
667
+ name: 'price',
668
+ title: '价格',
669
+ span: 4,
670
+ getValueOf: (item) => &#96;¥${item.price}&#96;
671
+ },
672
+ {
673
+ name: 'stock',
674
+ title: '库存',
675
+ span: 4,
676
+ getValueOf: (item) => (
677
+ <span style={{ color: item.stock < 50 ? 'red' : 'green' }}>
678
+ {item.stock}
679
+ </span>
680
+ )
681
+ },
682
+ {
683
+ name: 'status',
684
+ title: '状态',
685
+ span: 4,
686
+ getValueOf: (item) => (
687
+ <Tag color={item.status === '在售' ? 'success' : 'default'}>
688
+ {item.status}
689
+ </Tag>
690
+ )
259
691
  }
260
- }];
692
+ ];
693
+
694
+ // 基础表格选择
695
+ const BasicTableExample = ({ isPopup }) => {
696
+ const [value, setValue] = useState([]);
697
+
698
+ return (
699
+ <Flex vertical gap={8}>
700
+ <span>多选表格:</span>
701
+ <SelectTableList
702
+ options={employeeOptions}
703
+ columns={employeeColumns}
704
+ valueKey="id"
705
+ labelKey="name"
706
+ value={value}
707
+ onChange={setValue}
708
+ isPopup={isPopup}
709
+ placeholder="请选择员工"
710
+ style={{ width: 600 }}
711
+ />
712
+ {value.length > 0 && (
713
+ <div>已选 {value.length} 人:{value.map(item => item.name).join('、')}</div>
714
+ )}
715
+ </Flex>
716
+ );
717
+ };
718
+
719
+ // 单选表格
720
+ const SingleTableExample = ({ isPopup }) => {
721
+ const [value, setValue] = useState(null);
722
+
723
+ return (
724
+ <Flex vertical gap={8}>
725
+ <span>单选表格:</span>
726
+ <SelectTableList
727
+ single
728
+ options={productOptions}
729
+ columns={productColumns}
730
+ valueKey="id"
731
+ labelKey="productName"
732
+ value={value}
733
+ onChange={setValue}
734
+ isPopup={isPopup}
735
+ placeholder="请选择产品"
736
+ style={{ width: 600 }}
737
+ />
738
+ {value && <div>已选:{value.productName}</div>}
739
+ </Flex>
740
+ );
741
+ };
742
+
743
+ // 带搜索的表格选择
744
+ const SearchableTableExample = ({ isPopup }) => {
745
+ const [value, setValue] = useState([]);
746
+
747
+ return (
748
+ <Flex vertical gap={8}>
749
+ <span>带搜索功能:</span>
750
+ <SelectTableList
751
+ options={employeeOptions}
752
+ columns={employeeColumns}
753
+ valueKey="id"
754
+ labelKey="name"
755
+ value={value}
756
+ onChange={setValue}
757
+ isPopup={isPopup}
758
+ placeholder="搜索姓名、邮箱或部门"
759
+ getSearchCallback={({ searchText }, item) => {
760
+ if (!searchText) return true;
761
+ const keyword = searchText.toLowerCase();
762
+ return (
763
+ item.name.toLowerCase().includes(keyword) ||
764
+ item.email.toLowerCase().includes(keyword) ||
765
+ item.department.toLowerCase().includes(keyword)
766
+ );
767
+ }}
768
+ style={{ width: 600 }}
769
+ />
770
+ </Flex>
771
+ );
772
+ };
773
+
774
+ // 全选功能
775
+ const SelectAllTableExample = ({ isPopup }) => {
776
+ const [value, setValue] = useState([]);
777
+
778
+ return (
779
+ <Flex vertical gap={8}>
780
+ <span>支持全选:</span>
781
+ <SelectTableList
782
+ allowSelectedAll
783
+ options={productOptions.filter(item => item.status === '在售')}
784
+ columns={productColumns}
785
+ valueKey="id"
786
+ labelKey="productName"
787
+ value={value}
788
+ onChange={setValue}
789
+ isPopup={isPopup}
790
+ placeholder="请选择在售产品"
791
+ style={{ width: 600 }}
792
+ />
793
+ </Flex>
794
+ );
795
+ };
796
+
797
+ // 自定义底部
798
+ const CustomFooterExample = ({ isPopup }) => {
799
+ const [value, setValue] = useState([]);
800
+
801
+ return (
802
+ <Flex vertical gap={8}>
803
+ <span>自定义底部操作:</span>
804
+ <SelectTableList
805
+ options={employeeOptions}
806
+ columns={employeeColumns}
807
+ valueKey="id"
808
+ labelKey="name"
809
+ value={value}
810
+ onChange={setValue}
811
+ isPopup={isPopup}
812
+ placeholder="请选择员工"
813
+ footer={({ close, reload }) => (
814
+ <Flex justify="space-between" align="center">
815
+ <Button type="link" onClick={reload}>
816
+ 刷新数据
817
+ </Button>
818
+ <Button type="primary" onClick={close}>
819
+ 确认选择
820
+ </Button>
821
+ </Flex>
822
+ )}
823
+ style={{ width: 600 }}
824
+ />
825
+ </Flex>
826
+ );
827
+ };
828
+
829
+ // 直接展示在页面上(无触发器)
830
+ const DirectRenderExample = () => {
831
+ const [value, setValue] = useState([]);
832
+
833
+ return (
834
+ <Flex vertical gap={8}>
835
+ <span>直接展示在页面(嵌入模式):</span>
836
+ <SelectTableList
837
+ options={employeeOptions}
838
+ columns={employeeColumns}
839
+ valueKey="id"
840
+ labelKey="name"
841
+ value={value}
842
+ onChange={setValue}
843
+ placeholder="请选择员工"
844
+ getSearchCallback={({ searchText }, item) => {
845
+ if (!searchText) return true;
846
+ const keyword = searchText.toLowerCase();
847
+ return (
848
+ item.name.toLowerCase().includes(keyword) ||
849
+ item.email.toLowerCase().includes(keyword) ||
850
+ item.department.toLowerCase().includes(keyword)
851
+ );
852
+ }}
853
+ style={{ width: '100%' }}
854
+ renderContent={(content) => (
855
+ <div style={{
856
+ border: '1px solid #d9d9d9',
857
+ borderRadius: 6,
858
+ padding: 16
859
+ }}>
860
+ {content}
861
+ </div>
862
+ )}
863
+ />
864
+ {value.length > 0 && (
865
+ <div style={{ padding: '8px 12px', backgroundColor: '#e6f4ff', borderRadius: 4 }}>
866
+ 已选择 {value.length} 人:{value.map(item => item.name).join('、')}
867
+ </div>
868
+ )}
869
+ </Flex>
870
+ );
871
+ };
261
872
 
262
873
  const BaseExample = () => {
263
- return <Space wrap>
264
- <SelectTableList options={optionList} columns={columns} valueKey="id" footer={<Button type="link">预览</Button>} />
265
- <SelectTableList single options={optionList} columns={columns} valueKey="id"
266
- footer={<Button type="link">预览</Button>} />
267
- <SelectTableList allowSelectedAll options={optionList} columns={columns} valueKey="id"
268
- footer={<Button type="link">预览</Button>} getSearchCallback={({ searchText }, item) => {
269
- return !searchText || item.label.indexOf(searchText) > -1;
270
- }} />
271
- <SelectTableList options={optionList} columns={columns} isPopup={false} valueKey="id"
272
- footer={<Button type="link">预览</Button>} />
273
- <SelectTableList allowSelectedAll options={optionList} columns={columns} isPopup={false} valueKey="id"
274
- footer={<Button type="link">预览</Button>} getSearchCallback={({ searchText }, item) => {
275
- return !searchText || item.label.indexOf(searchText) > -1;
276
- }} />
277
- <SelectTableList single options={optionList} columns={columns} isPopup={false} valueKey="id"
278
- footer={<Button type="link">预览</Button>} />
279
- <SelectTableList single options={[]} columns={columns} isPopup={false} valueKey="id"
280
- footer={<Button type="link">预览</Button>} />
281
- <div>
874
+ const [isPopup, setIsPopup] = useState(true);
875
+
876
+ return (
877
+ <Flex vertical gap={24}>
878
+ <Flex align="center" gap={12}>
879
+ <span>展示模式:</span>
880
+ <Switch
881
+ checked={isPopup}
882
+ onChange={setIsPopup}
883
+ checkedChildren="下拉"
884
+ unCheckedChildren="弹窗"
885
+ />
886
+ <span style={{ color: '#666', fontSize: 12 }}>
887
+ {isPopup ? '点击输入框展开下拉菜单' : '点击输入框打开弹窗'}
888
+ </span>
889
+ </Flex>
890
+ <Divider />
891
+ <BasicTableExample isPopup={isPopup} />
892
+ <Divider />
893
+ <SingleTableExample isPopup={isPopup} />
282
894
  <Divider />
283
- <SelectTableList allowSelectedAll options={optionList} columns={columns} isPopup={false} valueKey="id"
284
- onChange={(value) => {
285
- console.log(value);
286
- }} getSearchCallback={({ searchText }, item) => {
287
- return !searchText || item.label.indexOf(searchText) > -1;
288
- }} footer={<Button type="link">预览</Button>} renderContent={(target) => target} />
289
- </div>
290
- </Space>;
895
+ <SearchableTableExample isPopup={isPopup} />
896
+ <Divider />
897
+ <SelectAllTableExample isPopup={isPopup} />
898
+ <Divider />
899
+ <CustomFooterExample isPopup={isPopup} />
900
+ <Divider />
901
+ <DirectRenderExample />
902
+ </Flex>
903
+ );
291
904
  };
292
905
 
293
906
  render(<BaseExample />);
294
907
 
295
908
  ```
296
909
 
297
- - select-tree
298
- - 树选择
910
+ - SelectTree 树形选择
911
+ - 树形结构的选择组件,适用于组织架构、地区、分类等层级数据的选择
299
912
  - _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
300
913
 
301
914
  ```jsx
302
915
  const { SelectTree } = _SuperSelect;
303
- const { Space, Button } = antd;
916
+ const { Space, Button, Flex, Divider, Tag, Switch } = antd;
917
+ const { useState } = React;
304
918
 
305
- const options = [
919
+ // 组织架构数据
920
+ const organizationTree = [
921
+ {
922
+ id: 'root',
923
+ parentId: null,
924
+ name: '集团总部',
925
+ code: 'HQ',
926
+ employeeCount: 500
927
+ },
928
+ {
929
+ id: 'tech',
930
+ parentId: 'root',
931
+ name: '技术中心',
932
+ code: 'TECH',
933
+ employeeCount: 200
934
+ },
935
+ {
936
+ id: 'tech-fe',
937
+ parentId: 'tech',
938
+ name: '前端开发组',
939
+ code: 'FE',
940
+ employeeCount: 50
941
+ },
942
+ {
943
+ id: 'tech-be',
944
+ parentId: 'tech',
945
+ name: '后端开发组',
946
+ code: 'BE',
947
+ employeeCount: 80
948
+ },
949
+ {
950
+ id: 'tech-qa',
951
+ parentId: 'tech',
952
+ name: '质量保障组',
953
+ code: 'QA',
954
+ employeeCount: 30
955
+ },
306
956
  {
307
- id: '216822533465310208',
308
- parentId: '216822162877580288',
309
- name: '点点滴滴',
310
- description: '点点滴滴',
311
- index: 0,
312
- createdAt: '2025-08-21T07:35:20.346Z',
313
- updatedAt: '2025-08-21T07:35:20.346Z',
314
- deletedAt: null,
315
- tenantId: '216429049541559296'
957
+ id: 'tech-devops',
958
+ parentId: 'tech',
959
+ name: '运维组',
960
+ code: 'DEVOPS',
961
+ employeeCount: 20
316
962
  },
317
963
  {
318
- id: '216827588281107456',
319
- parentId: '216822162877580288',
320
- name: '都是发的身份',
321
- description: '水电费是的水电费水电费',
322
- index: 0,
323
- createdAt: '2025-08-21T07:55:25.508Z',
324
- updatedAt: '2025-08-21T07:55:25.508Z',
325
- deletedAt: null,
326
- tenantId: '216429049541559296'
964
+ id: 'product',
965
+ parentId: 'root',
966
+ name: '产品中心',
967
+ code: 'PRODUCT',
968
+ employeeCount: 100
327
969
  },
328
970
  {
329
- id: '216820469385397248',
971
+ id: 'product-design',
972
+ parentId: 'product',
973
+ name: '产品设计组',
974
+ code: 'DESIGN',
975
+ employeeCount: 40
976
+ },
977
+ {
978
+ id: 'product-pm',
979
+ parentId: 'product',
980
+ name: '项目管理组',
981
+ code: 'PM',
982
+ employeeCount: 30
983
+ },
984
+ {
985
+ id: 'operation',
986
+ parentId: 'root',
987
+ name: '运营中心',
988
+ code: 'OP',
989
+ employeeCount: 80
990
+ },
991
+ {
992
+ id: 'operation-marketing',
993
+ parentId: 'operation',
994
+ name: '市场营销组',
995
+ code: 'MARKETING',
996
+ employeeCount: 50
997
+ },
998
+ {
999
+ id: 'operation-cs',
1000
+ parentId: 'operation',
1001
+ name: '客户服务组',
1002
+ code: 'CS',
1003
+ employeeCount: 30
1004
+ },
1005
+ {
1006
+ id: 'hr',
1007
+ parentId: 'root',
1008
+ name: '人力资源部',
1009
+ code: 'HR',
1010
+ employeeCount: 40
1011
+ },
1012
+ {
1013
+ id: 'finance',
1014
+ parentId: 'root',
1015
+ name: '财务部',
1016
+ code: 'FINANCE',
1017
+ employeeCount: 30
1018
+ }
1019
+ ];
1020
+
1021
+ // 地区数据
1022
+ const regionTree = [
1023
+ {
1024
+ id: 'china',
330
1025
  parentId: null,
331
- name: '水电费水电费是11111',
332
- description: '水电费水电费是的撒地方水电费水电费水电费水电费水电费水电费水电费水电费水电费水电费水电费水电费水电费的身份',
333
- index: 0,
334
- createdAt: '2025-08-21T07:27:08.230Z',
335
- updatedAt: '2025-08-21T08:16:50.232Z',
336
- deletedAt: null,
337
- tenantId: '216429049541559296'
338
- },
339
- {
340
- id: '216838887668974592',
341
- parentId: '216822162877580288',
342
- name: '水电费水电费',
343
- description: '电饭锅梵蒂冈电饭锅',
344
- index: 0,
345
- createdAt: '2025-08-21T08:40:19.491Z',
346
- updatedAt: '2025-08-21T08:40:19.491Z',
347
- deletedAt: null,
348
- tenantId: '216429049541559296'
349
- },
350
- {
351
- id: '216838908569191424',
352
- parentId: '216822162877580288',
353
- name: '电饭锅电饭锅',
354
- description: '电饭锅电饭锅电饭锅电饭锅电饭锅',
355
- index: 0,
356
- createdAt: '2025-08-21T08:40:24.475Z',
357
- updatedAt: '2025-08-21T08:40:24.475Z',
358
- deletedAt: null,
359
- tenantId: '216429049541559296'
360
- },
361
- {
362
- id: '216838930408932352',
363
- parentId: '216822162877580288',
364
- name: '规范化风格化',
365
- description: '风格化风格化风格化风格化风格化',
366
- index: 0,
367
- createdAt: '2025-08-21T08:40:29.682Z',
368
- updatedAt: '2025-08-21T08:40:29.682Z',
369
- deletedAt: null,
370
- tenantId: '216429049541559296'
371
- },
372
- {
373
- id: '216843395140682752',
1026
+ name: '中国',
1027
+ code: 'CN'
1028
+ },
1029
+ {
1030
+ id: 'beijing',
1031
+ parentId: 'china',
1032
+ name: '北京市',
1033
+ code: 'BJ'
1034
+ },
1035
+ {
1036
+ id: 'shanghai',
1037
+ parentId: 'china',
1038
+ name: '上海市',
1039
+ code: 'SH'
1040
+ },
1041
+ {
1042
+ id: 'guangdong',
1043
+ parentId: 'china',
1044
+ name: '广东省',
1045
+ code: 'GD'
1046
+ },
1047
+ {
1048
+ id: 'guangzhou',
1049
+ parentId: 'guangdong',
1050
+ name: '广州市',
1051
+ code: 'GZ'
1052
+ },
1053
+ {
1054
+ id: 'shenzhen',
1055
+ parentId: 'guangdong',
1056
+ name: '深圳市',
1057
+ code: 'SZ'
1058
+ },
1059
+ {
1060
+ id: 'zhejiang',
1061
+ parentId: 'china',
1062
+ name: '浙江省',
1063
+ code: 'ZJ'
1064
+ },
1065
+ {
1066
+ id: 'hangzhou',
1067
+ parentId: 'zhejiang',
1068
+ name: '杭州市',
1069
+ code: 'HZ'
1070
+ },
1071
+ {
1072
+ id: 'jiangsu',
1073
+ parentId: 'china',
1074
+ name: '江苏省',
1075
+ code: 'JS'
1076
+ },
1077
+ {
1078
+ id: 'nanjing',
1079
+ parentId: 'jiangsu',
1080
+ name: '南京市',
1081
+ code: 'NJ'
1082
+ },
1083
+ {
1084
+ id: 'usa',
374
1085
  parentId: null,
375
- name: '水电费的身份',
376
- description: '水电费是的的身份',
377
- index: 0,
378
- createdAt: '2025-08-21T08:58:14.156Z',
379
- updatedAt: '2025-08-21T08:58:14.156Z',
380
- deletedAt: null,
381
- tenantId: '216429049541559296'
382
- },
383
- {
384
- id: '216844313588401152',
385
- parentId: '216843395140682752',
386
- name: '水电费水电费',
387
- description: '身份是的水电费水电费',
388
- index: 0,
389
- createdAt: '2025-08-21T09:01:53.132Z',
390
- updatedAt: '2025-08-21T09:01:53.132Z',
391
- deletedAt: null,
392
- tenantId: '216429049541559296'
393
- },
394
- {
395
- id: '216844336053093376',
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',
1086
+ name: '美国',
1087
+ code: 'US'
1088
+ },
1089
+ {
1090
+ id: 'newyork',
1091
+ parentId: 'usa',
1092
+ name: '纽约州',
1093
+ code: 'NY'
1094
+ },
1095
+ {
1096
+ id: 'california',
1097
+ parentId: 'usa',
1098
+ name: '加利福尼亚州',
1099
+ code: 'CA'
1100
+ }
1101
+ ];
1102
+
1103
+ // 分类数据
1104
+ const categoryTree = [
1105
+ {
1106
+ id: 'electronics',
451
1107
  parentId: null,
452
- name: '水电费是的',
453
- description: '的身份是的的身份水电费',
454
- index: 0,
455
- createdAt: '2025-08-21T09:13:25.732Z',
456
- updatedAt: '2025-08-21T09:13:25.732Z',
457
- deletedAt: null,
458
- tenantId: '216429049541559296'
459
- },
460
- {
461
- id: '216854106755564544',
462
- parentId: '216847218563351552',
463
- name: '让是非得失的',
464
- description: '电饭锅地方地方电饭锅电饭锅',
465
- index: 0,
466
- createdAt: '2025-08-21T09:40:48.005Z',
467
- updatedAt: '2025-08-21T09:40:48.005Z',
468
- deletedAt: null,
469
- tenantId: '216429049541559296'
470
- },
471
- {
472
- id: '216854194546541568',
473
- parentId: '216847218563351552',
474
- name: '电饭锅电饭锅电饭锅',
475
- description: '电饭锅电饭锅地方电饭锅电饭锅',
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',
1108
+ name: '电子产品'
1109
+ },
1110
+ {
1111
+ id: 'phone',
1112
+ parentId: 'electronics',
1113
+ name: '手机'
1114
+ },
1115
+ {
1116
+ id: 'computer',
1117
+ parentId: 'electronics',
1118
+ name: '电脑'
1119
+ },
1120
+ {
1121
+ id: 'laptop',
1122
+ parentId: 'computer',
1123
+ name: '笔记本'
1124
+ },
1125
+ {
1126
+ id: 'desktop',
1127
+ parentId: 'computer',
1128
+ name: '台式机'
1129
+ },
1130
+ {
1131
+ id: 'clothing',
484
1132
  parentId: null,
485
- name: '发水电费是的',
486
- description: '发的电饭锅地方个电饭锅电饭锅电饭锅地方',
487
- index: 0,
488
- createdAt: '2025-08-21T09:52:05.211Z',
489
- updatedAt: '2025-08-21T09:52:05.211Z',
490
- deletedAt: null,
491
- tenantId: '216429049541559296'
1133
+ name: '服装'
1134
+ },
1135
+ {
1136
+ id: 'mens',
1137
+ parentId: 'clothing',
1138
+ name: '男装'
1139
+ },
1140
+ {
1141
+ id: 'womens',
1142
+ parentId: 'clothing',
1143
+ name: '女装'
492
1144
  }
493
1145
  ];
494
1146
 
495
- const BaseExample = () => {
1147
+ // 基础树选择
1148
+ const BasicTreeExample = ({ isPopup }) => {
1149
+ const [value, setValue] = useState([]);
1150
+
1151
+ return (
1152
+ <Flex vertical gap={8}>
1153
+ <span>组织架构多选:</span>
1154
+ <SelectTree
1155
+ options={organizationTree}
1156
+ valueKey="id"
1157
+ labelKey="name"
1158
+ value={value}
1159
+ onChange={setValue}
1160
+ isPopup={isPopup}
1161
+ placeholder="请选择部门"
1162
+ style={{ width: 320 }}
1163
+ />
1164
+ {value.length > 0 && (
1165
+ <Flex wrap gap={4}>
1166
+ {value.map(item => (
1167
+ <Tag key={item.id} color="blue">{item.name}</Tag>
1168
+ ))}
1169
+ </Flex>
1170
+ )}
1171
+ </Flex>
1172
+ );
1173
+ };
1174
+
1175
+ // 单选树
1176
+ const SingleTreeExample = ({ isPopup }) => {
1177
+ const [value, setValue] = useState(null);
1178
+
496
1179
  return (
497
- <Space wrap>
498
- <SelectTree options={options} valueKey="id" labelKey="name" />
1180
+ <Flex vertical gap={8}>
1181
+ <span>地区单选:</span>
1182
+ <SelectTree
1183
+ single
1184
+ options={regionTree}
1185
+ valueKey="id"
1186
+ labelKey="name"
1187
+ value={value}
1188
+ onChange={setValue}
1189
+ isPopup={isPopup}
1190
+ placeholder="请选择地区"
1191
+ style={{ width: 320 }}
1192
+ />
1193
+ {value && <Tag color="green">已选:{value.name} ({value.code})</Tag>}
1194
+ </Flex>
1195
+ );
1196
+ };
499
1197
 
500
- <SelectTree single options={options} valueKey="id" labelKey="name" />
1198
+ // 带搜索的树选择
1199
+ const SearchableTreeExample = ({ isPopup }) => {
1200
+ const [value, setValue] = useState([]);
501
1201
 
1202
+ return (
1203
+ <Flex vertical gap={8}>
1204
+ <span>带搜索功能:</span>
502
1205
  <SelectTree
503
- name="tree"
504
- label="树选择"
505
- options={[
506
- {
507
- value: '1',
508
- label: '父节点'
509
- },
510
- {
511
- value: '2',
512
- label: '子节点',
513
- parentId: '1'
514
- }
515
- ]}
1206
+ options={organizationTree}
1207
+ valueKey="id"
1208
+ labelKey="name"
1209
+ value={value}
1210
+ onChange={setValue}
1211
+ isPopup={isPopup}
1212
+ placeholder="搜索部门名称或编码"
1213
+ style={{ width: 320 }}
1214
+ />
1215
+ </Flex>
1216
+ );
1217
+ };
1218
+
1219
+ // 分类选择
1220
+ const CategoryTreeExample = ({ isPopup }) => {
1221
+ const [value, setValue] = useState([]);
1222
+
1223
+ return (
1224
+ <Flex vertical gap={8}>
1225
+ <span>商品分类选择:</span>
1226
+ <SelectTree
1227
+ options={categoryTree}
1228
+ valueKey="id"
1229
+ labelKey="name"
1230
+ value={value}
1231
+ onChange={setValue}
1232
+ isPopup={isPopup}
1233
+ placeholder="请选择分类"
1234
+ style={{ width: 320 }}
516
1235
  />
517
- </Space>
1236
+ {value.length > 0 && (
1237
+ <div>已选分类:{value.map(item => item.name).join(' > ')}</div>
1238
+ )}
1239
+ </Flex>
1240
+ );
1241
+ };
1242
+
1243
+ const BaseExample = () => {
1244
+ const [isPopup, setIsPopup] = useState(true);
1245
+
1246
+ return (
1247
+ <Flex vertical gap={24}>
1248
+ <Flex align="center" gap={12}>
1249
+ <span>展示模式:</span>
1250
+ <Switch
1251
+ checked={isPopup}
1252
+ onChange={setIsPopup}
1253
+ checkedChildren="下拉"
1254
+ unCheckedChildren="弹窗"
1255
+ />
1256
+ <span style={{ color: '#666', fontSize: 12 }}>
1257
+ {isPopup ? '点击输入框展开下拉菜单' : '点击输入框打开弹窗'}
1258
+ </span>
1259
+ </Flex>
1260
+ <Divider />
1261
+ <BasicTreeExample isPopup={isPopup} />
1262
+ <Divider />
1263
+ <SingleTreeExample isPopup={isPopup} />
1264
+ <Divider />
1265
+ <SearchableTreeExample isPopup={isPopup} />
1266
+ <Divider />
1267
+ <CategoryTreeExample isPopup={isPopup} />
1268
+ </Flex>
518
1269
  );
519
1270
  };
520
1271
 
@@ -522,35 +1273,774 @@ render(<BaseExample />);
522
1273
 
523
1274
  ```
524
1275
 
525
- - ref
526
- - 展示ref的使用
1276
+ - Ref 使用方法
1277
+ - 展示如何通过 ref 控制选择器的打开/关闭、获取/设置值、程序化选择等操作
527
1278
  - _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
528
1279
 
529
1280
  ```jsx
530
1281
  const { default: SuperSelect } = _SuperSelect;
531
- const { Space, Button } = antd;
532
- const { useRef } = React;
1282
+ const { Space, Button, Flex, Divider, message } = antd;
1283
+ const { useRef, useState } = React;
1284
+
1285
+ // 基础 ref 操作示例
1286
+ const BasicRefExample = () => {
1287
+ const selectRef = useRef();
1288
+ const [value, setValue] = useState([]);
533
1289
 
534
- const optionList = Array.from({ length: 20 }).map((item, key) => {
535
- return {
536
- label: `第${key + 1}项`, value: key + 1, disabled: key === 1
1290
+ const departmentOptions = [
1291
+ { value: 'tech', label: '技术研发部' },
1292
+ { value: 'product', label: '产品设计部' },
1293
+ { value: 'operation', label: '运营管理部' },
1294
+ { value: 'hr', label: '人力资源部' }
1295
+ ];
1296
+
1297
+ return (
1298
+ <Flex vertical gap={12}>
1299
+ <span>通过 ref 控制选择器:</span>
1300
+ <Flex gap={8}>
1301
+ <SuperSelect
1302
+ ref={selectRef}
1303
+ options={departmentOptions}
1304
+ value={value}
1305
+ onChange={setValue}
1306
+ placeholder="请选择部门"
1307
+ style={{ width: 240 }}
1308
+ />
1309
+ <Button type="primary" onClick={() => selectRef.current?.onOpenChange(true)}>
1310
+ 打开
1311
+ </Button>
1312
+ <Button onClick={() => selectRef.current?.onOpenChange(false)}>
1313
+ 关闭
1314
+ </Button>
1315
+ </Flex>
1316
+ </Flex>
1317
+ );
1318
+ };
1319
+
1320
+ // 完整 ref 属性展示
1321
+ const FullRefExample = () => {
1322
+ const selectRef = useRef();
1323
+ const [value, setValue] = useState([]);
1324
+ const [log, setLog] = useState([]);
1325
+
1326
+ const addLog = (msg) => {
1327
+ setLog(prev => [...prev, &#96;[${new Date().toLocaleTimeString()}] ${msg}&#96;]);
537
1328
  };
538
- });
1329
+
1330
+ const userOptions = Array.from({ length: 15 }).map((_, i) => ({
1331
+ value: &#96;user_${i + 1}&#96;,
1332
+ label: &#96;用户${i + 1}&#96;
1333
+ }));
1334
+
1335
+ const handleGetValue = () => {
1336
+ const currentValue = selectRef.current?.value || [];
1337
+ addLog(&#96;当前值: ${JSON.stringify(currentValue.map(v => v.label))}&#96;);
1338
+ message.info(&#96;已选 ${currentValue.length} 项&#96;);
1339
+ };
1340
+
1341
+ const handleClear = () => {
1342
+ selectRef.current?.setValue([]);
1343
+ addLog('已清空选择');
1344
+ };
1345
+
1346
+ const handleSelectFirst = () => {
1347
+ const firstOption = userOptions[0];
1348
+ if (firstOption) {
1349
+ selectRef.current?.onSelect(firstOption);
1350
+ addLog(&#96;已选择: ${firstOption.label}&#96;);
1351
+ }
1352
+ };
1353
+
1354
+ return (
1355
+ <Flex vertical gap={12}>
1356
+ <span>ref 完整功能展示:</span>
1357
+ <Flex gap={8} wrap>
1358
+ <SuperSelect
1359
+ ref={selectRef}
1360
+ options={userOptions}
1361
+ value={value}
1362
+ onChange={setValue}
1363
+ placeholder="请选择用户"
1364
+ style={{ width: 240 }}
1365
+ />
1366
+ </Flex>
1367
+ <Flex gap={8} wrap>
1368
+ <Button type="primary" onClick={() => selectRef.current?.onOpenChange(true)}>
1369
+ 打开下拉
1370
+ </Button>
1371
+ <Button onClick={() => selectRef.current?.onOpenChange(false)}>
1372
+ 关闭下拉
1373
+ </Button>
1374
+ <Button onClick={handleGetValue}>
1375
+ 获取当前值
1376
+ </Button>
1377
+ <Button onClick={handleClear}>
1378
+ 清空选择
1379
+ </Button>
1380
+ <Button onClick={handleSelectFirst}>
1381
+ 选择第一项
1382
+ </Button>
1383
+ </Flex>
1384
+ <div style={{
1385
+ background: '#f5f5f5',
1386
+ padding: 12,
1387
+ borderRadius: 4,
1388
+ maxHeight: 120,
1389
+ overflow: 'auto',
1390
+ fontSize: 12
1391
+ }}>
1392
+ <div style={{ marginBottom: 4, fontWeight: 'bold' }}>操作日志:</div>
1393
+ {log.length === 0 ? (
1394
+ <div style={{ color: '#999' }}>暂无操作</div>
1395
+ ) : (
1396
+ log.map((item, index) => <div key={index}>{item}</div>)
1397
+ )}
1398
+ </div>
1399
+ </Flex>
1400
+ );
1401
+ };
1402
+
1403
+ // ref 常见场景
1404
+ const CommonScenariosExample = () => {
1405
+ const selectRef = useRef();
1406
+
1407
+ const options = [
1408
+ { value: 1, label: '选项一' },
1409
+ { value: 2, label: '选项二' },
1410
+ { value: 3, label: '选项三' }
1411
+ ];
1412
+
1413
+ return (
1414
+ <Flex vertical gap={12}>
1415
+ <span>常见使用场景:</span>
1416
+ <Flex gap={8} align="center">
1417
+ <SuperSelect
1418
+ ref={selectRef}
1419
+ options={options}
1420
+ placeholder="请选择"
1421
+ style={{ width: 200 }}
1422
+ />
1423
+ <Button
1424
+ type="primary"
1425
+ onClick={() => {
1426
+ selectRef.current?.onOpenChange(true);
1427
+ }}
1428
+ >
1429
+ 外部触发打开
1430
+ </Button>
1431
+ </Flex>
1432
+ <div style={{ color: '#666', fontSize: 12 }}>
1433
+ 提示:ref 可用于表单联动、外部控制弹窗、程序化操作等场景
1434
+ </div>
1435
+ </Flex>
1436
+ );
1437
+ };
539
1438
 
540
1439
  const BaseExample = () => {
541
- const ref = useRef();
542
- return <Space wrap>
543
- <SuperSelect options={optionList} ref={ref} />
544
- <Button onClick={() => {
545
- ref.current.onOpenChange(true);
546
- }}>打开弹窗</Button>
547
- </Space>;
1440
+ return (
1441
+ <Flex vertical gap={24}>
1442
+ <BasicRefExample />
1443
+ <Divider />
1444
+ <FullRefExample />
1445
+ <Divider />
1446
+ <CommonScenariosExample />
1447
+ </Flex>
1448
+ );
548
1449
  };
549
1450
 
550
1451
  render(<BaseExample />);
551
1452
 
552
1453
  ```
553
1454
 
1455
+ - SelectCascader 级联选择
1456
+ - 级联选择组件,支持多列菜单展示、父子关联选择、末级选择限制、搜索过滤等功能
1457
+ - _SuperSelect(@kne/current-lib_super-select)[import * as _SuperSelect from "@kne/super-select"],antd(antd),(@kne/current-lib_super-select/dist/index.css)
1458
+
1459
+ ```jsx
1460
+ const { SelectCascader } = _SuperSelect;
1461
+ const { Space, Button, Flex, Divider, Tag, Switch, message } = antd;
1462
+ const { useState, useRef } = React;
1463
+
1464
+ // 中国地区数据
1465
+ const regionData = [
1466
+ {
1467
+ id: 'beijing',
1468
+ name: '北京市',
1469
+ children: [
1470
+ { id: 'haidian', name: '海淀区' },
1471
+ { id: 'chaoyang', name: '朝阳区' },
1472
+ { id: 'dongcheng', name: '东城区' },
1473
+ { id: 'xicheng', name: '西城区' }
1474
+ ]
1475
+ },
1476
+ {
1477
+ id: 'shanghai',
1478
+ name: '上海市',
1479
+ children: [
1480
+ { id: 'pudong', name: '浦东新区' },
1481
+ { id: 'huangpu', name: '黄浦区' },
1482
+ { id: 'jingan', name: '静安区' },
1483
+ { id: 'xuhui', name: '徐汇区' }
1484
+ ]
1485
+ },
1486
+ {
1487
+ id: 'guangdong',
1488
+ name: '广东省',
1489
+ children: [
1490
+ {
1491
+ id: 'guangzhou',
1492
+ name: '广州市',
1493
+ children: [
1494
+ { id: 'tianhe', name: '天河区' },
1495
+ { id: 'yuexiu', name: '越秀区' },
1496
+ { id: 'panyu', name: '番禺区' }
1497
+ ]
1498
+ },
1499
+ {
1500
+ id: 'shenzhen',
1501
+ name: '深圳市',
1502
+ children: [
1503
+ { id: 'nanshan', name: '南山区' },
1504
+ { id: 'futian', name: '福田区' },
1505
+ { id: 'luohu', name: '罗湖区' }
1506
+ ]
1507
+ },
1508
+ { id: 'dongguan', name: '东莞市' }
1509
+ ]
1510
+ },
1511
+ {
1512
+ id: 'zhejiang',
1513
+ name: '浙江省',
1514
+ children: [
1515
+ {
1516
+ id: 'hangzhou',
1517
+ name: '杭州市',
1518
+ children: [
1519
+ { id: 'xihu', name: '西湖区' },
1520
+ { id: 'binjiang', name: '滨江区' }
1521
+ ]
1522
+ },
1523
+ {
1524
+ id: 'ningbo',
1525
+ name: '宁波市',
1526
+ children: [
1527
+ { id: 'haishu', name: '海曙区' },
1528
+ { id: 'yinzhou', name: '鄞州区' }
1529
+ ]
1530
+ }
1531
+ ]
1532
+ },
1533
+ {
1534
+ id: 'jiangsu',
1535
+ name: '江苏省',
1536
+ children: [
1537
+ {
1538
+ id: 'nanjing',
1539
+ name: '南京市',
1540
+ children: [
1541
+ { id: 'xuanwu', name: '玄武区' },
1542
+ { id: 'qinhuai', name: '秦淮区' }
1543
+ ]
1544
+ },
1545
+ {
1546
+ id: 'suzhou',
1547
+ name: '苏州市',
1548
+ children: [
1549
+ { id: 'gusu', name: '姑苏区' },
1550
+ { id: 'industrial', name: '工业园区' }
1551
+ ]
1552
+ }
1553
+ ]
1554
+ }
1555
+ ];
1556
+
1557
+ // 组织架构数据
1558
+ const organizationData = [
1559
+ {
1560
+ id: 'tech',
1561
+ name: '技术研发中心',
1562
+ code: 'TECH',
1563
+ children: [
1564
+ {
1565
+ id: 'tech-fe',
1566
+ name: '前端开发组',
1567
+ code: 'FE',
1568
+ children: [
1569
+ { id: 'fe-react', name: 'React 团队', code: 'REACT' },
1570
+ { id: 'fe-vue', name: 'Vue 团队', code: 'VUE' }
1571
+ ]
1572
+ },
1573
+ {
1574
+ id: 'tech-be',
1575
+ name: '后端开发组',
1576
+ code: 'BE',
1577
+ children: [
1578
+ { id: 'be-java', name: 'Java 团队', code: 'JAVA' },
1579
+ { id: 'be-go', name: 'Go 团队', code: 'GO' }
1580
+ ]
1581
+ },
1582
+ { id: 'tech-qa', name: '质量保障组', code: 'QA' }
1583
+ ]
1584
+ },
1585
+ {
1586
+ id: 'product',
1587
+ name: '产品设计中心',
1588
+ code: 'PRODUCT',
1589
+ children: [
1590
+ { id: 'product-design', name: 'UI设计组', code: 'DESIGN' },
1591
+ { id: 'product-pm', name: '产品经理组', code: 'PM' }
1592
+ ]
1593
+ },
1594
+ {
1595
+ id: 'operation',
1596
+ name: '运营中心',
1597
+ code: 'OP',
1598
+ children: [
1599
+ { id: 'op-marketing', name: '市场营销组', code: 'MARKETING' },
1600
+ { id: 'op-cs', name: '客户服务组', code: 'CS' }
1601
+ ]
1602
+ }
1603
+ ];
1604
+
1605
+ // 商品分类数据
1606
+ const categoryData = [
1607
+ {
1608
+ id: 'electronics',
1609
+ name: '电子产品',
1610
+ children: [
1611
+ {
1612
+ id: 'phone',
1613
+ name: '手机',
1614
+ children: [
1615
+ { id: 'iphone', name: 'iPhone' },
1616
+ { id: 'android', name: '安卓手机' }
1617
+ ]
1618
+ },
1619
+ {
1620
+ id: 'computer',
1621
+ name: '电脑',
1622
+ children: [
1623
+ { id: 'laptop', name: '笔记本' },
1624
+ { id: 'desktop', name: '台式机' }
1625
+ ]
1626
+ }
1627
+ ]
1628
+ },
1629
+ {
1630
+ id: 'clothing',
1631
+ name: '服装',
1632
+ children: [
1633
+ {
1634
+ id: 'mens',
1635
+ name: '男装',
1636
+ children: [
1637
+ { id: 'mens-shirt', name: '衬衫' },
1638
+ { id: 'mens-pants', name: '裤子' }
1639
+ ]
1640
+ },
1641
+ {
1642
+ id: 'womens',
1643
+ name: '女装',
1644
+ children: [
1645
+ { id: 'womens-dress', name: '连衣裙' },
1646
+ { id: 'womens-blouse', name: '上衣' }
1647
+ ]
1648
+ }
1649
+ ]
1650
+ }
1651
+ ];
1652
+
1653
+ // 超长文字测试数据
1654
+ const longTextData = [
1655
+ {
1656
+ id: 'dept-1',
1657
+ name: '人工智能与机器学习应用技术研发中心',
1658
+ children: [
1659
+ {
1660
+ id: 'dept-1-1',
1661
+ name: '自然语言处理与智能对话系统研发组',
1662
+ children: [
1663
+ { id: 'dept-1-1-1', name: '大语言模型训练与优化专项小组' },
1664
+ { id: 'dept-1-1-2', name: '智能客服机器人产品研发团队' },
1665
+ { id: 'dept-1-1-3', name: '多语言机器翻译引擎研发组' },
1666
+ { id: 'dept-1-1-4', name: '知识图谱构建与智能问答系统研发小组' },
1667
+ { id: 'dept-1-1-5', name: '文本挖掘与情感分析技术研发团队' }
1668
+ ]
1669
+ },
1670
+ {
1671
+ id: 'dept-1-2',
1672
+ name: '计算机视觉与图像识别技术研发组',
1673
+ children: [
1674
+ { id: 'dept-1-2-1', name: '工业质检视觉检测算法研发小组' },
1675
+ { id: 'dept-1-2-2', name: '人脸识别与活体检测技术研发团队' },
1676
+ { id: 'dept-1-2-3', name: '医疗影像AI辅助诊断研发组' },
1677
+ { id: 'dept-1-2-4', name: '自动驾驶视觉感知算法研发小组' },
1678
+ { id: 'dept-1-2-5', name: '视频内容理解与智能分析研发团队' }
1679
+ ]
1680
+ },
1681
+ {
1682
+ id: 'dept-1-3',
1683
+ name: '语音识别与合成技术研发小组',
1684
+ children: [
1685
+ { id: 'dept-1-3-1', name: '端到端语音识别引擎研发团队' },
1686
+ { id: 'dept-1-3-2', name: '多风格语音合成与情感表达研发组' }
1687
+ ]
1688
+ },
1689
+ {
1690
+ id: 'dept-1-4',
1691
+ name: '强化学习与决策智能研发组',
1692
+ children: [
1693
+ { id: 'dept-1-4-1', name: '智能博弈与游戏AI研发团队' },
1694
+ { id: 'dept-1-4-2', name: '机器人控制与路径规划算法研发组' }
1695
+ ]
1696
+ }
1697
+ ]
1698
+ },
1699
+ {
1700
+ id: 'dept-2',
1701
+ name: '云计算与大数据平台技术中心',
1702
+ children: [
1703
+ {
1704
+ id: 'dept-2-1',
1705
+ name: '分布式存储与计算架构研发组',
1706
+ children: [
1707
+ { id: 'dept-2-1-1', name: '高可用分布式数据库内核研发团队' },
1708
+ { id: 'dept-2-1-2', name: '云原生容器编排与调度系统研发组' },
1709
+ { id: 'dept-2-1-3', name: '对象存储与分布式文件系统研发小组' },
1710
+ { id: 'dept-2-1-4', name: '微服务架构与服务网格技术研发团队' }
1711
+ ]
1712
+ },
1713
+ {
1714
+ id: 'dept-2-2',
1715
+ name: '数据中台与数据治理解决方案团队',
1716
+ children: [
1717
+ { id: 'dept-2-2-1', name: '企业级数据仓库建模与ETL开发组' },
1718
+ { id: 'dept-2-2-2', name: '实时数据流处理与计算引擎研发组' },
1719
+ { id: 'dept-2-2-3', name: '数据资产管理与元数据管理研发小组' },
1720
+ { id: 'dept-2-2-4', name: '数据质量监控与异常检测系统研发团队' }
1721
+ ]
1722
+ },
1723
+ {
1724
+ id: 'dept-2-3',
1725
+ name: '云安全与合规性保障研发组',
1726
+ children: [
1727
+ { id: 'dept-2-3-1', name: '云原生安全架构与容器安全研发团队' },
1728
+ { id: 'dept-2-3-2', name: '数据加密与密钥管理系统研发组' }
1729
+ ]
1730
+ }
1731
+ ]
1732
+ },
1733
+ {
1734
+ id: 'dept-3',
1735
+ name: '网络安全与隐私保护技术中心',
1736
+ children: [
1737
+ {
1738
+ id: 'dept-3-1',
1739
+ name: '网络攻防与安全应急响应团队',
1740
+ children: [
1741
+ { id: 'dept-3-1-1', name: '威胁情报分析与安全态势感知研发组' },
1742
+ { id: 'dept-3-1-2', name: '零信任安全架构与企业安全网关研发组' },
1743
+ { id: 'dept-3-1-3', name: '漏洞挖掘与渗透测试技术研发小组' },
1744
+ { id: 'dept-3-1-4', name: '安全编排自动化与响应(SOAR)平台研发团队' }
1745
+ ]
1746
+ },
1747
+ {
1748
+ id: 'dept-3-2',
1749
+ name: '数据隐私计算与联邦学习研发小组',
1750
+ children: [
1751
+ { id: 'dept-3-2-1', name: '多方安全计算与隐私求交技术研发团队' },
1752
+ { id: 'dept-3-2-2', name: '联邦学习平台与隐私保护机器学习研发组' }
1753
+ ]
1754
+ }
1755
+ ]
1756
+ },
1757
+ {
1758
+ id: 'dept-4',
1759
+ name: '智能硬件与物联网技术研发中心',
1760
+ children: [
1761
+ {
1762
+ id: 'dept-4-1',
1763
+ name: '嵌入式系统与边缘计算研发组',
1764
+ children: [
1765
+ { id: 'dept-4-1-1', name: '物联网设备固件与操作系统研发团队' },
1766
+ { id: 'dept-4-1-2', name: '边缘AI推理与模型优化部署研发小组' },
1767
+ { id: 'dept-4-1-3', name: '工业物联网网关与协议转换研发组' }
1768
+ ]
1769
+ },
1770
+ {
1771
+ id: 'dept-4-2',
1772
+ name: '智能传感器与MEMS技术研发团队',
1773
+ children: [
1774
+ { id: 'dept-4-2-1', name: '多模态传感器融合算法研发小组' },
1775
+ { id: 'dept-4-2-2', name: '环境感知与智能检测传感器研发组' }
1776
+ ]
1777
+ },
1778
+ {
1779
+ id: 'dept-4-3',
1780
+ name: '智能家居与消费电子解决方案团队',
1781
+ children: [
1782
+ { id: 'dept-4-3-1', name: '智能音箱与语音交互产品研发小组' },
1783
+ { id: 'dept-4-3-2', name: '智能穿戴设备与健康监测研发团队' },
1784
+ { id: 'dept-4-3-3', name: '智能家居控制中枢与生态系统研发组' }
1785
+ ]
1786
+ }
1787
+ ]
1788
+ },
1789
+ {
1790
+ id: 'dept-5',
1791
+ name: '企业数字化转型与咨询服务事业部',
1792
+ children: [
1793
+ {
1794
+ id: 'dept-5-1',
1795
+ name: '行业解决方案与数字化咨询团队',
1796
+ children: [
1797
+ { id: 'dept-5-1-1', name: '金融行业数字化解决方案与实施团队' },
1798
+ { id: 'dept-5-1-2', name: '制造业智能制造与工业互联网咨询组' },
1799
+ { id: 'dept-5-1-3', name: '医疗健康行业数字化转型解决方案团队' },
1800
+ { id: 'dept-5-1-4', name: '零售电商与新零售数字化咨询研发组' }
1801
+ ]
1802
+ },
1803
+ {
1804
+ id: 'dept-5-2',
1805
+ name: '项目交付与技术支持服务团队',
1806
+ children: [
1807
+ { id: 'dept-5-2-1', name: '企业级系统架构设计与集成实施小组' },
1808
+ { id: 'dept-5-2-2', name: '客户成功与售后技术支持服务团队' }
1809
+ ]
1810
+ }
1811
+ ]
1812
+ }
1813
+ ];
1814
+
1815
+ // 基础级联选择
1816
+ const BasicExample = ({ isPopup }) => {
1817
+ const [value, setValue] = useState([]);
1818
+ return (
1819
+ <Flex vertical gap={8}>
1820
+ <span>地区多选(父子关联):</span>
1821
+ <SelectCascader
1822
+ options={regionData}
1823
+ value={value}
1824
+ onChange={setValue}
1825
+ isPopup={isPopup}
1826
+ valueKey="id"
1827
+ labelKey="name"
1828
+ placeholder="请选择地区"
1829
+ menuItemWidth={160}
1830
+ style={{ width: 320 }}
1831
+ />
1832
+ {value.length > 0 && (
1833
+ <Flex wrap gap={4}>
1834
+ {value.map(item => (
1835
+ <Tag key={item.id} color="blue">{item.name}</Tag>
1836
+ ))}
1837
+ </Flex>
1838
+ )}
1839
+ </Flex>
1840
+ );
1841
+ };
1842
+
1843
+ // 单选模式
1844
+ const SingleExample = ({ isPopup }) => {
1845
+ const [value, setValue] = useState(null);
1846
+ return (
1847
+ <Flex vertical gap={8}>
1848
+ <span>地区单选:</span>
1849
+ <SelectCascader
1850
+ single
1851
+ options={regionData}
1852
+ value={value}
1853
+ onChange={setValue}
1854
+ isPopup={isPopup}
1855
+ valueKey="id"
1856
+ labelKey="name"
1857
+ placeholder="请选择地区"
1858
+ menuItemWidth={160}
1859
+ style={{ width: 320 }}
1860
+ />
1861
+ {value && <Tag color="green">已选:{value.name}</Tag>}
1862
+ </Flex>
1863
+ );
1864
+ };
1865
+
1866
+ // 只选末级
1867
+ const OnlyLastLevelExample = ({ isPopup }) => {
1868
+ const [value, setValue] = useState([]);
1869
+
1870
+ return (
1871
+ <Flex vertical gap={8}>
1872
+ <span>只允许选择末级节点:</span>
1873
+ <SelectCascader
1874
+ options={organizationData}
1875
+ value={value}
1876
+ onChange={setValue}
1877
+ isPopup={isPopup}
1878
+ valueKey="id"
1879
+ labelKey="name"
1880
+ onlyAllowLastLevel
1881
+ placeholder="请选择团队"
1882
+ menuItemWidth={180}
1883
+ style={{ width: 360 }}
1884
+ />
1885
+ {value.length > 0 && (
1886
+ <div>
1887
+ 已选团队:{value.map(item => item.name).join('、')}
1888
+ </div>
1889
+ )}
1890
+ </Flex>
1891
+ );
1892
+ };
1893
+
1894
+ // 数量限制
1895
+ const MaxLimitExample = ({ isPopup }) => {
1896
+ const [value, setValue] = useState([]);
1897
+
1898
+ return (
1899
+ <Flex vertical gap={8}>
1900
+ <span>最多选择 3 项:</span>
1901
+ <SelectCascader
1902
+ options={regionData}
1903
+ value={value}
1904
+ onChange={setValue}
1905
+ isPopup={isPopup}
1906
+ valueKey="id"
1907
+ labelKey="name"
1908
+ maxLength={3}
1909
+ placeholder="请选择地区(最多3项)"
1910
+ menuItemWidth={160}
1911
+ style={{ width: 320 }}
1912
+ />
1913
+ <Tag color={value.length >= 3 ? 'red' : 'blue'}>
1914
+ 已选择 {value.length}/3 项
1915
+ </Tag>
1916
+ </Flex>
1917
+ );
1918
+ };
1919
+
1920
+ // 带搜索功能
1921
+ const SearchExample = ({ isPopup }) => {
1922
+ const [value, setValue] = useState([]);
1923
+
1924
+ return (
1925
+ <Flex vertical gap={8}>
1926
+ <span>带搜索功能:</span>
1927
+ <SelectCascader
1928
+ options={regionData}
1929
+ value={value}
1930
+ onChange={setValue}
1931
+ isPopup={isPopup}
1932
+ valueKey="id"
1933
+ labelKey="name"
1934
+ onSearch={(searchText, { mapping }) => {
1935
+ return Array.from(mapping.values()).filter(item =>
1936
+ item.name.toLowerCase().includes(searchText.toLowerCase())
1937
+ );
1938
+ }}
1939
+ searchPlaceholder="搜索地区名称"
1940
+ placeholder="搜索并选择地区"
1941
+ menuItemWidth={160}
1942
+ style={{ width: 360 }}
1943
+ />
1944
+ </Flex>
1945
+ );
1946
+ };
1947
+
1948
+ // 商品分类选择
1949
+ const CategoryExample = ({ isPopup }) => {
1950
+ const [value, setValue] = useState([]);
1951
+
1952
+ return (
1953
+ <Flex vertical gap={8}>
1954
+ <span>商品分类选择:</span>
1955
+ <SelectCascader
1956
+ options={categoryData}
1957
+ value={value}
1958
+ onChange={setValue}
1959
+ isPopup={isPopup}
1960
+ valueKey="id"
1961
+ labelKey="name"
1962
+ placeholder="请选择商品分类"
1963
+ menuItemWidth={160}
1964
+ style={{ width: 320 }}
1965
+ />
1966
+ {value.length > 0 && (
1967
+ <div>
1968
+ 已选分类:{value.map(item => item.name).join(' > ')}
1969
+ </div>
1970
+ )}
1971
+ </Flex>
1972
+ );
1973
+ };
1974
+
1975
+ // 超长文字测试
1976
+ const LongTextExample = ({ isPopup }) => {
1977
+ const [value, setValue] = useState([]);
1978
+
1979
+ return (
1980
+ <Flex vertical gap={8}>
1981
+ <span>超长文字省略测试(部门选择):</span>
1982
+ <SelectCascader
1983
+ options={longTextData}
1984
+ value={value}
1985
+ onChange={setValue}
1986
+ isPopup={isPopup}
1987
+ valueKey="id"
1988
+ labelKey="name"
1989
+ placeholder="请选择部门"
1990
+ menuItemWidth={200}
1991
+ style={{ width: 400 }}
1992
+ />
1993
+ {value.length > 0 && (
1994
+ <Flex wrap gap={4}>
1995
+ {value.map(item => (
1996
+ <Tag key={item.id} color="purple" style={{ maxWidth: 200, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
1997
+ {item.name}
1998
+ </Tag>
1999
+ ))}
2000
+ </Flex>
2001
+ )}
2002
+ </Flex>
2003
+ );
2004
+ };
2005
+
2006
+ const BaseExample = () => {
2007
+ const [isPopup, setIsPopup] = useState(true);
2008
+
2009
+ return (
2010
+ <Flex vertical gap={24}>
2011
+ <Flex align="center" gap={12}>
2012
+ <span>展示模式:</span>
2013
+ <Switch
2014
+ checked={isPopup}
2015
+ onChange={setIsPopup}
2016
+ checkedChildren="下拉"
2017
+ unCheckedChildren="弹窗"
2018
+ />
2019
+ <span style={{ color: '#666', fontSize: 12 }}>
2020
+ {isPopup ? '点击输入框展开下拉菜单' : '点击输入框打开弹窗'}
2021
+ </span>
2022
+ </Flex>
2023
+ <Divider />
2024
+ <BasicExample isPopup={isPopup} />
2025
+ <Divider />
2026
+ <SingleExample isPopup={isPopup} />
2027
+ <Divider />
2028
+ <OnlyLastLevelExample isPopup={isPopup} />
2029
+ <Divider />
2030
+ <MaxLimitExample isPopup={isPopup} />
2031
+ <Divider />
2032
+ <SearchExample isPopup={isPopup} />
2033
+ <Divider />
2034
+ <CategoryExample isPopup={isPopup} />
2035
+ <Divider />
2036
+ <LongTextExample isPopup={isPopup} />
2037
+ </Flex>
2038
+ );
2039
+ };
2040
+
2041
+ render(<BaseExample />);
2042
+
2043
+ ```
554
2044
 
555
2045
  ### API
556
2046
 
@@ -560,23 +2050,45 @@ render(<BaseExample />);
560
2050
 
561
2051
  | 属性名 | 说明 | 类型 | 默认值 |
562
2052
  |-------------------|-------------------|-------------------------------|---------------------|
563
- | value | 当前选中的值 | array | [] |
564
- | onChange | 选中值变化时的回调函数 | function(value, item, {type}) | - |
565
- | dataSource | 数据源 | array | [] |
566
- | idField | 数据项唯一标识字段 | string | 'id' |
567
- | multiple | 是否支持多选 | boolean | false |
568
- | max | 最多可选数量 | number | - |
2053
+ | value | 当前选中的值 | array \| object | [] |
2054
+ | defaultValue | 默认选中的值 | array \| object | [] |
2055
+ | onChange | 选中值变化时的回调函数 | function(value) | - |
2056
+ | single | 是否单选模式 | boolean | false |
2057
+ | maxLength | 最多可选数量(多选模式) | number | - |
569
2058
  | disabled | 是否禁用 | boolean | false |
570
- | readOnly | 是否只读 | boolean | false |
2059
+ | size | 选择框尺寸 | 'small' \| 'default' \| 'large' | 'default' |
2060
+ | placeholder | 输入框占位符 | string | '请选择' |
2061
+ | labelKey | 数据项显示文本字段 | string | 'label' |
2062
+ | valueKey | 数据项唯一标识字段 | string | 'value' |
2063
+ | isPopup | 是否下拉模式(false 为弹窗)| boolean | true |
2064
+ | placement | 下拉菜单位置 | string | 'bottomLeft' |
2065
+ | overlayWidth | 下拉菜单宽度 | number \| string | 同输入框宽度 |
2066
+ | overlayClassName | 下拉菜单自定义类名 | string | - |
2067
+ | labelWrap | 标签是否换行显示 | boolean | false |
2068
+ | allowClear | 是否允许清空 | boolean | true |
2069
+ | allowSelectedAll | 是否显示全选按钮 | boolean | false |
2070
+ | selectedAllValue | 全选项的值配置 | object | { value: 'all', label: '全选' } |
2071
+ | prefix | 输入框前缀 | ReactNode \| function | - |
2072
+ | suffix | 输入框后缀 | ReactNode \| function | - |
571
2073
  | className | 自定义类名 | string | - |
572
2074
  | style | 自定义样式 | object | - |
573
2075
  | children | 自定义渲染内容 | function(props) | - |
574
- | locale | 国际化配置 | object | 默认中文 |
575
- | getContainer | 指定下拉菜单挂载的 HTML 节点 | function | () => document.body |
576
- | getPopupContainer | 菜单渲染父节点 | function(triggerNode) | () => document.body |
577
- | onExceed | 超出最大可选数量时的回调 | function(value, item) | - |
578
- | onSelect | 选择时的回调 | function(value, item) | - |
579
- | onDeselect | 取消选择时的回调 | function(value, item) | - |
2076
+ | renderModal | 自定义弹窗渲染(非 isPopup 模式)| function(contextProps) | 默认 Modal 弹窗 |
2077
+ | renderContent | 自定义内容渲染 | function(children) | - |
2078
+ | inputRender | 自定义输入框渲染 | function(props, contextProps) | - |
2079
+ | open | 是否打开下拉菜单 | boolean | - |
2080
+ | defaultOpen | 默认是否打开 | boolean | false |
2081
+ | onOpenChange | 下拉菜单状态变化回调 | function(open) | - |
2082
+
2083
+ ##### 标签溢出处理
2084
+
2085
+ 组件内置了标签溢出处理功能:
2086
+
2087
+ - **单选模式**:文本超出输入框宽度时显示省略号
2088
+ - **多选模式**:
2089
+ - 单个标签最大宽度为 `min(150px, 容器宽度 - 60px)`
2090
+ - 超出容器宽度的标签自动隐藏,显示 `+N` 标签表示隐藏数量
2091
+ - 标签宽度根据实际内容动态计算,确保精确显示
580
2092
 
581
2093
  #### SelectList
582
2094
 
@@ -735,3 +2247,69 @@ import { zhCN, enUS } from '@kne/super-select/locale';
735
2247
  | items | 项文案 | 项 |
736
2248
  | exceed | 超出限制提示文案 | 最多只能选择 {max} 项 |
737
2249
 
2250
+ #### SelectCascader
2251
+
2252
+ 级联选择组件,适用于地区选择、组织架构、商品分类等层级数据的选择场景。支持多列菜单展示、父子关联选择、末级限制、搜索过滤等功能。
2253
+
2254
+ | 属性名 | 说明 | 类型 | 默认值 |
2255
+ |-------------------|-------------------|-------------------------------|---------------------|
2256
+ | options | 级联数据源 | array | [] |
2257
+ | value | 当前选中的值 | array \| object | [] |
2258
+ | onChange | 选中值变化时的回调函数 | function(value) | - |
2259
+ | defaultValue | 默认选中的值 | array | [] |
2260
+ | single | 是否单选模式 | boolean | false |
2261
+ | maxLength | 最多可选数量 | number | Number.MAX_VALUE |
2262
+ | onlyAllowLastLevel | 是否只允许选择末级节点 | boolean | false |
2263
+ | openLoadData | 是否开启懒加载 | boolean | false |
2264
+ | onLoadMore | 懒加载回调函数 | function({ [parentIdKey]: id }) | - |
2265
+ | parentIdKey | 父节点ID字段名 | string | 'id' |
2266
+ | menuItemWidth | 每列菜单宽度 | number | 180 |
2267
+ | isPopup | 是否下拉模式(false 为弹窗)| boolean | true |
2268
+ | searchPlaceholder| 搜索框占位符 | string | '搜索...' |
2269
+ | onSearch | 搜索回调函数 | function(searchText, { mapping }) | - |
2270
+ | valueKey | 数据项唯一标识字段 | string | 'id' |
2271
+ | labelKey | 数据项显示文本字段 | string | 'label' |
2272
+ | placeholder | 输入框占位符 | string | '请选择' |
2273
+ | disabled | 是否禁用 | boolean | false |
2274
+ | size | 选择框尺寸 | 'small' \| 'default' \| 'large' | 'default' |
2275
+ | overlayWidth | 下拉菜单宽度 | number | menuItemWidth * 2 |
2276
+
2277
+ ##### options 数据结构
2278
+
2279
+ ```javascript
2280
+ [
2281
+ {
2282
+ id: 'node1', // 唯一标识,字段名可通过 valueKey 配置
2283
+ name: '节点名称', // 显示文本,字段名可通过 labelKey 配置
2284
+ children: [ // 子节点
2285
+ {
2286
+ id: 'node1-1',
2287
+ name: '子节点1',
2288
+ children: []
2289
+ }
2290
+ ]
2291
+ }
2292
+ ]
2293
+ ```
2294
+
2295
+ ##### 父子关联选择
2296
+
2297
+ 组件默认支持父子关联选择:
2298
+ - 选中父节点时,自动选中所有子节点
2299
+ - 取消父节点时,自动取消所有子节点
2300
+ - 当所有子节点都被选中时,父节点自动选中
2301
+
2302
+ ##### 搜索功能
2303
+
2304
+ 通过 `onSearch` 属性开启搜索功能:
2305
+
2306
+ ```jsx
2307
+ <SelectCascader
2308
+ options={data}
2309
+ onSearch={(searchText, { mapping }) => {
2310
+ return Array.from(mapping.values()).filter(item =>
2311
+ item.name.includes(searchText)
2312
+ );
2313
+ }}
2314
+ />
2315
+ ```