自动保存编写的文章

This commit is contained in:
augushong
2020-08-19 13:47:33 +08:00
parent ba4d69f416
commit 182dd118e3
3 changed files with 54 additions and 35 deletions

View File

@@ -257,6 +257,12 @@
</div>
<script>
var lastUpdateSecond = 0;
var currentSecond = 0;
setInterval(() => {
currentSecond++
}, 1000);
var categoryList = JSON.parse('{:json_encode($post->categorys->column("category_id"))}')
var tagList = JSON.parse('{:json_encode($post->tags->column("tag_id"))}')
@@ -301,18 +307,34 @@
} else {
console.log('Cursor not in the editor');
}
});
quill.on('text-change', function (delta, oldDelta, source) {
currentRange.index = delta.ops[0].retain
if (source == 'api') {
console.log("An API call triggered this change.");
} else if (source == 'user') {
console.log("A user action triggered this change.");
}
if (currentSecond - lastUpdateSecond > 30) {
var formData = {
'id': '{$post.id}'
};
formData.content = quill.getContents().ops
formData.content_html = $('#editor .ql-editor').html()
$.post('{:url("update")}', formData, function (result) {
lastUpdateSecond = currentSecond
layer.msg('自动保存成功',{
offset: 't'
})
})
}
});
upload.render({
@@ -369,8 +391,6 @@
formData.content = quill.getContents().ops
formData.content_html = $('#editor .ql-editor').html()
console.log(formData);
$.post('{:url("update")}', formData, function (result) {
layer.msg('保存成功')