首页 > 其他分享 >Tinymce富文本相关内容和配置

Tinymce富文本相关内容和配置

时间:2023-02-08 10:45:33浏览次数:38  
标签:Tinymce formData 配置 tinymce reload let import 文本 newValue

<template>
  <div class="tinymce-editor">
    <editor
      v-if="!reloading"
      v-model="myValue"
      :init="init"
      :disabled="disabled"
      @onClick="onClick">
    </editor>
  </div>
</template>

<script>
  import tinymce from 'tinymce/tinymce'
  import Editor from '@tinymce/tinymce-vue'
  import 'tinymce/themes/silver/theme'

  // 引入富文本编辑器主题的js和css
import 'tinymce/skins/content/default/content.css'
import 'tinymce/themes/silver/theme.min.js'
import 'tinymce/icons/default/icons' // 解决了icons.js 报错Unexpected token '<'

  import 'tinymce/icons/default'
  import "tinymce/icons/default/icons";
import "tinymce/themes/silver";
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/preview";
import "tinymce/plugins/code";
import "tinymce/plugins/link";
import "tinymce/plugins/advlist";
import "tinymce/plugins/codesample";
import "tinymce/plugins/hr";
import "tinymce/plugins/fullscreen";
import "tinymce/plugins/textpattern";
import "tinymce/plugins/searchreplace";
import "tinymce/plugins/autolink";
import "tinymce/plugins/directionality";
import "tinymce/plugins/visualblocks";
import "tinymce/plugins/visualchars";
import "tinymce/plugins/template";
import "tinymce/plugins/charmap";
import "tinymce/plugins/nonbreaking";
import "tinymce/plugins/insertdatetime";
import "tinymce/plugins/imagetools";
import "tinymce/plugins/autosave";
import "tinymce/plugins/autoresize";

  import { uploadAction,getFileAccessHttpUrl } from '@/api/manage'
  import { getVmParentByName } from '@/utils/util'
  export default {
    components: {
      Editor
    },
    props: {
      value: {
        type: String,
        required:false
      },
      tinymceHeight: {
        type: Number,
        default: 300
      },
      triggerChange:{
        type: Boolean,
        default: false,
        required:false
      },
      disabled: {
        type: Boolean,
        default: false
      },
      plugins: {
        type: [String, Array],
        default: 'lists image link media table textcolor wordcount contextmenu fullscreen advlist autolink code colorpicker'
      },
      toolbar: {
        type: [String, Array],
        default:
        "code undo redo restoredraft | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough link codesample | alignleft aligncenter alignright alignjustify formatpainter | \
    styleselect formatselect fontselect fontsizeselect | bullist numlist | blockquote subscript superscript removeformat | \
    table image media charmap hr pagebreak insertdatetime | fullscreen preview",
        //default: 'undo redo |  formatselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | lists link unlink image media table | removeformat | fullscreen',
        branding:false
      }
    },
    data() {
      return {
        //初始化配置
        init: {
          language_url: '/tinymce/langs/zh_CN.js',
          language: 'zh_CN',
          skin_url: '/tinymce/skins/lightgray',
          height: this.tinymceHeight,
          plugins: this.plugins,
          toolbar: this.toolbar,
          font_formats:
          "微软雅黑=Microsoft YaHei, sans-serif;苹果苹方=PingFang SC,Microsoft YaHei,sans-serif;宋体=simsun,serif;仿宋体=FangSong,serif;黑体=SimHei,sans-serif;思源宋体=思源宋体,Noto,Serif,SC;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Times New Roman=Times New Roman, sans-serif;Book Antiqua=book antiqua,palatino;",
          branding: false,
          menubar: false,
          toolbar_drawer: false,
          convert_urls : false,// 如果你设置该选项为false,那么它会试着保持URL的完整性。默认为true,意味着URL会依据 relative_urls的状态而被强制为绝对或相对的
          browser_spellcheck: true, // 拼写检查
          paste_data_images: true, // 允许粘贴图像
          images_upload_handler: (blobInfo, success) => {
            let formData = new FormData()
            formData.append('file', blobInfo.blob(), blobInfo.filename());
            formData.append('biz', "jeditor");
            formData.append("jeditor","1");
            uploadAction(window._CONFIG['domianURL']+"/sys/common/upload", formData).then((res) => {
              if (res.success) {
                if(res.message == 'local'){
                  const img = 'data:image/jpeg;base64,' + blobInfo.base64()
                  success(img)
                }else{
                  let img = getFileAccessHttpUrl(res.message)
                  success(img)
                }
              }
            })
          }
        },
        myValue: this.value,
        reloading: false,
      }
    },
    mounted() {
      this.initATabsChangeAutoReload()
    },
    methods: {

      reload() {
        this.reloading = true
        this.$nextTick(() => this.reloading = false)
      },

      onClick(e) {
        this.$emit('onClick', e, tinymce)
      },
      //可以添加一些自己的自定义事件,如清空内容
      clear() {
        this.myValue = ''
      },

      /**
       * 自动判断父级是否是 <a-tabs/> 组件,然后添加事件监听,自动触发reload()
       *
       * 由于 tabs 组件切换会导致 tinymce 无法输入,
       * 只有重新加载才能使用(无论是vue版的还是jQuery版tinymce都有这个通病)
       */
      initATabsChangeAutoReload() {
        // 获取父级
        let tabs = getVmParentByName(this, 'ATabs')
        let tabPane = getVmParentByName(this, 'ATabPane')
        if (tabs && tabPane) {
          // 用户自定义的 key
          let currentKey = tabPane.$vnode.key
          // 添加事件监听
          tabs.$on('change', (key) => {
            // 切换到自己时执行reload
            if (currentKey === key) {
              this.reload()
            }
          })
         
          this.reload()
          
        }else{
          
          let tabLayout = getVmParentByName(this, 'TabLayout')
          
          try {
            tabLayout.excuteCallback(() => {
              this.reload()
            })
          } catch (error) {
            if (tabLayout) {
              this.reload()
            }
          }
          
        }
      },

    },
    watch: {
      value(newValue) {
        this.myValue = (newValue == null ? '' : newValue)
      },
      myValue(newValue) {
        if(this.triggerChange){
          this.$emit('change', newValue)
        }else{
          this.$emit('input', newValue)
        }
      }
    }
  }

