修复 私聊聊天 头像不正确的bug

This commit is contained in:
sx 2025-02-18 15:02:33 +08:00
parent 0fa8e522b1
commit 0084fe8aa1
1 changed files with 557 additions and 550 deletions

View File

@ -1,10 +1,10 @@
<script setup>
/**
/**
* 聊天页面
*/
//
import TencentCloudChat from '@tencentcloud/chat';
import {
//
import TencentCloudChat from '@tencentcloud/chat';
import {
ref,
reactive,
nextTick,
@ -13,37 +13,37 @@ import {
computed,
getCurrentInstance,
watch,
} from 'vue'
// api
import api from '@/api/index.js'
//
import util from '@/common/js/util.js'
import {
} from 'vue'
// api
import api from '@/api/index.js'
//
import util from '@/common/js/util.js'
import {
onLoad,
onReady,
onPageScroll,
onUnload
} from "@dcloudio/uni-app"
} from "@dcloudio/uni-app"
//
import newsTemplate from './components/news-temp'
//
import emoji from './emoji.vue'
//
import JyVoice from './jy-voice.vue'
//
import JyPlus from './jy-plus.vue'
//
import newsTemplate from './components/news-temp'
//
import emoji from './emoji.vue'
//
import JyVoice from './jy-voice.vue'
//
import JyPlus from './jy-plus.vue'
import {
import {
useStore
} from 'vuex'
const {
} from 'vuex'
const {
proxy
} = getCurrentInstance()
const store = useStore()
} = getCurrentInstance()
const store = useStore()
//
const msg = reactive({
//
const msg = reactive({
//
id: '',
// C2C GROUP
@ -52,41 +52,41 @@ const msg = reactive({
num: '',
//
isCustomer: false,
})
//
const content = ref('')
//
const loading = ref(false)
//
const userinfo = computed(() => {
})
//
const content = ref('')
//
const loading = ref(false)
//
const userinfo = computed(() => {
let result = store.state.userinfo
return result
})
//
const list = reactive({
})
//
const list = reactive({
//
limit: 20,
//
data: [],
//
total: 0,
})
//
const top = ref(0)
//
const toolHeight = ref(0)
//
const messageItem = ref({})
// voice input emoji plus
const toolStatus = ref('input')
// video
const videoUrl = ref('')
//
const videoContext = ref(null)
//
const redPacket = reactive({})
})
//
const top = ref(0)
//
const toolHeight = ref(0)
//
const messageItem = ref({})
// voice input emoji plus
const toolStatus = ref('input')
// video
const videoUrl = ref('')
//
const videoContext = ref(null)
//
const redPacket = reactive({})
onLoad(option => {
onLoad(option => {
//
let title = ''
//
@ -121,30 +121,30 @@ onLoad(option => {
})
})
// #endif
})
})
onReady(() => {
onReady(() => {
uni.createSelectorQuery().in(proxy).select('#tool').boundingClientRect((rect) => {
toolHeight.value = rect.height
}).exec();
//
videoContext.value = uni.createVideoContext('video')
})
})
onPageScroll((ev) => {
onPageScroll((ev) => {
onContentScroll(ev)
})
})
onUnload(() => {
onUnload(() => {
// #ifdef APP
uni.offKeyboardHeightChange(() => { })
uni.offKeyboardHeightChange(() => {})
// #endif
videoContext.value.stop()
})
})
//
function addListener() {
let onMessageReceived = function (event) {
//
function addListener() {
let onMessageReceived = function(event) {
console.log('TencentCloudChat.EVENT.MESSAGE_RECEIVED', event)
setTimeout(() => {
//
@ -156,32 +156,32 @@ function addListener() {
}
uni.$chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);
}
}
//
function removeListener() {
//
function removeListener() {
uni.$chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED);
}
}
//
function getMoreHistroy() {
//
function getMoreHistroy() {
//
if (list.total <= list.data.length) return
getHistory({
msgId: list.data[0].id
})
}
}
/**
/**
* 获取历史记录
* @param {Object} param
*/
function getHistory(param = {}) {
function getHistory(param = {}) {
// sdk
let isReady = uni.$chat.isReady();
//
if (!isReady && userinfo.value.id) {
setTimeout(function () {
setTimeout(function() {
getHistory(param)
}, 200);
return
@ -207,6 +207,8 @@ function getHistory(param = {}) {
if (res.code === 200) {
//
const result = res.data
//
list.faceUrl = result.faceUrl
//
if (param.limit == 1) {
@ -238,10 +240,10 @@ function getHistory(param = {}) {
}).finally(() => {
loading.value = false
})
}
}
//
function scrollToBottom() {
//
function scrollToBottom() {
uni.createSelectorQuery().in(proxy).select('#scroll-content').boundingClientRect((res) => {
top.value = res.height
@ -251,29 +253,29 @@ function scrollToBottom() {
})
// console.log('top.value', top.value)
}).exec();
}
}
//
function debounce(func, wait = 500) {
//
function debounce(func, wait = 500) {
let timeout = null;
return function (...args) {
return function(...args) {
clearTimeout(timeout)
timeout = setTimeout(() => {
func.apply(this, args)
}, wait);
}
}
}
//
function onContentScroll(ev) {
//
function onContentScroll(ev) {
if (ev.scrollTop == 50) getMoreHistroy()
debounce(() => {
top.value = ev.detail.scrollTop
})
}
}
//
function handleSend() {
//
function handleSend() {
//
sendMsg({
query: {
@ -289,21 +291,21 @@ function handleSend() {
content.value = ''
}
})
}
}
/**
/**
* 加号菜单发送
* @param {Object} message 消息对象
*/
function handlePlusSend(message) {
function handlePlusSend(message) {
sendMsg(message)
}
}
/**
/**
* 发送消息
* @param {Object} param
*/
function sendMsg(param) {
function sendMsg(param) {
//
let request = api.news.sendUserMsg
//
@ -326,13 +328,13 @@ function sendMsg(param) {
}).catch((rs) => {
console.log('sendMsg error:', rs);
})
}
}
/**
/**
* 打开红包详情
* @param {Object} ev
*/
function handleRedPacket(ev) {
function handleRedPacket(ev) {
messageItem.value = ev
api.news.getRedPacketInfo({
query: {
@ -350,10 +352,10 @@ function handleRedPacket(ev) {
showCancel: false,
})
})
}
}
//
function handleOpenReadPacket() {
//
function handleOpenReadPacket() {
//
if (redPacket.redStatus == false) return
//
@ -371,7 +373,7 @@ function handleOpenReadPacket() {
sendType: {
'C2C': '1',
'GROUP': '2',
}[msg.type],
} [msg.type],
}
}).then(rs => {
if (rs.code == 200) {
@ -386,73 +388,73 @@ function handleOpenReadPacket() {
showCancel: false,
})
})
}
}
// emoji
function emojiTap(val) {
// emoji
function emojiTap(val) {
content.value = content.value + val
}
}
//
function handleTool(val) {
//
function handleTool(val) {
if (toolStatus.value === val) {
toolStatus.value = 'input'
return
}
toolStatus.value = val
}
}
//
function onFocus() {
//
function onFocus() {
handleTool('input')
}
}
//
function voiceSend(message) {
//
function voiceSend(message) {
console.log('handlePlusSend', message)
sendMsg({
message,
})
}
}
//
const handleScroll = (e) => {
//
const handleScroll = (e) => {
if (e.detail.scrollTop === 0) {
getHistory()
}
}
}
//
const showGhost = ref(false)
//
const ghostBox = ref({
//
const showGhost = ref(false)
//
const ghostBox = ref({
height: '0px',
duration: '0.25s'
})
})
//
function keyboardheightchange(res) {
//
function keyboardheightchange(res) {
ghostBox.value = res.detail
nextTick(() => {
showGhost.value = res.detail.height > 0 ? true : false
})
}
}
/**
/**
* 看视频
* @param {Object} item 聊天消息对象
*/
function handleViewVideo(item) {
function handleViewVideo(item) {
videoUrl.value = item.payload.videoUrl
//
videoContext.value.requestFullScreen()
}
}
//
function onScreenChange(ev) {
//
function onScreenChange(ev) {
console.log('onScreenChange', ev)
if (!ev.fullScreen) videoContext.value.pause()
}
}
</script>
<template>
@ -464,13 +466,18 @@ function onScreenChange(ev) {
<!-- 普通消息 -->
<view class="message"
:class="[(item.From_Account || item.fromId) == userinfo.id ? 'self' : 'friend']">
<template v-if="msg.type == 'C2C'">
<!-- 如果是我自己 -->
<view v-if="msg.type == 'C2C'">
<template v-if="(item.From_Account || item.fromId) == userinfo.id">
<image :src="userinfo.avatar" class="avatar wh80" mode="aspectFill" />
</template>
<template v-else>
<image :src="list.faceUrl" class="avatar wh80" mode="aspectFill" />
</view>
<view v-else>
</template>
</template>
<template v-else>
<image :src="item.fromFaceUrl" class="avatar wh80" mode="aspectFill" />
</view>
</template>
<view class="df fdc mlr20">
<!-- 昵称 -->
@ -567,17 +574,17 @@ function onScreenChange(ev) {
<style lang="scss" scoped>
@import './index.scss';
@import './index.scss';
//
#video {
//
#video {
position: fixed;
top: 100%;
left: 0;
}
}
//
.red-bag {
//
.red-bag {
position: relative;
width: 528rpx;
height: 60vh;
@ -709,5 +716,5 @@ function onScreenChange(ev) {
}
}
}
}
}
</style>