| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <script lang="ts" setup> |
| | | import type { Message } from '#/views/im/home/types' |
| | | |
| | | import { computed, inject } from 'vue' |
| | | |
| | | import { confirm } from '#/packages/effects/common-ui/src' |
| | | import { IconifyIcon as Icon } from '#/packages/icons/src' |
| | | |
| | | import { useMessageMultiSelect } from '#/views/im/home/composables/useMessageMultiSelect' |
| | | import { useConversationStore } from '#/views/im/home/store/conversationStore' |
| | | import { useMessageStore } from '#/views/im/home/store/messageStore' |
| | | import { ImForwardMode, isNormalMessage } from '#/views/im/utils/constants' |
| | | import { getClientConversationId } from '#/views/im/utils/db' |
| | | |
| | | import { IM_FORWARD_DIALOG_KEY } from '../message/forward/keys' |
| | | |
| | | defineOptions({ name: 'ImMessageMultiSelectBar' }) |
| | | |
| | | const conversationStore = useConversationStore() |
| | | const messageStore = useMessageStore() |
| | | const openForwardDialog = inject(IM_FORWARD_DIALOG_KEY) |
| | | const multiSelect = useMessageMultiSelect() |
| | | |
| | | /** é䏿¡æ° */ |
| | | const selectedCount = computed(() => multiSelect.state.selectedClientMessageIds.length) |
| | | |
| | | /** å½åä¼è¯å
å·²éæ¶æ¯ */ |
| | | function getSelectedMessages(): Message[] { |
| | | const conversation = conversationStore.activeConversation |
| | | if (!conversation) { |
| | | return [] |
| | | } |
| | | const ids = multiSelect.selectedIdSet.value |
| | | return messageStore |
| | | .getMessages(getClientConversationId(conversation.type, conversation.targetId)) |
| | | .filter((message) => ids.has(message.clientMessageId) && isNormalMessage(message.type)) |
| | | } |
| | | |
| | | /** éæ¡è½¬åï¼å¼ ForwardDialog åæ¡æ¨¡å¼ */ |
| | | function handleForwardOneByOne() { |
| | | const conversation = conversationStore.activeConversation |
| | | if (!conversation) { |
| | | return |
| | | } |
| | | const messages = getSelectedMessages() |
| | | if (messages.length === 0) { |
| | | return |
| | | } |
| | | openForwardDialog?.({ |
| | | mode: ImForwardMode.SINGLE, |
| | | messages, |
| | | sourceConversation: conversation |
| | | }) |
| | | } |
| | | |
| | | /** å并转åï¼å¼ ForwardDialog åå¹¶æ¨¡å¼ */ |
| | | function handleForwardMerged() { |
| | | const conversation = conversationStore.activeConversation |
| | | if (!conversation) { |
| | | return |
| | | } |
| | | const messages = getSelectedMessages() |
| | | if (messages.length === 0) { |
| | | return |
| | | } |
| | | openForwardDialog?.({ |
| | | mode: ImForwardMode.MERGE, |
| | | messages, |
| | | sourceConversation: conversation |
| | | }) |
| | | } |
| | | |
| | | /** å é¤ï¼å¼¹ç¡®è®¤æ¡ â æ¬å°æ¹éç§»é¤ï¼ä¸åæ¥å端ï¼å¯¹é½å¾®ä¿¡ãå é¤ãè¯ä¹ï¼ */ |
| | | async function handleDelete() { |
| | | const conversation = conversationStore.activeConversation |
| | | if (!conversation) { |
| | | return |
| | | } |
| | | const messages = getSelectedMessages() |
| | | if (messages.length === 0) { |
| | | return |
| | | } |
| | | try { |
| | | await confirm(`确认å é¤éä¸ç ${messages.length} æ¡æ¶æ¯ï¼`, { |
| | | cancelText: 'åæ¶', |
| | | confirmText: 'ç¡®å®', |
| | | icon: 'warning', |
| | | title: 'å é¤ç¡®è®¤' |
| | | }) |
| | | } catch { |
| | | return |
| | | } |
| | | for (const m of messages) { |
| | | messageStore.removeMessage(conversation.type, conversation.targetId, { |
| | | id: m.id, |
| | | clientMessageId: m.clientMessageId |
| | | }) |
| | | } |
| | | multiSelect.exit() |
| | | } |
| | | |
| | | /** åæ¶å¤é */ |
| | | function handleCancel() { |
| | | multiSelect.exit() |
| | | } |
| | | </script> |
| | | |
| | | <template> |
| | | <div |
| | | v-if="multiSelect.state.active" |
| | | class="flex items-center justify-center gap-12 px-5 w-full h-full border-t border-t-solid bg-[var(--ant-color-bg-container)] border-[var(--im-border-color-lighter)]" |
| | | > |
| | | <span |
| | | class="absolute left-5 top-1/2 -translate-y-1/2 text-12px text-[var(--ant-color-text-secondary)]" |
| | | > |
| | | å·²é {{ selectedCount }} æ¡ |
| | | </span> |
| | | |
| | | <button |
| | | class="inline-flex flex-col items-center gap-1 px-3 py-1 text-12px rounded-md border-0 bg-transparent cursor-pointer transition-colors text-[var(--ant-color-text)] hover:text-[var(--ant-color-primary)] hover:bg-[var(--ant-color-fill)] disabled:text-[var(--ant-color-text-disabled)] disabled:cursor-not-allowed disabled:bg-transparent" |
| | | :disabled="selectedCount === 0" |
| | | @click="handleForwardOneByOne" |
| | | > |
| | | <Icon icon="ant-design:share-alt-outlined" :size="22" /> |
| | | <span>éæ¡è½¬å</span> |
| | | </button> |
| | | |
| | | <button |
| | | class="inline-flex flex-col items-center gap-1 px-3 py-1 text-12px rounded-md border-0 bg-transparent cursor-pointer transition-colors text-[var(--ant-color-text)] hover:text-[var(--ant-color-primary)] hover:bg-[var(--ant-color-fill)] disabled:text-[var(--ant-color-text-disabled)] disabled:cursor-not-allowed disabled:bg-transparent" |
| | | :disabled="selectedCount === 0" |
| | | @click="handleForwardMerged" |
| | | > |
| | | <Icon icon="tabler:arrow-merge" :size="22" /> |
| | | <span>å并转å</span> |
| | | </button> |
| | | |
| | | <button |
| | | class="inline-flex flex-col items-center gap-1 px-3 py-1 text-12px rounded-md border-0 bg-transparent cursor-pointer transition-colors text-[var(--ant-color-text)] hover:bg-[var(--ant-color-fill)] hover:text-[var(--ant-color-error)] disabled:text-[var(--ant-color-text-disabled)] disabled:cursor-not-allowed disabled:bg-transparent" |
| | | :disabled="selectedCount === 0" |
| | | @click="handleDelete" |
| | | > |
| | | <Icon icon="ant-design:delete-outlined" :size="22" /> |
| | | <span>å é¤</span> |
| | | </button> |
| | | |
| | | <button |
| | | class="absolute right-5 top-1/2 -translate-y-1/2 inline-flex items-center justify-center w-7 h-7 rounded-full border-0 bg-transparent cursor-pointer transition-colors text-[var(--ant-color-text-secondary)] hover:text-[var(--ant-color-text)] hover:bg-[var(--ant-color-fill)]" |
| | | @click="handleCancel" |
| | | > |
| | | <Icon icon="ant-design:close-outlined" :size="20" /> |
| | | </button> |
| | | </div> |
| | | </template> |