处理按群成员搜索聊天记录页面的接口调用与跳转;处理聊天信息推送的信息接收与跳转
This commit is contained in:
parent
d7c813977d
commit
92a7d74c6c
35
src/main.js
35
src/main.js
@ -14,6 +14,7 @@ import { vLoading } from '@/components/x-loading/index.js'
|
|||||||
import messagePopup from '@/components/x-message/useMessagePopup'
|
import messagePopup from '@/components/x-message/useMessagePopup'
|
||||||
import pageAnimation from '@/components/page-animation/index.vue'
|
import pageAnimation from '@/components/page-animation/index.vue'
|
||||||
import * as plugins from './plugins'
|
import * as plugins from './plugins'
|
||||||
|
import { useDialogueStore, useTalkStore } from '@/store'
|
||||||
const { showMessage } = messagePopup()
|
const { showMessage } = messagePopup()
|
||||||
dayjs.locale('zh-cn')
|
dayjs.locale('zh-cn')
|
||||||
if (import.meta.env.VITE_SHOW_CONSOLE === 'true') {
|
if (import.meta.env.VITE_SHOW_CONSOLE === 'true') {
|
||||||
@ -40,6 +41,40 @@ export function createApp() {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
//获取当前聊天页面所在页面,并通过当前的receiver_id判断是否要创建本地通知栏消息
|
||||||
|
window.getCurrentChatRoute = (msg) => {
|
||||||
|
let pushMsg = JSON.parse(decodeURIComponent(msg))
|
||||||
|
//当前所在聊天会话的receiver_id
|
||||||
|
const receiver_id = pushMsg?.payload?.receiver_id
|
||||||
|
// 获取当前页面路径
|
||||||
|
const pages = getCurrentPages()
|
||||||
|
const page = pages[pages.length - 1]
|
||||||
|
console.log(page.route)
|
||||||
|
|
||||||
|
const dialogueStore = useDialogueStore()
|
||||||
|
console.log(dialogueStore?.talk?.receiver_id)
|
||||||
|
if (
|
||||||
|
page?.route === 'pages/dialog/index' &&
|
||||||
|
receiver_id === dialogueStore?.talk?.receiver_id
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let OAWebView = plus.webview.all()
|
||||||
|
//all里面第一个是入口webview
|
||||||
|
OAWebView[0].evalJS(`doCreatePushMessage('${msg}')`)
|
||||||
|
}
|
||||||
|
|
||||||
|
//处理聊天推送弹窗点开
|
||||||
|
window.openUniPushMsg = (msg) => {
|
||||||
|
console.log("=====点击通知栏消息")
|
||||||
|
let pushMsg = JSON.parse(decodeURIComponent(msg))
|
||||||
|
//由于弹窗前处理了不该弹窗的场景,因此这里弹窗可以一并处理
|
||||||
|
//也就是都跳转到聊天页面
|
||||||
|
const talkStore = useTalkStore()
|
||||||
|
talkStore.toTalk(pushMsg?.payload?.talk_type, pushMsg?.payload?.receiver_id)
|
||||||
|
}
|
||||||
|
|
||||||
window.message = ['success', 'error', 'warning'].reduce((acc, type) => {
|
window.message = ['success', 'error', 'warning'].reduce((acc, type) => {
|
||||||
acc[type] = (message) => {
|
acc[type] = (message) => {
|
||||||
if (typeof message === 'string') {
|
if (typeof message === 'string') {
|
||||||
|
@ -381,7 +381,7 @@ const handleClickItem = (item) => {
|
|||||||
}
|
}
|
||||||
if(props?.manageType === 'searchRecord'){
|
if(props?.manageType === 'searchRecord'){
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/search/searchByCondition/index?condition=member'
|
url: '/pages/search/searchByCondition/index?condition=member&groupMemberId=' + item.id
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -561,13 +561,18 @@ const state = ref({
|
|||||||
useCustomLoadMore: false, //是否使用自定义加载更多事件(下拉刷新、上拉加载)
|
useCustomLoadMore: false, //是否使用自定义加载更多事件(下拉刷新、上拉加载)
|
||||||
recordDate: '', //按日期查询聊天记录的开始日期
|
recordDate: '', //按日期查询聊天记录的开始日期
|
||||||
serveFindRecord: [], //调用接口查找到的聊天记录
|
serveFindRecord: [], //调用接口查找到的聊天记录
|
||||||
|
middleMsg: {}, //缓存中没有时,调用接口初次使用的依据记录
|
||||||
|
keepDialogInfo: false, //是否保存会话信息
|
||||||
})
|
})
|
||||||
|
|
||||||
uniOnload(async (options) => {
|
uniOnload(async (options) => {
|
||||||
console.log('onLoad' + options)
|
console.log('onLoad' + JSON.stringify(options))
|
||||||
if (options.sessionId) {
|
if (options.sessionId) {
|
||||||
state.value.sessionId = options.sessionId
|
state.value.sessionId = options.sessionId
|
||||||
}
|
}
|
||||||
|
if (options.keepDialogInfo) {
|
||||||
|
state.value.keepDialogInfo = options.keepDialogInfo === '1' ? true : false
|
||||||
|
}
|
||||||
if (options.msgInfo) {
|
if (options.msgInfo) {
|
||||||
const msgInfo = JSON.parse(decodeURIComponent(options.msgInfo))
|
const msgInfo = JSON.parse(decodeURIComponent(options.msgInfo))
|
||||||
queryRecordsByMsgInfo(msgInfo)
|
queryRecordsByMsgInfo(msgInfo)
|
||||||
@ -974,11 +979,11 @@ const withdrawerConfirm = () => {
|
|||||||
|
|
||||||
// 添加检查是否可以重新编辑撤回消息的函数
|
// 添加检查是否可以重新编辑撤回消息的函数
|
||||||
const canEditRevokedMessage = (item) => {
|
const canEditRevokedMessage = (item) => {
|
||||||
console.log(item)
|
// console.log(item)
|
||||||
if (item.is_revoke === 1 && item.msg_type === 1) {
|
if (item.is_revoke === 1 && item.msg_type === 1) {
|
||||||
const now = new Date().getTime()
|
const now = new Date().getTime()
|
||||||
const revokeTime = new Date(item.created_at).getTime()
|
const revokeTime = new Date(item.created_at).getTime()
|
||||||
console.log(now)
|
// console.log(now)
|
||||||
// 检查是否在5分钟内
|
// 检查是否在5分钟内
|
||||||
return now - revokeTime <= 5 * 60 * 1000
|
return now - revokeTime <= 5 * 60 * 1000
|
||||||
}
|
}
|
||||||
@ -1099,14 +1104,17 @@ watch(
|
|||||||
state.value.localPageLoadDone = true
|
state.value.localPageLoadDone = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (
|
// 只在正常加载模式下检查是否加载完缓存数据
|
||||||
newValue[newValue.length - 1]?.sequence ===
|
if (!state.value.useCustomLoadMore) {
|
||||||
dialogueList?.records?.[0]?.sequence
|
if (
|
||||||
) {
|
newValue[newValue.length - 1]?.sequence ===
|
||||||
//相同意味着分页加载缓存中的聊天记录完毕
|
dialogueList?.records?.[0]?.sequence
|
||||||
state.value.localPageLoadDone = true
|
) {
|
||||||
} else {
|
//相同意味着分页加载缓存中的聊天记录完毕
|
||||||
state.value.localPageLoadDone = false
|
state.value.localPageLoadDone = true
|
||||||
|
} else {
|
||||||
|
state.value.localPageLoadDone = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1134,7 +1142,13 @@ const onScrollToLower = async () => {
|
|||||||
)
|
)
|
||||||
console.log(moreRecords)
|
console.log(moreRecords)
|
||||||
|
|
||||||
virtualList.value = moreRecords.concat(tempVirtualList).reverse()
|
// 格式化新加载的消息
|
||||||
|
const formattedMoreRecords = moreRecords.map((item) => ({
|
||||||
|
...item,
|
||||||
|
float: item.user_id === talkParams.uid ? 'right' : 'left',
|
||||||
|
}))
|
||||||
|
|
||||||
|
virtualList.value = formattedMoreRecords.concat(tempVirtualList).reverse()
|
||||||
|
|
||||||
console.log(virtualList.value)
|
console.log(virtualList.value)
|
||||||
} else {
|
} else {
|
||||||
@ -1181,7 +1195,16 @@ const onScrollToUpper = async () => {
|
|||||||
tempVirtualList[tempVirtualList.length - 1].sequence,
|
tempVirtualList[tempVirtualList.length - 1].sequence,
|
||||||
)
|
)
|
||||||
console.log(moreRecords)
|
console.log(moreRecords)
|
||||||
virtualList.value = tempVirtualList.concat(moreRecords.reverse()).reverse()
|
|
||||||
|
// 格式化新加载的消息
|
||||||
|
const formattedMoreRecords = moreRecords.map((item) => ({
|
||||||
|
...item,
|
||||||
|
float: item.user_id === talkParams.uid ? 'right' : 'left',
|
||||||
|
}))
|
||||||
|
|
||||||
|
virtualList.value = tempVirtualList
|
||||||
|
.concat(formattedMoreRecords.reverse())
|
||||||
|
.reverse()
|
||||||
|
|
||||||
console.log(virtualList.value)
|
console.log(virtualList.value)
|
||||||
|
|
||||||
@ -1309,6 +1332,7 @@ const getMentionSelectLists = (mentionSelectList) => {
|
|||||||
//根据msg信息找到对应的聊天记录,并根据sequence等查看上下文
|
//根据msg信息找到对应的聊天记录,并根据sequence等查看上下文
|
||||||
const queryRecordsByMsgInfo = async (msgInfo) => {
|
const queryRecordsByMsgInfo = async (msgInfo) => {
|
||||||
console.log(msgInfo)
|
console.log(msgInfo)
|
||||||
|
state.value.middleMsg = msgInfo
|
||||||
const dialogueList = getDialogueList(talkParams.index_name)
|
const dialogueList = getDialogueList(talkParams.index_name)
|
||||||
const recordIndex = dialogueList?.records?.findIndex(
|
const recordIndex = dialogueList?.records?.findIndex(
|
||||||
(record) => record.msg_id === msgInfo.msg_id,
|
(record) => record.msg_id === msgInfo.msg_id,
|
||||||
@ -1325,6 +1349,15 @@ const queryRecordsByMsgInfo = async (msgInfo) => {
|
|||||||
// console.log(recordIndex-startRecordIndex)
|
// console.log(recordIndex-startRecordIndex)
|
||||||
recordsList = dialogueList.records.slice(startRecordIndex, endRecordIndex)
|
recordsList = dialogueList.records.slice(startRecordIndex, endRecordIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 格式化消息,确保每条消息都有正确的 float
|
||||||
|
recordsList = recordsList.map((item) => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
float: item.user_id === talkParams.uid ? 'right' : 'left',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
zpagingRef.value.complete(recordsList.reverse())
|
zpagingRef.value.complete(recordsList.reverse())
|
||||||
loadConfig.status = dialogueList?.records?.[0]?.sequence > 1 ? 1 : 2
|
loadConfig.status = dialogueList?.records?.[0]?.sequence > 1 ? 1 : 2
|
||||||
@ -1376,6 +1409,7 @@ const findTalkRecords = (record, isMiddle, sequence, appointParams) => {
|
|||||||
end_time: '',
|
end_time: '',
|
||||||
group_member_user_id: 0, //群成员id,当查询群历史消息的时候,需要指定群成员的时候送
|
group_member_user_id: 0, //群成员id,当查询群历史消息的时候,需要指定群成员的时候送
|
||||||
sort_sequence: 'asc',
|
sort_sequence: 'asc',
|
||||||
|
create_time: state.value.middleMsg.created_at,
|
||||||
}
|
}
|
||||||
if (record) {
|
if (record) {
|
||||||
params = Object.assign({}, params, {
|
params = Object.assign({}, params, {
|
||||||
@ -1474,7 +1508,7 @@ const rpxToPx = (rpx) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
if (!state.value.recordDate) {
|
if (!state.value.keepDialogInfo) {
|
||||||
dialogueStore.setDialogue({})
|
dialogueStore.setDialogue({})
|
||||||
}
|
}
|
||||||
clearMultiSelect()
|
clearMultiSelect()
|
||||||
|
@ -96,6 +96,7 @@ import {
|
|||||||
import HighlightText from './highLightText.vue'
|
import HighlightText from './highLightText.vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { beautifyTime } from '@/utils/datetime'
|
import { beautifyTime } from '@/utils/datetime'
|
||||||
|
import { ChatMsgTypeMapping } from '@/constant/message'
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
searchItem: Object | Number,
|
searchItem: Object | Number,
|
||||||
@ -175,6 +176,13 @@ const keyMapping = {
|
|||||||
name: 'receiver_name',
|
name: 'receiver_name',
|
||||||
group_num: 'group_num',
|
group_num: 'group_num',
|
||||||
},
|
},
|
||||||
|
search_by_member_condition: {
|
||||||
|
avatar: 'avatar',
|
||||||
|
name: 'nickname',
|
||||||
|
created_at: 'created_at',
|
||||||
|
msg_type: 'msg_type',
|
||||||
|
detailKey: 'chatMessageType',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
//获取key对应值
|
//获取key对应值
|
||||||
const getKeyValue = (keys) => {
|
const getKeyValue = (keys) => {
|
||||||
@ -254,6 +262,12 @@ const resultDetail = computed(() => {
|
|||||||
case 'extra':
|
case 'extra':
|
||||||
result_detail = props.searchItem?.extra
|
result_detail = props.searchItem?.extra
|
||||||
break
|
break
|
||||||
|
case 'chatMessageType':
|
||||||
|
result_detail =
|
||||||
|
props.searchItem?.msg_type === 1
|
||||||
|
? props.searchItem?.extra?.content
|
||||||
|
: ChatMsgTypeMapping[props.searchItem?.msg_type]
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
result_detail = ''
|
result_detail = ''
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
:auto="false"
|
:auto="false"
|
||||||
:loading-more-default-as-loading="true"
|
:loading-more-default-as-loading="true"
|
||||||
:inside-more="true"
|
:inside-more="true"
|
||||||
|
v-model="state.flatList"
|
||||||
>
|
>
|
||||||
<template #top v-if="state.showPageTitle">
|
<template #top v-if="state.showPageTitle">
|
||||||
<customNavbar :title="state.pageTitle"></customNavbar>
|
<customNavbar :title="state.pageTitle"></customNavbar>
|
||||||
@ -73,11 +74,7 @@
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="search-by-condition-input"
|
class="search-by-condition-input"
|
||||||
v-if="
|
v-if="state.condition === 'file' || state.condition === 'link'"
|
||||||
state.condition === 'file' ||
|
|
||||||
state.condition === 'link' ||
|
|
||||||
state.condition === 'member'
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<customInput
|
<customInput
|
||||||
:searchText="state.searchText"
|
:searchText="state.searchText"
|
||||||
@ -117,11 +114,24 @@
|
|||||||
v-for="(item, index) in conditionItem.monthResultList"
|
v-for="(item, index) in conditionItem.monthResultList"
|
||||||
:key="index"
|
:key="index"
|
||||||
:style="{
|
:style="{
|
||||||
border: state.condition === 'imgAndVideo' ? '0' : '',
|
border:
|
||||||
|
state.condition === 'imgAndVideo' ||
|
||||||
|
state.condition === 'member'
|
||||||
|
? '0'
|
||||||
|
: '',
|
||||||
padding:
|
padding:
|
||||||
state.condition === 'imgAndVideo' ? '0 0 10rpx' : '',
|
state.condition === 'imgAndVideo' ? '0 0 10rpx' : '',
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
|
<div class="condition-result-member">
|
||||||
|
<searchItem
|
||||||
|
@click="toDialogueByMember(item)"
|
||||||
|
:searchResultKey="'search_by_member_condition'"
|
||||||
|
:searchItem="item"
|
||||||
|
:searchText="state.searchText"
|
||||||
|
:searchRecordDetail="true"
|
||||||
|
></searchItem>
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
class="condition-result-imgAndVideo"
|
class="condition-result-imgAndVideo"
|
||||||
v-if="state.condition === 'imgAndVideo'"
|
v-if="state.condition === 'imgAndVideo'"
|
||||||
@ -295,6 +305,7 @@ const state = reactive({
|
|||||||
cursor: 0, //上次查询的游标
|
cursor: 0, //上次查询的游标
|
||||||
msg_type: 0, //查询的消息类型
|
msg_type: 0, //查询的消息类型
|
||||||
group_member_id: 0, //群成员id
|
group_member_id: 0, //群成员id
|
||||||
|
flatList: [], // 用于存储扁平化的数据
|
||||||
})
|
})
|
||||||
|
|
||||||
onLoad((options) => {
|
onLoad((options) => {
|
||||||
@ -302,7 +313,10 @@ onLoad((options) => {
|
|||||||
if (options.condition) {
|
if (options.condition) {
|
||||||
state.condition = options.condition
|
state.condition = options.condition
|
||||||
if (options.condition === 'member') {
|
if (options.condition === 'member') {
|
||||||
// queryAllSearch()
|
state.showPageTitle = true
|
||||||
|
state.pageTitle = t('search.condition.member')
|
||||||
|
state.group_member_id = options.groupMemberId
|
||||||
|
queryAllSearch()
|
||||||
} else if (options.condition === 'date') {
|
} else if (options.condition === 'date') {
|
||||||
state.showPageTitle = true
|
state.showPageTitle = true
|
||||||
state.pageTitle = t('search.condition.date')
|
state.pageTitle = t('search.condition.date')
|
||||||
@ -426,6 +440,7 @@ const selectDate = async (e) => {
|
|||||||
url:
|
url:
|
||||||
'/pages/dialog/index?sessionId=' +
|
'/pages/dialog/index?sessionId=' +
|
||||||
sessionId +
|
sessionId +
|
||||||
|
'&keepDialogInfo=1' +
|
||||||
'&recordDate=' +
|
'&recordDate=' +
|
||||||
parseTime(e, '{y}-{m}-{d}'),
|
parseTime(e, '{y}-{m}-{d}'),
|
||||||
})
|
})
|
||||||
@ -557,18 +572,25 @@ const queryAllSearch = () => {
|
|||||||
} else {
|
} else {
|
||||||
noMore = true
|
noMore = true
|
||||||
}
|
}
|
||||||
console.log(dateList)
|
|
||||||
|
// 保存分组数据用于显示
|
||||||
|
state.searchResultList = dateList
|
||||||
|
|
||||||
|
// 将分组数据扁平化,用于z-paging分页
|
||||||
|
state.flatList = dateList.reduce((acc, group) => {
|
||||||
|
return acc.concat(group.monthResultList)
|
||||||
|
}, [])
|
||||||
|
|
||||||
if (state.cursor === 0) {
|
if (state.cursor === 0) {
|
||||||
state.searchResultList = dateList
|
zPaging.value?.complete(state.flatList)
|
||||||
zPaging.value?.complete(dateList)
|
|
||||||
} else {
|
} else {
|
||||||
state.searchResultList = dateList
|
zPaging.value?.completeByNoMore(state.flatList, noMore)
|
||||||
zPaging.value?.completeByNoMore(dateList, noMore)
|
|
||||||
}
|
}
|
||||||
state.cursor = data?.cursor
|
state.cursor = data?.cursor
|
||||||
} else {
|
} else {
|
||||||
if (state.cursor === 0) {
|
if (state.cursor === 0) {
|
||||||
state.searchResultList = []
|
state.searchResultList = []
|
||||||
|
state.flatList = []
|
||||||
}
|
}
|
||||||
zPaging.value?.complete([])
|
zPaging.value?.complete([])
|
||||||
}
|
}
|
||||||
@ -577,6 +599,7 @@ const queryAllSearch = () => {
|
|||||||
resp.catch(() => {
|
resp.catch(() => {
|
||||||
if (state.cursor === 0) {
|
if (state.cursor === 0) {
|
||||||
state.searchResultList = []
|
state.searchResultList = []
|
||||||
|
state.flatList = []
|
||||||
}
|
}
|
||||||
zPaging.value?.complete([])
|
zPaging.value?.complete([])
|
||||||
})
|
})
|
||||||
@ -637,6 +660,22 @@ const downloadAndOpenFile = (item) => {
|
|||||||
})
|
})
|
||||||
dtask.start()
|
dtask.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//跳转到对应的记录位置
|
||||||
|
const toDialogueByMember = async (msgInfo) => {
|
||||||
|
const sessionId = await getSessionId(
|
||||||
|
dialogueParams.talk_type,
|
||||||
|
dialogueParams.receiver_id,
|
||||||
|
)
|
||||||
|
uni.navigateTo({
|
||||||
|
url:
|
||||||
|
'/pages/dialog/index?sessionId=' +
|
||||||
|
sessionId +
|
||||||
|
'&keepDialogInfo=1' +
|
||||||
|
'&msgInfo=' +
|
||||||
|
encodeURIComponent(JSON.stringify(msgInfo)),
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.search-by-date {
|
.search-by-date {
|
||||||
|
@ -144,6 +144,7 @@ export const useTalkStore = defineStore('talk', {
|
|||||||
|
|
||||||
ServeCreateTalkList({
|
ServeCreateTalkList({
|
||||||
talk_type,
|
talk_type,
|
||||||
|
receiver_id,
|
||||||
erp_user_id,
|
erp_user_id,
|
||||||
}).then(({ code, data, message }) => {
|
}).then(({ code, data, message }) => {
|
||||||
if (code == 200) {
|
if (code == 200) {
|
||||||
|
Loading…
Reference in New Issue
Block a user