mirror of
https://github.com/cjango/dcat-vue.git
synced 2025-12-06 22:40:03 +08:00
一些优化
This commit is contained in:
@@ -5,10 +5,11 @@ namespace Weiwait\DcatVue\Field;
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
|
||||
class DateRange extends Field\DateRange
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
public function render()
|
||||
{
|
||||
@@ -50,7 +51,6 @@ class DateRange extends Field\DateRange
|
||||
{
|
||||
$this->addVariables([
|
||||
'component' => 'DateRange',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,11 @@ namespace Weiwait\DcatVue\Field;
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
|
||||
class Distpicker extends Field
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
// 地图高度
|
||||
protected string $height = '380px';
|
||||
// 模板id
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
use Weiwait\DcatVue\Field\Traits\UploadTrait;
|
||||
|
||||
class Editor extends Field\Editor
|
||||
{
|
||||
use UploadTrait;
|
||||
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use UploadTrait, FieldCommon;
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
@@ -4,11 +4,13 @@ namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
use Weiwait\DcatVue\Models\WeiwaitUpload;
|
||||
|
||||
class File extends Field\File
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
protected string $disk;
|
||||
|
||||
protected function prepareInputValue($file)
|
||||
|
||||
@@ -5,11 +5,13 @@ namespace Weiwait\DcatVue\Field;
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
use Weiwait\DcatVue\Models\WeiwaitUpload;
|
||||
|
||||
class Image extends Field\Image
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
protected string $disk;
|
||||
protected bool $disableCropper = false;
|
||||
|
||||
|
||||
@@ -7,11 +7,13 @@ use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
use function Swoole\Coroutine\map;
|
||||
|
||||
class KeyValue extends Field\KeyValue
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
private bool $is_list = false;
|
||||
private bool $is_serial = false;
|
||||
private bool $is_sortable = false;
|
||||
|
||||
@@ -5,10 +5,11 @@ namespace Weiwait\DcatVue\Field;
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
|
||||
class ListField extends Field\ListField
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
@@ -4,11 +4,13 @@ namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
use Weiwait\DcatVue\Models\WeiwaitUpload;
|
||||
|
||||
class MultipleFile extends Field\MultipleFile
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
protected string $disk;
|
||||
|
||||
protected function prepareInputValue($file): array
|
||||
|
||||
@@ -5,11 +5,13 @@ namespace Weiwait\DcatVue\Field;
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
use Weiwait\DcatVue\Models\WeiwaitUpload;
|
||||
|
||||
class MultipleImage extends Field\MultipleImage
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
protected string $disk;
|
||||
|
||||
protected function prepareInputValue($file)
|
||||
|
||||
@@ -5,10 +5,12 @@ namespace Weiwait\DcatVue\Field;
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
|
||||
class MultipleSelect extends Field\MultipleSelect
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
private string $optionsFromKeyValueField = '';
|
||||
private string $concatSeparator = '';
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
|
||||
class Number extends Field\Number
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
public function render()
|
||||
{
|
||||
@@ -44,7 +44,6 @@ class Number extends Field\Number
|
||||
{
|
||||
$this->addVariables([
|
||||
'component' => 'Number',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,13 @@ namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
use Weiwait\DcatVue\Field\Traits\HasOptions;
|
||||
|
||||
class Select extends Field\Select
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use HasOptions, FieldCommon;
|
||||
|
||||
private string $optionsFromKeyValueField = '';
|
||||
private string $concatSeparator = '';
|
||||
|
||||
@@ -69,7 +71,6 @@ class Select extends Field\Select
|
||||
{
|
||||
$this->addVariables([
|
||||
'component' => 'Select',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
'optionsFromKeyValueField' => $this->optionsFromKeyValueField,
|
||||
'concatSeparator' => $this->concatSeparator,
|
||||
]);
|
||||
|
||||
@@ -5,10 +5,11 @@ namespace Weiwait\DcatVue\Field;
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
|
||||
class Tag extends Field\Tags
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
33
src/Field/Traits/FieldCommon.php
Normal file
33
src/Field/Traits/FieldCommon.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Weiwait\DcatVue\Field\Traits;
|
||||
|
||||
trait FieldCommon
|
||||
{
|
||||
protected string $vid;
|
||||
|
||||
public function __construct($column, $arguments = [])
|
||||
{
|
||||
parent::__construct($column, $arguments);
|
||||
|
||||
$this->view = 'weiwait.dcat-vue::common';
|
||||
|
||||
$this->makeVid();
|
||||
}
|
||||
|
||||
public function makeVid(): static
|
||||
{
|
||||
$this->vid = 'vid' . md5(uuid_create());
|
||||
|
||||
$this->addVariables([
|
||||
'vid' => $this->vid,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function vid(): string
|
||||
{
|
||||
return $this->vid;
|
||||
}
|
||||
}
|
||||
66
src/Field/Traits/HasOptions.php
Normal file
66
src/Field/Traits/HasOptions.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Weiwait\DcatVue\Field\Traits;
|
||||
|
||||
use Dcat\Admin\Exception\RuntimeException;
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
trait HasOptions
|
||||
{
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function modelLoad(string $model, string $id, string $field, array $filters = [], int $perPage = 0): static
|
||||
{
|
||||
if (! class_exists($model) || ! in_array(Model::class, class_parents($model))) {
|
||||
throw new RuntimeException("[$model] must be a valid model class");
|
||||
}
|
||||
|
||||
self::composing(function (Field $field) use($filters) {
|
||||
$refs = [];
|
||||
|
||||
foreach ($filters as $name => $condition) {
|
||||
if (is_numeric($name)) {
|
||||
$ref = explode('.', $condition);
|
||||
$name = $condition;
|
||||
$condition = $ref[0];
|
||||
} else {
|
||||
$ref = explode('.', $name);
|
||||
}
|
||||
|
||||
|
||||
$refField = $field->form
|
||||
->fields()
|
||||
->filter(fn(Field $field) => $field->column() === $ref[0])
|
||||
->values()
|
||||
->get($filter[1] ?? 0);
|
||||
|
||||
if (!$refField) {
|
||||
throw new \Exception("找不到参考字段[$ref[0]");
|
||||
}
|
||||
|
||||
$refs[] = ['vid' => $refField->vid(), 'name' => $name, 'condition' => $condition];
|
||||
}
|
||||
|
||||
$field->addVariables([
|
||||
'loadRefs' => $refs,
|
||||
]);
|
||||
});
|
||||
|
||||
$filters = array_map(fn($k, $v) => is_numeric($k) ? $v : $k, array_keys($filters), array_values($filters));
|
||||
|
||||
$this->addVariables([
|
||||
'load' => [
|
||||
'model' => $model,
|
||||
'id' => $id,
|
||||
'field' => $field,
|
||||
'perPage' => $perPage,
|
||||
'filters' => $filters,
|
||||
'url' => route('dcat.admin.weiwait.options.model'),
|
||||
]
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,11 @@ namespace Weiwait\DcatVue\Field;
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Dcat\Admin\Widgets\Checkbox as WidgetCheckbox;
|
||||
use Weiwait\DcatVue\Field\Traits\FieldCommon;
|
||||
|
||||
class Vue extends Field\Checkbox
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
use FieldCommon;
|
||||
|
||||
protected array $watch = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user