<style lang="less">
    @import '../../styles/common.less';
    @import './editor.less';
</style>

<template>
    <textarea id="articleEditor" v-model="content"></textarea>
</template>

<script>
import tinymce from 'tinymce';
export default {
    name: 'eidtor',
    props: {
        editorContent: String
    },
    watch: {
        editorContent() {
            if (tinymce.activeEditor) {
                if (this.editorContent) {
                    tinymce.activeEditor.setContent(this.editorContent);
                } else {
                    tinymce.activeEditor.setContent("");
                }
            }
            this.content = this.editorContent;
        }
    },
    data() {
        return {
            content: this.editorContent || ""
        }
    },
    mounted () {
        tinymce.init({
            selector: '#articleEditor',
            images_upload_url: 'https://wechat.sotype.com/upload',
            branding: false,
            elementpath: false,
            height: 600,
            language: 'zh_CN.GB2312',
            menubar: 'edit insert view format table tools',
            theme: 'modern',
            plugins: [
                'advlist autolink lists link image charmap print preview hr anchor pagebreak imagetools',
                'searchreplace visualblocks visualchars code fullscreen fullpage',
                'insertdatetime media nonbreaking save table contextmenu directionality',
                'emoticons paste textcolor colorpicker textpattern imagetools codesample'
            ],
            toolbar1: ' newnote print fullscreen preview | undo redo | insert | styleselect | forecolor backcolor bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image emoticons media codesample',
            autosave_interval: '20s',
            image_advtab: true,
            table_default_styles: {
                width: '100%',
                borderCollapse: 'collapse'
            }
        });
    },
    destroyed () {
        tinymce.get('articleEditor').destroy();
    }
};
</script>
