提交 0e782796 编写于 作者: DCloud_JSON's avatar DCloud_JSON

更新 修复web端在部分情况下,本地创建的单聊临时会话相关页面,打开后直接刷新会出错的问题

上级 4fee4e75
......@@ -412,6 +412,18 @@
this.$refs["chat-input"]?.focus()
}, 100)
}
const {is_temp,friend_uid} = this.conversation
if(is_temp && friend_uid){
// 为了避免在web端刷新页面之后,本地单聊临时会话丢失,将地址栏中的会话id参数替换为好友的uid,以此来确保在刷新页面之后,本地能够再次创建临时会话。
const {route:path,options} = getCurrentPages().pop()
delete options.conversation_id
options.user_id = friend_uid
let paramSrt
for (const key in options) {
paramSrt = `${key}=${options[key]}`
}
history.replaceState(null, '', `/#/${path}?${paramSrt}`)
}
// #endif
},
onclickMsgList(){
......
......@@ -97,23 +97,9 @@ export default {
methods: {
async load(options) {
console.log('options',options);
let conversation_id = options.conversation_id || options.id
// 如果只传了user_id,需要先获取conversation_id
if(!conversation_id){
if(!options.user_id){
console.error('参数错误')
return uni.showToast({
title: '参数错误',
icon: 'none'
});
}
conversation_id = await uniIm.utils.getConversationId(options.user_id)
console.log('conversation_id',conversation_id);
}
let conversation = await uniIm.conversation.get(conversation_id)
this.conversation = conversation
this.friend_uid = conversation.friend_uid
const {user_id,id} = options
this.conversation = await uniIm.conversation.get(user_id ? {user_id} : id)
this.friend_uid = this.conversation.friend_uid
let field = '_id,nickname,avatar_file'
if (this.uniIDHasRole('staff')) {
field += ',email'
......
......@@ -57,7 +57,7 @@
ref="uni-im-filtered-conversation-list"
id="conversation-list-box"
:keyword="keyword"
@to-chat="toChat($event)"
@to-chat="toChat"
@to-chat-filtered="toChatFiltered($event)"
></uni-im-filtered-conversation-list>
</template>
......@@ -81,7 +81,7 @@
<uni-icons @click="showChatInfo" class="more" type="more-filled" size="20"></uni-icons>
</view>
<view class="content">
<chat-filtered v-if="filteredConversationId" ref="chat-filtered" @to-chat="toChat($event)"/>
<chat-filtered v-if="filteredConversationId" ref="chat-filtered" @to-chat="toChat"/>
<chat-view v-else ref="chat-view"></chat-view>
<view v-if="chatInfoIsShow" class="chatInfoBox" @click.stop="chatInfoIsShow = false">
<view @click.stop class="group-info-parent">
......@@ -473,6 +473,11 @@
// goods,
// user_id
// });
if(user_id || conversation_id){
this.toChat(conversation_id || {user_id})
}
// 如果初始化时,指定了要访问的会话。将指定要访问的会话排序位置置顶,方便看到
setTimeout(()=> this.currentConversation.customIndex = Date.now(), 0);
// 如果列表小于30个会话,尝试着从云端拉取一次
if( this.conversationList.length < 30 ){
......@@ -481,27 +486,6 @@
}else{
console.log('会话列表已满一页,需要用户自己滚动到底,再拉取更多');
}
// console.log('this.conversationList.length',this.conversationList.length);
if (conversation_id) {
console.log('conversation_id', conversation_id);
this.toChat(conversation_id)
} else if (user_id) {
//创建会话
const currentConversation = await uniIm.conversation.get({
friend_uid: user_id
})
// console.log('currentConversation', currentConversation);
// 当前用户给对方发个消息
this.toChat(currentConversation.id)
}
if(user_id){
// 如果初始化时,指定了要访问的user会话。将指定要访问的会话排序位置置顶,方便看到
// 场景:插件市场,点击联系作者。自动将此会话放到首个
setTimeout(()=> {
this.currentConversation.customIndex = Date.now()
}, 0);
}
// 传递参数goods(对象格式,包含:商品名称name,链接url。自动设置对话框默认内容
if (this.isWidescreen && goods) {
......@@ -527,7 +511,7 @@
if(joinGroup){
// #ifdef H5
//删除URL后面的参数(主要是删除joinGroup=xxx),且不刷新页面
history.pushState({}, '', '/#/');
history.replaceState(null, '', '/#/')
// #endif
this.joinGroup(joinGroup)
};
......@@ -598,45 +582,26 @@
})
}
},
async toChat(param) {
this.chatInfoIsShow = false;
this.keyword = ''
this.filteredConversationId = false
const conversation_id = await getConversationId(param)
// console.log('toChat', conversation_id)
uniIm.currentConversationId = conversation_id
const {id} = await uniIm.conversation.get(param)
uniIm.currentConversationId = id
if (this.isWidescreen) { // 若为宽屏,则切换右侧的组件
this.$nextTick(() => {
let chatViewRef = this.$refs['chat-view']
if (chatViewRef) {
chatViewRef.load(conversation_id)
chatViewRef.load(id)
}
})
} else { // 若为窄屏,则打开新窗体
// param 转成字符串
uni.navigateTo({
url: '/uni_modules/uni-im/pages/chat/chat?conversation_id=' + conversation_id,
url: '/uni_modules/uni-im/pages/chat/chat?conversation_id=' + id,
animationDuration: 300
})
}
async function getConversationId(param){
if (typeof param == 'string') {
return param
} else {
if (param.conversation_id) {
return param.conversation_id
} else if (param.group_id) {
return 'group_' + param.group_id
} else if (param.user_id || param.friend_uid) {
// 获取会话id(如果此单聊会话未创建会自动创建)
return (await uniIm.conversation.get(param)).id
} else {
throw new Error("toChat param is error")
}
}
}
},
showChatInfo() {
this.chatInfoIsShow = !this.chatInfoIsShow
......
......@@ -75,21 +75,14 @@ import uniIm from '@/uni_modules/uni-im/sdk/index.js';
'more'; // oading 的状态,可选值:more(loading前)、loading(loading中)、noMore(没有更多了)
},
async toChat(user_id) {
//拿到会话(如果没有自动创建)
const currentConversation = await uniIm.conversation.get({
friend_uid:user_id
});
console.log('currentConversation', currentConversation);
// 当前用户给对方发个消息
if (this.isWidescreen) {
//若为宽屏,则触发右侧详情页的自定义事件,通知右侧窗体刷新详情
uni.navigateTo({
url: '/uni_modules/uni-im/pages/index/index?conversation_id=' + currentConversation.id
});
location.href = '/#/uni_modules/uni-im/pages/index/index?user_id=' + user_id
} else {
// 若为窄屏,则打开新窗体,在新窗体打开详情页面
uni.navigateTo({
url: '/uni_modules/uni-im/pages/chat/chat?conversation_id=' + currentConversation.id
url: '/uni_modules/uni-im/pages/chat/chat?user_id=' + user_id
});
}
},
......
......@@ -50,6 +50,14 @@ export default class Conversation extends CloudData {
// 设置为默认按id查找会话,而不是按_id查找
return {id:param}
}else if(typeof param === 'object' && param !== null && !Array.isArray(param)){
const {user_id,friend_uid,conversation_id:id} = param
if(id){
param.id = id
delete param.conversation_id
}else if(user_id){
param.friend_uid = friend_uid || user_id
delete param.user_id
}
if('source' in param){
// 本地查找不需要source字段
const source = param.source
......@@ -67,13 +75,6 @@ export default class Conversation extends CloudData {
}
},0)
}
if('user_id' in param){
// param = {friend_uid:param.user_id}
param.friend_uid = param.user_id
delete param.user_id
}else if('conversation_id' in param){
param = {id:param.conversation_id}
}
return param
}
}
......@@ -91,7 +92,9 @@ export default class Conversation extends CloudData {
"type": param.friend_uid ? 1 : 2,
"msgList": [],
"update_time": Date.now(),
"customSortTime": Date.now()
"customSortTime": Date.now(),
// 是本地临时会话数据
"is_temp": true
}
const conversation = this.add(conversationData)
$users.get(friend_uid).then(res => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册