tinymce富文本

tinymce从本地引入加载

先从官网下载对应版本包之后复制到public下 附官网:https://www.tiny.cloud/get-tiny/self-hosted/

tinymce组件中改动如下:

const tinymceCDN = "/js/tinymce/tinymce.min.js"/*https://cdn.jsdelivr.net/npm/tinymce-all-in-one@4.9.3/tinymce.min.js*/
initTinymce() {
      const _this = this
      window.tinymce.init({
        selector: `#${this.tinymceId}`,
        /*language: this.languageTypeList['zh'],*/
        language_url:'/js/tinymce/langs/zh_CN.js',
        height: this.height,
        body_class: 'panel-body ',
        object_resizing: true,
        toolbar: this.toolbar.length > 0 ? this.toolbar : toolbar,
        menubar: this.menubar,
        plugins: plugins,
				end_container_on_empty_block: true,
        powerpaste_word_import: 'propmt',
				powerpaste_html_import: 'propmt',
				powerpaste_allow_local_images: true,
				paste_data_images: true,
        code_dialog_height: 450,
        code_dialog_width: 1000,
        advlist_bullet_styles: 'square',
        advlist_number_styles: 'default',
        imagetools_cors_hosts: ['www.tinymce.com', 'codepen.io'],
        default_link_target: '_blank',
        link_title: false,
        fontsize_formats: "11pt 12pt 12pt 14pt 18pt 24pt 36pt 72pt",
        nonbreaking_force_tab: true, // inserting nonbreaking space   need Nonbreaking Space Plugin
        init_instance_callback: editor => {
          if (_this.modelValue) {
            editor.setContent(_this.modelValue)
          }
          _this.hasInit = true
          editor.on('NodeChange Change KeyUp SetContent', () => {
            this.$emit('update:modelValue', editor.getContent())
          })
        },
				paste_preprocess: (plugin, args) => {
					// 处理远程图片
					let imageArray = []
					args.content.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, (match, capture) => {
						//判断是否需要本地化
						if(capture.indexOf('//')===0) imageArray.push('http:'+capture)
						else imageArray.push(capture)
					})
					if (imageArray.length > 0) this.uploadRemoteFile(imageArray, 0)
				},
        images_upload_handler: function (blobInfo, success, failure) {
          // 处理本地图片
          // 在回调中,记得调用success函数,传入上传好的图片地址;
          // blobInfo.blob() 得到图片的file对象;
          let files = blobInfo.blob()
          if (!files.name) {
            files = new window.File([files], 'image.png')
          }
          let formData = new FormData();
          formData.append('file', files)
          uploadImage(formData)
          .then(res => {
            success(process.env.VUE_APP_Image + '/' + res.data)
          })
        },
        setup(editor) {
          editor.on('FullscreenStateChanged', (e) => {
            _this.fullscreen = e.state
          })
        },
        convert_urls: false
      })
    },

最后就可以愉快的使用了!!
著作权归作者所有。
商业转载请联系作者获得授权,非商业转载请注明出处。
作者:TW
链接:http://www.lucklytw.cn/detail/7
来源:lucklytw.cn 著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值