完成搜索框中点击更多通讯录、更多群聊、点击通讯录、群聊、聊天记录对应的跳转,并处理加载更多场景;处理跳转到指定搜索记录的功能,并实现向上向下加载更多数据,并保持滚动位置
This commit is contained in:
parent
331ca65db6
commit
e1e11b7633
@ -5,6 +5,16 @@ export const ServeSeachQueryAll = (data = {}) => {
|
|||||||
return post('/api/v1/elasticsearch/query-all', data)
|
return post('/api/v1/elasticsearch/query-all', data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ES搜索用户数据
|
||||||
|
export const ServeQueryUser = (data) => {
|
||||||
|
return post('/api/v1/elasticsearch/query-user', data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ES搜索群组数据
|
||||||
|
export const ServeQueryGroup = (data) => {
|
||||||
|
return post('/api/v1/elasticsearch/query-group', data)
|
||||||
|
}
|
||||||
|
|
||||||
//ES搜索聊天记录-主页搜索什么都有、聊天记录
|
//ES搜索聊天记录-主页搜索什么都有、聊天记录
|
||||||
export const ServeQueryTalkRecord = (data = {}) => {
|
export const ServeQueryTalkRecord = (data = {}) => {
|
||||||
return post('/api/v1/elasticsearch/query-talk-record', data)
|
return post('/api/v1/elasticsearch/query-talk-record', data)
|
||||||
|
@ -41,7 +41,13 @@
|
|||||||
>
|
>
|
||||||
<searchItem
|
<searchItem
|
||||||
@click="clickSearchItem(searchResultKey, item)"
|
@click="clickSearchItem(searchResultKey, item)"
|
||||||
v-if="(props.listLimit && index < 3) || !props.listLimit"
|
v-if="(
|
||||||
|
searchResultKey === 'user_infos'
|
||||||
|
? (state.userInfosShowAll || (props.listLimit && index < 3))
|
||||||
|
: searchResultKey === 'combinedGroup'
|
||||||
|
? (state.groupInfosShowAll || (props.listLimit && index < 3))
|
||||||
|
: (props.listLimit && index < 3)
|
||||||
|
) || !props.listLimit"
|
||||||
:searchResultKey="searchResultKey"
|
:searchResultKey="searchResultKey"
|
||||||
:searchItem="item"
|
:searchItem="item"
|
||||||
:searchText="state.searchText"
|
:searchText="state.searchText"
|
||||||
@ -56,8 +62,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="result-has-more"
|
class="result-has-more"
|
||||||
v-if="getHasMoreResult(searchResultKey)"
|
v-if="
|
||||||
@click="toMoreResultPage(searchResultKey)"
|
getHasMoreResult(searchResultKey) &&
|
||||||
|
!(
|
||||||
|
(searchResultKey === 'user_infos' && state.userInfosExpand) ||
|
||||||
|
(searchResultKey === 'combinedGroup' && state.groupInfosExpand)
|
||||||
|
)
|
||||||
|
"
|
||||||
|
@click="onMoreResultClick(searchResultKey)"
|
||||||
>
|
>
|
||||||
<span class="text-[14px] font-regular">
|
<span class="text-[14px] font-regular">
|
||||||
{{ getHasMoreResult(searchResultKey) }}
|
{{ getHasMoreResult(searchResultKey) }}
|
||||||
@ -147,6 +159,7 @@
|
|||||||
import { NInfiniteScroll } from 'naive-ui'
|
import { NInfiniteScroll } from 'naive-ui'
|
||||||
import searchItem from './searchItem.vue'
|
import searchItem from './searchItem.vue'
|
||||||
import { ref, reactive, defineEmits, defineProps, onMounted, watch } from 'vue'
|
import { ref, reactive, defineEmits, defineProps, onMounted, watch } from 'vue'
|
||||||
|
import { ServeQueryUser, ServeQueryGroup } from '@/api/search'
|
||||||
|
|
||||||
const emits = defineEmits([
|
const emits = defineEmits([
|
||||||
'toMoreResultPage',
|
'toMoreResultPage',
|
||||||
@ -164,7 +177,16 @@ const state = reactive({
|
|||||||
uid: 12303, //当前用户id
|
uid: 12303, //当前用户id
|
||||||
clickStayItem: '', //点击停留的item
|
clickStayItem: '', //点击停留的item
|
||||||
hasMore: true, //是否还有更多数据
|
hasMore: true, //是否还有更多数据
|
||||||
loading: false //加载锁
|
loading: false, //加载锁
|
||||||
|
userInfosExpand: false, // 控制通讯录全部加载完
|
||||||
|
userInfosLoading: false, // 控制通讯录加载更多状态
|
||||||
|
userInfosLastId: undefined, // 记录通讯录分页的 last_id
|
||||||
|
userInfosShowAll: false, // 只要点过"更多通讯录"就为 true
|
||||||
|
groupInfosExpand: false, // 控制群聊全部加载完
|
||||||
|
groupInfosLoading: false, // 控制群聊加载更多状态
|
||||||
|
groupInfosLastGroupId: 0, // 记录群聊分页的 last_group_id
|
||||||
|
groupInfosLastMemberId: 0, // 记录群聊分页的 last_member_id
|
||||||
|
groupInfosShowAll: false // 只要点过"更多群聊"就为 true
|
||||||
})
|
})
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -214,7 +236,11 @@ const props = defineProps({
|
|||||||
useCustomTitle: {
|
useCustomTitle: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
} //是否使用自定义标题
|
}, //是否使用自定义标题
|
||||||
|
selectItemInList: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
} //在列表选中的聊天记录搜索项
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@ -247,6 +273,13 @@ watch(
|
|||||||
emits('clickStayItemChange', state.clickStayItem)
|
emits('clickStayItemChange', state.clickStayItem)
|
||||||
//重置搜索条件
|
//重置搜索条件
|
||||||
emits('lastIdChange', 0, 0, 0, '', '')
|
emits('lastIdChange', 0, 0, 0, '', '')
|
||||||
|
state.userInfosExpand = false
|
||||||
|
state.userInfosShowAll = false
|
||||||
|
state.userInfosLastId = undefined
|
||||||
|
state.groupInfosExpand = false
|
||||||
|
state.groupInfosShowAll = false
|
||||||
|
state.groupInfosLastGroupId = 0
|
||||||
|
state.groupInfosLastMemberId = 0
|
||||||
queryAllSearch()
|
queryAllSearch()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -384,6 +417,12 @@ const queryAllSearch = (doClearSearchResult) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.pageNum = state.pageNum + 1
|
state.pageNum = state.pageNum + 1
|
||||||
|
// 同步 userInfosLastId
|
||||||
|
if (typeof data.last_id !== 'undefined') {
|
||||||
|
state.userInfosLastId = data.last_id
|
||||||
|
} else {
|
||||||
|
state.userInfosLastId = undefined
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (state.pageNum === 1) {
|
if (state.pageNum === 1) {
|
||||||
// 第一页请求失败,清空结果
|
// 第一页请求失败,清空结果
|
||||||
@ -538,6 +577,13 @@ const clickSearchItem = (searchResultKey, searchItem) => {
|
|||||||
|
|
||||||
//加载更多数据
|
//加载更多数据
|
||||||
const doLoadMore = (doClearSearchResult) => {
|
const doLoadMore = (doClearSearchResult) => {
|
||||||
|
if (
|
||||||
|
state.userInfosLoading ||
|
||||||
|
state.userInfosShowAll ||
|
||||||
|
state.groupInfosShowAll // 新增判断,群聊展开后不再触发 queryAllSearch
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!state.hasMore || state.loading) {
|
if (!state.hasMore || state.loading) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -546,6 +592,134 @@ const doLoadMore = (doClearSearchResult) => {
|
|||||||
state.loading = false
|
state.loading = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.selectItemInList,
|
||||||
|
(newVal, oldVal) => {
|
||||||
|
if (newVal) {
|
||||||
|
const selectedItem = JSON.parse(decodeURIComponent(newVal))
|
||||||
|
clickSearchItem('general_infos', selectedItem)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deep: true,
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// 单独维护通讯录加载更多逻辑,基于 last_id 分页
|
||||||
|
async function loadMoreUserInfos() {
|
||||||
|
if (state.userInfosLoading) return
|
||||||
|
state.userInfosLoading = true
|
||||||
|
try {
|
||||||
|
let params = {
|
||||||
|
key: state.searchText,
|
||||||
|
last_id: state.userInfosLastId,
|
||||||
|
size: 10
|
||||||
|
}
|
||||||
|
const resp = await ServeQueryUser(params)
|
||||||
|
if (resp.code === 200 && Array.isArray(resp.data.user_infos)) {
|
||||||
|
if (!state.userInfosLastId) {
|
||||||
|
// 第一次加载,直接替换
|
||||||
|
state.searchResult = {
|
||||||
|
...state.searchResult,
|
||||||
|
user_infos: resp.data.user_infos
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 后续加载,追加
|
||||||
|
state.searchResult = {
|
||||||
|
...state.searchResult,
|
||||||
|
user_infos: (state.searchResult.user_infos || []).concat(resp.data.user_infos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state.userInfosLastId = resp.data.last_id
|
||||||
|
// 判断是否全部加载完
|
||||||
|
if (
|
||||||
|
!resp.data.last_id ||
|
||||||
|
(Array.isArray(resp.data.user_infos) && resp.data.user_infos.length < 10)
|
||||||
|
) {
|
||||||
|
state.userInfosExpand = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
state.userInfosLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理"更多通讯录"、 "更多群聊"点击,调用新方法
|
||||||
|
function onMoreResultClick(searchResultKey) {
|
||||||
|
if (searchResultKey === 'user_infos') {
|
||||||
|
state.userInfosShowAll = true
|
||||||
|
loadMoreUserInfos()
|
||||||
|
} else if (searchResultKey === 'combinedGroup') {
|
||||||
|
state.groupInfosShowAll = true
|
||||||
|
loadMoreGroupInfos()
|
||||||
|
} else {
|
||||||
|
emits('toMoreResultPage', searchResultKey, state.searchText)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单独维护群聊加载更多逻辑,基于 last_id 分页
|
||||||
|
async function loadMoreGroupInfos() {
|
||||||
|
if (state.groupInfosLoading) return
|
||||||
|
state.groupInfosLoading = true
|
||||||
|
try {
|
||||||
|
let params = {
|
||||||
|
key: state.searchText,
|
||||||
|
last_group_id: state.groupInfosLastGroupId,
|
||||||
|
last_member_id: state.groupInfosLastMemberId,
|
||||||
|
size: 10
|
||||||
|
}
|
||||||
|
const resp = await ServeQueryGroup(params)
|
||||||
|
if (resp.code === 200) {
|
||||||
|
const groupInfos = Array.isArray(resp.data.group_infos) ? resp.data.group_infos : []
|
||||||
|
const groupMemberInfos = Array.isArray(resp.data.group_member_infos) ? resp.data.group_member_infos : []
|
||||||
|
|
||||||
|
// 给新数据加上 groupTempType
|
||||||
|
groupInfos.forEach(item => {
|
||||||
|
item.groupTempType = 'group_infos'
|
||||||
|
item.group_type = item.type // 保持一致性
|
||||||
|
})
|
||||||
|
groupMemberInfos.forEach(item => {
|
||||||
|
item.groupTempType = 'group_member_infos'
|
||||||
|
})
|
||||||
|
|
||||||
|
const isFirstLoad = (!state.groupInfosLastGroupId && !state.groupInfosLastMemberId) ||
|
||||||
|
(state.groupInfosLastGroupId === 0 && state.groupInfosLastMemberId === 0)
|
||||||
|
if (isFirstLoad) {
|
||||||
|
// 第一次加载,直接替换
|
||||||
|
state.searchResult = {
|
||||||
|
...state.searchResult,
|
||||||
|
group_infos: groupInfos,
|
||||||
|
group_member_infos: groupMemberInfos,
|
||||||
|
combinedGroup: groupInfos.concat(groupMemberInfos)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 后续加载,追加
|
||||||
|
const allGroupInfos = (state.searchResult.group_infos || []).concat(groupInfos)
|
||||||
|
const allGroupMemberInfos = (state.searchResult.group_member_infos || []).concat(groupMemberInfos)
|
||||||
|
state.searchResult = {
|
||||||
|
...state.searchResult,
|
||||||
|
group_infos: allGroupInfos,
|
||||||
|
group_member_infos: allGroupMemberInfos,
|
||||||
|
combinedGroup: allGroupInfos.concat(allGroupMemberInfos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state.groupInfosLastGroupId = resp.data.last_group_id
|
||||||
|
state.groupInfosLastMemberId = resp.data.last_member_id
|
||||||
|
// 判断是否全部加载完
|
||||||
|
const noMoreData = (
|
||||||
|
(!groupInfos.length && !groupMemberInfos.length) ||
|
||||||
|
(resp.data.last_group_id === 0 && resp.data.last_member_id === 0)
|
||||||
|
)
|
||||||
|
if (noMoreData) {
|
||||||
|
state.groupInfosExpand = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
state.groupInfosLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.search-list {
|
.search-list {
|
||||||
|
@ -14,8 +14,9 @@ interface Params {
|
|||||||
interface SpecialParams extends Params {
|
interface SpecialParams extends Params {
|
||||||
msg_id?: string
|
msg_id?: string
|
||||||
cursor?: number
|
cursor?: number
|
||||||
direction?: 'up' | 'down',
|
direction?: 'up' | 'down'
|
||||||
sort_sequence?: string
|
sort_sequence?: string
|
||||||
|
type?: 'loadMore'
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LoadOptions {
|
interface LoadOptions {
|
||||||
@ -38,7 +39,11 @@ export const useTalkRecord = (uid: number) => {
|
|||||||
talk_type: 0,
|
talk_type: 0,
|
||||||
status: 0,
|
status: 0,
|
||||||
cursor: 0,
|
cursor: 0,
|
||||||
specialParams: undefined as SpecialParams | undefined
|
specialParams: undefined as SpecialParams | undefined,
|
||||||
|
isLocatingMessage: false,
|
||||||
|
isLoadingMore: false,
|
||||||
|
lastLoadMoreTime: 0,
|
||||||
|
targetMessagePosition: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
// 重置 loadConfig
|
// 重置 loadConfig
|
||||||
@ -138,12 +143,11 @@ export const useTalkRecord = (uid: number) => {
|
|||||||
if (el) {
|
if (el) {
|
||||||
if (request.cursor == 0) {
|
if (request.cursor == 0) {
|
||||||
el.scrollTop = el.scrollHeight
|
el.scrollTop = el.scrollHeight
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log('el.scrollHeight',el.scrollHeight)
|
console.log('el.scrollHeight', el.scrollHeight)
|
||||||
console.log('request.cursor == 0')
|
console.log('request.cursor == 0')
|
||||||
el.scrollTop = el.scrollHeight + 1000
|
el.scrollTop = el.scrollHeight + 1000
|
||||||
|
|
||||||
}, 500)
|
}, 500)
|
||||||
} else {
|
} else {
|
||||||
console.log('request.cursor !== 0')
|
console.log('request.cursor !== 0')
|
||||||
@ -161,13 +165,13 @@ export const useTalkRecord = (uid: number) => {
|
|||||||
const getMinSequence = () => {
|
const getMinSequence = () => {
|
||||||
console.error('records.value', records.value)
|
console.error('records.value', records.value)
|
||||||
if (!records.value.length) return 0
|
if (!records.value.length) return 0
|
||||||
console.error(Math.min(...records.value.map(item => item.sequence)))
|
console.error(Math.min(...records.value.map((item) => item.sequence)))
|
||||||
return Math.min(...records.value.map(item => item.sequence))
|
return Math.min(...records.value.map((item) => item.sequence))
|
||||||
}
|
}
|
||||||
// 获取当前消息的最大 sequence
|
// 获取当前消息的最大 sequence
|
||||||
const getMaxSequence = () => {
|
const getMaxSequence = () => {
|
||||||
if (!records.value.length) return 0
|
if (!records.value.length) return 0
|
||||||
return Math.max(...records.value.map(item => item.sequence))
|
return Math.max(...records.value.map((item) => item.sequence))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,7 +181,10 @@ export const useTalkRecord = (uid: number) => {
|
|||||||
*/
|
*/
|
||||||
const onLoad = (params: Params, options?: LoadOptions) => {
|
const onLoad = (params: Params, options?: LoadOptions) => {
|
||||||
// 如果会话切换,重置所有状态
|
// 如果会话切换,重置所有状态
|
||||||
if (params.talk_type !== loadConfig.talk_type || params.receiver_id !== loadConfig.receiver_id) {
|
if (
|
||||||
|
params.talk_type !== loadConfig.talk_type ||
|
||||||
|
params.receiver_id !== loadConfig.receiver_id
|
||||||
|
) {
|
||||||
resetLoadConfig()
|
resetLoadConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,34 +204,67 @@ export const useTalkRecord = (uid: number) => {
|
|||||||
...params,
|
...params,
|
||||||
...options.specifiedMsg
|
...options.specifiedMsg
|
||||||
}
|
}
|
||||||
|
//msg_id是用来做定位的,不做参数,所以这里清空
|
||||||
|
contextParams.msg_id = ''
|
||||||
ServeTalkRecords(contextParams).then(({ data, code }) => {
|
ServeTalkRecords(contextParams).then(({ data, code }) => {
|
||||||
if (code !== 200) {
|
if (code !== 200) {
|
||||||
loadConfig.status = 2
|
loadConfig.status = 2
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// dialogueStore.clearDialogueRecord()
|
// 记录当前滚动高度
|
||||||
|
const el = document.getElementById('imChatPanel')
|
||||||
|
const scrollHeight = el?.scrollHeight || 0
|
||||||
|
|
||||||
|
if (contextParams.direction === 'down' && !contextParams.type) {
|
||||||
|
dialogueStore.clearDialogueRecord()
|
||||||
|
}
|
||||||
const items = (data.items || []).map((item: ITalkRecord) => formatTalkRecord(uid, item))
|
const items = (data.items || []).map((item: ITalkRecord) => formatTalkRecord(uid, item))
|
||||||
dialogueStore.unshiftDialogueRecord(contextParams.direction === 'down' ? items : items.reverse())
|
if (contextParams.type && contextParams.type === 'loadMore') {
|
||||||
loadConfig.status = items.length >= contextParams.limit ? 1 : 2
|
dialogueStore.addDialogueRecordForLoadMore(items)
|
||||||
|
} else {
|
||||||
|
dialogueStore.unshiftDialogueRecord(
|
||||||
|
contextParams.direction === 'down' ? items : items.reverse()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
contextParams.direction === 'up' ||
|
||||||
|
(contextParams.direction === 'down' && !contextParams.type)
|
||||||
|
) {
|
||||||
|
loadConfig.status = items[0].sequence == 1 || data.length === 0 ? 2 : 1
|
||||||
|
}
|
||||||
loadConfig.cursor = data.cursor
|
loadConfig.cursor = data.cursor
|
||||||
nextTick(() => {
|
|
||||||
setTimeout(() => {
|
// 使用 requestAnimationFrame 来确保在下一帧渲染前设置滚动位置
|
||||||
const el = document.getElementById('imChatPanel')
|
requestAnimationFrame(() => {
|
||||||
const target = document.getElementById(options.specifiedMsg?.msg_id || '')
|
const el = document.getElementById('imChatPanel')
|
||||||
if (el && target) {
|
const target = document.getElementById(options.specifiedMsg?.msg_id || '')
|
||||||
|
if (el && target) {
|
||||||
|
// 如果是向上加载更多,保持原有内容位置
|
||||||
|
if (contextParams.direction === 'up') {
|
||||||
|
el.scrollTop = el.scrollHeight - scrollHeight
|
||||||
|
} else if (contextParams.type && contextParams.type === 'loadMore') {
|
||||||
|
// 如果是向下加载更多,保持目标消息在可视区域底部
|
||||||
|
// 使用可视区域高度来调整,而不是新内容的总高度
|
||||||
|
nextTick(() => {
|
||||||
|
if (el) {
|
||||||
|
el.scrollTop = scrollHeight - el.clientHeight
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 如果是定位到特定消息,计算并滚动到目标位置
|
||||||
const containerRect = el.getBoundingClientRect()
|
const containerRect = el.getBoundingClientRect()
|
||||||
const targetRect = target.getBoundingClientRect()
|
const targetRect = target.getBoundingClientRect()
|
||||||
const offset = targetRect.top - containerRect.top
|
const offset = targetRect.top - containerRect.top
|
||||||
|
loadConfig.isLocatingMessage = true
|
||||||
// 居中
|
// 居中
|
||||||
const scrollTo = el.scrollTop + offset - el.clientHeight / 2 + target.clientHeight / 2
|
const scrollTo = el.scrollTop + offset - el.clientHeight / 2 + target.clientHeight / 2
|
||||||
el.scrollTo({ top: scrollTo, behavior: 'smooth' })
|
el.scrollTo({ top: scrollTo, behavior: 'smooth' })
|
||||||
|
|
||||||
addClass(target, 'border')
|
addClass(target, 'border')
|
||||||
setTimeout(() => removeClass(target, 'border'), 3000)
|
setTimeout(() => removeClass(target, 'border'), 3000)
|
||||||
} else if (el) {
|
|
||||||
el.scrollTop = el.scrollHeight
|
|
||||||
}
|
}
|
||||||
}, 50)
|
} else if (el) {
|
||||||
|
el.scrollTop = el.scrollHeight
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@ -243,8 +283,10 @@ export const useTalkRecord = (uid: number) => {
|
|||||||
// 判断是否是特殊参数模式
|
// 判断是否是特殊参数模式
|
||||||
if (loadConfig.specialParams && typeof loadConfig.specialParams === 'object') {
|
if (loadConfig.specialParams && typeof loadConfig.specialParams === 'object') {
|
||||||
// 检查特殊参数是否与当前会话匹配
|
// 检查特殊参数是否与当前会话匹配
|
||||||
if (loadConfig.specialParams.talk_type === loadConfig.talk_type &&
|
if (
|
||||||
loadConfig.specialParams.receiver_id === loadConfig.receiver_id) {
|
loadConfig.specialParams.talk_type === loadConfig.talk_type &&
|
||||||
|
loadConfig.specialParams.receiver_id === loadConfig.receiver_id
|
||||||
|
) {
|
||||||
// 特殊参数模式下,direction: 'up',cursor: 当前最小 sequence
|
// 特殊参数模式下,direction: 'up',cursor: 当前最小 sequence
|
||||||
onLoad(
|
onLoad(
|
||||||
{
|
{
|
||||||
@ -257,7 +299,11 @@ export const useTalkRecord = (uid: number) => {
|
|||||||
...loadConfig.specialParams,
|
...loadConfig.specialParams,
|
||||||
direction: 'up',
|
direction: 'up',
|
||||||
sort_sequence: '',
|
sort_sequence: '',
|
||||||
cursor: getMinSequence()
|
cursor: getMinSequence(),
|
||||||
|
msg_id:
|
||||||
|
records.value.find((item) =>
|
||||||
|
item.sequence === getMinSequence() ? item.msg_id : ''
|
||||||
|
)?.msg_id || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -281,13 +327,33 @@ export const useTalkRecord = (uid: number) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向下加载更多(兼容特殊参数模式)
|
// 向下加载更多(特殊参数模式才生效,普通模式无效,因为普通模式的数据就是从最新开始加载历史的,所以不需要加载更新的数据)
|
||||||
const onLoadMoreDown = () => {
|
const onLoadMoreDown = () => {
|
||||||
// 判断是否是特殊参数模式
|
// 判断是否是特殊参数模式
|
||||||
if (loadConfig.specialParams && typeof loadConfig.specialParams === 'object') {
|
if (loadConfig.specialParams && typeof loadConfig.specialParams === 'object') {
|
||||||
|
if (loadConfig.isLocatingMessage) {
|
||||||
|
loadConfig.isLocatingMessage = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 添加时间间隔限制,至少间隔 500ms 才能触发下一次加载
|
||||||
|
const now = Date.now()
|
||||||
|
if (now - loadConfig.lastLoadMoreTime < 500) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loadConfig.lastLoadMoreTime = now
|
||||||
|
|
||||||
|
// 记录当前目标消息的位置
|
||||||
|
const el = document.getElementById('imChatPanel')
|
||||||
|
if (el) {
|
||||||
|
loadConfig.targetMessagePosition = el.scrollHeight - el.scrollTop
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('onLoadMoreDown 特殊模式触底了')
|
||||||
// 检查特殊参数是否与当前会话匹配
|
// 检查特殊参数是否与当前会话匹配
|
||||||
if (loadConfig.specialParams.talk_type === loadConfig.talk_type &&
|
if (
|
||||||
loadConfig.specialParams.receiver_id === loadConfig.receiver_id) {
|
loadConfig.specialParams.talk_type === loadConfig.talk_type &&
|
||||||
|
loadConfig.specialParams.receiver_id === loadConfig.receiver_id
|
||||||
|
) {
|
||||||
onLoad(
|
onLoad(
|
||||||
{
|
{
|
||||||
receiver_id: loadConfig.receiver_id,
|
receiver_id: loadConfig.receiver_id,
|
||||||
@ -298,27 +364,23 @@ export const useTalkRecord = (uid: number) => {
|
|||||||
specifiedMsg: {
|
specifiedMsg: {
|
||||||
...loadConfig.specialParams,
|
...loadConfig.specialParams,
|
||||||
direction: 'down',
|
direction: 'down',
|
||||||
cursor: getMaxSequence()
|
sort_sequence: 'asc',
|
||||||
|
cursor: getMaxSequence(),
|
||||||
|
type: 'loadMore'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
// 如果不匹配,重置为普通模式
|
|
||||||
resetLoadConfig()
|
|
||||||
load({
|
|
||||||
receiver_id: loadConfig.receiver_id,
|
|
||||||
talk_type: loadConfig.talk_type,
|
|
||||||
limit: 30
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
load({
|
|
||||||
receiver_id: loadConfig.receiver_id,
|
|
||||||
talk_type: loadConfig.talk_type,
|
|
||||||
limit: 30
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { loadConfig, records, onLoad, onRefreshLoad, onLoadMoreDown, onJumpMessage, resetLoadConfig }
|
return {
|
||||||
|
loadConfig,
|
||||||
|
records,
|
||||||
|
onLoad,
|
||||||
|
onRefreshLoad,
|
||||||
|
onLoadMoreDown,
|
||||||
|
onJumpMessage,
|
||||||
|
resetLoadConfig
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,10 @@ export const useDialogueStore = defineStore('dialogue', {
|
|||||||
unshiftDialogueRecord(records) {
|
unshiftDialogueRecord(records) {
|
||||||
this.records.unshift(...records)
|
this.records.unshift(...records)
|
||||||
},
|
},
|
||||||
|
//数组尾部加入更多对话记录
|
||||||
|
addDialogueRecordForLoadMore(records){
|
||||||
|
this.records.push(...records)
|
||||||
|
},
|
||||||
async getGroupInfo(){
|
async getGroupInfo(){
|
||||||
const { code, data } = await ServeGroupDetail({
|
const { code, data } = await ServeGroupDetail({
|
||||||
group_id: this.talk.receiver_id
|
group_id: this.talk.receiver_id
|
||||||
|
@ -74,6 +74,24 @@ const renderChatAppSearch = () => {
|
|||||||
console.log(searchText, searchResultKey, talk_type, receiver_id)
|
console.log(searchText, searchResultKey, talk_type, receiver_id)
|
||||||
const result = JSON.parse(decodeURIComponent(res))
|
const result = JSON.parse(decodeURIComponent(res))
|
||||||
console.log(result)
|
console.log(result)
|
||||||
|
if (searchResultKey === 'general_infos') {
|
||||||
|
state.ServeQueryTalkRecordParams = encodeURIComponent(
|
||||||
|
JSON.stringify({
|
||||||
|
talk_type: 0, //1私聊2群聊
|
||||||
|
receiver_id: 0, //查详情的时候需传入
|
||||||
|
last_group_id: 0, //最后一条群id
|
||||||
|
last_member_id: 0, //最后一条用户id
|
||||||
|
last_receiver_user_name: '', //最后一条用户名
|
||||||
|
last_receiver_group_name: '' //最后一条群名
|
||||||
|
})
|
||||||
|
)
|
||||||
|
state.isShowSearchRecordModal = true
|
||||||
|
state.searchRecordText = searchText
|
||||||
|
state.selectItemInList = res
|
||||||
|
} else {
|
||||||
|
talkStore.toTalk(talk_type, receiver_id, router)
|
||||||
|
}
|
||||||
|
state.showSearchDropdown = false
|
||||||
},
|
},
|
||||||
onToMoreResultPage: (searchResultKey, searchText) => {
|
onToMoreResultPage: (searchResultKey, searchText) => {
|
||||||
if (searchResultKey === 'general_infos') {
|
if (searchResultKey === 'general_infos') {
|
||||||
@ -277,7 +295,9 @@ const state = reactive({
|
|||||||
apiParams: '',
|
apiParams: '',
|
||||||
lastId: undefined as any,
|
lastId: undefined as any,
|
||||||
total: 0
|
total: 0
|
||||||
}
|
},
|
||||||
|
showSearchDropdown: false, // 是否显示搜索下拉框
|
||||||
|
selectItemInList: '' // 在列表选中的聊天记录搜索项
|
||||||
})
|
})
|
||||||
|
|
||||||
const items = computed((): ISession[] => {
|
const items = computed((): ISession[] => {
|
||||||
@ -292,9 +312,9 @@ const items = computed((): ISession[] => {
|
|||||||
|
|
||||||
// 置顶和非置顶分组
|
// 置顶和非置顶分组
|
||||||
const topItems = filtered
|
const topItems = filtered
|
||||||
.filter(item => item.is_top === 1)
|
.filter((item) => item.is_top === 1)
|
||||||
.sort((a, b) => new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime())
|
.sort((a, b) => new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime())
|
||||||
const normalItems = filtered.filter(item => item.is_top !== 1)
|
const normalItems = filtered.filter((item) => item.is_top !== 1)
|
||||||
|
|
||||||
return [...topItems, ...normalItems]
|
return [...topItems, ...normalItems]
|
||||||
})
|
})
|
||||||
@ -589,8 +609,8 @@ const handleGroupChatListPaginationSize = (value) => {
|
|||||||
//处理搜索聊天记录点击
|
//处理搜索聊天记录点击
|
||||||
const handleClickSearchItem = (searchText, searchResultKey, talk_type, receiver_id, res) => {
|
const handleClickSearchItem = (searchText, searchResultKey, talk_type, receiver_id, res) => {
|
||||||
console.log(searchText, searchResultKey, talk_type, receiver_id)
|
console.log(searchText, searchResultKey, talk_type, receiver_id)
|
||||||
const result = JSON.parse(decodeURIComponent(res))
|
// const result = JSON.parse(decodeURIComponent(res))
|
||||||
console.log(result)
|
// console.log(result)
|
||||||
if (searchResultKey === 'general_infos') {
|
if (searchResultKey === 'general_infos') {
|
||||||
// 先清空右侧
|
// 先清空右侧
|
||||||
state.isShowSearchRecordDetailInfo = false
|
state.isShowSearchRecordDetailInfo = false
|
||||||
@ -722,6 +742,8 @@ const handleEnterSearchResultChat = () => {
|
|||||||
trigger="click"
|
trigger="click"
|
||||||
:options="state.chatSearchOptions"
|
:options="state.chatSearchOptions"
|
||||||
style="width: 248px; height: 677px;"
|
style="width: 248px; height: 677px;"
|
||||||
|
:show="state.showSearchDropdown"
|
||||||
|
@clickoutside="state.showSearchDropdown = false"
|
||||||
>
|
>
|
||||||
<n-input
|
<n-input
|
||||||
placeholder="搜索好友 / 群聊"
|
placeholder="搜索好友 / 群聊"
|
||||||
@ -729,6 +751,7 @@ const handleEnterSearchResultChat = () => {
|
|||||||
round
|
round
|
||||||
clearable
|
clearable
|
||||||
style="width: 78%;"
|
style="width: 78%;"
|
||||||
|
@click="state.showSearchDropdown = true"
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<n-icon :component="Search" />
|
<n-icon :component="Search" />
|
||||||
@ -950,6 +973,7 @@ const handleEnterSearchResultChat = () => {
|
|||||||
@clickStayItemChange="handleClickStayItemChange"
|
@clickStayItemChange="handleClickStayItemChange"
|
||||||
@lastIdChange="handleSearchListLastIdChange"
|
@lastIdChange="handleSearchListLastIdChange"
|
||||||
:searchResultMaxHeight="'517px'"
|
:searchResultMaxHeight="'517px'"
|
||||||
|
:selectItemInList="state.selectItemInList"
|
||||||
></chatAppSearchList>
|
></chatAppSearchList>
|
||||||
</div>
|
</div>
|
||||||
<div class="search-record-detail">
|
<div class="search-record-detail">
|
||||||
|
@ -47,6 +47,7 @@ interface State {
|
|||||||
currentReadDetailPage: number
|
currentReadDetailPage: number
|
||||||
hasMoreReadListDetail: boolean
|
hasMoreReadListDetail: boolean
|
||||||
loadingReadListDetail: boolean
|
loadingReadListDetail: boolean
|
||||||
|
lastScrollTop: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -76,7 +77,7 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const { loadConfig, records, onLoad, onRefreshLoad, onJumpMessage } = useTalkRecord(props.uid)
|
const { loadConfig, records, onLoad, onRefreshLoad, onJumpMessage, onLoadMoreDown } = useTalkRecord(props.uid)
|
||||||
const uploadsStore = useUploadsStore()
|
const uploadsStore = useUploadsStore()
|
||||||
const { useMessage } = useUtil()
|
const { useMessage } = useUtil()
|
||||||
const { dropdown, showDropdownMenu, closeDropdownMenu } = useMenu()
|
const { dropdown, showDropdownMenu, closeDropdownMenu } = useMenu()
|
||||||
@ -125,8 +126,16 @@ const onPanelScroll = (e: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const height = e.target.scrollTop + e.target.clientHeight
|
const height = e.target.scrollTop + e.target.clientHeight
|
||||||
|
const scrollHeight = e.target.scrollHeight
|
||||||
|
const isScrollingDown = e.target.scrollTop > state.value.lastScrollTop
|
||||||
|
state.value.lastScrollTop = e.target.scrollTop
|
||||||
|
|
||||||
skipBottom.value = height < e.target.scrollHeight - 200
|
// 触底且必须是向下滚动
|
||||||
|
if (height === scrollHeight && isScrollingDown) {
|
||||||
|
onLoadMoreDown()
|
||||||
|
}
|
||||||
|
|
||||||
|
skipBottom.value = height < scrollHeight - 200
|
||||||
if (!skipBottom.value && dialogueStore.unreadBubble) {
|
if (!skipBottom.value && dialogueStore.unreadBubble) {
|
||||||
dialogueStore.setUnreadBubble(0)
|
dialogueStore.setUnreadBubble(0)
|
||||||
}
|
}
|
||||||
@ -400,7 +409,8 @@ const state = ref<State>({
|
|||||||
currentMsgReadDetail: null,
|
currentMsgReadDetail: null,
|
||||||
currentReadDetailPage: 1,
|
currentReadDetailPage: 1,
|
||||||
hasMoreReadListDetail: true,
|
hasMoreReadListDetail: true,
|
||||||
loadingReadListDetail: false
|
loadingReadListDetail: false,
|
||||||
|
lastScrollTop: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
// 定义观察者变量
|
// 定义观察者变量
|
||||||
|
Loading…
Reference in New Issue
Block a user