dev-v2
Joe 3 months ago
parent 241983f819
commit 0408fe50d0

@ -55,8 +55,6 @@
"@dnd-kit/utilities": "^3.2.2",
"@tinymce/tinymce-react": "^6.2.1",
"@umijs/route-utils": "^2.2.2",
"@wangeditor-next/editor": "^5.6.36",
"@wangeditor-next/editor-for-react": "^1.0.9",
"aliyun-aliplayer": "^2.29.1",
"aliyun-upload-vod": "^1.0.6",
"antd": "^5.2.2",
@ -71,9 +69,7 @@
"react": "^18.2.0",
"react-dev-inspector": "^1.8.4",
"react-dom": "^18.2.0",
"react-helmet-async": "^1.3.0",
"wang-editor-next-plugin-import-from-word": "^0.0.3",
"wang-editor-plugin-import-from-word": "^0.0.2"
"react-helmet-async": "^1.3.0"
},
"devDependencies": {
"@ant-design/pro-cli": "^2.1.5",

@ -1,86 +0,0 @@
import React, { useState, useEffect } from 'react';
import '@wangeditor-next/editor/dist/css/style.css'; // 引入wangEditor样式
import { IDomEditor, IEditorConfig, IToolbarConfig, Boot } from '@wangeditor-next/editor';
import { Editor, Toolbar } from '@wangeditor-next/editor-for-react';
// import wordModule from 'wang-editor-plugin-import-from-word';
interface WangEditorProps {
value?: string;
onChange?: (value: string) => void;
}
const WangEditor: React.FC<WangEditorProps> = ({ value, onChange }) => {
const [editor, setEditor] = useState<IDomEditor | null>(null);
const [html, setHtml] = useState(value ?? '<p>请输入内容...</p>');
// 外部value变化时同步到内部
useEffect(() => {
if (typeof value === 'string' && value !== html) {
setHtml(value);
}
}, [value]);
// 工具栏配置
const toolbarConfig: Partial<IToolbarConfig> = {};
// 编辑器配置
const editorConfig: Partial<IEditorConfig> = {
placeholder: '请输入内容...',
MENU_CONF: {
//@ts-ignore
// importFromWord: {
// server: process.env.BASE_URL + '/oss/imgUpload', //一个文件地址
// timeout: 5 * 1000, // 5s
// fieldName: 'file',
// headers: { Accept: 'text/x-json' },
// maxFileSize: 20 * 1024 * 1024, // 10M
// maxNumberOfFiles: 1,
// }
}
};
// 组件卸载时销毁editor实例
useEffect(() => {
// Boot.registerModule(wordModule);
return () => {
if (editor == null) return;
editor.destroy();
setEditor(null);
};
}, [editor]);
const handleChange = (editor: IDomEditor) => {
const newHtml = editor.getHtml();
setHtml(newHtml);
if (onChange) {
onChange(newHtml);
}
};
return (
<div style={{ border: '1px solid #ccc', zIndex: 100 }}>
<Toolbar
editor={editor}
defaultConfig={toolbarConfig}
mode="default"
style={{ borderBottom: '1px solid #ccc' }}
/>
<Editor
defaultConfig={editorConfig}
value={html}
onCreated={setEditor}
onChange={handleChange}
mode="default"
style={{ height: '300px', overflowY: 'hidden' }}
/>
<div style={{ marginTop: 16 }}>
<b></b>
<div dangerouslySetInnerHTML={{ __html: html }} />
</div>
</div>
);
};
export default WangEditor;
Loading…
Cancel
Save