编辑器上传图片

master
lion 3 years ago
parent 3fbe2d532d
commit 1728d3ff69

@ -1,9 +1,9 @@
<template> <template>
<div class="upload-container"> <div class="upload-container">
<el-button icon="el-icon-upload" size="mini" type="primary" @click=" dialogVisible=true"> <!-- <el-button icon="el-icon-upload" size="mini" type="primary" @click="dialogVisible=true">
上传图片 上传图片
</el-button> </el-button> -->
<el-dialog :visible.sync="dialogVisible" :modal="false"> <el-dialog :visible.sync="dialogVisible" :modal="false" @close="canceldialogVisible">
<el-upload <el-upload
:multiple="true" :multiple="true"
:file-list="fileList" :file-list="fileList"
@ -19,7 +19,7 @@
点击上传 点击上传
</el-button> </el-button>
</el-upload> </el-upload>
<el-button @click="dialogVisible = false"> <el-button @click="canceldialogVisible">
取消 取消
</el-button> </el-button>
<el-button type="primary" @click="handleSubmit"> <el-button type="primary" @click="handleSubmit">
@ -36,15 +36,24 @@ import { Message } from 'element-ui'
export default { export default {
name: 'EditorSlideUpload', name: 'EditorSlideUpload',
props: { props: {
show:{
type:Boolean,
default:false
}
}, },
data() { data() {
return { return {
action:`${process.env.VUE_APP_BASE_API}api/admin/upload-file`, action:`${process.env.VUE_APP_BASE_API}api/admin/upload-file`,
dialogVisible: false, dialogVisible: this.show,
listObj: {}, listObj: {},
fileList: [] fileList: []
} }
}, },
watch:{
show(val){
this.dialogVisible = val
}
},
methods: { methods: {
checkAllSuccess() { checkAllSuccess() {
return Object.keys(this.listObj).every(item => this.listObj[item].hasSuccess) return Object.keys(this.listObj).every(item => this.listObj[item].hasSuccess)
@ -59,6 +68,12 @@ export default {
this.listObj = {} this.listObj = {}
this.fileList = [] this.fileList = []
this.dialogVisible = false this.dialogVisible = false
this.$emit('updateshow',this.dialogVisible)
// this.show = false
},
canceldialogVisible(){
this.dialogVisible = false
this.$emit('updateshow',this.dialogVisible)
}, },
handleSuccess(response, file) { handleSuccess(response, file) {
const uid = file.uid const uid = file.uid

@ -2,8 +2,10 @@
<div class="tinymce"> <div class="tinymce">
<Editor v-model="myValue" :init="init" :disabled="disabled"></Editor> <Editor v-model="myValue" :init="init" :disabled="disabled"></Editor>
<EditorImage <EditorImage
:show="showImg"
class="tinymce__upload" class="tinymce__upload"
@successCBK="imageSuccessCBK" @successCBK="imageSuccessCBK"
@updateshow="updateshow"
></EditorImage> ></EditorImage>
</div> </div>
</template> </template>
@ -54,18 +56,19 @@ export default {
}, },
toolbar: { toolbar: {
type: [String, Array], type: [String, Array],
default: ` undo redo restoredraft | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough anchor | alignleft aligncenter alignright alignjustify outdent indent | default: ` undo redo restoredraft | assignment | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough anchor | alignleft aligncenter alignright alignjustify outdent indent |
styleselect formatselect fontselect fontsizeselect | table image charmap emoticons hr pagebreak |bullist numlist | blockquote subscript superscript removeformat | styleselect formatselect fontselect fontsizeselect | table image charmap emoticons hr pagebreak |bullist numlist | blockquote subscript superscript removeformat |
insertdatetime print preview | fullscreen | bdmap indent2em lineheight formatpainter axupimgs`, insertdatetime print preview | fullscreen | bdmap indent2em lineheight formatpainter axupimgs`,
}, },
menubar: { menubar: {
type: String, type: String,
default: "edit insert view format table", default: "edit insert view format table CardBtn",
}, },
}, },
data() { data() {
return { return {
myValue: this.value, myValue: this.value,
showImg:false,
init: { init: {
language_url: "@/asset/tinymce/langs/zh_CN.js", // language_url: "@/asset/tinymce/langs/zh_CN.js", //
language: "zh_CN", language: "zh_CN",
@ -75,6 +78,18 @@ export default {
toolbar: this.toolbar, toolbar: this.toolbar,
branding: false, branding: false,
menubar: this.menubar, menubar: this.menubar,
setup: (editor) => {
let _this = this
// assignment toolbar
editor.ui.registry.addButton('assignment', {
text: `<i class="el-icon-position" style="font-size: 16px">上传</i>`,
tooltip: '图片上传',
onAction: () => {
this.showImg = true
// _this.showEdit = true
},
})
},
//base64 //base64
//ajaxhttps://www.tiny.cloud/docs/configure/file-image-upload/#images_upload_handler //ajaxhttps://www.tiny.cloud/docs/configure/file-image-upload/#images_upload_handler
// images_upload_handler: (blobInfo, success, failure) => { // images_upload_handler: (blobInfo, success, failure) => {
@ -85,6 +100,9 @@ export default {
}; };
}, },
methods: { methods: {
updateshow(val){
this.showImg = val
},
imageSuccessCBK(arr) { imageSuccessCBK(arr) {
arr.forEach( arr.forEach(
(v) => (this.myValue += `<img class="wscnph" src="${v.url}" >`) (v) => (this.myValue += `<img class="wscnph" src="${v.url}" >`)
@ -115,5 +133,8 @@ export default {
right: 4px; right: 4px;
top: 0px; top: 0px;
} }
::v-deep .tox.tox-tinymce.tox-fullscreen{
z-index:0
}
} }
</style> </style>

Loading…
Cancel
Save