78 lines
2.5 KiB
Vue
Raw Normal View History

2025-05-30 18:05:17 +08:00
<template>
<ToolbarItemContainer
:iconFile="fileIcon"
title="文件"
:iconWidth="isUniFrameWork ? '32px' : '20px'"
:iconHeight="isUniFrameWork ? '25px' : '18px'"
:needDialog="false"
@onIconClick="onIconClick"
>
<div :class="['file-upload', !isPC && 'file-upload-h5']">
2025-06-27 09:53:36 +08:00
<input ref="inputRef" title="文件" type="file" data-type="file" accept="*" @change="sendFileMessage" />
2025-05-30 18:05:17 +08:00
</div>
</ToolbarItemContainer>
</template>
<script lang="ts" setup>
import TUIChatEngine, {
TUIChatService,
TUIStore,
StoreName,
IConversationModel,
SendMessageParams,
2025-06-27 09:53:36 +08:00
SendMessageOptions
2025-05-30 18:05:17 +08:00
} from '@tencentcloud/chat-uikit-engine';
import { ref } from '../../../../adapter-vue';
import ToolbarItemContainer from '../toolbar-item-container/index.vue';
import fileIconLight from '../../../../assets/icon/file-light.svg';
import fileIconDark from '../../../../assets/icon/file-dark.svg';
import { isPC, isUniFrameWork } from '../../../../utils/env';
import { isEnabledMessageReadReceiptGlobal } from '../../utils/utils';
import OfflinePushInfoManager, { IOfflinePushInfoCreateParams } from '../../offlinePushInfoManager/index';
import TUIChatConfig from '../../config';
const fileIcon = TUIChatConfig.getTheme() === 'dark' ? fileIconDark : fileIconLight;
const inputRef = ref();
const currentConversation = ref<IConversationModel>();
TUIStore.watch(StoreName.CONV, {
currentConversation: (conversation: IConversationModel) => {
currentConversation.value = conversation;
2025-06-27 09:53:36 +08:00
}
2025-05-30 18:05:17 +08:00
});
const onIconClick = () => {
if (isUniFrameWork) {
return;
} else {
inputRef?.value?.click && inputRef?.value?.click();
}
};
const sendFileMessage = (e: any) => {
if (e?.target?.files?.length <= 0) {
return;
}
const options = {
2025-06-27 09:53:36 +08:00
to: currentConversation?.value?.groupProfile?.groupID || currentConversation?.value?.userProfile?.userID,
2025-05-30 18:05:17 +08:00
conversationType: currentConversation?.value?.type,
payload: {
2025-06-27 09:53:36 +08:00
file: e?.target
2025-05-30 18:05:17 +08:00
},
2025-06-27 09:53:36 +08:00
needReadReceipt: isEnabledMessageReadReceiptGlobal()
2025-05-30 18:05:17 +08:00
} as SendMessageParams;
const offlinePushInfoCreateParams: IOfflinePushInfoCreateParams = {
conversation: currentConversation.value,
payload: options.payload,
2025-06-27 09:53:36 +08:00
messageType: TUIChatEngine.TYPES.MSG_FILE
2025-05-30 18:05:17 +08:00
};
const sendMessageOptions: SendMessageOptions = {
2025-06-27 09:53:36 +08:00
offlinePushInfo: OfflinePushInfoManager.create(offlinePushInfoCreateParams)
2025-05-30 18:05:17 +08:00
};
TUIChatService.sendFileMessage(options, sendMessageOptions);
e.target.value = '';
};
</script>
<style lang="scss" scoped>
2025-06-27 09:53:36 +08:00
@import '../../../../assets/styles/common';
2025-05-30 18:05:17 +08:00
</style>