jeecg-boot集成了tinyMCE编辑器,找到JEditor.vue(components/jeecg/JEditor)

引用 import { postAction } from '@/api/manage'

将images_upload_handler:里的方法替换掉就可以了

<script>
  import { postAction } from '@/api/manage'
  import tinymce from 'tinymce/tinymce'
  import Editor from '@tinymce/tinymce-vue'
  import 'tinymce/themes/silver/theme'
  import 'tinymce/plugins/image'
  import 'tinymce/plugins/media'
  import 'tinymce/plugins/table'
  import 'tinymce/plugins/lists'
  import 'tinymce/plugins/contextmenu'
  import 'tinymce/plugins/wordcount'
  import 'tinymce/plugins/colorpicker'
  import 'tinymce/plugins/textcolor'
  import 'tinymce/plugins/fullscreen'
  export default {
    components: {
      Editor
    },
    props: {
      value: {
        type: String,
        required:false
      },
      triggerChange:{
        type: Boolean,
        default: false,
        required:false
      },
      disabled: {
        type: Boolean,
        default: false
      },
      plugins: {
        type: [String, Array],
        default: 'lists image media table textcolor wordcount contextmenu fullscreen'
      },
      toolbar: {
        type: [String, Array],
        default: 'undo redo |  formatselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | lists image media table | removeformat | fullscreen'
      }
    },
    data() {
      return {
        //初始化配置
        init: {
          language_url: '/tinymce/langs/zh_CN.js',
          language: 'zh_CN',
          skin_url: '/tinymce/skins/lightgray',
          height: 300,
          plugins: this.plugins,
          toolbar: this.toolbar,
          branding: false,
          menubar: false,
          images_upload_handler: (blobInfo, success, failure) => {
            // const img = 'data:image/jpeg;base64,' + blobInfo.base64()
            // success(img)
            this.handleImgUpload(blobInfo, success, failure)
          }
        },
        myValue: this.value,
        url: {
          fileUpload: window._CONFIG['domianURL'] + '/sys/common/upload',
        },
      }
    },
    mounted() {
      tinymce.init({})
    },
    methods: {

      onClick(e) {
        this.$emit('onClick', e, tinymce)
      },
      //可以添加一些自己的自定义事件,如清空内容
      clear() {
        this.myValue = ''
      },
      handleImgUpload (blobInfo, success, failure) {
        let formdata = new FormData()
        formdata.set('file', blobInfo.blob())
        postAction(this.url.fileUpload, formdata).then(res => {
          success(res.message)
        }).catch(res => {
          failure('error')
        })
      }
    },
    watch: {
      value(newValue) {
        this.myValue = (newValue == null ? '' : newValue)
      },
      myValue(newValue) {
        if(this.triggerChange){
          this.$emit('change', newValue)
        }else{
          this.$emit('input', newValue)
        }
      }
    }
  }

</script>

 

 

Logo

前往低代码交流专区

更多推荐