address-book-shell 0.0.40 → 0.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "address-book-shell",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "private": false,
5
5
  "author": "houdajian@163.com",
6
6
  "main": "lib/address-book-shell.umd.js",
@@ -125,6 +125,8 @@ export default {
125
125
  this.treeData = Object.freeze(res.nodes.children)
126
126
  // console.log(this.treeData, 'treeData')
127
127
  if (cb) {
128
+ console.log('this.currentNode', this.currentNode)
129
+
128
130
  this.$nextTick(() => {
129
131
  cb({ depId: this.currentNode })
130
132
  })
@@ -161,79 +163,91 @@ export default {
161
163
  },
162
164
  // 部门选择
163
165
  handleSelectDep(item) {
166
+ // 统一 depId 字段
164
167
  item.depId = item.depId || item.depid
165
- //在这次选中节点之前被选中的节点
166
- let lastNode = null
167
- let currentNode = null
168
- if (this.$refs.videoTree && this.$refs.videoTree.getCurrentNode()) {
169
- lastNode = this.$refs.videoTree.getNode(this.$refs.videoTree.getCurrentNode())
170
- //这次选中的节点
171
- currentNode = this.$refs.videoTree.getNode(item.depId)
172
- }
173
- // console.log(lastNode, 'lastNode')
174
168
 
169
+ // 获取树组件实例
170
+ const tree = this.$refs.videoTree
171
+ if (!tree) return
172
+
173
+ // 获取当前节点
174
+ const currentNode = tree.getNode(item.depId)
175
175
  if (!currentNode) return
176
- //收起之前因选中而展开的节点
177
- if (lastNode) {
178
- if (lastNode.level) {
179
- let parentLevel
180
- do {
181
- lastNode.expanded = false
182
- lastNode = lastNode.parent
183
- parentLevel = lastNode.level
184
- } while (parentLevel)
185
- }
176
+
177
+ // 收起之前展开的节点
178
+ const lastNode = tree.getCurrentNode() && tree.getNode(tree.getCurrentNode())
179
+ if (lastNode && lastNode.level) {
180
+ let node = lastNode
181
+ do {
182
+ node.expanded = false
183
+ node = node.parent
184
+ } while (node && node.level)
186
185
  }
187
186
 
188
- let currentNodeId = currentNode.data.itemTypeId
189
- let parentLevel
190
- let nodeIndex = 0 //当前选中节点在当前树的位置
191
- //计算nodeCount和nodeIndex
192
- do {
193
- // 获取当前部门的父级部门数据
194
- currentNode = currentNode.parent
195
- // 保存父级部门level值
196
- parentLevel = currentNode.level
197
- let childNodes = currentNode.childNodes
187
+ // 计算节点位置
188
+ let nodeIndex = 0
189
+ let node = currentNode
190
+ let currentNodeId = node.data.itemTypeId
191
+
192
+ while (node.parent && node.parent.level) {
193
+ const parentNode = node.parent
194
+ const childNodes = parentNode.childNodes
195
+
198
196
  for (let i = 0; i < childNodes.length; i++) {
199
- if (childNodes[i].data.itemTypeId == currentNodeId) {
200
- // 计算当前选中的部门在其父部分的第几个
197
+ if (childNodes[i].data.itemTypeId === currentNodeId) {
201
198
  nodeIndex += i + 1
199
+ break
202
200
  }
203
201
  }
204
- // 保存当前部门的部门id,用于查找其在父级部门第几个
205
- currentNodeId = currentNode.data.itemTypeId
206
- } while (parentLevel)
207
- // 展开选中的节点
202
+
203
+ node = parentNode
204
+ currentNodeId = node.data.itemTypeId
205
+ }
206
+
207
+ // 展开并选中当前节点
208
208
  this.expandedKeys = [item.depId]
209
- // 选中节点
210
- this.$refs.videoTree.setCurrentKey(item.depId)
211
- // 获取 侧边导航盒子高度
212
- let scrollHeight = this.$refs['address-aside-scroll'].$el.offsetHeight
213
- //一个节点的高度是35px
214
- let nodeHight = 35
215
- // 需要滚动的距离
216
- console.log(nodeIndex, nodeHight)
217
- this.setTop = nodeIndex * nodeHight - scrollHeight / 2
218
- console.log(this.setTop, 'this.setTop')
219
- if (8 < nodeIndex) {
220
- this.setScrollheight(this.setTop, 500)
221
- } else {
222
- this.setScrollheight(0, 500)
209
+ tree.setCurrentKey(item.depId)
210
+
211
+ // 计算滚动位置并执行滚动
212
+ const addressAsideScroll = this.$refs['address-aside-scroll']
213
+ if (!addressAsideScroll || !addressAsideScroll.$el) return
214
+ const scrollContainer = addressAsideScroll.$el
215
+ if (scrollContainer) {
216
+ const scrollHeight = scrollContainer.offsetHeight
217
+ const nodeHeight = 35 // 节点高度
218
+ const scrollTop = nodeIndex * nodeHeight - scrollHeight / 2
219
+
220
+ if (nodeIndex > 8) {
221
+ this.setScrollheight(scrollTop, 500)
222
+ } else {
223
+ this.setScrollheight(0, 500)
224
+ }
223
225
  }
226
+
227
+ // 触发数据更新
224
228
  this.$emit('asideChange', item)
225
229
  },
226
230
 
227
231
  // 部门搜索清除
228
232
  clearSearchHandler() {
233
+ // 重置搜索状态
229
234
  this.depname = ''
230
235
  this.currentNode = ''
231
- this.$refs.videoTree.setCurrentKey(this.currentNode)
232
- const tree = this.$refs.videoTree.store.nodesMap
233
- for (let key in tree) {
234
- tree[key].expanded = false
236
+
237
+ // 重置树状态
238
+ const tree = this.$refs.videoTree
239
+ if (tree) {
240
+ tree.setCurrentKey(this.currentNode)
241
+
242
+ // 收起所有节点
243
+ if (tree.store && tree.store.nodesMap) {
244
+ Object.values(tree.store.nodesMap).forEach((node) => {
245
+ node.expanded = false
246
+ })
247
+ }
235
248
  }
236
- // this.$emit('asideChange', null)
249
+
250
+ // 清空自动完成列表并通知父组件
237
251
  this.autocompleteCB([])
238
252
  this.$emit('asideChange', null)
239
253
  },
@@ -192,6 +192,7 @@ export default {
192
192
 
193
193
  myFriengInput: '',
194
194
  loadingTimer: null,
195
+ isAllSelected: false, // 是否全选
195
196
  }
196
197
  },
197
198
 
@@ -329,6 +330,9 @@ export default {
329
330
  item.hrId = item.hrId || ''
330
331
  item.avatar = item.userImage || ''
331
332
  })
333
+ if (this.isAllSelected) {
334
+ this.$emit('addSelectionList', data.detail)
335
+ }
332
336
  }
333
337
  table.loading = false
334
338
  if (initScrollTop) {
@@ -349,31 +353,31 @@ export default {
349
353
  },
350
354
  setDisableSelect() {
351
355
  const hasDisableData = this.selectDisabledlist.length
352
-
356
+
353
357
  // 如果没有需要设置的条件,直接返回
354
358
  if (!this.disableLeaderSelection && !hasDisableData) {
355
359
  return
356
360
  }
357
-
361
+
358
362
  // 创建禁用列表的 Map 以提高查找效率
359
- const disabledMap = hasDisableData
360
- ? new Map(this.selectDisabledlist.map(item => [item.hrId, true]))
363
+ const disabledMap = hasDisableData
364
+ ? new Map(this.selectDisabledlist.map((item) => [item.hrId, true]))
361
365
  : new Map()
362
-
366
+
363
367
  // 遍历数据并设置禁用状态
364
- this.table.tableDataList.forEach(item => {
368
+ this.table.tableDataList.forEach((item) => {
365
369
  let shouldDisable = false
366
-
370
+
367
371
  // 检查是否禁用领导
368
372
  if (this.disableLeaderSelection && (item.depid === 'D1' || item.depId === 'D1')) {
369
373
  shouldDisable = true
370
374
  }
371
-
375
+
372
376
  // 检查是否在禁用列表中
373
377
  if (!shouldDisable && hasDisableData && disabledMap.has(item.hrId)) {
374
378
  shouldDisable = true
375
379
  }
376
-
380
+
377
381
  // 只有状态发生变化时才更新,避免不必要的变更
378
382
  if (shouldDisable !== item.disable) {
379
383
  item.disable = shouldDisable
@@ -384,56 +388,40 @@ export default {
384
388
  recoverySelect(falg = false, item = null) {
385
389
  let data = this.table.tableDataList
386
390
  if (!item) {
387
- // 如果不传item,比较费性能,不推荐
388
391
  this.emptySelect()
389
392
  this.$nextTick(() => {
390
- // item为数组则表示恢复多个table勾选状态
391
- let arr = this.selected
392
- if (arr.length) {
393
- arr.forEach((item) => {
394
- // item.badge = item.badge || item.fdBadge
395
- let hasArr = data.filter((it) => {
396
- return item.hrId === it.hrId
397
- })
398
- if (hasArr.length) {
399
- hasArr.forEach((i) => {
400
- this.toggleRowSelection(i, true)
401
- })
402
- }
403
- })
404
- }
393
+ if (!this.selected.length) return
394
+ const dataMap = new Map(data.map((row) => [row.hrId, row]))
395
+ this.selected.forEach((selectedItem) => {
396
+ const matchedRow = dataMap.get(selectedItem.hrId)
397
+ if (matchedRow) {
398
+ this.toggleRowSelection(matchedRow, true)
399
+ }
400
+ })
405
401
  })
406
402
  } else {
407
403
  // 有item 不用对比数据,直接恢复勾选,推荐
408
404
  // 传item必须传flag,true 勾选; false 取消勾选
409
- return
410
- // if (item?.constructor === Object) {
411
- // // item为对象,则表示恢复单个状态
412
- // item.badge = item.badge || item.fdBadge
413
- // for (let i = 0; i < data.length; i++) {
414
- // if (
415
- // item.badge === data[i].tagProfileCustomBadge ||
416
- // item.badge === data[i].badge
417
- // ) {
418
- // console.log(data[i], 'data[i]')
419
- // this.toggleRowSelection(data[i], falg, true)
420
- // break
421
- // }
422
- // }
423
- // } else {
424
- // let hasArr = []
425
- // item.forEach((it) => {
426
- // let i = this.objectInArrayIndex(data, it, 'badge')
427
- // if (i > -1) {
428
- // hasArr.push(data[i])
429
- // }
430
- // })
431
- // if (hasArr.length) {
432
- // hasArr.forEach((i) => {
433
- // this.toggleRowSelection(i, falg, true)
434
- // })
435
- // }
436
- // }
405
+ if (Array.isArray(item)) {
406
+ // item为数组,表示恢复多个状态
407
+ const dataMap = new Map(data.map((row) => [row.badge, row]))
408
+ item.forEach((it) => {
409
+ const badge = it.badge || it.fdBadge
410
+ const matchedRow = dataMap.get(badge)
411
+ if (matchedRow) {
412
+ this.toggleRowSelection(matchedRow, falg)
413
+ }
414
+ })
415
+ } else if (item && typeof item === 'object') {
416
+ // item为对象,表示恢复单个状态
417
+ const badge = item.badge || item.fdBadge
418
+ const matchedRow = data.find(
419
+ (row) => row.tagProfileCustomBadge === badge || row.badge === badge
420
+ )
421
+ if (matchedRow) {
422
+ this.toggleRowSelection(matchedRow, falg)
423
+ }
424
+ }
437
425
  }
438
426
  },
439
427
  // 清空勾选状态
@@ -441,35 +429,66 @@ export default {
441
429
  this.$refs.addressTable.clearSelection()
442
430
  },
443
431
  tableScroll() {
444
- let table = this.table
445
- let scrollTop = table.tableDom.scrollTop // 滚动距离
446
- let scrollHeight = table.tableDom.scrollHeight //滚动条高度
447
- let clientHeight = table.tableDom.clientHeight // table 高度
448
- let isBottom = scrollHeight - scrollTop - clientHeight < 100 //( 滚动条高度 - 滚动距离 - table 高度) = 0 则代表已经滚动到最底端
432
+ const table = this.table
433
+
434
+ // 边界检查
435
+ if (!table.tableDom || table.loading || table.flag) {
436
+ return
437
+ }
438
+
439
+ const scrollTop = table.tableDom.scrollTop // 滚动距离
440
+ const scrollHeight = table.tableDom.scrollHeight // 滚动条高度
441
+ const clientHeight = table.tableDom.clientHeight // table 高度
442
+ const isBottom = scrollHeight - scrollTop - clientHeight < 100 // 距离底部50px时触发
443
+
449
444
  if (isBottom) {
450
- let height = table.currentPage * 48 * table.pageSize
451
- console.log('scrollHeight888', scrollHeight, height)
452
- // 这里就是如果是满载的情况下继续加载,直到当前页都不是满载情况下那就是最后一页即不请求数据
453
- if (scrollHeight >= height) {
454
- // 表示有数据传入了table
445
+ const tableDataLength = table.tableDataList.length
446
+ const targetLength = table.pageSize * table.currentPage
447
+
448
+ // 检查是否需要加载更多数据
449
+ if (tableDataLength >= targetLength) {
450
+ // 表示当前页数据已满,需要加载下一页
455
451
  table.flag = true
456
452
  table.currentPage++
457
- this.recoverySelect()
458
453
  this.queryData()
459
454
  }
460
455
  }
461
456
  },
457
+ // 节流函数
458
+ throttle(func, delay) {
459
+ let timer = null
460
+ return function () {
461
+ if (!timer) {
462
+ timer = setTimeout(() => {
463
+ func.apply(this, arguments)
464
+ timer = null
465
+ }, delay)
466
+ }
467
+ }
468
+ },
469
+
462
470
  listenTableScroll() {
463
- if (this.$refs.addressTable && this.$refs.addressTable.bodyWrapper) {
471
+ const tableDom = this.$refs.addressTable
472
+ if (tableDom) {
464
473
  let table = this.table
465
- table.tableDom = this.$refs.addressTable.bodyWrapper
466
- table.tableDom.addEventListener('scroll', this.tableScroll)
474
+ // 兼容不同版本的 Element UI DOM 结构
475
+ const bodyWrapper = tableDom.bodyWrapperScrollbar || tableDom.bodyWrapper
476
+
477
+ if (bodyWrapper) {
478
+ table.tableDom = bodyWrapper
479
+ // 使用节流处理滚动事件
480
+ this.tableScroll = this.throttle(this.tableScroll, 200)
481
+ table.tableDom.addEventListener('scroll', this.tableScroll)
482
+ } else {
483
+ console.warn('Could not find table scroll container')
484
+ }
467
485
  }
468
486
  },
469
487
  initScrollTop() {
470
488
  this.$nextTick(() => {
471
- if (!this.table.tableDom) {
472
- this.table.tableDom = this.$refs.addressTable.bodyWrapper
489
+ const tableDom = this.$refs.addressTable
490
+ if (!this.table.tableDom && tableDom) {
491
+ this.table.tableDom = tableDom.bodyWrapperScrollbar || tableDom.bodyWrapper
473
492
  }
474
493
  this.table.tableDom.scrollTop = 0
475
494
  })
@@ -485,35 +504,32 @@ export default {
485
504
  },
486
505
  // 动勾选数据行的 Checkbox 时触发
487
506
  select(selection, item) {
488
- if(item.disable) return
489
- // console.log(selection, item, '动勾选数据行的 Checkbox 时触发')
507
+ if (item.disable) return
508
+
490
509
  if (this.radio) {
491
- // 单选
492
- if (selection.length == 2) {
510
+ // 单选模式
511
+ if (selection.length >= 2) {
493
512
  this.$refs.addressTable.clearSelection()
494
- this.$refs.addressTable.toggleRowSelection(selection[selection.length - 1]) //只显示选中最后一个 这时val还是多选的列表(就是你选中的几个数据)
513
+ if (selection.length === 2) {
514
+ this.$refs.addressTable.toggleRowSelection(selection[1])
515
+ }
495
516
  } else if (selection.length === 1) {
496
- this.selection = [selection[selection.length - 1]]
497
- } else if (selection.length > 2) {
498
- this.$refs.addressTable.clearSelection()
517
+ this.selection = [selection[0]]
499
518
  }
500
519
  }
501
- let isAdd = selection.findIndex((it) => it.hrId === item.hrId) > -1 ? true : false //是否为添加操作
502
- if (isAdd) {
503
- // 添加
504
- this.$emit('addSelectionItem', item)
505
- console.log('勾选数据', item)
506
- } else {
507
- // 删除操作
508
- this.$emit('deleteSelectionItem', item)
509
- }
520
+
521
+ // 判断是添加还是删除操作
522
+ const isAdd = selection.some(it => it.hrId === item.hrId)
523
+ this.$emit(isAdd ? 'addSelectionItem' : 'deleteSelectionItem', item)
510
524
  },
511
525
  selectAll(selection) {
512
526
  if (selection.length) {
513
527
  // 全选
528
+ this.isAllSelected = true
514
529
  this.$emit('addSelectionList', selection)
515
530
  } else {
516
531
  // 全取消
532
+ this.resetAllSelected()
517
533
  let dataList = this.table.tableDataList
518
534
  this.$emit('deleteSelectionList', dataList)
519
535
  }
@@ -521,12 +537,9 @@ export default {
521
537
  // 手动修改选中状态
522
538
  toggleRowSelection(data, flag = true) {
523
539
  this.$nextTick(() => {
524
- let i = this.table.tableDataList.findIndex((item) => {
525
- return item.hrId === data.hrId
526
- })
527
- if (i > -1) {
528
- // 如果删除的是当前显示的列表数据,直接在列表中取消勾选
529
- this.$refs.addressTable.toggleRowSelection(this.table.tableDataList[i], flag)
540
+ const matchedRow = this.table.tableDataList.find(item => item.hrId === data.hrId)
541
+ if (matchedRow) {
542
+ this.$refs.addressTable.toggleRowSelection(matchedRow, flag)
530
543
  }
531
544
  })
532
545
  },
@@ -668,6 +681,9 @@ export default {
668
681
  this.searchInput.searchToTable = false
669
682
  this.queryData()
670
683
  },
684
+ resetAllSelected() {
685
+ this.isAllSelected = false
686
+ },
671
687
  },
672
688
  computed: {
673
689
  currentTypeList() {
@@ -704,6 +720,22 @@ export default {
704
720
  this.loadingTimer = null
705
721
  }
706
722
  },
723
+ 'table.currentPage': {
724
+ handler(newVal) {
725
+ if (newVal === 1) {
726
+ console.log('当前页码', newVal)
727
+ this.resetAllSelected()
728
+ }
729
+ },
730
+ },
731
+ 'table.depId': {
732
+ handler(newVal, oldVal) {
733
+ if (newVal !== oldVal) {
734
+ console.log('部门id', newVal)
735
+ this.resetAllSelected()
736
+ }
737
+ },
738
+ },
707
739
  },
708
740
  destroyed() {
709
741
  this.table.tableDom.removeEventListener('scroll', this.tableScroll)
@@ -721,6 +753,9 @@ export default {
721
753
  &::before {
722
754
  height: 0;
723
755
  }
756
+ ::v-deep .el-scrollbar__wrap {
757
+ height: 100% !important;
758
+ }
724
759
  }
725
760
  height: 100%;
726
761
  width: 100%;
@@ -299,7 +299,7 @@
299
299
  </div>
300
300
 
301
301
  <div class="selected">
302
- <templete v-if="!showOnlyNewPersonnels">
302
+ <template v-if="!showOnlyNewPersonnels">
303
303
  <AddreddGroup
304
304
  class="selected-list"
305
305
  :class="nameImport ? 'has-name-import' : ''"
@@ -315,7 +315,7 @@
315
315
  >
316
316
  </AddreddGroup>
317
317
  <span v-show="!selectedList.length" class="no-selected-data">还未进行选择</span>
318
- </templete>
318
+ </template>
319
319
  <template v-else>
320
320
  <AddreddGroup
321
321
  class="selected-list"