Skip to content

Commit c70a2fd

Browse files
author
weilei
committed
refactor(core): 优化会话组件
1 parent 1d1a28e commit c70a2fd

File tree

3 files changed

+20
-66
lines changed

3 files changed

+20
-66
lines changed

packages/element-ui-x/src/components/Conversations/src/main.vue

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,9 @@
4242
@scroll="handleVirtualScroll"
4343
>
4444
<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+
<!-- 会话项目 -->
6647
<conversations-item
67-
v-else
6848
:item="item"
6949
:active="item.uniqueKey === active"
7050
:items-style="itemsStyle"
@@ -299,8 +279,8 @@
299279

300280
<script>
301281
import { get } from 'lodash';
302-
import ConversationsItem from './components/item.vue';
303282
import { RecycleScroller } from 'vue-virtual-scroller';
283+
import ConversationsItem from './components/item.vue';
304284
export default {
305285
name: 'ElXConversations',
306286
@@ -564,23 +544,14 @@
564544
if (this.shouldUseGrouping) {
565545
const result = [];
566546
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+
// 直接添加分组内容,不添加分组标题项
579548
group.children.forEach(item => {
580549
result.push({
581550
type: 'item',
582551
...item,
583552
groupKey: group.key,
553+
groupTitle: group.title, // 添加分组标题信息用于粘性标题显示
554+
isUngrouped: group.isUngrouped,
584555
// 为虚拟滚动指定项目的高度
585556
virtualHeight: this.virtualScrollOptions.size || 60,
586557
size: this.virtualScrollOptions.size || 60,
@@ -829,18 +800,13 @@
829800
// 计算当前应该显示的粘性分组
830801
let currentGroupKey = null;
831802
let accumulatedHeight = 0;
803+
const itemHeight = this.virtualScrollOptions.size || 60;
832804
833805
// 遍历扁平化列表,找到当前滚动位置对应的分组
834806
for (const item of this.flattenedList) {
835-
const itemHeight =
836-
item.type === 'group-title' ? 40 : this.virtualScrollOptions.size || 60;
837-
838807
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) {
844810
currentGroupKey = item.groupKey;
845811
}
846812
break;
@@ -1025,22 +991,6 @@
1025991
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
1026992
}
1027993
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-
1044994
/* 确保虚拟滚动容器有正确的相对定位 */
1045995
.el-x-conversations-scroll-wrapper {
1046996
position: relative;

packages/element-ui-x/src/components/Thinking/src/main.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@
6969
</transition>
7070
</button>
7171

72-
<Transition name="slide">
72+
<transition name="slide">
7373
<div
74-
v-show="isExpanded"
75-
v-if="displayedContent"
74+
v-if="isExpanded && displayedContent"
7675
class="content-wrapper"
7776
:class="{ 'error-state': localStatus === 'error' }"
7877
>
@@ -94,7 +93,7 @@
9493
</slot>
9594
</div>
9695
</div>
97-
</Transition>
96+
</transition>
9897
</div>
9998
</template>
10099

packages/element-ui-x/src/styles/Thinking.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,23 @@
6868

6969
.slide-enter-active,
7070
.slide-leave-active {
71-
height: max-content;
72-
transition: height var(--el-x-thinking-animation-duration) ease-in-out,
71+
transition: max-height var(--el-x-thinking-animation-duration) ease-in-out,
7372
opacity var(--el-x-thinking-animation-duration) ease-in-out;
7473
overflow: hidden;
7574
}
7675

7776
.slide-enter-from,
7877
.slide-leave-to {
79-
height: 0 !important;
78+
max-height: 0;
8079
opacity: 0;
8180
}
8281

82+
.slide-enter-to,
83+
.slide-leave-from {
84+
max-height: 1000px;
85+
opacity: 1;
86+
}
87+
8388
.content-wrapper {
8489
box-sizing: border-box;
8590
min-width: 0;

0 commit comments

Comments
 (0)