diff --git a/src/api/chat.js b/src/api/chat.js index 3273fc5..df04eb1 100644 --- a/src/api/chat.js +++ b/src/api/chat.js @@ -94,3 +94,8 @@ export const ServeConfirmVoteHandle = (data = {}) => { export const ServeEmptyMessage = (data) => { return post('/api/v1/talk/message/empty', data) } + +//获取消息已读未读详情 +export const ServeMessageReadDetail = (data) => { + return post('/api/v1/talk/my-records/read/condition', data) +} diff --git a/src/api/search.js b/src/api/search.js index 7fa5928..6ea2ee9 100644 --- a/src/api/search.js +++ b/src/api/search.js @@ -5,6 +5,16 @@ export const ServeSeachQueryAll = (data = {}) => { return post('/api/v1/elasticsearch/query-all', data) } +// ES搜索用户数据 +export const ServeQueryUser = (data) => { + return post('/api/v1/elasticsearch/query-user', data) +} + +// ES搜索群组数据 +export const ServeQueryGroup = (data) => { + return post('/api/v1/elasticsearch/query-group', data) +} + //ES搜索聊天记录-主页搜索什么都有、聊天记录 export const ServeQueryTalkRecord = (data = {}) => { return post('/api/v1/elasticsearch/query-talk-record', data) diff --git a/src/components/group/GroupPanel.vue b/src/components/group/GroupPanel.vue index 3d85ee1..64e0620 100644 --- a/src/components/group/GroupPanel.vue +++ b/src/components/group/GroupPanel.vue @@ -11,13 +11,14 @@ import { ServeSecedeGroup, ServeUpdateGroupCard, ServeGetGroupNotices, - ServeEditGroup + ServeEditGroup, + ServeDismissGroup } from '@/api/group' import { useInject } from '@/hooks' import customModal from '@/components/common/customModal.vue' import avatarModule from '@/components/avatar-module/index.vue' import UserCardModal from '@/components/user/UserCardModal.vue' -import { ServeEmptyMessage } from '@/api/chat' +import { ServeEmptyMessage, ServeTopTalkList, ServeSetNotDisturb } from '@/api/chat' import { parseTime } from '@/utils/datetime' const userStore = useUserStore() @@ -48,6 +49,12 @@ const props = defineProps({ } }) +const talkParams = reactive({ + isTop: computed(() => talkStore.findItem(props.talkType + '_' + props.gid)?.is_top), + isDisturb: computed(() => talkStore.findItem(props.talkType + '_' + props.gid)?.is_disturb), + sessionId: computed(() => talkStore.findItem(props.talkType + '_' + props.gid)?.id) +}) + watch(props, () => { if (props.talkType === 2) { loadDetail() @@ -98,7 +105,8 @@ const state = reactive({ }, //群公告信息 editGroupName: false, //是否编辑群名称 editGroupNameValue: '', //编辑中的群名称 - chatSettingOperateType: '' //聊天设置操作类型 + chatSettingOperateType: '', //聊天设置操作类型 + isLastAdmin: false //是否是最后一个管理员 }) const members = ref([]) @@ -177,17 +185,36 @@ const onClose = () => { emit('close') } -const onSignOut = () => { +const onSignOut = (closeLoading) => { ServeSecedeGroup({ group_id: props.gid - }).then((res) => { - if (res.code == 200) { - window['$message'].success('已退出群聊') - onClose() - } else { - window['$message'].error(res.message) - } }) + .then((res) => { + closeLoading() + if (res.code == 200) { + window['$message'].success('已退出群聊') + state.isShowModal = false + onClose() + } else { + window['$message'].error(res.message || res.msg) + } + }) + .catch((err) => { + closeLoading() + window['$message'].error(err.message) + }) +} + +const onDismiss = async (closeLoading) => { + const { code, message } = await ServeDismissGroup({ group_id: props.gid }) + closeLoading() + if (code === 200) { + onClose() + state.isShowModal = false + window['$message'].success('群聊已解散') + } else { + window['$message'].info(message) + } } const onChangeRemark = () => { @@ -236,8 +263,18 @@ const handleModalConfirm = (closeLoading) => { closeLoading() window['$message'].error(err.message) }) - } else if (state.chatSettingOperateType == 'quit'){ + } else if (state.chatSettingOperateType == 'quit') { //退出群聊 + if (state.isLastAdmin) { + //如果是最后一个管理员,则退出同时解散群聊 + onDismiss(closeLoading) + } else { + //如果不是最后一个管理员,则退出群聊 + onSignOut(closeLoading) + } + } else if (state.chatSettingOperateType == 'dismiss') { + //解散群聊 + onDismiss(closeLoading) } } @@ -256,12 +293,15 @@ const showChatSettingOperateModal = (type: string) => { break case 'quit': state.chatSettingOperateHint = '确定退出群聊' - const findAdmin = groupMemberList.value.find((item) => item.leader === 2 || item.leader === 1) - const isLastAdmin = findAdmin && findAdmin.user_id === userStore.uid - if (isLastAdmin) { - state.chatSettingOperateSubHint = '退出后,本群将被解散' - } else { + const findOtherAdmin = groupMemberList.value.find( + (item) => (item.leader === 2 || item.leader === 1) && item.user_id !== userStore.uid + ) + if (findOtherAdmin) { + state.isLastAdmin = false state.chatSettingOperateSubHint = '退出后,聊天记录将被清空' + } else { + state.isLastAdmin = true + state.chatSettingOperateSubHint = '退出后,本群将被解散' } break } @@ -380,6 +420,42 @@ const handleEditGroupNameConfirm = () => { } }) } + +//设置会话置顶 +const onTopChange = (value: boolean) => { + ServeTopTalkList({ + list_id: talkParams.sessionId, + type: value ? 1 : 2 + }).then(({ code, message }) => { + if (code == 200) { + talkStore.updateItem({ + index_name: props.talkType + '_' + props.gid, + is_top: talkParams.isTop == 0 ? 1 : 0 + }) + } else { + window['$message'].error(message) + } + }) +} + +//设置会话免打扰 +const onDisturbChange = (value: boolean) => { + ServeSetNotDisturb({ + talk_type: props.talkType, + receiver_id: props.gid, + is_disturb: value ? 1 : 0 + }).then(({ code, message }) => { + if (code == 200) { + window['$message'].success('设置成功!') + talkStore.updateItem({ + index_name: props.talkType + '_' + props.gid, + is_disturb: value ? 1 : 0 + }) + } else { + window['$message'].error(message) + } + }) +}