chore:修改保存操作时的逻辑

This commit is contained in:
zhaoxuhui 2018-08-23 16:24:03 +08:00
parent 41c04ba5aa
commit ef15e51666
2 changed files with 36 additions and 27 deletions

View File

@ -104,7 +104,6 @@
<textarea
v-model="value"
@keydown.tab="tab"
@keydown.meta.83="save"
@keyup.enter="enter"
@keyup.delete="onDelete"
ref="textarea"

View File

@ -123,6 +123,7 @@ export default {
this.$refs.textarea.focus();
})
this.init();
this.addListener();
},
methods : {
init() {
@ -134,11 +135,7 @@ export default {
});
if (autoSave) {
this.timerId = setInterval(() => {
this.$emit('on-save', {
markdownValue : this.value,
htmlValue : this.previewMarkdown,
theme
});
this.handleSave();
}, interval)
}
@ -333,6 +330,9 @@ export default {
},
save(e) { // 保存
e.preventDefault();
this.handleSave();
},
handleSave() {
this.$emit('on-save', {
markdownValue : this.value,
htmlValue : this.previewMarkdown,
@ -365,14 +365,24 @@ export default {
print() { // 打印文件
const dom = this.$refs.preview;
Print(dom);
},
addListener() { // 事件监听,阻止保存
document.addEventListener('keydown', e => {
if (e.keyCode === 83 && e.metaKey) {
e.preventDefault();
this.handleSave();
}
})
}
},
watch : {
value() {
clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(() => {
this.previewMarkdown = marked(this.value, {
sanitize : true
});
}, 30)
this.indexLenth = this.value.split('\n').length;
const height_1 = this.indexLenth * 22;
const height_2 = this.$refs.textarea.scrollHeight;