打印/下载
基础用法
上传图片
垃圾回收

引入

import {Tinymce} from '@/library/ui'
import '../tinymce'
import Editor from '@tinymce/tinymce-vue'

Html

<editor v-model="editor.content" :init="editor.init"></editor>

JavaScript

export default {
  components: {Editor},
  data(){
    return {
      editor: {init:Tinymce(),content:''},
    }
  },
  created(){
    /* 配置 */
    this.editor.init = Tinymce();
    /* 上传图片 */
    this.editor.init.images_upload_handler = (blob,success)=>{};
  },
  methods:{
    /* 提交 */
    subEditor(){},
  },
}

JavaScript

this.editor.init.images_upload_handler = (blob,success)=>{
  // 类型
  let ext = blob.filename().split('.').pop();
  let type = Inc.getBaseType(ext);
  // 图片
  const img = type+blob.base64();
  // 请求
  Post('index/upImage',{base64:img},(res)=>{
    const d = res.data;
    if(d.code==0) success(d.img);
    else Toast(d.msg,'error');
  });
};

PHP

<?php
namespace app\modules\admin\controller;

use app\controller\Base;
use app\library\Upload;

class IndexController extends Base{

  static private $dir = 'upload/img/';

  /* 编辑器-上传图片 */
  function upImageAction(){
        $base64 = $this->request->get('base64','string');
        if(empty($base64)) return self::getJSON(['code'=>4000]);
        // 上传
        $id = '1';
        $dir = self::$dir.$id.'/editor/';
        $res = Upload::base64(['path'=>$dir,'base64'=>$base64]);
        if(is_array($res)){
            return self::getJSON(['code'=>0,'img'=>$this->config->base_url.$dir.$res['filename']]);
        }else{
            return self::getJSON(['code'=>4030,'msg'=>$res]);
        }
  }

}

JavaScript

subEditor(){
  let content = encodeURIComponent(this.editor.content);
  // 请求
  Post('index/edit',{content:content},(res)=>{
    const d = res.data;
    if(d.code!==0) Toast(d.msg,'error');
    else Toast(d.msg,'success');
  });
}

PHP

/* 编辑器-垃圾回收 */
function editAction(){
  $content = $this->request->get('content','string');
  $content = urldecode($content);
  // 获取Html图片
  $imgs = Upload::getHtmlImg($content);
  // 清理图片
  $id = '1';
  $dir = self::$dir.$id.'/editor/';
  Upload::clearImg($dir,$imgs);
  return self::getJSON(['code'=>0]);
}
{{copy}}