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-container>
<el-header class="top editor__header"> <el-header class="top editor__header">
<editor-header <editor-header
@uploaded="uploaded"
@cssChanged="cssChanged" @cssChanged="cssChanged"
@showBox="showBox = !showBox" @showBox="showBox = !showBox"
@showAboutDialog="aboutDialogVisible = true" @showAboutDialog="aboutDialogVisible = true"
@ -164,6 +165,7 @@ export default {
}, },
// //
uploaded(response, file, fileList) { uploaded(response, file, fileList) {
if (response) {
if (response.success) { if (response.success) {
// //
const cursor = this.editor.getCursor() const cursor = this.editor.getCursor()
@ -185,27 +187,13 @@ export default {
type: 'error' type: 'error'
}) })
} }
}, } else {
// this.$message({
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({
showClose: true, showClose: true,
message: '已复制渲染后的文章到剪贴板,可直接到公众号后台粘贴', message: '上传图片未知异常',
offset: 80, type: 'error'
duration: 1600,
type: 'success'
}) })
}
}, },
// //
leftAndRightScroll() { leftAndRightScroll() {

View File

@ -4,7 +4,7 @@
<el-upload class="header__item" action="https://imgkr.com/api/files/upload" <el-upload class="header__item" action="https://imgkr.com/api/files/upload"
:headers="{'Content-Type': 'multipart/form-data'}" :headers="{'Content-Type': 'multipart/form-data'}"
:show-file-list="false" :multiple="true" accept=".jpg,.jpeg,.png,.gif" name="file" :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"> <el-tooltip effect="dark" content="上传图片" placement="bottom-start">
<i class="el-icon-upload" size="medium"></i> <i class="el-icon-upload" size="medium"></i>
</el-tooltip> </el-tooltip>
@ -130,30 +130,6 @@ export default {
this.setCiteStatus(val) this.setCiteStatus(val)
this.editorRefresh() 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) { beforeUpload(file) {
const checkImageResult = isImageIllegal(file); const checkImageResult = isImageIllegal(file);
@ -170,7 +146,7 @@ export default {
fd.append('file', file); fd.append('file', file);
fileApi.fileUpload(fd).then(res => { fileApi.fileUpload(fd).then(res => {
this.uploaded(res) this.$emit('uploaded', res)
}).catch(err => { }).catch(err => {
console.log(err.message) console.log(err.message)
}) })
@ -179,9 +155,17 @@ export default {
// //
copy() { copy() {
let clipboardDiv = document.getElementById('output') let clipboardDiv = document.getElementById('output')
const clipboardHTML = clipboardDiv.innerHTML solveWeChatImage()
// solveWeChatImage() this.setHtml(solveHtml())
this.html = 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({ this.$notify({
showClose: true, showClose: true,
@ -190,7 +174,7 @@ export default {
duration: 1600, duration: 1600,
type: 'success' type: 'success'
}) })
clipboardDiv.innerHTML = clipboardHTML; // clipboardDiv.innerHTML = this.output; //
}, },
// CSS // CSS
async customStyle () { async customStyle () {
@ -244,7 +228,7 @@ export default {
document.body.removeChild(downLink) document.body.removeChild(downLink)
}, },
...mapMutations(['editorRefresh', 'clearEditorToDefault','setCurrentColor', 'setCiteStatus', ...mapMutations(['editorRefresh', 'clearEditorToDefault','setCurrentColor', 'setCiteStatus',
'setCurrentFont', 'setCurrentSize', 'setCssEditorValue', 'setWxRendererOptions']) 'setHtml', 'setCurrentFont', 'setCurrentSize', 'setCssEditorValue', 'setWxRendererOptions'])
}, },
mounted() { mounted() {
this.selectFont = this.currentFont this.selectFont = this.currentFont

View File

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

View File

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