feat: 保存文集
This commit is contained in:
parent
1982910745
commit
615c7b30ba
|
@ -22,7 +22,7 @@ exports.menuRebuild = (mainWindow) => {
|
||||||
: []),
|
: []),
|
||||||
// { role: 'fileMenu' }
|
// { role: 'fileMenu' }
|
||||||
{
|
{
|
||||||
label: 'File',
|
label: '文件',
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: '打开目录',
|
label: '打开目录',
|
||||||
|
|
|
@ -64,7 +64,10 @@ const ItemTree = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
store.subscribe(() => {
|
store.subscribe(() => {
|
||||||
let fileDirDate = store.getState().dirMessage.data;
|
let fileDirDate = store.getState().dirMessage.data;
|
||||||
console.log("打开目录fileDirDate:", fileDirDate)
|
if (fileDirDate.length===0){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log("打开目录1fileDirDate:", fileDirDate)
|
||||||
for (let i = 0; i < fileDirDate.length; i++) {
|
for (let i = 0; i < fileDirDate.length; i++) {
|
||||||
const node = fileDirDate[i];
|
const node = fileDirDate[i];
|
||||||
console.log("node:", node)
|
console.log("node:", node)
|
||||||
|
|
|
@ -28,9 +28,10 @@ import {CLEAR_HISTORY_COMMAND} from "lexical";
|
||||||
import ActionPlugin from "../../../components/ActionPlug"
|
import ActionPlugin from "../../../components/ActionPlug"
|
||||||
import {func} from "prop-types";
|
import {func} from "prop-types";
|
||||||
import store from "../../../redux/store";
|
import store from "../../../redux/store";
|
||||||
import {useSelector} from 'react-redux'
|
|
||||||
import {SAVE} from "../../../utils/HotkeyConst";
|
import {SAVE} from "../../../utils/HotkeyConst";
|
||||||
import md5 from "md5"
|
import md5 from "md5"
|
||||||
|
import {isEmpty} from "../../../utils/ObjectUtils";
|
||||||
|
|
||||||
function Placeholder() {
|
function Placeholder() {
|
||||||
return <div className="editor-placeholder">Enter some rich text...</div>;
|
return <div className="editor-placeholder">Enter some rich text...</div>;
|
||||||
|
@ -85,15 +86,22 @@ function ImportFilePlugin(props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function SaveFilePlugin(props) {
|
function SaveFilePlugin(props) {
|
||||||
const [editor] = useLexicalComposerContext();
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
store.subscribe(() => {
|
store.subscribe(() => {
|
||||||
|
console.log("触发保存")
|
||||||
let data = store.getState().pushHotkeys.data;
|
let data = store.getState().pushHotkeys.data;
|
||||||
const editorState = {"editorState":editor.getEditorState()};
|
console.log("props.editorState",props.editorState)
|
||||||
|
if (isEmpty(props.editorState)){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const editorState = {"editorState":JSON.parse(props.editorState)};
|
||||||
let resultSave = JSON.stringify(editorState);
|
let resultSave = JSON.stringify(editorState);
|
||||||
|
console.log("data === SAVE",data,SAVE,data === SAVE)
|
||||||
if (data === SAVE) {
|
if (data === SAVE) {
|
||||||
importFile(props.filePath).then(value => {
|
importFile(props.filePath).then(value => {
|
||||||
if (md5(resultSave)!==md5(JSON.stringify(JSON.parse(value.toString())))){
|
let save = md5(resultSave)!==md5(JSON.stringify(JSON.parse(value.toString())));
|
||||||
|
console.log("md5(resultSave)!==md5(JSON.stringify(JSON.parse(value.toString())))",resultSave,save)
|
||||||
|
if (save){
|
||||||
console.log("保存重写")
|
console.log("保存重写")
|
||||||
overWriteFile(props.filePath, resultSave)
|
overWriteFile(props.filePath, resultSave)
|
||||||
}
|
}
|
||||||
|
@ -103,7 +111,7 @@ function SaveFilePlugin(props) {
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, editor)
|
}, props)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从字符串化 JSON 设置编辑器状态
|
// 从字符串化 JSON 设置编辑器状态
|
||||||
|
@ -122,6 +130,32 @@ export default function Hlexical(props) {
|
||||||
setEditorState(JSON.stringify(editorStateJSON));
|
setEditorState(JSON.stringify(editorStateJSON));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
store.subscribe(() => {
|
||||||
|
console.log("触发保存")
|
||||||
|
let data = store.getState().pushHotkeys.data;
|
||||||
|
console.log("props.editorState",editorState)
|
||||||
|
if (isEmpty(editorState)){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const editorStateSave = {"editorState":JSON.parse(editorState)};
|
||||||
|
console.log("editorStateSave",editorStateSave)
|
||||||
|
let resultSave = JSON.stringify(editorStateSave);
|
||||||
|
console.log("data === SAVE",resultSave,data === SAVE)
|
||||||
|
if (data === SAVE) {
|
||||||
|
importFile(props.filePath).then(value => {
|
||||||
|
let save = md5(resultSave)!==md5(JSON.stringify(JSON.parse(value.toString())));
|
||||||
|
console.log("md5(resultSave)!==md5(JSON.stringify(JSON.parse(value.toString())))",resultSave,save)
|
||||||
|
if (save){
|
||||||
|
console.log("保存重写")
|
||||||
|
overWriteFile(props.filePath, resultSave)
|
||||||
|
}
|
||||||
|
}).catch(error =>
|
||||||
|
console.error(error)
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LexicalComposer initialConfig={editorConfig}>
|
<LexicalComposer initialConfig={editorConfig}>
|
||||||
<div className="editor-container">
|
<div className="editor-container">
|
||||||
|
@ -145,7 +179,7 @@ export default function Hlexical(props) {
|
||||||
<MarkdownShortcutPlugin transformers={TRANSFORMERS}/>
|
<MarkdownShortcutPlugin transformers={TRANSFORMERS}/>
|
||||||
<OnChangePlugin onChange={onChange}/>
|
<OnChangePlugin onChange={onChange}/>
|
||||||
<ImportFilePlugin filePath={props.filePath}/>
|
<ImportFilePlugin filePath={props.filePath}/>
|
||||||
<SaveFilePlugin filePath={props.filePath}/>
|
{/*<SaveFilePlugin filePath={props.filePath} editorState={editorState} />*/}
|
||||||
{/*<ActionPlugin/>*/}
|
{/*<ActionPlugin/>*/}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue