|
42 | 42 | @scroll="handleVirtualScroll" |
43 | 43 | > |
44 | 44 | <template #default="{ item }"> |
45 | | - <div |
46 | | - class="virtual-item-wrapper" |
47 | | - :class="{ |
48 | | - 'is-group-title': item.type === 'group-title', |
49 | | - 'is-conversation-item': item.type === 'item', |
50 | | - }" |
51 | | - > |
52 | | - <!-- 分组标题 --> |
53 | | - <div |
54 | | - v-if="item.type === 'group-title'" |
55 | | - class="el-x-conversation-group-title virtual-group-title" |
56 | | - > |
57 | | - <slot |
58 | | - name="group-title" |
59 | | - :group="item" |
60 | | - > |
61 | | - {{ item.title }} |
62 | | - </slot> |
63 | | - </div> |
64 | | - |
65 | | - <!-- 普通项目 --> |
| 45 | + <div class="virtual-item-wrapper"> |
| 46 | + <!-- 会话项目 --> |
66 | 47 | <conversations-item |
67 | | - v-else |
68 | 48 | :item="item" |
69 | 49 | :active="item.uniqueKey === active" |
70 | 50 | :items-style="itemsStyle" |
|
299 | 279 |
|
300 | 280 | <script> |
301 | 281 | import { get } from 'lodash'; |
302 | | - import ConversationsItem from './components/item.vue'; |
303 | 282 | import { RecycleScroller } from 'vue-virtual-scroller'; |
| 283 | + import ConversationsItem from './components/item.vue'; |
304 | 284 | export default { |
305 | 285 | name: 'ElXConversations', |
306 | 286 |
|
|
564 | 544 | if (this.shouldUseGrouping) { |
565 | 545 | const result = []; |
566 | 546 | this.groups.forEach(group => { |
567 | | - // 添加分组标题 |
568 | | - result.push({ |
569 | | - type: 'group-title', |
570 | | - key: `group-${group.key}`, |
571 | | - title: group.title, |
572 | | - groupKey: group.key, |
573 | | - isUngrouped: group.isUngrouped, |
574 | | - // 为虚拟滚动指定分组标题的高度 |
575 | | - virtualHeight: 40, // 分组标题高度 |
576 | | - size: 40, |
577 | | - }); |
578 | | - // 添加分组内容 |
| 547 | + // 直接添加分组内容,不添加分组标题项 |
579 | 548 | group.children.forEach(item => { |
580 | 549 | result.push({ |
581 | 550 | type: 'item', |
582 | 551 | ...item, |
583 | 552 | groupKey: group.key, |
| 553 | + groupTitle: group.title, // 添加分组标题信息用于粘性标题显示 |
| 554 | + isUngrouped: group.isUngrouped, |
584 | 555 | // 为虚拟滚动指定项目的高度 |
585 | 556 | virtualHeight: this.virtualScrollOptions.size || 60, |
586 | 557 | size: this.virtualScrollOptions.size || 60, |
|
829 | 800 | // 计算当前应该显示的粘性分组 |
830 | 801 | let currentGroupKey = null; |
831 | 802 | let accumulatedHeight = 0; |
| 803 | + const itemHeight = this.virtualScrollOptions.size || 60; |
832 | 804 |
|
833 | 805 | // 遍历扁平化列表,找到当前滚动位置对应的分组 |
834 | 806 | for (const item of this.flattenedList) { |
835 | | - const itemHeight = |
836 | | - item.type === 'group-title' ? 40 : this.virtualScrollOptions.size || 60; |
837 | | -
|
838 | 807 | if (accumulatedHeight + itemHeight > scrollTop) { |
839 | | - // 如果当前项目是分组标题且已经滚动过了,使用这个分组 |
840 | | - if (item.type === 'group-title' && accumulatedHeight <= scrollTop) { |
841 | | - currentGroupKey = item.groupKey; |
842 | | - } else if (item.groupKey) { |
843 | | - // 如果是普通项目,使用其所属分组 |
| 808 | + // 直接使用项目的分组信息 |
| 809 | + if (item.groupKey) { |
844 | 810 | currentGroupKey = item.groupKey; |
845 | 811 | } |
846 | 812 | break; |
|
1025 | 991 | box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); |
1026 | 992 | } |
1027 | 993 |
|
1028 | | - /* 虚拟滚动中的分组标题样式 */ |
1029 | | - .virtual-group-title { |
1030 | | - margin-bottom: 0 !important; |
1031 | | - } |
1032 | | -
|
1033 | | - /* 虚拟项目包装器样式调整 */ |
1034 | | - .virtual-item-wrapper { |
1035 | | - &.is-group-title { |
1036 | | - margin-bottom: 0 !important; |
1037 | | - } |
1038 | | -
|
1039 | | - &.is-conversation-item { |
1040 | | - margin-top: 0 !important; |
1041 | | - } |
1042 | | - } |
1043 | | -
|
1044 | 994 | /* 确保虚拟滚动容器有正确的相对定位 */ |
1045 | 995 | .el-x-conversations-scroll-wrapper { |
1046 | 996 | position: relative; |
|
0 commit comments