diff --git a/src/components/codeMirror/header.vue b/src/components/codeMirror/header.vue index 4143738..0de5ab0 100644 --- a/src/components/codeMirror/header.vue +++ b/src/components/codeMirror/header.vue @@ -58,7 +58,7 @@ - 复制 + 复制 关于
@@ -73,7 +73,8 @@ import { setColorWithCustomTemplate, setFontSize, - isImageIllegal + isImageIllegal, + fixCodeWhiteSpace } from '../../scripts/util' import fileApi from '../../api/file'; import { @@ -170,21 +171,25 @@ export default { return false; }, // 复制到微信公众号 - copy() { + copy(e) { this.$emit('startCopy'); setTimeout(() => { - let clipboardDiv = document.getElementById('output') - solveWeChatImage() - this.setHtml(solveHtml(this.nightMode)) + solveWeChatImage(); + fixCodeWhiteSpace(); + this.setOutput(solveHtml()); + let clipboardDiv = document.getElementById('output'); - clipboardDiv.focus() - window.getSelection().removeAllRanges() - let range = document.createRange() + clipboardDiv.focus(); + window.getSelection().removeAllRanges(); + let range = document.createRange(); - range.setStartBefore(clipboardDiv.firstChild) - range.setEndAfter(clipboardDiv.lastChild) - window.getSelection().addRange(range) - document.execCommand('copy') + range.setStartBefore(clipboardDiv.firstChild); + range.setEndAfter(clipboardDiv.lastChild); + window.getSelection().addRange(range); + document.execCommand('copy'); + range.setStartBefore(clipboardDiv.firstChild); + range.setEndAfter(clipboardDiv.firstChild); + fixCodeWhiteSpace('normal'); // 输出提示 this.$notify({ showClose: true, @@ -192,11 +197,11 @@ export default { offset: 80, duration: 1600, type: 'success' - }) - clipboardDiv.innerHTML = this.output; // 恢复现场 + }); this.$emit('refresh'); this.$emit('endCopy'); }, 350); + e.target.blur(); }, // 自定义CSS样式 async customStyle () { @@ -247,7 +252,7 @@ export default { document.body.removeChild(downLink) }, ...mapMutations(['clearEditorToDefault','setCurrentColor', 'setCiteStatus', 'themeChanged', - 'setHtml', 'setCurrentFont', 'setCurrentSize', 'setCssEditorValue', 'setWxRendererOptions']) + 'setOutput', 'setCurrentFont', 'setCurrentSize', 'setCssEditorValue', 'setWxRendererOptions']) }, mounted() { this.selectFont = this.currentFont; diff --git a/src/scripts/renderers/wx-renderer.js b/src/scripts/renderers/wx-renderer.js index 93ac65b..535c12d 100644 --- a/src/scripts/renderers/wx-renderer.js +++ b/src/scripts/renderers/wx-renderer.js @@ -140,7 +140,7 @@ const WxRenderer = function (opts) { return `
-
+            
                 ${codeLines.join('')}
             
diff --git a/src/scripts/util.js b/src/scripts/util.js index aa48894..c70174e 100644 --- a/src/scripts/util.js +++ b/src/scripts/util.js @@ -204,3 +204,13 @@ export function formatDoc(content) { }) return doc } + +export function fixCodeWhiteSpace(value = 'pre') { + const preDomList = document.getElementsByClassName('code__pre'); + + if (preDomList.length > 0) { + preDomList.forEach(pre=> { + pre.style.whiteSpace = value; + }) + } +} \ No newline at end of file diff --git a/src/store/index.js b/src/store/index.js index 6bfc516..71669f2 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -18,7 +18,6 @@ const state = { output: '', editor: null, cssEditor: null, - html: '', currentFont: '', currentSize: '', currentColor: '', @@ -26,8 +25,8 @@ const state = { nightMode: false }; const mutations = { - setHtml(state, data) { - state.html = data; + setOutput(state, data) { + state.output = data; }, setEditorValue(state, data) { state.editor.setValue(data)