</script>
<style scoped>
</style>

 

标签:Tinymce,formData,配置,tinymce,reload,let,import,文本,newValue
From: https://www.cnblogs.com/zhangliang88/p/17100916.html

相关文章

  • 终端(terminal)代理配置方案
    因为macos的终端在默认情况中,不走代理,只会走本地流量。即使我们使用了系统代理,也无法自动代理到公司内网。但是在利用终端安装一些软件配置一些服务的时候,我们不得不依赖......
  • linux配置jdk
    1、root用户配置,vim/etc/profile,添加如下内容#setjavaenviromentJAVA_HOME=/opt/jdk1.8.0_311JRE_HOME=/opt/jdk1.8.0_311/jreCLASS_PATH=.:$JAVA_HOME/lib/dt.jar......
  • TiDB Operator配置TiDB集群故障自动转移
    TiDB集群包括PD、TiKV、TiDB、TiFlash、TiCDC和Pump六个组件。目前TiCDC和Pump并不支持故障自动转移,PD、TiKV、TiDB和TiFlash的故障转移策略会有所不同。PD故障......
  • 配置Freeswitch(mod_unimrcp)与百度Mrcp Server实现实时语音识别(ASR)
    前面我们已经搭建好了百度MrcpServer服务器,接下来我们将Freeswitch与unimrcpserver两者连接起来,配置百度unimrcpserver的文章大家去这里看一下:搭建百度MrcpServer与Fr......
  • 690 IDEA与tomcat相关配置
    IDEA与tomcat相关配置1.IDEA会为每一个tomcat部署的项目单独创建一份配置文件查看控制台的log:UsingCATALINA_BASE:C:\Users\86198\AppData\Local\JetBrains\Int......
  • 安装和配置Java开发环境JDK
    我们通常软件开发的操作系统选择Windows,生产环境选择linux或windowsServer。移动开发可能是安卓或IOS和鸿蒙系统等。Windows下一般选择的是64位的操作系统,一般建议CPUI5......
  • 安装和配置Maven项目管理工具
    1、下载Maven工具包:https://maven.apache.org/download.cgi2、解压apache-maven-3.8.4-bin.zip3、修改apache-maven-3.8.4\conf\settings.xml文件.一般情况下只需要修改......
  • CMake配置跨平台项目踩的坑
    当要在windows平台下使用MinGW作为cmake使用的make平台时,需要确保cmake能够在系统环境变量PATH中找到MinGW的bin目录,如果PATH中没有MinGW的话可以在CMakeLists文件中手动......
  • Django3.X使用富文本编辑器kindereditor上传图片时一直转圈圈,如何解决
    问题描述:在写bbs项目的时候,老师用的是Django1.X结合富文本编辑器kindeditor,实现了图片上传,但是我在用Django3.X的时候,代码和老师一模一样,上传图片的时候一直转圈圈???但是文......
  • 支持配置版本的flannel 服务
    我已经介绍了一个修改版本的flannel(主要是0.7.1版本的),当时是修改了一个固定版本,不方便如果我们的节点需要运行更多的flannel服务基于配置的就比较方便了参考修改核......