百度编辑器UEditor实现自动保存

<?php

namespace App\Admin\Extensions;

use Encore\Admin\Form\Field;

class NEditor extends Field
{
    protected $view = 'admin.neditor';

    protected static $css = [
        '/neditor/themes/notadd/css/neditor.css',
    ];

    protected static $js = [
        '/neditor/neditor.config.js',
        '/neditor/neditor.all.js'
    ];

    public function render()
    {


        $this->script = <<<EOT
        UE.delEditor("{$this->id}");

        var ue = UE.getEditor('{$this->id}',{
            initialFrameWidth:null,
            initialFrameHeight:400,
            autoHeight: false,
            elementPathEnabled: false,
            enableContextMenu: true,
            autoClearEmptyNode: true,
            wordCount: true,
            imagePopup: false,
            autotypeset: {indent: true, imageBlockLine: 'center'},
            allowDivTransTop: false,
            enterTag: 'br',
            autoHeightEnabled:false,
            enableAutoSave: true, //启用自动保存
            saveInterval: 500 //自动保存间隔时间, 单位ms
        });
        ue.ready(function () {
             ue.setHeight(400);
             ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
             
             //获取草稿内容
             var html = ue.getContent();
             if (html == '' || html == 'undefined') {
                 console.log('editor is null');
                 ue.execCommand('drafts');
             } else {
                 console.log('editor not null');
             }
        });

EOT;
        return parent::render();
    }
}
上一篇:《中国人工智能学会通讯》——3.6 跨网络链接预测的研究


下一篇:蚂蚁金服分布式链路跟踪组件 SOFATracer 总览|剖析