From 6690d96408b3242339027767f33b977b81b64c98 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Sat, 7 Dec 2019 16:46:30 +0800 Subject: [PATCH 1/2] 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 @@   + + +   + Date: Sat, 7 Dec 2019 16:57:13 +0800 Subject: [PATCH 2/2] docs: remove log and update default-content.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除控制台日志输出 - 更新默认内容 --- assets/default-content.md | 7 +++++++ assets/scripts/editor.js | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/assets/default-content.md b/assets/default-content.md index 47496bc..f7e4e14 100644 --- a/assets/default-content.md +++ b/assets/default-content.md @@ -80,6 +80,13 @@ Google 拥有专门设计的系统,可以自动捕获不适当的预测结果 目前有不少开源库都提供了这个功能,比如主流的搜索引擎框架 [Elasticsearch](https://www.elastic.co/products/elasticsearch)、[Solr](https://lucene.apache.org/solr/) 等,基于此,我们可以实现高效而强大的自动补全功能。 +#### 推荐阅读 +- [阿里又一个 20k+ stars 开源项目诞生,恭喜 fastjson!](https://mp.weixin.qq.com/s/RNKDCK2KoyeuMeEs6GUrow) +- [刷掉 90% 候选人的互联网大厂海量数据面试题(附题解 + 方法总结)](https://mp.weixin.qq.com/s/rjGqxUvrEqJNlo09GrT1Dw) +- [好用!期待已久的文本块功能究竟如何在 Java 13 中发挥作用?](https://mp.weixin.qq.com/s/kalGv5T8AZGxTnLHr2wDsA) +- [2019 GitHub 开源贡献排行榜新鲜出炉!微软谷歌领头,阿里跻身前 12!](https://mp.weixin.qq.com/s/_q812aGD1b9QvZ2WFI0Qgw) + + 欢迎关注我的公众号“Doocs开源社区”,原创技术文章第一时间推送。 ![](https://gitee.com/doocs/md/raw/master/assets/images/qrcode-for-doocs.jpg) \ No newline at end of file diff --git a/assets/scripts/editor.js b/assets/scripts/editor.js index ff46d94..d964984 100644 --- a/assets/scripts/editor.js +++ b/assets/scripts/editor.js @@ -174,7 +174,6 @@ let app = new Vue({ 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');