<template>
  <div class="editor-component">
    <vue-ueditor-wrap
      ref="ueditor"
      v-model="msg"
      :destroy="false"
      :config="config"
    >
    </vue-ueditor-wrap>
    <el-button type="primary"  @click="passMessage" v-if="Number(id) > 0">保存富文本</el-button>
    <span class="text" v-if="Number(id) > 0">温馨提示: 由于富文本比较大，为了防止保存失败，请单独保存！</span>
  </div>
</template>

<script>
import VueUeditorWrap from 'vue-ueditor-wrap' // ES6 Module
import { envConfig } from '@/utils/env-config'

export default {
  name: 'editorComponent',
  props: {
    message: {
      type: String,
      default: ''
    },
    id: {
      type: String | Number,
      default: '-1'
    }
  },
  components: {
    VueUeditorWrap
  },
  data () {
    return {
      msg: '',
      config: {
        // 编辑器不自动被内容撑高
        autoFloatEnabled: false,
        // 初始容器高度
        initialFrameHeight: 400,
        elementPathEnabled : false,
        // 初始容器宽度
        initialFrameWidth: '100%',
        // 上传文件接口
        // serverUrl: 'http://35.201.165.105:8000/controller.php',
        serverUrl: `${envConfig[process.env.BUILD_ENV]['richTextUrl']}/api/PICAuEditorServiceImpl/initQuery`,
        //serverUrl: "http://10.177.15.154:8080/PICA_CMS_BE/rest/PICAuEditorServiceImpl/initQuery",
        // 是否自动抓取远程图片的地址(默认为true)
        catchRemoteImageEnable: false,
        // UEditor 资源文件的存放路径，如果你使用的是 vue-cli 生成的项目，通常不需要设置该选项，vue-ueditor-wrap 会自动处理常见的情况，如果需要特殊配置，参考下方的常见问题2
        UEDITOR_HOME_URL: window.location.host.indexOf("localhost") > -1 || window.location.host.indexOf("127.0.0.1") > -1 ? '/static/UEditor/':'/pica.cloud.web-admin-discuss/static/UEditor/',
        toolbars: [[ //insertvideo 表示视频，已经去掉
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
            'directionalityltr', 'directionalityrtl', 'indent', '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
             'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
            'simpleupload', 'insertimage', 'link', 'emotion', 'insertcode', 'pagebreak', 'template', 'background', '|',
            'horizontal', 'date', 'time', 'spechars', 'wordimage', '|',
            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
            'print', 'searchreplace', 'drafts', 'help'
        ]]
        // 配合最新编译的资源文件，你可以实现添加自定义Request Headers,详情https://github.com/HaoChuan9421/ueditor/commits/dev-1.4.3.3
        // headers: {
        //   access_token: '37e7c9e3fda54cca94b8c88a4b5ddbf3'
        // }
      }
    }
  },
  watch: {
    message(newv, oldv) {
      this.msg = this.message;
    }
  },
  mounted() {
    this.msg = this.message;
  },
  methods: {
    // 6. 查看绑定的数据
    passMessage () {
      this.$emit('setEditorMsge', this.msg);
    }
  }
}
</script>

<style scoped>
  .editor-component .text {
    color: blue;
  }
</style>