bug修复

This commit is contained in:
JimQing 2020-07-04 00:55:40 +08:00
parent fe64205913
commit b90d9ff59b
3 changed files with 27 additions and 25 deletions

View File

@ -73,7 +73,8 @@
import {
setColorWithCustomTemplate,
setFontSize,
isImageIllegal
isImageIllegal,
fixCodeWhiteSpace
} from '../../scripts/util'
import fileApi from '../../api/file';
import {
@ -173,20 +174,22 @@ export default {
copy() {
this.$emit('startCopy');
setTimeout(() => {
solveWeChatImage()
this.setOutput(solveHtml())
let clipboardDiv = document.getElementById('output')
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.firstChild)
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,
@ -194,7 +197,7 @@ export default {
offset: 80,
duration: 1600,
type: 'success'
})
});
this.$emit('refresh');
this.$emit('endCopy');
}, 350);

View File

@ -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;
})
}
}

View File

@ -236,17 +236,6 @@ export default {
},
mounted() {
this.leftAndRightScroll()
},
watch: {
isCoping(newVal) {
const preDomList = document.getElementsByClassName('code__pre');
if (preDomList.length > 0) {
preDomList.forEach(pre=> {
pre.style.whiteSpace = newVal ? 'pre' : 'normal';
})
}
}
}
}