自己写一些本地自动保存(别再出问题了,哈欠
load(componentClass, attrs) {
const body = { componentClass, attrs };
if (this.preventExit()) return;
// If we load a similar component into the composer, then Mithril will be
// able to diff the old/new contents and some DOM-related state from the
// old composer will remain. To prevent this from happening, we clear the
// component and force a redraw, so that the new component will be working
// on a blank slate.
if (this.isVisible()) {
this.clear();
m.redraw.sync();
}
this.body = body;
window.composerAutosave=()=>{
let username = app.session.user.data.attributes.username;
if(app.composer.data().relationships.discussion){
let discussionID = app.composer.data().relationships.discussion.data.id;
var storageName = username + 'replyTo' +discussionID
}else{
var storageName = 'newDiscussion'
}
if(app.composer.position!='hidden'){
console.log('autosave '+storageName)
window.localStorage.setItem(storageName ,app.composer.data().content)
setTimeout(()=>{
window.composerAutosave()
},500);
}
}
window.composerAutoLoad=()=>{
let username = app.session.user.data.attributes.username;
if(app.composer.data().relationships.discussion){
let discussionID = app.composer.data().relationships.discussion.data.id;
var storageName = username + 'replyTo' +discussionID
}else{
var storageName = 'newDiscussion'
}
//console.log('autoload '+storageName+' preload')
console.log(window.localStorage.getItem(storageName)?.length)
console.log( app.composer.data().content.length )
if(!app.composer.data().content.length && window.localStorage.getItem(storageName)?.length){
console.log('autoload '+storageName)
app.composer.editor.insertAtCursor(window.localStorage.getItem(storageName))}
}
setTimeout(()=>{
window.composerAutoLoad()
window.composerAutosave()
},500)
}
}else{
let storageName = 'newDiscussion'
}
if(window.localStorage[storageName])app.composer.editor.insertAtCursor(window.localStorage[storageName])
}