<template>
  <div class="richtext">
    <froala :id="'editor' + spareId" :tag="'textarea'" :config="froalaConfig" v-model="valueText" @input="inputHandler"></froala>
  </div>
</template>

<script>
import VueFroala from "vue-froala-wysiwyg";
export default {
  name: "",
  components: {},
  model: {
    prop: "valueText",
    event: "contentText",
  },
  props: {
    spareId: {
      type: String,
      required: true,
    },
    isText: {
      type: String,
      required: true,
      default: "",
    },
    valueText: {
      type: String,
      required: true,
    },
  },
  watch: {
    isText: {
      handler(newVal) {
        if (newVal) {
          this.froalaConfig.placeholderText = newVal;
        }
      },
      deep: true,
      immediate: true,
    },
  },
  data() {
    var that = this;
    return {
      editor: null,
      froalaConfig: {
        //More -> https://www.froala.com/wysiwyg-editor/docs/options
        // toolbarButtons: ['undo', 'redo', 'clearFormatting', '|', 'bold', 'italic', 'underline','strikeThrough','|', 'fontFamily', 'fontSize', 'color', '|','paragraphFormat', 'align', 'formatOL', 'formatUL', 'outdent', 'indent', 'quote', '-', 'insertLink', 'insertImage', 'insertVideo', 'embedly', 'insertFile', 'insertTable', '|', 'emoticons', 'specialCharacters', 'insertHR', 'selectAll', '|', 'print', 'spellChecker', 'help', '|', 'fullscreen'],//['fullscreen', 'bold', 'italic', 'underline', 'strikeThrough', 'subscript', 'superscript', '|', 'fontFamily', 'fontSize', 'color', 'inlineStyle', 'paragraphStyle', '|', 'paragraphFormat', 'align', 'formatOL', 'formatUL', 'outdent', 'indent', 'quote', '-', 'insertLink', 'insertImage', 'insertVideo', 'embedly', 'insertFile', 'insertTable', '|', 'emoticons', 'specialCharacters', 'insertHR', 'selectAll', 'clearFormatting', '|', 'print', 'spellChecker', 'help', 'html', '|', 'undo', 'redo'],//显示可操作项
        toolbarButtons: [
          "insertImage",
          "textColor",
          "bold",
          "italic",
          "underline",
          "strikeThrough",
          "fontFamily",
          "fontSize",
          "color",
          "paragraphStyle",
          "lineHeight",
          "paragraphFormat",
          "align",
          "insertHR",
          "undo",
          "redo",
        ],
        height: 400,
        fontSize: ["12", "14", "16", "18", "20", "24", "28", "32", "36", "40"],
        fontSizeDefaultSelection: "16",
        theme: "dark", //主题
        // placeholderText: this.isText,
        language: "zh_cn", //国际化
        imageUploadURL: import.meta.env.VITE_APP_API_ROOT + "/report/uploadImg", //上传url
        videoUploadURL: import.meta.env.VITE_APP_API_ROOT + "/report/uploadImg", //上传url
        fileUploadURL: import.meta.env.VITE_APP_API_ROOT + "/report/uploadImg", //上传url 更多上传介绍 请访问https://www.froala.com/wysiwyg-editor/docs/options
        imageDefaultWidth: false,
        // imageEditButtons:['imageAlign', 'imageCaption', 'imageRemove', '|', 'imageLink', 'linkOpen', 'linkEdit', 'linkRemove', '-', 'imageDisplay', 'imageStyle', 'imageAlt', 'imageSize'],
        quickInsertButtons: ["image", "table", "ul", "ol", "hr"], //快速插入项
        toolbarVisibleWithoutSelection: true, //是否开启 不选中模式
        // disableRightClick:true,//是否屏蔽右击
        // colorsHEXInput:false,//关闭16进制色值
        toolbarSticky: false, //操作栏是否自动吸顶
        // zIndex:99999,
        saveInterval: 0,
        events: {
          initialized: function () {
            // this.editor = editor;
            that.editor = this;
            // that.editor.html.set(that.value);
            // that.setHtml()
          },
          keyup: function (e, editor) {
            //添加事件，在每次按键按下时，都记录一下最后停留位置
            that.$nextTick(function () {
              that.lastEditRange = getSelection().getRangeAt(0);
            });
          },
          click: function (e, editor) {
            //添加事件，在每次鼠标点击时，都记录一下最后停留位置
            that.$nextTick(function () {
              that.lastEditRange = getSelection().getRangeAt(0);
            });
          },
        },
        charCounterCount: false,
        reportloadding: false,
        lastsavetime: "",
        isAddEnter: false, //是否已经添加过
        timer: null,
        ischange: false,
        isPublishloading: false,
      },
      value: "",
    };
  },
  methods: {
    inputHandler() {
      this.$emit("contentText", this.valueText);
    },
  },
};
</script>
<style lang="scss">
.richtext {
  .fr-placeholder {
    margin-top: 41px !important;
  }
  .fr-second-toolbar {
    display: none;
  }
}
</style>
