update:优化基础组件

This commit is contained in:
JaguarJack
2021-04-20 08:45:08 +08:00
parent be91cfbc4f
commit ceb5a396d8
7 changed files with 60 additions and 7 deletions

View File

@@ -14,6 +14,7 @@
namespace catcher\library\form;
use catcher\exceptions\FailedException;
use catcher\library\form\components\AreaTrait;
use catcher\library\form\components\Editor;
use FormBuilder\Exception\FormBuilderException;
use FormBuilder\Factory\Elm;
@@ -60,6 +61,7 @@ abstract class Form
use ValidateFactoryTrait;
use GroupFactoryTrait;
use FormValidates;
use AreaTrait;
protected $primaryKeyField = 'id';

View File

@@ -0,0 +1,50 @@
<?php
namespace catcher\library\form\components;
use catcher\traits\db\RewriteTrait;
use FormBuilder\Factory\Elm;
trait AreaTrait
{
public function area($field = 'area', $title = '地区', $props = [])
{
if (!count($props)) {
$props = self::props('name', 'id', [
'checkStrictly' => true
]);
}
return self::cascader($field, $title)
->options($this->getRegion(3))
->props($props)
->clearable(true)
->filterable(true);
}
public function createValidate()
{
// TODO: Implement createValidate() method.
return Elm::validateStr();
}
/**
* 支持四级
* $level 1,2,3,4
* @time 2021年04月19日
* @param int $level
* @return mixed
*/
protected function getRegion($level = 1)
{
$areaModel = new class extends \think\Model {
protected $name = 'region';
use RewriteTrait;
};
return $areaModel->where('level', '<=', $level)
->field(['id', 'name', 'parent_id'])
->select()->toTree();
}
}

View File

@@ -139,14 +139,15 @@ class Editor extends FormComponent
* 上传配置
*
* @time 2021年04月11日
* @param int $size
* @return $this
*/
public function uploadConf(): Editor
public function uploadConf(int $size = 10): Editor
{
$this->props([
'uploadConf' => array_merge([
'url' => Form::uploadImageUrl(),
'size' => 0.1,
'size' => $size,
], Form::authorization())
]);