diff --git a/README.md b/README.md index 2e254d9..8c30fd0 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,10 @@ ## 功能特性 - [x] 支持 Markdown 所有基础语法 - [x] 支持单独进行字体、字号设置 -- [x] **支持色盘取色**,并一键替换颜色 +- [x] 支持色盘取色,并一键替换颜色 - [x] 支持链接微信图文,外链自动转为文末索引 - [x] 支持一键复制并粘贴到公众号后台 +- [x] 支持图片上传并将 URL 插入编辑器光标定位处 ![select-and-replace-color-theme](./assets/images/select-and-replace-color-theme.gif) diff --git a/assets/scripts/editor.js b/assets/scripts/editor.js index bda8901..468967c 100644 --- a/assets/scripts/editor.js +++ b/assets/scripts/editor.js @@ -54,6 +54,7 @@ let app = new Vue({ this.refresh(); this.saveEditorContent(); }); + this.wxRenderer = new WxRenderer({ theme: setColor(this.currentColor), fonts: this.currentFont, @@ -106,6 +107,35 @@ let app = new Vue({ }); this.refresh(); }, + + // 图片上传结束 + uploaded(response, file, fileList) { + if (response.success) { + // 上传成功 + const cursor = this.editor.getCursor(); + const imageUrl = response.data.url + const markdownImage = `![](${imageUrl})` + this.editor.replaceSelection(`\n${markdownImage}\n`, cursor); + this.refresh(); + + this.$message({ + showClose: true, + message: '图片插入成功', + type: 'success' + }); + + } else { + // 上传失败 + this.$message({ + showClose: true, + message: response.message, + type: 'error' + }); + } + }, + failed(error, file, fileList) { + console.log(error) + }, // 刷新右侧预览 refresh() { this.output = this.renderWeChat(this.editor.getValue(0)); @@ -127,7 +157,7 @@ let app = new Vue({ range.setStartBefore(clipboardDiv.firstChild); range.setEndAfter(clipboardDiv.lastChild); window.getSelection().addRange(range); - + this.refresh() try { if (document.execCommand('copy')) { this.$notify({ diff --git a/index.html b/index.html index fbc5032..e6e0042 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,8 @@ - +