@ebiz/designer-components 0.0.39 → 0.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1046 @@
1
+ <template>
2
+ <div class="ebiz-employee-selector">
3
+ <!-- 选择框展示区 -->
4
+ <div style="display: flex; flex-direction: column; align-items: flex-start; gap: 10px;">
5
+ <div class="selected-items" v-if="selectedItems && selectedItems.length">
6
+ <div v-for="(item, index) in selectedItems" :key="index" class="selected-item">
7
+ <t-avatar v-if="item.avatar" :image="item.avatar" size="small" />
8
+ <t-avatar v-else size="small">{{ getAvatarText(item.name) }}</t-avatar>
9
+ <span class="item-info">
10
+ <span class="item-code">{{ item.no }} - </span>
11
+ <span class="item-name">{{ item.name }}</span>
12
+ </span>
13
+ <t-icon name="close" class="item-remove" @click="removeItem(index, item.id)"></t-icon>
14
+ </div>
15
+ </div>
16
+ <t-button @click="showDialog" variant="text" theme="primary">选择人员</t-button>
17
+ </div>
18
+
19
+ <!-- 选择弹窗 -->
20
+ <t-dialog v-model:visible="dialogVisible" header="选择人员" :width="800" footer :close-btn="true"
21
+ :close-on-esc-keydown="true" :close-on-overlay-click="true">
22
+
23
+ <!-- 选项卡 -->
24
+ <t-tabs v-model="activeTab" class="selector-tabs">
25
+ <t-tab-panel value="organization" label="组织架构" :destroyOnHide="false"></t-tab-panel>
26
+ <t-tab-panel value="role" label="角色" :destroyOnHide="false"></t-tab-panel>
27
+ <!-- <t-tab-panel value="position" label="岗位" :destroyOnHide="false"></t-tab-panel> -->
28
+ <!-- <t-tab-panel value="department" label="同部门" :destroyOnHide="false"></t-tab-panel> -->
29
+ <!-- <t-tab-panel value="subordinate" label="我的下属" :destroyOnHide="false"></t-tab-panel> -->
30
+ </t-tabs>
31
+
32
+
33
+ <div>
34
+
35
+ <div class="selector-dialog-content">
36
+ <!-- 左侧选择区域 -->
37
+ <div class="left-panel">
38
+ <!-- 内容区域 -->
39
+ <div class="content-area">
40
+ <div v-if="loading" class="loading-container">
41
+ <t-loading />
42
+ </div>
43
+
44
+ <!-- 组织架构 -->
45
+ <div v-show="activeTab === 'organization'" class="tab-content">
46
+ <t-tree ref="organizationTree" :data="organizationData"
47
+ :keys="{ label: 'name', value: 'id', children: 'children' }" hover activable :active="currentActive"
48
+ @active="handleActive" />
49
+ </div>
50
+
51
+ <!-- 角色 -->
52
+ <div v-show="activeTab === 'role'" class="tab-content">
53
+ <t-tree ref="roleTree" :data="roleData" :keys="{ label: 'name', value: 'id' }" hover activable
54
+ :active="currentActive" @active="handleActive" />
55
+ </div>
56
+
57
+ <!-- 岗位 -->
58
+ <div v-show="activeTab === 'position'" class="tab-content">
59
+ <t-tree ref="positionTree" :data="positionData" :keys="{ label: 'name', value: 'id' }" hover activable
60
+ :active="currentActive" @active="handleActive" />
61
+ </div>
62
+
63
+ <!-- 同部门 -->
64
+ <div v-show="activeTab === 'department'" class="tab-content">
65
+ <t-list :split="true" size="small">
66
+ <t-list-item v-for="(item, index) in departmentData" :key="index">
67
+ <div class="department-item" @click="selectDepartment(item)">
68
+ {{ item.name }}
69
+ </div>
70
+ </t-list-item>
71
+ </t-list>
72
+ </div>
73
+
74
+ <!-- 我的下属 -->
75
+ <div v-show="activeTab === 'subordinate'" class="tab-content">
76
+ <t-list :split="true" size="small">
77
+ <t-list-item v-for="(item, index) in subordinateData" :key="index">
78
+ <div class="department-item" @click="selectDepartment(item)">
79
+ {{ item.name }}
80
+ </div>
81
+ </t-list-item>
82
+ </t-list>
83
+ </div>
84
+ </div>
85
+ </div>
86
+
87
+ <!-- 右侧人员列表区域 -->
88
+ <div class="right-panel">
89
+ <div class="employee-header">
90
+ <div class="employee-title">
91
+ {{ currentNodeName || '人员列表' }}
92
+ <div v-if="activeTab === 'organization'" class="sub-dept-option">
93
+ <t-checkbox v-model="childDeptEnable">包含子部门</t-checkbox>
94
+ </div>
95
+ </div>
96
+ <div class="employee-count">
97
+ <t-checkbox v-model="selectAll" @change="handleSelectAll">全选</t-checkbox>
98
+ <span class="count-info">共 {{ employeeList.length }} 人</span>
99
+ </div>
100
+ </div>
101
+
102
+ <!-- 搜索框 -->
103
+ <div class="search-box">
104
+ <t-input v-model="searchText" placeholder="请输入姓名/拼音/工号搜索" clearable
105
+ @keyup.enter="handleSearchEnter">
106
+ <template #suffix-icon>
107
+ <t-icon name="search" @click="handleSearchClick"></t-icon>
108
+ </template>
109
+ </t-input>
110
+ <t-button v-if="searchText" size="small" theme="default" class="clear-search-btn" @click="clearSearch">清除搜索</t-button>
111
+ </div>
112
+
113
+ <div class="employee-list">
114
+ <div v-for="(item, index) in filteredEmployeeList" :key="index" class="employee-item">
115
+ <t-checkbox v-model="item.checked" @change="handleCheckChange(item)"></t-checkbox>
116
+ <div class="employee-avatar">
117
+ <t-avatar v-if="item.avatar" :image="item.avatar" size="small" />
118
+ <t-avatar v-else size="small">{{ getAvatarText(item.name) }}</t-avatar>
119
+ </div>
120
+ <div class="employee-info">
121
+ <div class="employee-code">{{ item.no }} - </div>
122
+ <div class="employee-name">{{ item.name }}</div>
123
+ </div>
124
+ </div>
125
+ <div v-if="filteredEmployeeList.length === 0" class="empty-data">
126
+ <t-empty />
127
+ </div>
128
+ </div>
129
+ </div>
130
+ </div>
131
+ </div>
132
+
133
+
134
+ <!-- 底部按钮区域 -->
135
+ <template #footer>
136
+ <div class="dialog-footer">
137
+ <div class="selected-preview">
138
+ 已选: {{ tempSelectedEmployees.length }} 人
139
+ <div class="selected-people-list" v-if="tempSelectedEmployees.length > 0">
140
+ <div v-for="(item, index) in tempSelectedEmployees" :key="index" class="selected-people-item">
141
+ <t-avatar v-if="item.avatar" :image="item.avatar" size="small" />
142
+ <t-avatar v-else size="small">{{ getAvatarText(item.name) }}</t-avatar>
143
+ <span class="item-info">
144
+ <span class="item-code">{{ item.no }}</span>
145
+ <span class="item-name">{{ item.name }}</span>
146
+ </span>
147
+ <t-icon name="close" class="item-remove" @click="removeSelectedEmployee(item)"></t-icon>
148
+ </div>
149
+ </div>
150
+ </div>
151
+ <div class="dialog-actions">
152
+ <t-button theme="default" @click="handleCancel">取消</t-button>
153
+ <t-button theme="primary" @click="handleConfirm">确定</t-button>
154
+ </div>
155
+ </div>
156
+ </template>
157
+ </t-dialog>
158
+ </div>
159
+ </template>
160
+
161
+ <script setup>
162
+ import { ref, computed, watch, onMounted } from 'vue';
163
+ import {
164
+ Dialog as TDialog,
165
+ Button as TButton,
166
+ Icon as TIcon,
167
+ Input as TInput,
168
+ Tabs as TTabs,
169
+ TabPanel as TTabPanel,
170
+ Loading as TLoading,
171
+ Tree as TTree,
172
+ Avatar as TAvatar,
173
+ Checkbox as TCheckbox,
174
+ Empty as TEmpty,
175
+ List as TList,
176
+ ListItem as TListItem,
177
+ MessagePlugin
178
+ } from 'tdesign-vue-next';
179
+ import dataService from '../apiService/simpleDataService';
180
+
181
+ // 定义组件属性
182
+ const props = defineProps({
183
+ // 选中的数据,支持v-model,只存储ID列表
184
+ modelValue: {
185
+ type: Array,
186
+ default: () => []
187
+ },
188
+ // 单选模式
189
+ single: {
190
+ type: Boolean,
191
+ default: false
192
+ },
193
+ // 是否包含部门
194
+ includeDepartment: {
195
+ type: Boolean,
196
+ default: false
197
+ },
198
+ // 默认标签页
199
+ defaultTab: {
200
+ type: String,
201
+ default: 'organization'
202
+ },
203
+ // 是否展示顶层组织
204
+ showRootOrg: {
205
+ type: Boolean,
206
+ default: true
207
+ },
208
+ // 最大选择数量,0表示不限制
209
+ maxCount: {
210
+ type: Number,
211
+ default: 0
212
+ }
213
+ });
214
+
215
+ // 定义组件事件
216
+ const emit = defineEmits(['update:modelValue', 'change']);
217
+
218
+ // 内部状态变量
219
+ const dialogVisible = ref(false);
220
+ const searchText = ref('');
221
+ const activeTab = ref(props.defaultTab);
222
+ const loading = ref(false);
223
+ const selectedItems = ref([]);
224
+ // 对话框中临时保存的选中员工列表
225
+ const tempSelectedEmployees = ref([]);
226
+ // 是否查询子部门
227
+ const childDeptEnable = ref(false);
228
+
229
+ // 数据源
230
+ const organizationData = ref([]);
231
+ const roleData = ref([]);
232
+ const positionData = ref([]);
233
+ const departmentData = ref([]);
234
+ const subordinateData = ref([]);
235
+ const employeeList = ref([]);
236
+ const currentActive = ref([]);
237
+ const currentNodeName = ref('');
238
+ const selectAll = ref(false);
239
+
240
+ // 从名称中获取头像显示文本
241
+ const getAvatarText = (name) => {
242
+ return name ? name.substring(0, 1) : '';
243
+ };
244
+
245
+ // 处理组织数据,转换为树形结构
246
+ const _processOrgData = (data) => {
247
+ // 转换数据结构为树形结构
248
+ const map = {};
249
+ const result = [];
250
+
251
+ data.forEach(item => {
252
+ map[item.id] = {
253
+ ...item,
254
+ name: item.name,
255
+ id: item.id,
256
+ children: []
257
+ };
258
+ });
259
+
260
+ data.forEach(item => {
261
+ const node = map[item.id];
262
+
263
+ if (item.manager_dept && map[item.manager_dept]) {
264
+ map[item.manager_dept].children.push(node);
265
+ } else {
266
+ // 只有在显示根组织或不存在父节点时才添加到结果中
267
+ if (props.showRootOrg || !item.manager_dept) {
268
+ result.push(node);
269
+ }
270
+ }
271
+ });
272
+
273
+ return result;
274
+ };
275
+
276
+ // 更新全选状态
277
+ const updateSelectAllStatus = () => {
278
+ selectAll.value = employeeList.value.length > 0 && employeeList.value.every(item => item.checked);
279
+ };
280
+
281
+ // 选中的员工列表
282
+ const selectedEmployees = computed(() => {
283
+ return employeeList.value.filter((item) => item.checked);
284
+ });
285
+
286
+ // 根据搜索文本过滤的员工列表
287
+ const filteredEmployeeList = computed(() => {
288
+ if (!searchText.value) {
289
+ return employeeList.value;
290
+ }
291
+
292
+ const keyword = searchText.value.toLowerCase();
293
+ return employeeList.value.filter((item) => {
294
+ return (
295
+ item.name.toLowerCase().includes(keyword) ||
296
+ (item.pinyin && item.pinyin.toLowerCase().includes(keyword)) ||
297
+ (item.code && item.code.toLowerCase().includes(keyword))
298
+ );
299
+ });
300
+ });
301
+
302
+ // 获取组织架构数据
303
+ const fetchOrganizationData = async () => {
304
+ loading.value = true;
305
+ try {
306
+ const response = await dataService.fetch(
307
+ {},
308
+ {
309
+ apiId: 1933,
310
+ key: 'organizationalStructure'
311
+ },"/process/deptList"
312
+ );
313
+ organizationData.value = response
314
+ // organizationData.value = processOrgData(response.data || []);
315
+ } catch (error) {
316
+ MessagePlugin.error({
317
+ content: '获取组织架构数据失败',
318
+ duration: 3000
319
+ });
320
+ } finally {
321
+ loading.value = false;
322
+ }
323
+ };
324
+
325
+ // 获取角色数据
326
+ const fetchRoleData = async () => {
327
+ loading.value = true;
328
+ try {
329
+ const response = await dataService.fetch(
330
+ {},
331
+ {},
332
+ '/process/roleList'
333
+ );
334
+ roleData.value = response || [];
335
+ } catch (error) {
336
+ MessagePlugin.error({
337
+ content: '获取角色数据失败',
338
+ duration: 3000
339
+ });
340
+ } finally {
341
+ loading.value = false;
342
+ }
343
+ };
344
+
345
+ // 获取岗位数据
346
+ const fetchPositionData = async () => {
347
+ loading.value = true;
348
+ try {
349
+ const response = await dataService.fetch(
350
+ {},
351
+ {
352
+ },
353
+ '/process/roleList'
354
+ );
355
+ positionData.value = response?.data || [];
356
+ } catch (error) {
357
+ MessagePlugin.error({
358
+ content: '获取岗位数据失败',
359
+ duration: 3000
360
+ });
361
+ } finally {
362
+ loading.value = false;
363
+ }
364
+ };
365
+
366
+ // 获取部门数据
367
+ const fetchDepartmentData = async () => {
368
+ loading.value = true;
369
+ try {
370
+ const response = await dataService.fetch(
371
+ {},
372
+ {
373
+ apiId: 1933,
374
+ key: 'departmentList',
375
+ apiType: 'MULTIPLE_DATA_SEARCH'
376
+ }
377
+ );
378
+ departmentData.value = response?.data || [];
379
+ } catch (error) {
380
+ MessagePlugin.error({
381
+ content: '获取部门数据失败',
382
+ duration: 3000
383
+ });
384
+ } finally {
385
+ loading.value = false;
386
+ }
387
+ };
388
+
389
+ // 获取下属数据
390
+ const fetchSubordinateData = async () => {
391
+ loading.value = true;
392
+ try {
393
+ const response = await dataService.fetch(
394
+ {},
395
+ {
396
+ apiKey: 'subordinateList',
397
+ apiType: 'MULTIPLE_DATA_SEARCH'
398
+ }
399
+ );
400
+ subordinateData.value = response?.data || [];
401
+ } catch (error) {
402
+ MessagePlugin.error({
403
+ content: '获取下属数据失败',
404
+ duration: 3000
405
+ });
406
+ } finally {
407
+ loading.value = false;
408
+ }
409
+ };
410
+
411
+ // 根据节点ID获取员工列表
412
+ const fetchEmployeesByNode = async (nodeId, type, keyword = searchText.value) => {
413
+ loading.value = true;
414
+
415
+ try {
416
+ const params = {};
417
+
418
+ // 只有当nodeId不为空且type有效时,添加对应参数
419
+ if (nodeId && type) {
420
+ // 根据不同类型设置不同的查询参数
421
+ switch (type) {
422
+ case 'organization':
423
+ params.deptId = Array.isArray(nodeId) ? nodeId[0] : nodeId;
424
+ // 添加子部门查询参数
425
+ params.childDeptEnable = childDeptEnable.value;
426
+ break;
427
+ case 'role':
428
+ params.roleId = nodeId;
429
+ break;
430
+ case 'position':
431
+ params.positionId = nodeId;
432
+ break;
433
+ case 'department':
434
+ params.departmentId = nodeId;
435
+ break;
436
+ case 'subordinate':
437
+ params.managerId = nodeId;
438
+ break;
439
+ }
440
+ }
441
+
442
+ // 如果有搜索关键词,添加到查询参数中
443
+ if (keyword) {
444
+ params.keyWord = keyword;
445
+ }
446
+
447
+ const response = await dataService.fetch(
448
+ params,
449
+ {},
450
+ '/process/userList'
451
+ );
452
+
453
+ // 获取当前已选择的员工ID列表
454
+ const selectedIds = new Set(tempSelectedEmployees.value.map(emp => emp.id));
455
+
456
+ // 处理返回数据,添加checked属性,保留已选状态
457
+ const employees = (response || []).map(emp => ({
458
+ ...emp,
459
+ checked: selectedIds.has(emp.id)
460
+ }));
461
+
462
+ employeeList.value = employees;
463
+ updateSelectAllStatus();
464
+ } catch (error) {
465
+ MessagePlugin.error({
466
+ content: '获取员工列表失败',
467
+ duration: 3000
468
+ });
469
+ } finally {
470
+ loading.value = false;
471
+ }
472
+ };
473
+
474
+ // 根据ID列表批量获取员工信息
475
+ const fetchEmployeesByIds = async (ids) => {
476
+ if (!ids || ids.length === 0) {
477
+ selectedItems.value = [];
478
+ return;
479
+ }
480
+
481
+ loading.value = true;
482
+ try {
483
+ const response = await dataService.fetch(
484
+ {
485
+ userIds: ids // 使用新的接口参数格式
486
+ },
487
+ {},
488
+ '/process/userList' // 直接使用新的API路径
489
+ );
490
+
491
+ if (response && Array.isArray(response)) {
492
+ selectedItems.value = response;
493
+ } else {
494
+ selectedItems.value = [];
495
+ MessagePlugin.warning({
496
+ content: '获取员工详情返回的数据格式不正确',
497
+ duration: 3000
498
+ });
499
+ }
500
+ } catch (error) {
501
+ selectedItems.value = [];
502
+ MessagePlugin.error({
503
+ content: '获取员工详情失败: ' + (error.message || '未知错误'),
504
+ duration: 3000
505
+ });
506
+ } finally {
507
+ loading.value = false;
508
+ }
509
+ };
510
+
511
+ // 处理节点激活
512
+ const handleActive = (value, context) => {
513
+ currentActive.value = [value];
514
+ currentNodeName.value = context.node?.label || '';
515
+
516
+ // 获取该节点下的员工
517
+ fetchEmployeesByNode(value, activeTab.value);
518
+ };
519
+
520
+ // 选择部门
521
+ const selectDepartment = (department) => {
522
+ currentNodeName.value = department.name;
523
+ fetchEmployeesByNode(department.id, activeTab.value);
524
+ };
525
+
526
+ // 处理全选
527
+ const handleSelectAll = (checked) => {
528
+ employeeList.value.forEach(item => {
529
+ item.checked = checked;
530
+
531
+ // 如果选中,确保添加到临时选中列表
532
+ if (checked && !tempSelectedEmployees.value.some(emp => emp.id === item.id)) {
533
+ tempSelectedEmployees.value.push(item);
534
+ }
535
+ });
536
+ };
537
+
538
+ // 处理选中状态变更
539
+ const handleCheckChange = (item) => {
540
+ // 单选模式下,取消其他选中
541
+ if (props.single && item.checked) {
542
+ employeeList.value.forEach(emp => {
543
+ if (emp.id !== item.id) {
544
+ emp.checked = false;
545
+ }
546
+ });
547
+
548
+ // 单选模式下,直接替换tempSelectedEmployees
549
+ tempSelectedEmployees.value = item.checked ? [item] : [];
550
+ } else {
551
+ // 多选模式
552
+ // 如果选中,添加到临时选中列表
553
+ if (item.checked && !tempSelectedEmployees.value.some(emp => emp.id === item.id)) {
554
+ tempSelectedEmployees.value.push(item);
555
+ } else if (!item.checked) {
556
+ // 如果取消选中,从临时选中列表中移除
557
+ const index = tempSelectedEmployees.value.findIndex(emp => emp.id === item.id);
558
+ if (index !== -1) {
559
+ tempSelectedEmployees.value.splice(index, 1);
560
+ }
561
+ }
562
+ }
563
+
564
+ // 检查最大选择数量限制
565
+ if (props.maxCount > 0) {
566
+ const checkedCount = tempSelectedEmployees.value.length;
567
+ if (checkedCount > props.maxCount) {
568
+ item.checked = false;
569
+ const index = tempSelectedEmployees.value.findIndex(emp => emp.id === item.id);
570
+ if (index !== -1) {
571
+ tempSelectedEmployees.value.splice(index, 1);
572
+ }
573
+ MessagePlugin.warning({
574
+ content: `最多只能选择${props.maxCount}个人员`,
575
+ duration: 3000
576
+ });
577
+ }
578
+ }
579
+
580
+ updateSelectAllStatus();
581
+ };
582
+
583
+ // 移除已选择的项目
584
+ const removeItem = (index, id) => {
585
+ // 移除ID
586
+ const newIds = [...props.modelValue];
587
+ const idIndex = newIds.indexOf(id);
588
+ if (idIndex !== -1) {
589
+ newIds.splice(idIndex, 1);
590
+ emit('update:modelValue', newIds);
591
+ emit('change', newIds);
592
+ }
593
+
594
+ // 移除展示项
595
+ selectedItems.value.splice(index, 1);
596
+ };
597
+
598
+ // 从已选列表中移除员工
599
+ const removeSelectedEmployee = (employee) => {
600
+ // 将员工的checked状态设为false
601
+ const foundEmployee = employeeList.value.find(item => item.id === employee.id);
602
+ if (foundEmployee) {
603
+ foundEmployee.checked = false;
604
+ }
605
+
606
+ // 从临时选中列表中移除
607
+ const index = tempSelectedEmployees.value.findIndex(emp => emp.id === employee.id);
608
+ if (index !== -1) {
609
+ tempSelectedEmployees.value.splice(index, 1);
610
+ }
611
+
612
+ // 更新全选状态
613
+ updateSelectAllStatus();
614
+ };
615
+
616
+ // 初始化选择器
617
+ const initSelector = async () => {
618
+ // 获取数据
619
+ if (activeTab.value === 'organization' && organizationData.value.length === 0) {
620
+ await fetchOrganizationData();
621
+ } else if (activeTab.value === 'role' && roleData.value.length === 0) {
622
+ await fetchRoleData();
623
+ } else if (activeTab.value === 'position' && positionData.value.length === 0) {
624
+ await fetchPositionData();
625
+ } else if (activeTab.value === 'department' && departmentData.value.length === 0) {
626
+ await fetchDepartmentData();
627
+ } else if (activeTab.value === 'subordinate' && subordinateData.value.length === 0) {
628
+ await fetchSubordinateData();
629
+ }
630
+ };
631
+
632
+ // 显示对话框
633
+ const showDialog = () => {
634
+ // 初始化临时选中列表
635
+ if (selectedItems.value.length > 0) {
636
+ tempSelectedEmployees.value = [...selectedItems.value];
637
+ } else {
638
+ tempSelectedEmployees.value = [];
639
+ }
640
+
641
+ // 初始化数据
642
+ initSelector();
643
+ dialogVisible.value = true;
644
+ };
645
+
646
+ // 确认选择
647
+ const handleConfirm = () => {
648
+ const selectedEmployeeIds = tempSelectedEmployees.value.map(item => item.id);
649
+
650
+ emit('update:modelValue', selectedEmployeeIds);
651
+ emit('change', selectedEmployeeIds);
652
+ dialogVisible.value = false;
653
+ };
654
+
655
+ // 取消选择
656
+ const handleCancel = () => {
657
+ // 放弃临时选择
658
+ tempSelectedEmployees.value = [];
659
+ dialogVisible.value = false;
660
+ };
661
+
662
+ // 监听标签页切换
663
+ watch(activeTab, () => {
664
+ // 切换标签页时重新加载数据
665
+ initSelector();
666
+ });
667
+
668
+ // 监听modelValue变化,更新展示的员工信息
669
+ watch(() => props.modelValue, (newIds, oldIds) => {
670
+ // 判断值是否真的变化了 (通过比较JSON字符串)
671
+ const newIdsStr = JSON.stringify(newIds || []);
672
+ const oldIdsStr = JSON.stringify(oldIds || []);
673
+
674
+ if (newIdsStr !== oldIdsStr) {
675
+ // 获取员工详情数据
676
+ fetchEmployeesByIds(newIds);
677
+ }
678
+ }, { immediate: true, deep: true });
679
+
680
+ // 监听选中员工变化,更新临时已选列表
681
+ watch(selectedEmployees, (newVal) => {
682
+ // 更新临时选中列表,保留之前不在当前列表中的已选员工
683
+ const currentIds = new Set(newVal.map(emp => emp.id));
684
+
685
+ // 移除tempSelectedEmployees中已经不再选中的员工
686
+ tempSelectedEmployees.value = tempSelectedEmployees.value.filter(emp =>
687
+ !currentIds.has(emp.id) || newVal.some(item => item.id === emp.id)
688
+ );
689
+
690
+ // 添加新选中的员工
691
+ newVal.forEach(emp => {
692
+ if (!tempSelectedEmployees.value.some(item => item.id === emp.id)) {
693
+ tempSelectedEmployees.value.push(emp);
694
+ }
695
+ });
696
+ }, { deep: true });
697
+
698
+ // 监听子部门查询开关变化
699
+ watch(childDeptEnable, () => {
700
+ // 如果当前在组织架构页面且有选中节点,重新加载员工列表
701
+ if (activeTab.value === 'organization' && currentActive.value && currentActive.value.length > 0) {
702
+ fetchEmployeesByNode(currentActive.value[0], activeTab.value);
703
+ }
704
+ });
705
+
706
+ // 防抖函数
707
+ const debounce = (fn, delay) => {
708
+ let timer = null;
709
+ return function(...args) {
710
+ if (timer) clearTimeout(timer);
711
+ timer = setTimeout(() => {
712
+ fn.apply(this, args);
713
+ }, delay);
714
+ };
715
+ };
716
+
717
+ // 防抖处理过的搜索函数
718
+ const debouncedSearch = debounce((keyword) => {
719
+ if (keyword) {
720
+ const nodeId = currentActive.value && currentActive.value.length > 0 ? currentActive.value[0] : null;
721
+ const type = nodeId ? activeTab.value : null;
722
+ fetchEmployeesByNode(nodeId, type, keyword);
723
+ } else if (currentActive.value && currentActive.value.length > 0) {
724
+ // 如果搜索框清空,恢复显示当前选中节点的员工列表
725
+ fetchEmployeesByNode(currentActive.value[0], activeTab.value);
726
+ } else {
727
+ // 如果没有选中节点,清空员工列表
728
+ employeeList.value = [];
729
+ }
730
+ }, 300); // 300ms防抖
731
+
732
+ // 监听搜索文本变化,触发搜索
733
+ watch(searchText, (newValue) => {
734
+ debouncedSearch(newValue);
735
+ }, { immediate: false });
736
+
737
+ // 组件挂载时执行
738
+ onMounted(() => {
739
+ // 获取已选员工详情
740
+ fetchEmployeesByIds(props.modelValue);
741
+ });
742
+
743
+ // 处理搜索图标点击
744
+ const handleSearchClick = () => {
745
+ if (searchText.value) {
746
+ const nodeId = currentActive.value && currentActive.value.length > 0 ? currentActive.value[0] : null;
747
+ const type = nodeId ? activeTab.value : null;
748
+ fetchEmployeesByNode(nodeId, type, searchText.value);
749
+ }
750
+ };
751
+
752
+ // 处理回车键搜索
753
+ const handleSearchEnter = () => {
754
+ if (searchText.value) {
755
+ const nodeId = currentActive.value && currentActive.value.length > 0 ? currentActive.value[0] : null;
756
+ const type = nodeId ? activeTab.value : null;
757
+ fetchEmployeesByNode(nodeId, type, searchText.value);
758
+ }
759
+ };
760
+
761
+ // 清除搜索
762
+ const clearSearch = () => {
763
+ searchText.value = '';
764
+ if (currentActive.value && currentActive.value.length > 0) {
765
+ fetchEmployeesByNode(currentActive.value[0], activeTab.value);
766
+ } else {
767
+ // 如果没有选中节点,重置员工列表但保留选中状态
768
+ employeeList.value = employeeList.value.map(emp => ({
769
+ ...emp,
770
+ checked: tempSelectedEmployees.value.some(item => item.id === emp.id)
771
+ }));
772
+ }
773
+ };
774
+ </script>
775
+
776
+ <style scoped>
777
+ .ebiz-employee-selector {
778
+ width: 100%;
779
+ display: flex;
780
+ flex-direction: column;
781
+ }
782
+
783
+ /* 选择框展示区 */
784
+ .employee-selector-container {
785
+ min-height: 32px;
786
+ width: 100%;
787
+ border: 1px solid #dcdcdc;
788
+ border-radius: 3px;
789
+ padding: 4px 8px;
790
+ display: flex;
791
+ flex-wrap: wrap;
792
+ gap: 8px;
793
+ align-items: center;
794
+ }
795
+
796
+ .selected-items {
797
+ display: flex;
798
+ flex-wrap: wrap;
799
+ gap: 8px;
800
+ }
801
+
802
+ .selected-item {
803
+ display: flex;
804
+ align-items: center;
805
+ background-color: #f0f0f0;
806
+ border-radius: 3px;
807
+ padding: 2px 8px 2px 2px;
808
+ gap: 8px;
809
+ }
810
+
811
+ .item-info {
812
+ display: flex;
813
+ align-items: center;
814
+ gap: 4px;
815
+ }
816
+
817
+ .item-code {
818
+ color: #999;
819
+ font-size: 12px;
820
+ }
821
+
822
+ .item-name {
823
+ font-size: 14px;
824
+ }
825
+
826
+ .item-remove {
827
+ cursor: pointer;
828
+ color: #999;
829
+ font-size: 12px;
830
+ }
831
+
832
+ .item-remove:hover {
833
+ color: #E34D59;
834
+ }
835
+
836
+ /* 选择弹窗 */
837
+ .selector-dialog-content {
838
+ display: flex;
839
+ height: 500px;
840
+ }
841
+
842
+ .left-panel, .right-panel {
843
+ height: 100%;
844
+ overflow: hidden;
845
+ display: flex;
846
+ flex-direction: column;
847
+ }
848
+
849
+ .left-panel {
850
+ width: 40%;
851
+ border-right: 1px solid #dcdcdc;
852
+ padding-right: 16px;
853
+ }
854
+
855
+ .right-panel {
856
+ width: 60%;
857
+ padding-left: 16px;
858
+ }
859
+
860
+ .search-box {
861
+ margin-bottom: 16px;
862
+ }
863
+
864
+ .right-panel .search-box {
865
+ margin-top: 8px;
866
+ margin-bottom: 16px;
867
+ display: flex;
868
+ align-items: center;
869
+ gap: 8px;
870
+ }
871
+
872
+ .right-panel .search-box .t-input {
873
+ width: 100%;
874
+ border-radius: 4px;
875
+ }
876
+
877
+ .right-panel .search-box .t-input__suffix-icon {
878
+ cursor: pointer;
879
+ }
880
+
881
+ .right-panel .search-box .t-input__suffix-icon:hover {
882
+ color: var(--td-brand-color);
883
+ }
884
+
885
+ .selector-tabs {
886
+ margin-bottom: 16px;
887
+ }
888
+
889
+ .content-area {
890
+ flex: 1;
891
+ overflow: auto;
892
+ position: relative;
893
+ }
894
+
895
+ .loading-container {
896
+ position: absolute;
897
+ top: 0;
898
+ left: 0;
899
+ right: 0;
900
+ bottom: 0;
901
+ display: flex;
902
+ justify-content: center;
903
+ align-items: center;
904
+ background-color: rgba(255, 255, 255, 0.6);
905
+ z-index: 1;
906
+ }
907
+
908
+ .tab-content {
909
+ height: 100%;
910
+ overflow: auto;
911
+ }
912
+
913
+ .department-item {
914
+ cursor: pointer;
915
+ padding: 8px;
916
+ }
917
+
918
+ .department-item:hover {
919
+ background-color: #f5f5f5;
920
+ }
921
+
922
+ .employee-header {
923
+ display: flex;
924
+ justify-content: space-between;
925
+ align-items: center;
926
+ margin-bottom: 16px;
927
+ }
928
+
929
+ .employee-title {
930
+ font-weight: bold;
931
+ font-size: 16px;
932
+ display: flex;
933
+ align-items: center;
934
+ gap: 10px;
935
+ }
936
+
937
+ .sub-dept-option {
938
+ margin-left: 10px;
939
+ font-weight: normal;
940
+ font-size: 14px;
941
+ }
942
+
943
+ .employee-count {
944
+ display: flex;
945
+ align-items: center;
946
+ gap: 8px;
947
+ }
948
+
949
+ .count-info {
950
+ color: #999;
951
+ font-size: 14px;
952
+ }
953
+
954
+ .employee-list {
955
+ flex: 1;
956
+ overflow: auto;
957
+ display: flex;
958
+ flex-direction: column;
959
+ gap: 8px;
960
+ }
961
+
962
+ .employee-item {
963
+ display: flex;
964
+ align-items: center;
965
+ gap: 12px;
966
+ padding: 8px;
967
+ border-radius: 4px;
968
+ }
969
+
970
+ .employee-item:hover {
971
+ background-color: #f5f5f5;
972
+ }
973
+
974
+ .employee-avatar {
975
+ display: flex;
976
+ align-items: center;
977
+ }
978
+
979
+ .employee-info {
980
+ display: flex;
981
+ gap: 8px;
982
+ align-items: center;
983
+ }
984
+
985
+ .employee-code {
986
+ color: #999;
987
+ font-size: 12px;
988
+ }
989
+
990
+ .employee-name {
991
+ font-size: 14px;
992
+ }
993
+
994
+ .empty-data {
995
+ display: flex;
996
+ justify-content: center;
997
+ align-items: center;
998
+ height: 200px;
999
+ }
1000
+
1001
+ .dialog-footer {
1002
+ display: flex;
1003
+ justify-content: space-between;
1004
+ align-items: center;
1005
+ padding: 16px 0;
1006
+ }
1007
+
1008
+ .selected-preview {
1009
+ color: #666;
1010
+ }
1011
+
1012
+ .dialog-actions {
1013
+ display: flex;
1014
+ gap: 8px;
1015
+ }
1016
+
1017
+ .selected-people-list {
1018
+ margin-top: 8px;
1019
+ display: flex;
1020
+ flex-wrap: wrap;
1021
+ gap: 8px;
1022
+ }
1023
+
1024
+ .selected-people-item {
1025
+ display: flex;
1026
+ align-items: center;
1027
+ background-color: #f0f0f0;
1028
+ border-radius: 3px;
1029
+ padding: 2px 8px 2px 2px;
1030
+ gap: 8px;
1031
+ }
1032
+
1033
+ .selected-people-item:hover {
1034
+ background-color: #e0e0e0;
1035
+ }
1036
+
1037
+ .selected-people-item .item-remove {
1038
+ cursor: pointer;
1039
+ color: #999;
1040
+ font-size: 12px;
1041
+ }
1042
+
1043
+ .selected-people-item .item-remove:hover {
1044
+ color: #E34D59;
1045
+ }
1046
+ </style>