Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-im
提交
0e782796
U
uni-im
项目概览
DCloud
/
uni-im
通知
3
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-im
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
0e782796
编写于
11月 08, 2024
作者:
DCloud_JSON
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新 修复web端在部分情况下,本地创建的单聊临时会话相关页面,打开后直接刷新会出错的问题
上级
4fee4e75
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
43 addition
and
84 deletion
+43
-84
pages/chat/chat.vue
pages/chat/chat.vue
+12
-0
pages/chat/info.vue
pages/chat/info.vue
+3
-17
pages/index/index.vue
pages/index/index.vue
+15
-50
pages/userList/userList.vue
pages/userList/userList.vue
+2
-9
sdk/state/Conversation.class.js
sdk/state/Conversation.class.js
+11
-8
未找到文件。
pages/chat/chat.vue
浏览文件 @
0e782796
...
...
@@ -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
(){
...
...
pages/chat/info.vue
浏览文件 @
0e782796
...
...
@@ -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
'
...
...
pages/index/index.vue
浏览文件 @
0e782796
...
...
@@ -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
...
...
pages/userList/userList.vue
浏览文件 @
0e782796
...
...
@@ -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
});
}
},
...
...
sdk/state/Conversation.class.js
浏览文件 @
0e782796
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录