This commit is contained in:
JimQing 2020-05-02 17:40:03 +08:00
parent 5f9b58c90f
commit a46672d4ee
4 changed files with 44 additions and 69 deletions

View File

@ -3,6 +3,7 @@
<el-container>
<el-header class="top editor__header">
<editor-header
@uploaded="uploaded"
@cssChanged="cssChanged"
@showBox="showBox = !showBox"
@showAboutDialog="aboutDialogVisible = true"
@ -164,6 +165,7 @@ export default {
},
//
uploaded(response, file, fileList) {
if (response) {
if (response.success) {
//
const cursor = this.editor.getCursor()
@ -185,27 +187,13 @@ export default {
type: 'error'
})
}
},
//
copy12() {
let clipboardDiv = document.getElementById('output')
clipboardDiv.focus()
window.getSelection().removeAllRanges()
let range = document.createRange()
range.setStartBefore(clipboardDiv.firstChild)
range.setEndAfter(clipboardDiv.lastChild)
window.getSelection().addRange(range)
document.execCommand('copy')
//
this.$notify({
} else {
this.$message({
showClose: true,
message: '已复制渲染后的文章到剪贴板,可直接到公众号后台粘贴',
offset: 80,
duration: 1600,
type: 'success'
message: '上传图片未知异常',
type: 'error'
})
}
},
//
leftAndRightScroll() {

View File

@ -4,7 +4,7 @@
<el-upload class="header__item" action="https://imgkr.com/api/files/upload"
:headers="{'Content-Type': 'multipart/form-data'}"
:show-file-list="false" :multiple="true" accept=".jpg,.jpeg,.png,.gif" name="file"
:before-upload="beforeUpload" :on-success="uploaded">
:before-upload="beforeUpload">
<el-tooltip effect="dark" content="上传图片" placement="bottom-start">
<i class="el-icon-upload" size="medium"></i>
</el-tooltip>
@ -130,30 +130,6 @@ export default {
this.setCiteStatus(val)
this.editorRefresh()
},
//
uploaded(response, file, fileList) {
if (response.success) {
//
const cursor = this.editor.getCursor()
const imageUrl = response.data
const markdownImage = `![](${imageUrl})`
// Markdown URL
this.editor.replaceSelection(`\n${markdownImage}\n`, cursor)
this.$message({
showClose: true,
message: '图片插入成功',
type: 'success'
})
this.editorRefresh()
} else {
//
this.$message({
showClose: true,
message: response.message,
type: 'error'
})
}
},
//
beforeUpload(file) {
const checkImageResult = isImageIllegal(file);
@ -170,7 +146,7 @@ export default {
fd.append('file', file);
fileApi.fileUpload(fd).then(res => {
this.uploaded(res)
this.$emit('uploaded', res)
}).catch(err => {
console.log(err.message)
})
@ -179,9 +155,17 @@ export default {
//
copy() {
let clipboardDiv = document.getElementById('output')
const clipboardHTML = clipboardDiv.innerHTML
// solveWeChatImage()
this.html = solveHtml();
solveWeChatImage()
this.setHtml(solveHtml())
clipboardDiv.focus()
window.getSelection().removeAllRanges()
let range = document.createRange()
range.setStartBefore(clipboardDiv.firstChild)
range.setEndAfter(clipboardDiv.lastChild)
window.getSelection().addRange(range)
document.execCommand('copy')
//
this.$notify({
showClose: true,
@ -190,7 +174,7 @@ export default {
duration: 1600,
type: 'success'
})
clipboardDiv.innerHTML = clipboardHTML; //
clipboardDiv.innerHTML = this.output; //
},
// CSS
async customStyle () {
@ -244,7 +228,7 @@ export default {
document.body.removeChild(downLink)
},
...mapMutations(['editorRefresh', 'clearEditorToDefault','setCurrentColor', 'setCiteStatus',
'setCurrentFont', 'setCurrentSize', 'setCssEditorValue', 'setWxRendererOptions'])
'setHtml', 'setCurrentFont', 'setCurrentSize', 'setCssEditorValue', 'setWxRendererOptions'])
},
mounted() {
this.selectFont = this.currentFont

View File

@ -1,7 +1,7 @@
import juice from 'juice'
export function solveWeChatImage() {
const clipboardDiv = document.getElementById(output);
const clipboardDiv = document.getElementById('output');
const images = clipboardDiv.getElementsByTagName("img");
for (let i = 0; i < images.length; i++) {
const image = images[i];
@ -24,6 +24,6 @@ export function solveHtml() {
preserveImportant: true
}
);
console.log(res);
// console.log(res);
return res;
}

View File

@ -24,6 +24,9 @@ const state = {
citeStatus: 0
};
const mutations = {
setHtml(state, data) {
state.html = data;
},
setEditorValue(state, data) {
state.editor.setValue(data)
},