mirror of
https://github.com/cjango/dcat-vue.git
synced 2025-12-07 06:50:03 +08:00
first commit
This commit is contained in:
66
src/Field/File.php
Normal file
66
src/Field/File.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Weiwait\DcatVue\Models\WeiwaitUpload;
|
||||
|
||||
class File extends Field\File
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::file';
|
||||
protected string $disk;
|
||||
|
||||
protected function prepareInputValue($file)
|
||||
{
|
||||
WeiwaitUpload::query()->whereIn('name', (array) $file)->delete();
|
||||
|
||||
return parent::prepareInputValue($file);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (!$this->shouldRender()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->setDefaultClass();
|
||||
|
||||
$this->callComposing();
|
||||
|
||||
$this->withScript();
|
||||
|
||||
$this->withProvides();
|
||||
|
||||
$this->addVariables([
|
||||
'provides' => $this->variables(),
|
||||
]);
|
||||
|
||||
return view($this->view(), $this->variables());
|
||||
}
|
||||
|
||||
protected function formatAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
protected function withProvides()
|
||||
{
|
||||
$disk = config('admin.upload.disk', config('filesystems.default'));
|
||||
|
||||
$this->addVariables([
|
||||
'component' => 'File',
|
||||
'multiple' => false,
|
||||
'disk' => $this->disk ?? $disk,
|
||||
'dir' => $this->getDirectory(),
|
||||
'uploaded_url' => route('dcat.admin.weiwait.file.uploaded'),
|
||||
'obs_config_url' => route('dcat.admin.weiwait.file.obs-config'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function disk($disk): self
|
||||
{
|
||||
$this->disk = $disk;
|
||||
|
||||
return parent::disk($disk);
|
||||
}
|
||||
}
|
||||
66
src/Field/MultipleFile.php
Normal file
66
src/Field/MultipleFile.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Weiwait\DcatVue\Models\WeiwaitUpload;
|
||||
|
||||
class MultipleFile extends Field\MultipleFile
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::file';
|
||||
protected string $disk;
|
||||
|
||||
protected function prepareInputValue($file): array
|
||||
{
|
||||
WeiwaitUpload::query()->whereIn('name', (array) $file)->delete();
|
||||
|
||||
return parent::prepareInputValue($file);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (!$this->shouldRender()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->setDefaultClass();
|
||||
|
||||
$this->callComposing();
|
||||
|
||||
$this->withScript();
|
||||
|
||||
$this->withProvides();
|
||||
|
||||
$this->addVariables([
|
||||
'provides' => $this->variables(),
|
||||
]);
|
||||
|
||||
return view($this->view(), $this->variables());
|
||||
}
|
||||
|
||||
protected function formatAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
protected function withProvides()
|
||||
{
|
||||
$disk = config('admin.upload.disk', config('filesystems.default'));
|
||||
|
||||
$this->addVariables([
|
||||
'component' => 'File',
|
||||
'multiple' => true,
|
||||
'disk' => $this->disk ?? $disk,
|
||||
'dir' => $this->getDirectory(),
|
||||
'uploaded_url' => route('dcat.admin.weiwait.file.uploaded'),
|
||||
'obs_config_url' => route('dcat.admin.weiwait.file.obs-config'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function disk($disk): self
|
||||
{
|
||||
$this->disk = $disk;
|
||||
|
||||
return parent::disk($disk);
|
||||
}
|
||||
}
|
||||
100
src/Field/Vue.php
Normal file
100
src/Field/Vue.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Dcat\Admin\Widgets\Checkbox as WidgetCheckbox;
|
||||
|
||||
class Vue extends Field\Checkbox
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::index';
|
||||
|
||||
protected array $watch = [];
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->checkboxRender();
|
||||
$this->selectRender();
|
||||
|
||||
if (! $this->shouldRender()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->setDefaultClass();
|
||||
|
||||
$this->callComposing();
|
||||
|
||||
$this->withScript();
|
||||
|
||||
$this->addVariables([
|
||||
'checked' => $this->checked,
|
||||
'watch' => $this->watch,
|
||||
]);
|
||||
|
||||
$this->addVariables([
|
||||
'provides' => $this->variables(),
|
||||
]);
|
||||
|
||||
return view($this->view(), $this->variables());
|
||||
}
|
||||
|
||||
protected function formatAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function disabled($disabled): Vue
|
||||
{
|
||||
$this->addVariables([
|
||||
'disabled' => (array) $disabled
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function watch($column, $handler): Vue
|
||||
{
|
||||
$this->watch[] = [
|
||||
'type' => "$column:change",
|
||||
'handler' => $handler,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function checkboxRender()
|
||||
{
|
||||
if ($this->options instanceof \Closure) {
|
||||
$this->options(
|
||||
$this->options->call($this->values(), $this->value(), $this)
|
||||
);
|
||||
}
|
||||
|
||||
$this->addCascadeScript();
|
||||
}
|
||||
|
||||
protected function selectRender()
|
||||
{
|
||||
$this->addDefaultConfig([
|
||||
'allowClear' => true,
|
||||
'placeholder' => [
|
||||
'id' => '',
|
||||
'text' => $this->placeholder(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->formatOptions();
|
||||
|
||||
$this->addVariables([
|
||||
'options' => $this->options,
|
||||
'groups' => $this->groups,
|
||||
'configs' => $this->config,
|
||||
'cascadeScript' => $this->getCascadeScript(),
|
||||
]);
|
||||
|
||||
$this->initSize();
|
||||
|
||||
$this->attribute('data-value', implode(',', Helper::array($this->value())));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user