Skip to content

Commit

Permalink
fix: 🪲️暂时修复分栏组件的ElScrollbar的渲染失效问题(原因暂时未知),完成历史会话加载开发
Browse files Browse the repository at this point in the history
  • Loading branch information
ZRMYDYCG committed Mar 4, 2025
1 parent c5b17ad commit 50dc3dc
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 17 deletions.
26 changes: 26 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/components/Column/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
</div>

<slot v-if="scrollbar" name="scroll-header"></slot>
<el-scrollbar v-if="scrollbar" ref="elScrollbar">
<ElScrollbar v-if="scrollbar" ref="elScrollbar">
<div class="gc-column__body">
<slot></slot>
</div>
</el-scrollbar>
</ElScrollbar>
<slot v-if="scrollbar" name="scroll-footer"></slot>

<div v-if="!scrollbar" class="gc-column__body">
Expand All @@ -25,14 +25,13 @@
</template>

<script lang="ts" setup>
import { ElScrollbar } from 'element-plus'
import { defineProps, ref, withDefaults } from 'vue'
defineOptions({
name: 'GcColumn',
})
withDefaults(
const props = withDefaults(
defineProps<{
scrollbar: boolean
}>(),
Expand All @@ -41,7 +40,7 @@ withDefaults(
},
)
const elScrollbar = ref<InstanceType<typeof ElScrollbar> | null>(null)
const elScrollbar = ref<any>()
defineExpose({
elScrollbar,
Expand Down
29 changes: 23 additions & 6 deletions src/components/List/index.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<!--
* 列表组件
-->
<template>
<div class="gc-list">
<div class="gc-list__wrapper">
<a
v-for="(item, index) in list"
:key="index"
href="javascript:void(0)"
class="gc-list__item is-active:text-[#26224e] is-active:bg-white is-active:shadow-[5px_15px_30px_0px_#f0f0f0] last:border-b-0 hover:bg-white hover:text-[#26224e] hover:shadow-[5px_15px_30px_0px_#f0f0f0]"
class="gc-list__item"
:class="{
'is-active': currentIndex === getObjectAttrValue(item, options.key),
}"
Expand All @@ -30,7 +27,7 @@ import { get as getObjectAttrValue } from 'lodash'
import { computed, nextTick, ref } from 'vue'
export default {
name: 'GcList',
name: 'GCList',
props: {
list: {
type: Array,
Expand Down Expand Up @@ -129,5 +126,25 @@ export default {
},
}
</script>
<style scoped>
.gc-list .gc-list__item {
display: flex;
align-items: center;
padding: 15px 10px;
margin: 0 10px;
border-bottom: 1px solid #f7f7f7;
border-radius: 10px;
transition: background 0.3s;
}
.gc-list .gc-list__item:hover,
.gc-list .gc-list__item.is-active {
color: #26224e;
background: #fff;
box-shadow: 5px 15px 30px 0px #f0f0f0;
}
<style scoped></style>
.gc-list .gc-list__item:last-child {
border-bottom: 0;
}
</style>
134 changes: 128 additions & 6 deletions src/view/chat/components/chat-history.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,133 @@
<script setup lang="ts">
import { useCurrentInstance } from '@/hooks'
import { useCurrentInstance, useLoadMore, usePageList } from '@/hooks'
import useChatStore from '@/store/modules/chat'
import { debounce } from 'lodash-es'
import { onMounted, ref, watch } from 'vue'
useCurrentInstance()
const { $api } = useCurrentInstance()
const chatStore = useChatStore()
interface SearchFormModel {
keywords: string
}
interface ChatItem {
user_id: string
avatar: string
nickname: string
send_time: string
last_message: string
}
const searchFormMdl = ref<SearchFormModel>({
keywords: '',
})
const chatListRef = ref<any>(null)
const {
list: chatList,
loadding,
getPageList,
} = usePageList<ChatItem>({
getPageListApi: $api.chat.getChatHistoryList,
searchParams: searchFormMdl,
})
onMounted(async () => {
await getPageList()
if (chatList.value.length) {
chatListRef.value?.handleChangeItem(chatList.value[0])
}
})
const gcColumnRef = ref<any>(null)
onMounted(() => {
useLoadMore({
type: 'bottom',
scrollBottomCallback: getPageList,
container: gcColumnRef.value?.elScrollbar.wrapRef,
distance: 150,
})
})
watch(
chatList,
() => {
chatStore.updateChatList(chatList.value)
},
{
immediate: true,
deep: true,
},
)
const handleChangeChatListItem = debounce((chatId: string, chat: ChatItem) => {
// console.log('聊天记录item切换', chatId, chat)
chatStore.updateActiveChatId(chatId)
}, 300)
</script>

<template>
<div>History</div>
</template>
<style scoped>
.chat-history {
width: 300px;
height: 100vh;
border-right: 1px solid #e0e4ea;
}
.chat-history :deep(.gc-column .gc-column__header) {
display: flex;
align-items: center;
height: 70px;
padding-left: 15px;
border-bottom: 1px solid #e0e4ea;
}
.chat-history :deep(.gc-column .list-title) {
font-size: 14px;
color: #96a1b1;
line-height: 45px;
padding-left: 15px;
margin-bottom: 5px;
}
.chat-history :deep(.gc-column .el-scrollbar .gc-list) {
padding-bottom: 30px;
}
.chat-history :deep(.gc-column .el-scrollbar .gc-list .gc-list__item .chat-item .user .avater) {
flex-shrink: 0;
width: 45px;
height: 45px;
margin-right: 15px;
}
.chat-history :deep(.gc-column .el-scrollbar .gc-list .gc-list__item .chat-item .user .avater img) {
border-radius: 50%;
}
.chat-history :deep(.gc-column .el-scrollbar .gc-list .gc-list__item .chat-item .user .info) {
flex: 1;
}
.chat-history :deep(.gc-column .el-scrollbar .gc-list .gc-list__item .chat-item .user .info-top .nickname) {
font-size: 15px;
font-weight: 600;
}
.chat-history :deep(.gc-column .el-scrollbar .gc-list .gc-list__item .chat-item .user .info-top .date) {
color: #404a5b;
font-size: 12px;
}
.chat-history :deep(.gc-column .el-scrollbar .gc-list .gc-list__item .chat-item .user .info-bottom) {
margin-top: 5px;
}
<style scoped></style>
.chat-history :deep(.gc-column .el-scrollbar .gc-list .gc-list__item .chat-item .user .info-bottom .last-message) {
width: 0;
flex: 1;
font-size: 13px;
color: #404a5b;
}
</style>

0 comments on commit 50dc3dc

Please sign in to comment.