修复已知问题
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
import TUIChatEngine, {
|
||||
TUIConversationService,
|
||||
TUIFriendService,
|
||||
TUIGroupService,
|
||||
TUIUserService
|
||||
} from '@tencentcloud/chat-uikit-engine-lite'
|
||||
import { useUI } from '../../utils/use-ui'
|
||||
@@ -11,6 +12,7 @@
|
||||
import { TUIGlobal } from '@tencentcloud/universal-api'
|
||||
import PopupBox from '../my-index/components/popup-box.vue'
|
||||
import SwitchBar from '../../TUIKit/components/common/SwitchBar/index.vue'
|
||||
import { TUIConstants, TUICore } from '@tencentcloud/tui-core-lite'
|
||||
|
||||
const { showLoading, hideLoading, showToast, showDialog } = useUI()
|
||||
|
||||
@@ -38,6 +40,53 @@
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示对应群信息
|
||||
* @param res 群信息
|
||||
* @param state 0 只能加入群 1 显示对应状态按钮
|
||||
*/
|
||||
const getGroupData = (res, state) => {
|
||||
console.log(res, '==')
|
||||
friendInfo.value = {
|
||||
...res,
|
||||
avatar: res.avatar,
|
||||
nick: res.name,
|
||||
cbType: 'group'
|
||||
}
|
||||
isDetail.value = !!res.selfInfo.role
|
||||
loading.value = false
|
||||
hideLoading()
|
||||
}
|
||||
|
||||
/** 获取群信息 */
|
||||
const getGroupInfo = () => {
|
||||
loading.value = true
|
||||
showLoading()
|
||||
TUICore.callService({
|
||||
serviceName: TUIConstants.TUISearch.SERVICE.NAME,
|
||||
method: TUIConstants.TUISearch.SERVICE.METHOD.SEARCH_GROUP,
|
||||
params: {
|
||||
groupID: userId.value
|
||||
}
|
||||
})
|
||||
.then(res => {
|
||||
TUIGroupService.getGroupProfile({
|
||||
groupID: res.data.group.groupID
|
||||
})
|
||||
.then(c => {
|
||||
getGroupData(c.data.group, 1)
|
||||
})
|
||||
.catch(crr => {
|
||||
getGroupData(res.data.group, 0)
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err, '==')
|
||||
loading.value = false
|
||||
hideLoading()
|
||||
})
|
||||
}
|
||||
|
||||
/** 获取好友信息 */
|
||||
const getFriendInfo = async () => {
|
||||
loading.value = true
|
||||
@@ -73,37 +122,68 @@
|
||||
}
|
||||
|
||||
const submit = async () => {
|
||||
// 在这里可以添加提交验证信息的逻辑
|
||||
let source = 'AddSource_Type_Web' // 来源渠道
|
||||
// #ifdef H5
|
||||
source = 'AddSource_Type_H5'
|
||||
// #endif
|
||||
|
||||
// 判断是否为 App(5+ App)
|
||||
// #ifdef APP-PLUS
|
||||
source = 'AddSource_Type_App'
|
||||
// #endif
|
||||
showLoading()
|
||||
try {
|
||||
await TUIFriendService.addFriend({
|
||||
to: userId.value,
|
||||
source,
|
||||
remark: remark.value || '',
|
||||
wording: verificationInfo.value,
|
||||
type: TUIChatEngine.TYPES.SNS_ADD_TYPE_BOTH
|
||||
if (friendInfo.value?.cbType === 'group') {
|
||||
TUIGroupService.joinGroup({
|
||||
groupID: friendInfo.value.groupID,
|
||||
applyMessage: verificationInfo.value
|
||||
})
|
||||
hideLoading()
|
||||
await showToast('好友请求已发送', 'success')
|
||||
navigateBack()
|
||||
} catch (error) {
|
||||
if (error.code === 30515) {
|
||||
.then(imResponse => {
|
||||
switch (imResponse?.data?.status) {
|
||||
case TUIChatEngine.TYPES.JOIN_STATUS_WAIT_APPROVAL: // Wait for administrator approval
|
||||
hideLoading()
|
||||
showToast('等待管理员同意', 'success')
|
||||
break
|
||||
case TUIChatEngine.TYPES.JOIN_STATUS_SUCCESS: // Join group successfully
|
||||
hideLoading()
|
||||
showToast('加群成功', 'success')
|
||||
break
|
||||
case TUIChatEngine.TYPES.JOIN_STATUS_ALREADY_IN_GROUP: // Already in the group
|
||||
hideLoading()
|
||||
showToast('您已是群成员', 'success')
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn('join group failed:', error)
|
||||
hideLoading()
|
||||
showToast('申请入群失败', 'error')
|
||||
})
|
||||
} else {
|
||||
// 在这里可以添加提交验证信息的逻辑
|
||||
let source = 'AddSource_Type_Web' // 来源渠道
|
||||
// #ifdef H5
|
||||
source = 'AddSource_Type_H5'
|
||||
// #endif
|
||||
|
||||
// 判断是否为 App(5+ App)
|
||||
// #ifdef APP-PLUS
|
||||
source = 'AddSource_Type_App'
|
||||
// #endif
|
||||
|
||||
try {
|
||||
await TUIFriendService.addFriend({
|
||||
to: userId.value,
|
||||
source,
|
||||
remark: remark.value || '',
|
||||
wording: verificationInfo.value,
|
||||
type: TUIChatEngine.TYPES.SNS_ADD_TYPE_BOTH
|
||||
})
|
||||
hideLoading()
|
||||
const show = await showDialog(
|
||||
'提示',
|
||||
'该用户在黑名单中,不允许加好友'
|
||||
)
|
||||
if (show) {
|
||||
navigateBack()
|
||||
await showToast('好友请求已发送', 'success')
|
||||
navigateBack()
|
||||
} catch (error) {
|
||||
if (error.code === 30515) {
|
||||
hideLoading()
|
||||
const show = await showDialog(
|
||||
'提示',
|
||||
'该用户在黑名单中,不允许加好友'
|
||||
)
|
||||
if (show) {
|
||||
navigateBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,38 +246,56 @@
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除好友 */
|
||||
/** 删除好友/删除群 */
|
||||
const onDeleteFriend = async () => {
|
||||
const show = await showDialog('提示', '确定要删除好友吗?')
|
||||
const isMode = friendInfo.value?.cbType === 'group'
|
||||
const show = await showDialog(
|
||||
'提示',
|
||||
`确定要${isMode ? '解除群聊' : '删除好友'}吗?`
|
||||
)
|
||||
if (!show) {
|
||||
return
|
||||
}
|
||||
showLoading()
|
||||
TUIFriendService.deleteFriend({
|
||||
userIDList: [friendInfo.value.userID],
|
||||
type: TUIChatEngine.TYPES.SNS_DELETE_TYPE_BOTH
|
||||
})
|
||||
.then(async res => {
|
||||
hideLoading()
|
||||
const { successUserIDList } = res.data
|
||||
if (successUserIDList[0].userID === friendInfo.value.userID) {
|
||||
await showToast('删除好友成功', 'success')
|
||||
if (isMode) {
|
||||
TUIGroupService.dismissGroup(friendInfo.value?.groupID)
|
||||
.then(async () => {
|
||||
await showToast('解除群聊成功', 'success')
|
||||
reLaunch('/TUIKit/components/TUIContact/index')
|
||||
} else {
|
||||
})
|
||||
.catch(async () => {
|
||||
hideLoading()
|
||||
await showToast('解除群聊失败', 'error')
|
||||
})
|
||||
} else {
|
||||
TUIFriendService.deleteFriend({
|
||||
userIDList: [friendInfo.value.userID],
|
||||
type: TUIChatEngine.TYPES.SNS_DELETE_TYPE_BOTH
|
||||
})
|
||||
.then(async res => {
|
||||
hideLoading()
|
||||
const { successUserIDList } = res.data
|
||||
if (successUserIDList[0].userID === friendInfo.value.userID) {
|
||||
await showToast('删除好友成功', 'success')
|
||||
reLaunch('/TUIKit/components/TUIContact/index')
|
||||
} else {
|
||||
await showToast('删除好友失败', 'error')
|
||||
}
|
||||
})
|
||||
.catch(async () => {
|
||||
hideLoading()
|
||||
await showToast('删除好友失败', 'error')
|
||||
}
|
||||
})
|
||||
.catch(async () => {
|
||||
hideLoading()
|
||||
await showToast('删除好友失败', 'error')
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/** 发送消息 */
|
||||
const onSendMessage = () => {
|
||||
TUIConversationService.switchConversation(
|
||||
`C2C${friendInfo.value.userID}`
|
||||
).then(() => {
|
||||
const data =
|
||||
friendInfo.value?.cbType === 'group'
|
||||
? `GROUP${friendInfo.value?.groupID}`
|
||||
: `C2C${friendInfo.value.userID}`
|
||||
TUIConversationService.switchConversation(data).then(() => {
|
||||
TUIGlobal?.navigateTo({
|
||||
url: `/TUIKit/components/TUIChat/index`
|
||||
})
|
||||
@@ -206,12 +304,19 @@
|
||||
|
||||
onLoad(e => {
|
||||
userId.value = e?.id || ''
|
||||
/** type: 不传为添加 1 为详情页 */
|
||||
isDetail.value = e?.type == 1 || false
|
||||
uni.setNavigationBarTitle({
|
||||
title: isDetail.value ? '好友信息' : '发送好友申请'
|
||||
})
|
||||
getFriendInfo()
|
||||
/** type: 不传为添加 1 为详情页 9 为群信息 */
|
||||
if (e?.type == 9) {
|
||||
uni.setNavigationBarTitle({
|
||||
title: '群聊信息'
|
||||
})
|
||||
getGroupInfo()
|
||||
} else {
|
||||
isDetail.value = e?.type == 1 || false
|
||||
uni.setNavigationBarTitle({
|
||||
title: isDetail.value ? '好友信息' : '发送好友申请'
|
||||
})
|
||||
getFriendInfo()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -229,10 +334,13 @@
|
||||
<uni-icons v-else type="contact-filled" size="80"></uni-icons>
|
||||
<view class="right-box">
|
||||
<text>{{ friendInfo.nick || '未知名称' }}</text>
|
||||
<text>手机号: {{ friendInfo.userID }}</text>
|
||||
<text>
|
||||
<text v-if="!friendInfo?.cbType == 'group'">
|
||||
手机号: {{ friendInfo.userID }}
|
||||
</text>
|
||||
<text v-if="!friendInfo?.cbType == 'group'">
|
||||
个性签名: {{ friendInfo.selfSignature || '暂无个性签名' }}
|
||||
</text>
|
||||
<text v-else>ID: {{ friendInfo.groupID }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -248,7 +356,10 @@
|
||||
</view>
|
||||
|
||||
<!-- 备注 -->
|
||||
<view v-if="!isDetail" class="remark">
|
||||
<view
|
||||
v-if="!friendInfo?.cbType == 'group' && !isDetail"
|
||||
class="remark"
|
||||
>
|
||||
<text>备注名</text>
|
||||
<input
|
||||
v-model="remark"
|
||||
@@ -264,7 +375,11 @@
|
||||
</view>
|
||||
|
||||
<!-- 修改好友信息======================== -->
|
||||
<view v-if="isDetail" class="remark" @click="showRemark = true">
|
||||
<view
|
||||
v-if="!friendInfo?.cbType == 'group' && isDetail"
|
||||
class="remark"
|
||||
@click="showRemark = true"
|
||||
>
|
||||
<text>备注名</text>
|
||||
<view style="display: flex; align-items: center">
|
||||
<text
|
||||
@@ -275,15 +390,30 @@
|
||||
<uni-icons type="right" color="#999999" size="36rpx"></uni-icons>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="isDetail" class="remark">
|
||||
<view
|
||||
v-if="!friendInfo?.cbType == 'group' && isDetail"
|
||||
class="remark"
|
||||
>
|
||||
<text>加入黑名单</text>
|
||||
<SwitchBar :value="isBlack" @click="switchChange" />
|
||||
</view>
|
||||
|
||||
<view v-if="isDetail" class="send-btn" @tap="onDeleteFriend">
|
||||
<view
|
||||
v-if="!friendInfo?.cbType == 'group' && isDetail"
|
||||
class="send-btn"
|
||||
@tap="onDeleteFriend"
|
||||
>
|
||||
<text style="color: #eb1c26">删除好友</text>
|
||||
</view>
|
||||
|
||||
<view
|
||||
v-if="friendInfo?.selfInfo?.role == 'Owner' && isDetail"
|
||||
class="send-btn"
|
||||
@tap="onDeleteFriend"
|
||||
>
|
||||
<text style="color: #eb1c26">解除群聊</text>
|
||||
</view>
|
||||
|
||||
<bottom-view v-if="isDetail">
|
||||
<cb-button @click="onSendMessage">发送信息</cb-button>
|
||||
</bottom-view>
|
||||
@@ -344,9 +474,7 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.title {
|
||||
font-family:
|
||||
PingFang SC,
|
||||
PingFang SC;
|
||||
font-family: PingFang SC, PingFang SC;
|
||||
font-weight: 500;
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
|
||||
@@ -1,27 +1,56 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { ref, computed } from 'vue'
|
||||
import TUICore, { TUIConstants } from '@tencentcloud/tui-core-lite'
|
||||
import { useUI } from '@/utils/use-ui'
|
||||
import { navigateTo } from '@/utils/router'
|
||||
import TUIChatEngine, {
|
||||
TUIFriendService
|
||||
TUIFriendService,
|
||||
TUIGroupService
|
||||
} from '@tencentcloud/chat-uikit-engine-lite'
|
||||
|
||||
const { showLoading, hideLoading } = useUI()
|
||||
const loading = ref(false)
|
||||
const searchValue = ref('')
|
||||
const searchList = ref([])
|
||||
const isSearc = ref(false)
|
||||
// const isSearc = ref(false)
|
||||
// 是否是好友
|
||||
const isFriend = ref(false)
|
||||
|
||||
/** 群列表 */
|
||||
const searchGroup = ref([])
|
||||
|
||||
const isSearc = computed(() => {
|
||||
return searchList.value.length === 0 && searchGroup.value.length === 0
|
||||
})
|
||||
const onCancel = () => {
|
||||
isFriend.value = false
|
||||
isSearc.value = false
|
||||
searchGroup.value = []
|
||||
searchList.value = []
|
||||
}
|
||||
|
||||
const search = () => {
|
||||
/** 群查询 */
|
||||
const getGroup = () => {
|
||||
showLoading()
|
||||
loading.value = true
|
||||
TUICore.callService({
|
||||
serviceName: TUIConstants.TUISearch.SERVICE.NAME,
|
||||
method: TUIConstants.TUISearch.SERVICE.METHOD.SEARCH_GROUP,
|
||||
params: {
|
||||
groupID: searchValue.value
|
||||
}
|
||||
})
|
||||
.then(res => {
|
||||
searchGroup.value = [res.data.group]
|
||||
})
|
||||
.catch(err => {
|
||||
searchGroup.value = []
|
||||
console.log(err, '==')
|
||||
loading.value = false
|
||||
hideLoading()
|
||||
})
|
||||
}
|
||||
|
||||
const search = async () => {
|
||||
if (!searchValue.value) {
|
||||
return
|
||||
}
|
||||
@@ -63,17 +92,29 @@
|
||||
loading.value = false
|
||||
hideLoading()
|
||||
})
|
||||
|
||||
getGroup()
|
||||
}
|
||||
|
||||
const onAdd = item => {
|
||||
navigateTo('/pages/adduser/details', { id: item.userID })
|
||||
}
|
||||
|
||||
const onDetails = item => {
|
||||
if (isFriend.value) {
|
||||
navigateTo('/pages/adduser/details', { id: item.userID, type: '1' })
|
||||
const onDetails = (item, state) => {
|
||||
if (state == 1) {
|
||||
navigateTo('/pages/adduser/details', {
|
||||
id: item.groupID,
|
||||
type: '9'
|
||||
})
|
||||
} else {
|
||||
onAdd(item)
|
||||
if (isFriend.value) {
|
||||
navigateTo('/pages/adduser/details', {
|
||||
id: item.userID,
|
||||
type: '1'
|
||||
})
|
||||
} else {
|
||||
onAdd(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -86,13 +127,14 @@
|
||||
radius="100"
|
||||
bgColor="#f4f4f4"
|
||||
textColor="#333333"
|
||||
placeholder="请输入用户手机号"
|
||||
placeholder="请输入用户手机号/群ID进行搜索"
|
||||
@confirm="search"
|
||||
@cancel="onCancel"
|
||||
></uni-search-bar>
|
||||
<cb-empty v-if="isSearc" name="未搜索到此账号"></cb-empty>
|
||||
<!-- 好友列表 -->
|
||||
<cb-empty v-if="!loading && isSearc" name="未搜索到"></cb-empty>
|
||||
|
||||
<view v-if="!loading" class="user-list">
|
||||
<!-- 好友列表 -->
|
||||
<view
|
||||
v-for="item in searchList"
|
||||
:key="item.userID"
|
||||
@@ -117,6 +159,32 @@
|
||||
<button v-else @click.stop="onAdd(item)">添加</button>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 群列表 -->
|
||||
<view
|
||||
v-for="item in searchGroup"
|
||||
:key="item.groupID"
|
||||
class="card"
|
||||
@click="onDetails(item, 1)"
|
||||
>
|
||||
<image
|
||||
v-if="item?.avatar"
|
||||
:src="item?.avatar"
|
||||
mode="aspectFill"
|
||||
class="avatar"
|
||||
></image>
|
||||
<view v-else class="avatar">
|
||||
<uni-icons type="contact-filled" size="130rpx"></uni-icons>
|
||||
</view>
|
||||
<view class="right-box">
|
||||
<view class="name-box">
|
||||
<text>{{ item.name || '未知名称' }}</text>
|
||||
<text>{{ item.groupID }}</text>
|
||||
</view>
|
||||
<text class="tag-but">群聊</text>
|
||||
<!-- <text v-if="isFriend" class="tag">已添加</text>
|
||||
<button v-else @click.stop="onAdd(item)">添加</button> -->
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -147,6 +215,12 @@
|
||||
font-size: 32rpx;
|
||||
color: #999999;
|
||||
}
|
||||
.tag-but {
|
||||
padding: 4rpx 20rpx;
|
||||
background: #00d9c5;
|
||||
color: #fff;
|
||||
border-radius: 30rpx;
|
||||
}
|
||||
.name-box {
|
||||
height: 96rpx;
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user