v0.0.1-final
tangjie 2026-07-16 17:25:26 +08:00
parent a80a96d1bd
commit 99381e8ed5
2 changed files with 36 additions and 27 deletions

View File

@ -1,34 +1,39 @@
// App.tsx // App.tsx
import { useRef, useState } from 'react'; import { useRef, useState, useEffect } from "react";
import { DocxEditor } from '@eigenpal/docx-editor-react'; import { DocxEditor } from "@eigenpal/docx-editor-react";
import '@eigenpal/docx-editor-react/styles.css'; import { createEmptyDocument } from "@eigenpal/docx-editor-core";
import "@eigenpal/docx-editor-react/styles.css";
import "./index.less";
export default function App() { export default function App() {
const editorRef = useRef(null); const editorRef = useRef(null);
const [file, setFile] = useState(null); const [currentDocument, setCurrentDocument] = useState(createEmptyDocument());
async function download() { const [documentBuffer, setDocumentBuffer] = useState();
const buffer = await editorRef.current?.save();
if (!buffer) return; const chooseWord = () => {
const blob = new Blob([buffer], { fetch(
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', `https://test-dragon-yf-pub.oss-cn-hangzhou.aliyuncs.com/jjb/6a589a40e4b0f40a8d939aa1.docx`,
)
.then((res) => res.arrayBuffer())
.then((buffer) => {
setDocumentBuffer(buffer);
}); });
const url = URL.createObjectURL(blob); };
const a = document.createElement('a');
a.href = url;
a.download = file?.name ?? 'document.docx';
a.click();
URL.revokeObjectURL(url);
}
return ( return (
<div style={{ height: '100vh', display: 'flex', flexDirection: 'column' }}> <div style={{ height: "100vh", display: "flex" }}>
<div style={{ padding: 8, display: 'flex', gap: 8 }}> <DocxEditor
<input ref={editorRef}
type="file" document={documentBuffer ? undefined : currentDocument}
accept=".docx" documentBuffer={documentBuffer}
onChange={(e) => setFile(e.target.files?.[0] ?? null)} mode="editing"
onSave={()=>{
console.log('save');
}}
/> />
<button onClick={download}>Download .docx</button> <div className="pick-word-container">
<div onClick={chooseWord}>文档</div>
</div> </div>
{file && <DocxEditor ref={editorRef} documentBuffer={file} mode="editing" />}
</div> </div>
); );
} }

View File

@ -0,0 +1,4 @@
.pick-word-container{
height: 100%;
width: 200px;
}