react @excalidraw/excalidraw 实时协作
import React, { PureComponent, useRef } from 'react';
import { history, connect } from 'umi';
import { Modal, Collapse, Button, NavBar, Toast } from "antd-mobile";
import { LeftOutline } from 'antd-mobile-icons'
import styles from './index.less';
import { handlePath, userInfo } from '@/utils/globalcommon.js';
import * as excalidrawLib from "@excalidraw/excalidraw";
import { Excalidraw, defaultLang, languages, MainMenu, MobileFooter, Sidebar, Footer, exportToBlob, LiveCollaborationTrigger } from "@excalidraw/excalidraw";
@connect(({ whiteboard, loading }) => ({
whiteboard,
loading: loading.models.whiteboard,
}))
class Whiteboard extends PureComponent {
state = {
excalidrawAPI: null,
exportEmbedScene: true,
shareDialogState: {},
scene: []
}
initialData = {}
componentWillUnmount() {
}
onChange=(elements)=>{}
render() {
const renderMenu = () => {
const that = this
return (
<MainMenu>
{/* 协调合作 */}
<MainMenu.DefaultItems.LiveCollaborationTrigger
isCollaborating={false}
onSelect={() =>
that.setShareDialogState()
}
/>
</MainMenu>
);
};
return (
<div className={styles.whiteboardWarpper}>
<div className={styles.contentBox}
excalidrawLib={excalidrawLib}
>
<Excalidraw
onChange={(elements, state) => {
this.setState({
scene: elements
})
this.onChange(elements)
}}
langCode={"zh-CN"} //简体中文
excalidrawAPI={(api) => this.setState({ excalidrawAPI: api })}
initialData={this.initialData}
renderTopRightUI={() => (
<LiveCollaborationTrigger
isCollaborating={true}
onSelect={() => {
window.alert("You clicked on collab button");
// setIsCollaborating(true);
}}
/>
)}
>
{renderMenu()}
</Excalidraw>
</div>
</div >
);
}
}
export default Whiteboard;
实现实时协作;