From 6690d96408b3242339027767f33b977b81b64c98 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Sat, 7 Dec 2019 16:46:30 +0800 Subject: [PATCH] feat: add reset function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加重置功能 --- assets/scripts/editor.js | 35 +++++++++++++++++++++++++++++------ index.html | 4 ++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/assets/scripts/editor.js b/assets/scripts/editor.js index ae87f8f..ff46d94 100644 --- a/assets/scripts/editor.js +++ b/assets/scripts/editor.js @@ -64,12 +64,7 @@ let app = new Vue({ if (localStorage.getItem("__editor_content")) { this.editor.setValue(localStorage.getItem("__editor_content")); } else { - axios({ - method: 'get', - url: './assets/default-content.md' - }).then(resp => { - this.editor.setValue(resp.data); - }) + this.setDefaultContent(); } }, methods: { @@ -148,6 +143,23 @@ let app = new Vue({ refresh() { this.output = this.renderWeChat(this.editor.getValue(0)); }, + // 重置页面 + reset() { + this.$confirm('此操作将丢失本地缓存的文本和自定义样式,是否继续?', '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + center: true + }).then(() => { + localStorage.removeItem('__editor_content'); + localStorage.removeItem('__css_content'); + this.setDefaultContent(); + this.editor.focus(); + this.refresh(); + }).catch(() => { + this.editor.focus(); + }); + }, // 将左侧编辑器内容保存到 LocalStorage saveEditorContent() { let content = this.editor.getValue(0); @@ -157,6 +169,17 @@ let app = new Vue({ localStorage.removeItem("__editor_content"); } }, + setDefaultContent() { + axios({ + method: 'get', + url: './assets/default-content.md' + }).then(resp => { + console.log(resp.data) + this.editor.setValue(resp.data); + }).catch(err => { + this.editor.setValue('# Your markdown here\n'); + }) + }, copy() { let clipboardDiv = document.getElementById('output'); clipboardDiv.focus(); diff --git a/index.html b/index.html index 9fdc264..3ecdaac 100644 --- a/index.html +++ b/index.html @@ -43,6 +43,10 @@   + + +   +