import * as React from "react"; import {Popover, Upload} from "antd"; import * as OSS from "ali-oss"; import {ToolBoxUpload} from "./ToolBoxUpload"; import {PPTProgressListener, UploadManager} from "./UploadManager"; import "./UploadBtn.less"; import {DeviceType, PPTKind, Room, WhiteWebSdk} from "white-web-sdk"; import * as image_icon from "../../assets/image/image_icon.svg"; import * as image_transform from "../../assets/image/image_transform.svg"; import * as web_transform from "../../assets/image/web_transform.svg"; import {TooltipPlacement} from "antd/lib/tooltip"; import {PPTDataType} from "../../components/menu/PPTDatas"; import {ToolBarPositionEnum, UploadDocumentEnum, UploadToolBoxType} from "../../pages/NetlessRoomTypes"; import { projectStore } from "../../models/ProjectStore"; export type ToolBoxUploadBoxState = { toolBoxColor: string, }; export const FileUploadStatic: string = "application/pdf, " + "application/vnd.openxmlformats-officedocument.presentationml.presentation, " + "application/vnd.ms-powerpoint, " + "application/msword, " + "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; export type UploadBtnProps = { oss: { accessKeyId: string, accessKeySecret: string, region: string, bucket: string, folder: string, prefix: string, }, room: Room, uuid: string, roomToken: string | null, whiteboardRef?: HTMLDivElement, onProgress?: PPTProgressListener, toolBarPosition?: ToolBarPositionEnum; uploadToolBox?: UploadToolBoxType[], ossUploadCallback?: (res: any) => void; documentFileCallback: (data: PPTDataType) => void; deviceType: DeviceType; }; export default class UploadBtn extends React.Component { private readonly client: any; public constructor(props: UploadBtnProps) { super(props); this.state = { toolBoxColor: "#A2A7AD", }; this.client = new OSS({ accessKeyId: this.props.oss.accessKeyId, accessKeySecret: this.props.oss.accessKeySecret, region: this.props.oss.region, bucket: this.props.oss.bucket, }); } private uploadStatic = async (event: any): Promise => { const {ossUploadCallback, uuid, documentFileCallback} = this.props; const uploadManager = new UploadManager(this.client, this.props.room, ossUploadCallback); const whiteWebSdk = new WhiteWebSdk({appIdentifier: "283/VGiScM9Wiw2HJg"}); const pptConverter = whiteWebSdk.pptConverter(this.props.roomToken!); await uploadManager.convertFile( event.file, pptConverter, PPTKind.Static, this.props.oss.folder, uuid, documentFileCallback, this.props.onProgress); } private uploadDynamic = async (event: any): Promise => { const {ossUploadCallback, uuid, documentFileCallback} = this.props; const uploadManager = new UploadManager(this.client, this.props.room, ossUploadCallback); const whiteWebSdk = new WhiteWebSdk({appIdentifier: "283/VGiScM9Wiw2HJg"}); const pptConverter = whiteWebSdk.pptConverter(this.props.roomToken!); await uploadManager.convertFile( event.file, pptConverter, PPTKind.Dynamic, this.props.oss.folder, uuid, documentFileCallback, this.props.onProgress, ); } private uploadImage = async (event: any): Promise => { const {ossUploadCallback} = this.props; const uploadFileArray: File[] = []; uploadFileArray.push(event.file); const uploadManager = new UploadManager(this.client, this.props.room, ossUploadCallback); if (this.props.whiteboardRef) { const {clientWidth, clientHeight} = this.props.whiteboardRef; await uploadManager.uploadImageFiles(uploadFileArray, clientWidth / 2, clientHeight / 2, this.props.onProgress); } else { const clientWidth = window.innerWidth; const clientHeight = window.innerHeight; await uploadManager.uploadImageFiles(uploadFileArray, clientWidth / 2, clientHeight / 2, this.props.onProgress); } } private renderUploadButton = (): React.ReactNode => { const {uploadToolBox} = this.props; let Nodes: React.ReactNode[]; if (uploadToolBox) { Nodes = uploadToolBox.map((data: UploadToolBoxType, index: number) => { if (data.type === UploadDocumentEnum.image) { if (data.enable) { return (
{data.title ? data.title : (projectStore.isEnglish() ? "upload image" : "上传图片")}
{data.script ? data.script : (projectStore.isEnglish() ? "Support for common formats." : "支持常见格式,可以改变图片大小和位置。")}
); } else { return null; } } else if (data.type === UploadDocumentEnum.dynamic_conversion) { if (data.enable) { return (
{data.title ? data.title : (projectStore.isEnglish() ? "PPTX transfer web" : "资料转网页")}
{data.script ? data.script : (projectStore.isEnglish() ? "Turn pptx into a web page for syncing." : "支持 pptx,如果是 ppt 格式文件,请手动转换。")}
); } else { return null; } } else { if (data.enable) { return (
{data.title ? data.title : (projectStore.isEnglish() ? "Docs transfer image" : "资料转图片")}
{data.script ? data.script : (projectStore.isEnglish() ? "Support ppt、pptx、word and pdf." : "支持 ppt、pptx、word 以及 pdf。")}
); } else { return null; } } }); return Nodes; } else { return [
{projectStore.isEnglish() ? "upload image" : "上传图片"}
{projectStore.isEnglish() ? "Support for common formats." : "支持常见格式,可以改变图片大小和位置。"}
,
{projectStore.isEnglish() ? "PPTX transfer web" : "资料转网页"}
{projectStore.isEnglish() ? "Turn pptx into a web page for syncing." : "支持 pptx,如果是 ppt 格式文件,请手动转换。"}
,
{projectStore.isEnglish() ? "Docs transfer image" : "资料转图片"}
{projectStore.isEnglish() ? "Support ppt、pptx、word and pdf." : "支持 ppt、pptx、word 以及 pdf。"}
, ]; } } private renderPopoverContent = (): React.ReactNode => { const {uploadToolBox} = this.props; if (uploadToolBox) { const length = uploadToolBox.filter(data => data.enable).length; return (
{this.renderUploadButton()}
); } else { return (
{this.renderUploadButton()}
); } } private handlePlacement = (): TooltipPlacement => { const {toolBarPosition} = this.props; switch (toolBarPosition) { case ToolBarPositionEnum.top: { return "top"; } case ToolBarPositionEnum.bottom: { return "bottom"; } case ToolBarPositionEnum.left : { return "left"; } default: { return "right"; } } } private handleVisibleChange = (e: any): void => { if (e) { this.setState({toolBoxColor: "#141414"}); } else { this.setState({toolBoxColor: "#A2A7AD"}); } } public render(): React.ReactNode { const {toolBarPosition} = this.props; return (
this.setState({toolBoxColor: "#141414"})} onMouseLeave={() => this.setState({toolBoxColor: "#A2A7AD"})} className={(toolBarPosition === ToolBarPositionEnum.left || toolBarPosition === ToolBarPositionEnum.right || toolBarPosition === undefined) ? "tool-box-cell-box-left" : "tool-box-cell-box"}>
); } }