@ebiz/designer-components 0.1.1 → 0.1.4

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