|
|
@@ -0,0 +1,111 @@
|
|
|
+import { DocumentEditor } from "@onlyoffice/document-editor-react";
|
|
|
+import React, {useState} from "react";
|
|
|
+import useStore from "@/store";
|
|
|
+
|
|
|
+interface IProps {
|
|
|
+ onValueChange: (state: boolean) => void;
|
|
|
+}
|
|
|
+
|
|
|
+const WordEditor:React.FC<IProps> = ({onValueChange}) => {
|
|
|
+
|
|
|
+ const store = useStore()
|
|
|
+
|
|
|
+
|
|
|
+ const [data, setData] = useState({
|
|
|
+ documentServerUrl: "http://47.111.23.171:8082/",
|
|
|
+
|
|
|
+ config: {
|
|
|
+ width: '100%',
|
|
|
+ height: '100%',
|
|
|
+ type: 'desktop',
|
|
|
+ documentType: "word",
|
|
|
+ mode: 'edit',
|
|
|
+ document: {
|
|
|
+ fileType: "docx",
|
|
|
+ key: "13412453353_123524534324", // 1
|
|
|
+ title: "13412453353_123524534324.docx", //2
|
|
|
+ url: "http://eai-files.oss-cn-shanghai.aliyuncs.com/13412453353_123524534324.docx", // 3
|
|
|
+ permissions: {
|
|
|
+ "chat": false,
|
|
|
+ "comment": false,
|
|
|
+ "copy": true,
|
|
|
+ "deleteCommentAuthorOnly": false,
|
|
|
+ "download": false,
|
|
|
+ "edit": true,
|
|
|
+ "editCommentAuthorOnly": false,
|
|
|
+ "fillForms": false,
|
|
|
+ "modifyContentControl": false,
|
|
|
+ "print": false,
|
|
|
+ "protect": false,
|
|
|
+ "review": false,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ editorConfig: {
|
|
|
+ lang: 'zh-CN',
|
|
|
+ callbackUrl: "http://47.111.23.171:8081/api/onlyoffice/callback", // 保存文件的回调函数
|
|
|
+ customization: {
|
|
|
+ "autosave": false, // 关闭自动保存
|
|
|
+ "comments": false, // 关闭评论
|
|
|
+ "compactHeader": true, // 紧凑的header
|
|
|
+ "compactToolbar": false, // 不启用紧凑的header
|
|
|
+ "compatibleFeatures": false,
|
|
|
+ "forcesave": true, //强制保存
|
|
|
+ "help": false, // 隐藏帮助界面
|
|
|
+ "hideRightMenu": true, // TODO 无效
|
|
|
+ "hideRulers": true, // 隐藏标尺
|
|
|
+ "macros": false, // 关闭宏
|
|
|
+ "mentionShare": false,
|
|
|
+ "mobileForceView": false,
|
|
|
+ "plugins": false, // 禁用插件
|
|
|
+ "toolbarHideFileName": true,
|
|
|
+ "toolbarNoTabs": false,
|
|
|
+ "uiTheme": "theme-light", // 编辑页面的主题色
|
|
|
+ },
|
|
|
+ // TODO 替换成系统用户信息
|
|
|
+ "user": { // 启用用户信息
|
|
|
+ "id": store.user.id+"", // 4
|
|
|
+ "name": store.user.name // 5
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const onDocumentReady = function (event: any) {
|
|
|
+ console.log("Document is loaded");
|
|
|
+ };
|
|
|
+
|
|
|
+ const onLoadComponentError = (errorCode: number, errorDescription: string) => {
|
|
|
+ switch (errorCode) {
|
|
|
+ case -1: // Unknown error loading component
|
|
|
+ console.log(errorDescription);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case -2: // Error load DocsAPI from http://documentserver/
|
|
|
+ console.log(errorDescription);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case -3: // DocsAPI is not defined
|
|
|
+ console.log(errorDescription);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const onDocumentStateChange = (event: any) => {
|
|
|
+ onValueChange(event.data)
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <DocumentEditor
|
|
|
+ id="docxEditor"
|
|
|
+ documentServerUrl={data.documentServerUrl}
|
|
|
+ config={data.config}
|
|
|
+ events_onDocumentReady={onDocumentReady}
|
|
|
+ onLoadComponentError={onLoadComponentError}
|
|
|
+ events_onDocumentStateChange={onDocumentStateChange}
|
|
|
+ ></DocumentEditor>
|
|
|
+ </>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+export default WordEditor;
|