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

@ -22,7 +22,7 @@ class CatchModelCollection extends Collection
*/ */
public function toTree($pid = 0, $pidField = 'parent_id', $children = 'children'): array public function toTree($pid = 0, $pidField = 'parent_id', $children = 'children'): array
{ {
return Tree::done($this->items, $pid, $pidField, $children); return Tree::done($this->toArray(), $pid, $pidField, $children);
} }

View File

@ -46,6 +46,6 @@ abstract class CatchModel extends \think\Model
*/ */
public function hasField(string $field) public function hasField(string $field)
{ {
return property_exists($this, 'field') ? in_array($field, $this->field) : false; return property_exists($this, 'field') && in_array($field, $this->field);
} }
} }

View File

@ -92,7 +92,7 @@ class Table
self::getTable()->drop(); self::getTable()->drop();
return self::exist(); return ! self::exist();
} }
/** /**

View File

@ -100,9 +100,9 @@ declare(strict_types=1);
{ {
$left = $this->total - $this->current; $left = $this->total - $this->current;
$empty = str_repeat(' ', $left * $this->average); $empty = str_repeat(' ', intval($left * $this->average));
$bar = str_repeat('>', $this->current * $this->average); $bar = str_repeat('>', intval($this->current * $this->average));
$percent = ((int)(sprintf('%.2f', $this->current/$this->total) * 100)) . '%'; $percent = ((int)(sprintf('%.2f', $this->current/$this->total) * 100)) . '%';

View File

@ -14,6 +14,7 @@
namespace catcher\library\form; namespace catcher\library\form;
use catcher\exceptions\FailedException; use catcher\exceptions\FailedException;
use catcher\library\form\components\AreaTrait;
use catcher\library\form\components\Editor; use catcher\library\form\components\Editor;
use FormBuilder\Exception\FormBuilderException; use FormBuilder\Exception\FormBuilderException;
use FormBuilder\Factory\Elm; use FormBuilder\Factory\Elm;
@ -60,6 +61,7 @@ abstract class Form
use ValidateFactoryTrait; use ValidateFactoryTrait;
use GroupFactoryTrait; use GroupFactoryTrait;
use FormValidates; use FormValidates;
use AreaTrait;
protected $primaryKeyField = 'id'; 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日 * @time 2021年04月11日
* @param int $size
* @return $this * @return $this
*/ */
public function uploadConf(): Editor public function uploadConf(int $size = 10): Editor
{ {
$this->props([ $this->props([
'uploadConf' => array_merge([ 'uploadConf' => array_merge([
'url' => Form::uploadImageUrl(), 'url' => Form::uploadImageUrl(),
'size' => 0.1, 'size' => $size,
], Form::authorization()) ], Form::authorization())
]); ]);