✨ feat(im): 前端增加「黑名单」的操作
parent
1b51926b19
commit
7141e431e2
|
|
@ -47,3 +47,13 @@ export const updateFriend = (data: ImFriendUpdateReqVO) => {
|
||||||
return request.put<boolean>({ url: '/im/friend/update', data })
|
return request.put<boolean>({ url: '/im/friend/update', data })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 拉黑好友(必须先是好友;单边屏蔽对方私聊消息)
|
||||||
|
export const blockFriend = (friendUserId: number | string) => {
|
||||||
|
return request.put<boolean>({ url: '/im/friend/block', params: { friendUserId } })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移出黑名单
|
||||||
|
export const unblockFriend = (friendUserId: number | string) => {
|
||||||
|
return request.put<boolean>({ url: '/im/friend/unblock', params: { friendUserId } })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
<div class="truncate">部门:{{ deptText }}</div>
|
<div class="truncate">部门:{{ deptText }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- 右上 "..." 菜单:仅 friend 态展示,菜单项目前只有"删除联系人"(其它 WeChat 选项业务上未支持) -->
|
<!-- 右上 "..." 菜单:仅 friend 态展示;含「加入/移出黑名单」 + 「删除联系人」 -->
|
||||||
<div v-if="relation === 'friend'" class="flex-shrink-0">
|
<div v-if="relation === 'friend'" class="flex-shrink-0">
|
||||||
<el-dropdown trigger="click" placement="bottom-end" popper-class="im-user-info__more-menu">
|
<el-dropdown trigger="click" placement="bottom-end" popper-class="im-user-info__more-menu">
|
||||||
<div
|
<div
|
||||||
|
|
@ -49,7 +49,10 @@
|
||||||
</div>
|
</div>
|
||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu>
|
<el-dropdown-menu>
|
||||||
<el-dropdown-item @click="handleDeleteFriend">
|
<!-- 拉黑 / 移出黑名单:按 friendInfo.blocked 切换文案 -->
|
||||||
|
<el-dropdown-item v-if="!isBlocked" @click="handleBlock">加入黑名单</el-dropdown-item>
|
||||||
|
<el-dropdown-item v-else @click="handleUnblock">移出黑名单</el-dropdown-item>
|
||||||
|
<el-dropdown-item divided @click="handleDeleteFriend">
|
||||||
<span class="text-[var(--el-color-danger)]">删除联系人</span>
|
<span class="text-[var(--el-color-danger)]">删除联系人</span>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
|
|
@ -237,11 +240,14 @@ const deptText = computed(() => full.value?.deptName || '-')
|
||||||
const genderIcon = computed(() => getGenderIcon(full.value?.sex))
|
const genderIcon = computed(() => getGenderIcon(full.value?.sex))
|
||||||
const genderColor = computed(() => getGenderColor(full.value?.sex))
|
const genderColor = computed(() => getGenderColor(full.value?.sex))
|
||||||
|
|
||||||
/** 好友关系记录:来源 / 添加时间从这里取(仅 friend 态下才有意义) */
|
/** 好友关系记录:来源 / 添加时间 / 是否拉黑从这里取(仅 friend 态下才有意义) */
|
||||||
const friendInfo = computed(() =>
|
const friendInfo = computed(() =>
|
||||||
props.user?.id ? friendStore.getFriend(props.user.id) : undefined
|
props.user?.id ? friendStore.getFriend(props.user.id) : undefined
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** 是否已拉黑:菜单项「加入黑名单 / 移出黑名单」按这个切换 */
|
||||||
|
const isBlocked = computed(() => !!friendInfo.value?.blocked)
|
||||||
|
|
||||||
/** 备注内联编辑:editingRemark 控制输入态;user 切换时由下面的 watch 复位避免脏态泄漏 */
|
/** 备注内联编辑:editingRemark 控制输入态;user 切换时由下面的 watch 复位避免脏态泄漏 */
|
||||||
const editingRemark = ref(false)
|
const editingRemark = ref(false)
|
||||||
const remarkInput = ref('')
|
const remarkInput = ref('')
|
||||||
|
|
@ -346,6 +352,26 @@ function handleAddFriend() {
|
||||||
addFriendVisible.value = true
|
addFriendVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 加入黑名单:confirm → friendStore.blockFriend;后端 FRIEND_BLOCK 推到时由 dispatcher 同步多端 */
|
||||||
|
async function handleBlock() {
|
||||||
|
if (!props.user?.id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const target = props.user
|
||||||
|
await message.confirm(`确定将「${target.nickname || ''}」加入黑名单吗?`, '加入黑名单')
|
||||||
|
await friendStore.blockFriend(target.id)
|
||||||
|
message.success('已加入黑名单')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 移出黑名单:操作温和不弹 confirm;后端 FRIEND_UNBLOCK 推到时由 dispatcher 同步多端 */
|
||||||
|
async function handleUnblock() {
|
||||||
|
if (!props.user?.id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await friendStore.unblockFriend(props.user.id)
|
||||||
|
message.success('已移出黑名单')
|
||||||
|
}
|
||||||
|
|
||||||
/** 删除联系人:confirm → friendStore.deleteFriend(内部级联清会话)→ 通知父级关浮层 / 清选中 */
|
/** 删除联系人:confirm → friendStore.deleteFriend(内部级联清会话)→ 通知父级关浮层 / 清选中 */
|
||||||
async function handleDeleteFriend() {
|
async function handleDeleteFriend() {
|
||||||
if (!props.user?.id) {
|
if (!props.user?.id) {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import {
|
||||||
getFriend as apiGetFriend,
|
getFriend as apiGetFriend,
|
||||||
deleteFriend as apiDeleteFriend,
|
deleteFriend as apiDeleteFriend,
|
||||||
updateFriend as apiUpdateFriend,
|
updateFriend as apiUpdateFriend,
|
||||||
|
blockFriend as apiBlockFriend,
|
||||||
|
unblockFriend as apiUnblockFriend,
|
||||||
type ImFriendRespVO
|
type ImFriendRespVO
|
||||||
} from '@/api/im/friend'
|
} from '@/api/im/friend'
|
||||||
import {
|
import {
|
||||||
|
|
@ -235,6 +237,26 @@ export const useFriendStore = defineStore('imFriendStore', {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** 拉黑好友:本端乐观更新 + 调接口;后端 FRIEND_BLOCK 推到时由 dispatcher 兜底同步多端 */
|
||||||
|
async blockFriend(friendUserId: number) {
|
||||||
|
await apiBlockFriend(friendUserId)
|
||||||
|
const friend = this.getFriend(friendUserId)
|
||||||
|
if (friend) {
|
||||||
|
friend.blocked = true
|
||||||
|
this.saveFriends()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 移出黑名单:本端乐观更新 + 调接口;后端 FRIEND_UNBLOCK 推到时由 dispatcher 兜底同步多端 */
|
||||||
|
async unblockFriend(friendUserId: number) {
|
||||||
|
await apiUnblockFriend(friendUserId)
|
||||||
|
const friend = this.getFriend(friendUserId)
|
||||||
|
if (friend) {
|
||||||
|
friend.blocked = false
|
||||||
|
this.saveFriends()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/** 修改好友展示备注(仅自己可见) */
|
/** 修改好友展示备注(仅自己可见) */
|
||||||
async setDisplayName(friendUserId: number, displayName: string) {
|
async setDisplayName(friendUserId: number, displayName: string) {
|
||||||
const value = displayName.trim()
|
const value = displayName.trim()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue