update:更新Editor组件

This commit is contained in:
JaguarJack 2021-04-11 21:01:41 +08:00
parent f321a71677
commit 898ffbc822
2 changed files with 146 additions and 14 deletions

View File

@ -153,9 +153,9 @@ abstract class Form
* @time 2021年03月03日 * @time 2021年03月03日
* @return string * @return string
*/ */
protected static function uploadImageUrl(): string public static function uploadImageUrl(): string
{ {
return env('app.domain') . '/cms/upload/image'; return env('app.domain') . '/upload/image';
} }
/** /**
@ -164,24 +164,19 @@ abstract class Form
* @time 2021年03月10日 * @time 2021年03月10日
* @return string * @return string
*/ */
protected static function uploadImageFile(): string public static function uploadFileUrl(): string
{ {
return env('app.domain') . '/cms/upload/file'; return env('app.domain') . '/upload/file';
} }
/** /**
* 上传图片地址 * auth token
* *
* @time 2021年03月03 * @time 2021年04月11
* @return string * @return string[]
*/ */
protected static function uploadFileUrl(): string public static function authorization(): array
{
return env('app.domain') . '/cms/upload/file';
}
protected static function authorization(): array
{ {
return [ return [
'authorization' => 'Bearer ' . request()->user()->remember_token, 'authorization' => 'Bearer ' . request()->user()->remember_token,

View File

@ -1,6 +1,7 @@
<?php <?php
namespace catcher\library\form\components; namespace catcher\library\form\components;
use catcher\library\form\Form;
use FormBuilder\Driver\FormComponent; use FormBuilder\Driver\FormComponent;
use FormBuilder\Factory\Elm; use FormBuilder\Factory\Elm;
@ -10,9 +11,145 @@ class Editor extends FormComponent
'type' => 'editor' 'type' => 'editor'
]; ];
protected $defaultPlugins = ['advlist anchor autolink autosave lists code codesample colorpicker colorpicker contextmenu directionality emoticons fullscreen hr image imagetools insertdatetime link lists media nonbreaking noneditable pagebreak paste preview print save searchreplace spellchecker tabfocus table template textcolor textpattern visualblocks visualchars wordcount'];
protected $defaultToolbars = ['searchreplace bold italic underline strikethrough alignleft aligncenter alignright outdent indent blockquote undo redo removeformat subscript superscript code codesample', 'hr bullist numlist link image charmap preview anchor pagebreak insertdatetime media table emoticons forecolor backcolor fullscreen'];
/**
* 初始化
*
* @time 2021年04月11日
* @return Editor|void
*/
protected function init(): Editor
{
return $this->plugins()
->toolbars()
->language()
->initContent()
->uploadConf();
}
public function createValidate() public function createValidate()
{ {
// TODO: Implement createValidate() method. // TODO: Implement createValidate() method.
return Elm::validateStr(); return Elm::validateStr();
} }
/**
* set plugins
*
* @time 2021年04月11日
* @param array $plugins
* @return Editor
*/
public function plugins(array $plugins = []): Editor
{
$this->props([
'plugins' => count($plugins) ? $plugins : $this->defaultPlugins,
]);
return $this;
}
/**
* set toolbars
*
* @time 2021年04月11日
* @param array $toolbars
* @return Editor
*/
public function toolbars(array $toolbars = []): Editor
{
$this->props([
'toolbar' => count($toolbars) ? $toolbars : $this->defaultToolbars,
]);
return $this;
}
/**
* 设置语言
* 支持 'es_MX', 'en', 'zh_CN', 'ja'
* @time 2021年04月11日
* @param string $language
* @return $this
*/
public function language(string $language = 'zh_CN'): Editor
{
$this->props([
'language' => $language
]);
return $this;
}
/**
* 编辑器高度
*
* @time 2021年04月11日
* @param int $height
* @return $this
*/
public function height(int $height = 500): Editor
{
$this->props([
'height' => $height
]);
return $this;
}
/**
* 宽度设置
*
* @time 2021年04月11日
* @param string $width
* @return $this
*/
public function width($width = 'auto'): Editor
{
$this->props([
'width' => $width
]);
return $this;
}
/**
* 编辑器默认内容
*
* @time 2021年04月11日
* @param string $content
* @return $this
*/
public function initContent(string $content = ''): Editor
{
$this->props([
'initContent' => $content
]);
return $this;
}
/**
* 上传配置
*
* @time 2021年04月11日
* @return $this
*/
public function uploadConf(): Editor
{
$this->props([
'uploadConf' => array_merge([
'url' => Form::uploadImageUrl(),
'size' => 0.1,
], Form::authorization())
]);
return $this;
}
} }