From 380b0120bceae996d459477a001b33bc46f74896 Mon Sep 17 00:00:00 2001
From: wangyifeng <812766448@qq.com>
Date: Sat, 15 Mar 2025 16:44:40 +0800
Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BB=8E=E6=90=9C=E7=B4=A2?=
=?UTF-8?q?=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95=E8=B7=B3=E8=BD=AC=E8=81=8A?=
=?UTF-8?q?=E5=A4=A9=E6=97=B6=EF=BC=8C=E4=B8=8B=E6=8B=89=E5=88=B7=E6=96=B0?=
=?UTF-8?q?=E4=B8=8A=E6=8B=89=E5=8A=A0=E8=BD=BD=E6=95=B0=E6=8D=AE=E9=94=99?=
=?UTF-8?q?=E8=AF=AF=E9=97=AE=E9=A2=98=EF=BC=9B=E8=A7=A3=E5=86=B3=E5=9B=BE?=
=?UTF-8?q?=E7=89=87=E3=80=81=E8=A7=86=E9=A2=91=E3=80=81=E6=96=87=E4=BB=B6?=
=?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=90=8E=E4=BC=9A=E5=8F=98=E6=88=902?=
=?UTF-8?q?=E6=9D=A1=E9=97=AE=E9=A2=98=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/App.vue | 2 +-
src/event/talk.js | 9 ++++
src/pages/dialog/components/filePanel.vue | 13 ++++--
src/pages/dialog/dialogDetail/userDetail.vue | 10 ++++-
src/pages/dialog/index.vue | 27 +++++-------
src/pages/search/components/searchItem.vue | 2 +
src/pages/search/components/searchList.vue | 26 ++++++++++-
src/pages/search/index.vue | 21 ++++++++-
src/pages/search/moreResult/moreResult.vue | 27 +++++++++++-
.../search/moreResult/moreResultDetail.vue | 44 ++++++++++++++++---
src/store/modules/dialogueList.js | 13 +++++-
src/store/modules/uploads.ts | 7 +--
12 files changed, 163 insertions(+), 38 deletions(-)
diff --git a/src/App.vue b/src/App.vue
index acd16a7..3514e2f 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -17,7 +17,7 @@ const handleWebview = () => {
// top: statusBarHeight_,
// bottom: 0,
// })
- // console.log(webview)
+ console.log("webview", webview)
token.value = webview.token
}
const init = () => {
diff --git a/src/event/talk.js b/src/event/talk.js
index 2c3b830..aaf7488 100644
--- a/src/event/talk.js
+++ b/src/event/talk.js
@@ -32,6 +32,11 @@ class Talk extends Base {
*/
talk_type = 0
+ /**
+ * 文件上传唯一随机值
+ */
+ fileNum = ''
+
/**
* 初始化构造方法
*
@@ -43,6 +48,10 @@ class Talk extends Base {
this.sender_id = resource.sender_id
this.receiver_id = resource.receiver_id
this.talk_type = resource.talk_type
+ // this.fileNum = resource.file_num
+ if(resource.file_num){
+ resource.data.file_num = resource.file_num
+ }
this.resource = resource.data
this.handle()
diff --git a/src/pages/dialog/components/filePanel.vue b/src/pages/dialog/components/filePanel.vue
index afd8612..f838083 100644
--- a/src/pages/dialog/components/filePanel.vue
+++ b/src/pages/dialog/components/filePanel.vue
@@ -74,7 +74,7 @@ const photoActionsSelect = (index) => {
console.log(res,'res');
res.tempFiles.forEach(async (file) => {
let data = await onUploadImageVideo(file, 'image')
- emit('selectImg', data)
+ emit('selectImg', data, data.file_num)
})
}
})
@@ -84,7 +84,7 @@ const photoActionsSelect = (index) => {
success: async (res) => {
console.log(res,'res');
let data = await onUploadImageVideo(res.tempFile, 'video',res.tempFilePath)
- emit('selectImg', data)
+ emit('selectImg', data, data.file_num)
}
})
}
@@ -119,6 +119,7 @@ const onUploadImageVideo = async (file, type = 'image',fileUrl) => {
is_read: 0,
is_revoke: 0,
msg_id: randomId,
+ file_num: randomId,
msg_type: 3,
nickname: userStore.nickname,
receiver_id: dialogueStore.talk.receiver_id,
@@ -137,7 +138,8 @@ const onUploadImageVideo = async (file, type = 'image',fileUrl) => {
url: data.ori_url,
size: file.size,
width: image.width,
- height: image.height
+ height: image.height,
+ file_num: randomId,
})
} else {
resolve('')
@@ -171,6 +173,7 @@ const onUploadImageVideo = async (file, type = 'image',fileUrl) => {
is_read: 0,
is_revoke: 0,
msg_id: randomId,
+ file_num: randomId,
msg_type: 5,
nickname: userStore.nickname,
receiver_id: dialogueStore.talk.receiver_id,
@@ -189,7 +192,8 @@ const onUploadImageVideo = async (file, type = 'image',fileUrl) => {
url: data.ori_url,
cover: data.cover_url,
duration: parseInt(resp.duration),
- size: file.size
+ size: file.size,
+ file_num: randomId,
})
} else {
// resolve('')
@@ -313,6 +317,7 @@ const chooseFile = () => {
is_read: 0,
is_revoke: 0,
msg_id: randomId,
+ file_num: randomId,
msg_type: 6,
nickname: userStore.nickname,
receiver_id: dialogueStore.talk.receiver_id,
diff --git a/src/pages/dialog/dialogDetail/userDetail.vue b/src/pages/dialog/dialogDetail/userDetail.vue
index 2024328..4f110b5 100644
--- a/src/pages/dialog/dialogDetail/userDetail.vue
+++ b/src/pages/dialog/dialogDetail/userDetail.vue
@@ -62,7 +62,11 @@
@@ -103,8 +107,9 @@ import ZPaging from '@/uni_modules/z-paging/components/z-paging/z-paging.vue'
import { onLoad } from '@dcloudio/uni-app'
import { reactive } from 'vue'
-import { useTalkStore } from '@/store'
+import { useTalkStore, useUserStore } from '@/store'
const talkStore = useTalkStore()
+const userStore = useUserStore()
import { getUserInfoByClickAvatar } from '@/api/user/index'
@@ -117,6 +122,7 @@ const state = reactive({
userBasicInfos: [], //用户基本信息
isShowPhoneCall: false, //是否显示电话拨号弹框
phoneNumber: '', //手机号
+ uid: computed(() => userStore.uid), //当前用户id
})
onLoad((options) => {
diff --git a/src/pages/dialog/index.vue b/src/pages/dialog/index.vue
index 6b0335e..be94a6c 100644
--- a/src/pages/dialog/index.vue
+++ b/src/pages/dialog/index.vue
@@ -863,8 +863,8 @@ const editorOption = {
placeholder: '',
}
-const handleSelectImg = (data) => {
- onSendMessage({ ...data })
+const handleSelectImg = (data, file_num) => {
+ onSendMessage({ ...data, file_num })
}
const virtualListChange = (vList) => {
@@ -1094,7 +1094,7 @@ const onScrollToLower = () => {
} else {
if (tempVirtualList[0].sequence > dialogueList.records[0].sequence) {
virtualList.value = dialogueList.records
- .slice(0, recordIndex)
+ .slice(Math.max(0, recordIndex - 10), recordIndex)
.concat(tempVirtualList)
.reverse()
// zpagingRef.value.setLocalPaging(
@@ -1131,27 +1131,22 @@ const onScrollToUpper = () => {
tempVirtualList[tempVirtualList.length - 1].sequence <
dialogueList.records[dialogueList.records.length - 1].sequence
) {
+ // 记住加载更多前消息的ID
+ const currentMsgId = tempVirtualList[tempVirtualList.length - 1].msg_id
+
virtualList.value = tempVirtualList
.concat(
dialogueList.records.slice(
- recordIndex + 1,
+ Math.min(recordIndex + 11, dialogueList.records.length),
dialogueList.records.length,
),
)
.reverse()
- // zpagingRef.value.setLocalPaging(
- // tempVirtualList
- // .concat(
- // dialogueList.records.slice(
- // recordIndex + 1,
- // dialogueList.records.length,
- // ),
- // )
- // .reverse(),
- // // zpagingRef.value.scrollIntoViewById('zp-id-' + virtualList.value[virtualList.value.length - 1].msg_id)
- // )
- console.log(virtualList.value)
+ // 数据更新后,滚动到之前的位置
+ nextTick(() => {
+ zpagingRef.value?.scrollIntoViewById('zp-id-' + currentMsgId)
+ })
}
}
}
diff --git a/src/pages/search/components/searchItem.vue b/src/pages/search/components/searchItem.vue
index 448348c..f1e6cc5 100644
--- a/src/pages/search/components/searchItem.vue
+++ b/src/pages/search/components/searchItem.vue
@@ -275,6 +275,7 @@ const resultDetail = computed(() => {
padding: 2rpx 14rpx;
border: 2rpx solid #000;
border-radius: 6rpx;
+ flex-shrink: 0;
span {
line-height: 34rpx;
}
@@ -299,6 +300,7 @@ const resultDetail = computed(() => {
.info-detail-searchRecordDetail {
span {
color: $theme-text;
+ word-break: break-all;
}
}
}
diff --git a/src/pages/search/components/searchList.vue b/src/pages/search/components/searchList.vue
index 7e9cb05..19cda5d 100644
--- a/src/pages/search/components/searchList.vue
+++ b/src/pages/search/components/searchList.vue
@@ -117,6 +117,10 @@ import { useI18n } from 'vue-i18n'
import { ref, reactive, defineEmits, defineProps, onMounted } from 'vue'
import pointerIconSrc from '@/static/image/search/search-item-pointer.png'
+import lodash from 'lodash'
+import { useUserStore } from '@/store'
+const userStore = useUserStore()
+
const zPaging = ref()
useZPaging(zPaging)
@@ -131,6 +135,7 @@ const state = reactive({
searchResultList: [], //搜素结果列表
searchResult: null, //搜索结果
pageNum: 1, //当前请求数据页数
+ uid: computed(() => userStore.uid), //当前用户id
})
const props = defineProps({
@@ -197,10 +202,29 @@ const queryAllSearch = (pageNum, searchResultPageSize) => {
})
}
if ((data.talk_record_infos || []).length > 0) {
+ let receiverInfo = lodash.cloneDeep(data.talk_record_infos[0])
+ if (receiverInfo.talk_type === 1) {
+ //单聊才需此判断
+ if (receiverInfo.user_id === state.uid) {
+ //发送人是自己,接收人不需要变
+ }
+ if (receiverInfo.receiver_id === state.uid) {
+ //接收人是自己,这里需要变成对方
+ let temp_id = receiverInfo.receiver_id
+ let temp_name = receiverInfo.receiver_name
+ let temp_avatar = receiverInfo.receiver_avatar
+ receiverInfo.receiver_id = receiverInfo.user_id
+ receiverInfo.receiver_name = receiverInfo.user_name
+ receiverInfo.receiver_avatar = receiverInfo.user_avatar
+ receiverInfo.user_id = temp_id
+ receiverInfo.user_name = temp_name
+ receiverInfo.user_avatar = temp_avatar
+ }
+ }
state.first_talk_record_infos = Object.assign(
{},
state.first_talk_record_infos,
- data.talk_record_infos[0],
+ receiverInfo,
)
;(data.talk_record_infos || []).forEach((item) => {
item.group_type = 0
diff --git a/src/pages/search/index.vue b/src/pages/search/index.vue
index b84a80b..a158244 100644
--- a/src/pages/search/index.vue
+++ b/src/pages/search/index.vue
@@ -17,6 +17,10 @@ import { ServeSeachQueryAll } from '@/api/search/index'
import { onMounted } from 'vue'
import { handleSetWebviewStyle } from '@/utils/common'
+import { useDialogueStore } from '@/store'
+
+const dialogueStore = useDialogueStore()
+
onMounted(() => {
handleSetWebviewStyle()
})
@@ -38,9 +42,24 @@ const clickSearchItem = (
searchResultKey,
talk_type,
receiver_id,
+ res,
) => {
console.log(searchResultKey)
- if (searchResultKey === 'general_infos') {
+ const result = JSON.parse(decodeURIComponent(res))
+ console.log(result)
+ if (searchResultKey === 'user_infos') {
+
+
+ } else if (searchResultKey === 'combinedGroup') {
+ dialogueStore.setDialogue({
+ name: result.name || result.group_name,
+ talk_type: result.type || 2,
+ receiver_id: result.id || result.group_id,
+ })
+ uni.navigateTo({
+ url: '/pages/dialog/index',
+ })
+ } else if (searchResultKey === 'general_infos') {
uni.navigateTo({
url:
'/pages/search/moreResult/moreResultDetail?searchText=' +
diff --git a/src/pages/search/moreResult/moreResult.vue b/src/pages/search/moreResult/moreResult.vue
index d946698..bb187ed 100644
--- a/src/pages/search/moreResult/moreResult.vue
+++ b/src/pages/search/moreResult/moreResult.vue
@@ -24,6 +24,10 @@ import {
} from '@/api/search/index'
import { reactive } from 'vue'
+import { useDialogueStore } from '@/store'
+
+const dialogueStore = useDialogueStore()
+
const state = reactive({
apiRequest: Function,
apiParams: String,
@@ -86,8 +90,27 @@ const lastIdChange = (last_id, last_group_id, last_member_id) => {
}
//点击了搜索结果项
-const clickSearchItem = (searchText) => {
- if (state.searchResultKey === 'general_infos') {
+const clickSearchItem = (
+ searchText,
+ searchResultKey,
+ talk_type,
+ receiver_id,
+ res,
+) => {
+ console.log(state.searchResultKey)
+ const result = JSON.parse(decodeURIComponent(res))
+ console.log(result)
+ if (state.searchResultKey === 'user_infos') {
+ } else if (state.searchResultKey === 'combinedGroup') {
+ dialogueStore.setDialogue({
+ name: result.name || result.group_name,
+ talk_type: result.type || 2,
+ receiver_id: result.id || result.group_id,
+ })
+ uni.navigateTo({
+ url: '/pages/dialog/index',
+ })
+ } else if (state.searchResultKey === 'general_infos') {
uni.navigateTo({
url: '/pages/search/moreResult/moreResultDetail?searchText=' + searchText,
})
diff --git a/src/pages/search/moreResult/moreResultDetail.vue b/src/pages/search/moreResult/moreResultDetail.vue
index 247b809..4debfc6 100644
--- a/src/pages/search/moreResult/moreResultDetail.vue
+++ b/src/pages/search/moreResult/moreResultDetail.vue
@@ -20,13 +20,16 @@ import searchList from '../components/searchList.vue'
import { onLoad } from '@dcloudio/uni-app'
import { ServeTalkRecord } from '@/api/search/index'
import { reactive } from 'vue'
-import { useDialogueStore } from "@/store";
+import { useDialogueStore, useUserStore } from '@/store'
+import lodash from 'lodash'
-const dialogueStore = useDialogueStore();
+const dialogueStore = useDialogueStore()
+const userStore = useUserStore()
const state = reactive({
apiParams: String,
searchText: String,
+ uid: computed(() => userStore.uid), //当前用户id
})
onLoad((options) => {
@@ -80,15 +83,42 @@ const clickSearchItem = (
receiver_id,
res,
) => {
+ console.log(searchResultKey)
let result = JSON.parse(decodeURIComponent(res))
+ console.log(result)
+ let receiverInfo = lodash.cloneDeep(result)
+ if (receiverInfo.talk_type === 1) {
+ //单聊才需此判断
+ if (receiverInfo.user_id === state.uid) {
+ //发送人是自己,接收人不需要变
+ }
+ if (receiverInfo.receiver_id === state.uid) {
+ //接收人是自己,这里需要变成对方
+ let temp_id = receiverInfo.receiver_id
+ let temp_name = receiverInfo.receiver_name
+ let temp_avatar = receiverInfo.receiver_avatar
+ receiverInfo.receiver_id = receiverInfo.user_id
+ receiverInfo.receiver_name = receiverInfo.user_name
+ receiverInfo.receiver_avatar = receiverInfo.user_avatar
+ receiverInfo.user_id = temp_id
+ receiverInfo.user_name = temp_name
+ receiverInfo.user_avatar = temp_avatar
+ }
+ }
dialogueStore.setDialogue({
- name: result.receiver_name,
+ name: receiverInfo.receiver_name,
talk_type: talk_type,
- receiver_id: receiver_id,
- })
- uni.navigateTo({
- url: '/pages/dialog/index?msgInfo=' + res,
+ receiver_id: receiverInfo.receiver_id,
})
+ if (searchResultKey === 'talk_record_infos_receiver') {
+ uni.navigateTo({
+ url: '/pages/dialog/index',
+ })
+ } else {
+ uni.navigateTo({
+ url: '/pages/dialog/index?msgInfo=' + res,
+ })
+ }
}
diff --git a/src/store/modules/dialogueList.js b/src/store/modules/dialogueList.js
index e190589..7dc58f1 100644
--- a/src/store/modules/dialogueList.js
+++ b/src/store/modules/dialogueList.js
@@ -107,7 +107,18 @@ export const useDialogueListStore = createGlobalState(() => {
const addChatRecord = (indexName, item) => {
const dialogue = lodash.cloneDeep(useDialogueStore())
if (dialogue?.index_name === indexName) {
- zpagingRef.value?.addChatRecordData(item, false, false)
+ const index = virtualList.value.findIndex(
+ (v) => v?.file_num === item?.file_num,
+ )
+ if (index > -1) {
+ // 保持响应性的同时替换整个对象
+ virtualList.value.splice(index, 1, {
+ ...virtualList.value[index], // 保留原有不需要修改的字段
+ ...item, // 覆盖需要更新的字段
+ })
+ } else {
+ zpagingRef.value?.addChatRecordData(item, false, false)
+ }
}
}
diff --git a/src/store/modules/uploads.ts b/src/store/modules/uploads.ts
index 219d036..baba8b7 100644
--- a/src/store/modules/uploads.ts
+++ b/src/store/modules/uploads.ts
@@ -104,7 +104,7 @@ export const useUploadsStore = defineStore('uploads', {
console.log(msgId,'msgId');
updateUploadProgress(msgId,100)
- this.sendUploadMessage(item)
+ this.sendUploadMessage(item, msgId)
} else {
const percentage = (item.uploadIndex / item.files.length) * 100
item.percentage = percentage.toFixed(1)
@@ -124,11 +124,12 @@ export const useUploadsStore = defineStore('uploads', {
},
// 发送上传消息
- sendUploadMessage(item: any) {
+ sendUploadMessage(item: any, file_num: String) {
ServeSendTalkFile({
upload_id: item.upload_id,
receiver_id: item.receiver_id,
- talk_type: item.talk_type
+ talk_type: item.talk_type,
+ file_num: file_num
})
}
}