feat:保存触发一次
This commit is contained in:
parent
beef468477
commit
5feda5bd83
|
@ -82,7 +82,7 @@ function ImportFilePlugin(props) {
|
||||||
// editor.setEditorState(editorState);
|
// editor.setEditorState(editorState);
|
||||||
|
|
||||||
export default function Hlexical(props) {
|
export default function Hlexical(props) {
|
||||||
console.log("this.props.filePath=============:", props.filePath)
|
console.log("this.props.filePath:", props.filePath)
|
||||||
const [editorState, setEditorState] = useState("");
|
const [editorState, setEditorState] = useState("");
|
||||||
const [lastId ,setLastId]= useState("");
|
const [lastId ,setLastId]= useState("");
|
||||||
function onChange(editorState) {
|
function onChange(editorState) {
|
||||||
|
@ -94,30 +94,35 @@ export default function Hlexical(props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function SaveFilePlugin(props) {
|
function SaveFilePlugin(props) {
|
||||||
let unsubscribe = store.subscribe(() => {
|
useEffect(()=>{
|
||||||
console.log("触发保存")
|
let unsubscribe = store.subscribe(() => {
|
||||||
console.log("props.editorState", props)
|
console.log("触发保存")
|
||||||
if (isEmpty(props.editorState)) {
|
console.log("props.editorState", props)
|
||||||
return
|
if (isEmpty(props.editorState)) {
|
||||||
}
|
return
|
||||||
const editorStateSave = {"editorState": JSON.parse(props.editorState)};
|
}
|
||||||
let resultSave = JSON.stringify(editorStateSave);
|
const editorStateSave = {"editorState": JSON.parse(props.editorState)};
|
||||||
console.log("store.getState().pushHotkeys", store.getState().pushHotkeys)
|
let resultSave = JSON.stringify(editorStateSave);
|
||||||
console.log("lastId", lastId)
|
console.log("store.getState().pushHotkeys", store.getState().pushHotkeys)
|
||||||
if ((lastId === "" || lastId !== store.getState().pushHotkeys.id) && store.getState().pushHotkeys.data === SAVE) {
|
console.log("lastId", lastId)
|
||||||
setLastId(store.getState().pushHotkeys.id);
|
if ((lastId === "" || lastId !== store.getState().pushHotkeys.id) && store.getState().pushHotkeys.data === SAVE) {
|
||||||
importFile(props.filePath).then(value => {
|
setLastId(store.getState().pushHotkeys.id);
|
||||||
let save = md5(resultSave) !== md5(JSON.stringify(JSON.parse(value.toString())));
|
importFile(props.filePath).then(value => {
|
||||||
console.log("md5(resultSave)!==md5(JSON.stringify(JSON.parse(value.toString())))", resultSave, save)
|
let save = md5(resultSave) !== md5(JSON.stringify(JSON.parse(value.toString())));
|
||||||
if (save) {
|
console.log("md5(resultSave)!==md5(JSON.stringify(JSON.parse(value.toString())))", resultSave, save)
|
||||||
console.log("保存重写")
|
if (save) {
|
||||||
overWriteFile(props.filePath, resultSave)
|
console.log("保存重写")
|
||||||
}
|
overWriteFile(props.filePath, resultSave)
|
||||||
}).catch(error =>
|
}
|
||||||
console.error(error)
|
}).catch(error =>
|
||||||
)
|
console.error(error)
|
||||||
}
|
)
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
console.log("return unsubscribe();")
|
||||||
|
return ()=>unsubscribe();
|
||||||
|
},[props])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -9,8 +9,7 @@ export const pushHotkeysSlice = createSlice({
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
pushHotkeys: (state, action) => {
|
pushHotkeys: (state, action) => {
|
||||||
console.log("pushHotkeys:pushHotkeys---------state", state)
|
console.log("pushHotkeys:pushHotkeys", action.payload)
|
||||||
console.log("pushHotkeys:pushHotkeys---------action", action)
|
|
||||||
if(action.payload){
|
if(action.payload){
|
||||||
state.data = action.payload;
|
state.data = action.payload;
|
||||||
state.id = nanoid();
|
state.id = nanoid();
|
||||||
|
|
Loading…
Reference in New Issue