mirror of
https://github.com/cjango/dcat-vue.git
synced 2025-12-06 22:40:03 +08:00
一些优化,新增行政区划
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DateRange extends Field\DateRange
|
||||
{
|
||||
@@ -49,6 +50,7 @@ class DateRange extends Field\DateRange
|
||||
{
|
||||
$this->addVariables([
|
||||
'component' => 'DateRange',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
167
src/Field/Distpicker.php
Normal file
167
src/Field/Distpicker.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Distpicker extends Field
|
||||
{
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
// 地图高度
|
||||
protected string $height = '380px';
|
||||
// 模板id
|
||||
protected string $areaId = '';
|
||||
// 关闭地图
|
||||
protected bool $disableMap = false;
|
||||
// 地址详细字段
|
||||
protected string $detailField = '';
|
||||
// 经度字段
|
||||
protected string $lngField = '';
|
||||
// 纬度字段
|
||||
protected string $latField = '';
|
||||
// 省字段
|
||||
protected string $provinceField = '';
|
||||
// 市字段
|
||||
protected string $cityField = '';
|
||||
// 区字段
|
||||
protected string $districtField = '';
|
||||
// 地图缩放字段
|
||||
protected string $zoomField = '';
|
||||
// 地图缩放
|
||||
protected float $zoom = 13.14;
|
||||
// 禁止选择
|
||||
protected array $disables = [];
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($label)
|
||||
{
|
||||
$this->areaId = md5(Str::uuid());
|
||||
parent::__construct([], [$label]);
|
||||
}
|
||||
|
||||
public function dist(string $province = null, string $city = null, string $district = null): self
|
||||
{
|
||||
if ($province) {
|
||||
$this->column[$province] = $province;
|
||||
$this->provinceField = $province;
|
||||
}
|
||||
|
||||
if ($city) {
|
||||
$this->column[$city] = $city;
|
||||
$this->cityField = $city;
|
||||
}
|
||||
|
||||
if ($district) {
|
||||
$this->column[$district] = $district;
|
||||
$this->districtField = $district;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function coordinate(string $lat, string $lng): self
|
||||
{
|
||||
$this->column[$lat] = $lat;
|
||||
$this->column[$lng] = $lng;
|
||||
|
||||
$this->latField = $lat;
|
||||
$this->lngField = $lng;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function detail(string $detail): self
|
||||
{
|
||||
$this->column[$detail] = $detail;
|
||||
|
||||
$this->detailField = $detail;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function mapHeight(int $height, string $unit = 'px'): self
|
||||
{
|
||||
$this->height = $height . $unit;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function disableMap(bool $disable = true): self
|
||||
{
|
||||
$this->disableMap = $disable;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function mapZoom(float $zoom = 13.14, string $column = ''): self
|
||||
{
|
||||
$this->zoom = $zoom;
|
||||
|
||||
if ($column) {
|
||||
$this->column[$column] = $column;
|
||||
|
||||
$this->zoomField = $column;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function disableRegions(array $regions): self
|
||||
{
|
||||
$this->disables = $regions;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function withProvides()
|
||||
{
|
||||
$this->addVariables([
|
||||
'component' => 'DistPicker',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
'height' => $this->height,
|
||||
'areaId' => $this->areaId,
|
||||
'provinceField' => $this->provinceField,
|
||||
'cityField' => $this->cityField,
|
||||
'districtField' => $this->districtField,
|
||||
'detailField' => $this->detailField,
|
||||
'lngField' => $this->lngField,
|
||||
'latField' => $this->latField,
|
||||
'disableMap' => $this->disableMap,
|
||||
'zoom' => $this->zoom,
|
||||
'zoomField' => $this->zoomField,
|
||||
'disables' => $this->disables,
|
||||
'urls' => [
|
||||
'address2ll' => route('dcat.admin.weiwait.distpicker.address2ll'),
|
||||
'll2address' => route('dcat.admin.weiwait.distpicker.ll2address'),
|
||||
'regions' => route('dcat.admin.weiwait.distpicker.regions'),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (! $this->shouldRender()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->setDefaultClass();
|
||||
|
||||
$this->callComposing();
|
||||
|
||||
$this->withScript();
|
||||
|
||||
/****************************** custom ************************************/
|
||||
|
||||
$this->withProvides();
|
||||
|
||||
$this->addVariables([
|
||||
'provides' => $this->variables(),
|
||||
]);
|
||||
|
||||
return view($this->view(), $this->variables());
|
||||
}
|
||||
}
|
||||
61
src/Field/Editor.php
Normal file
61
src/Field/Editor.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Field\Traits\UploadTrait;
|
||||
|
||||
class Editor extends Field\Editor
|
||||
{
|
||||
use UploadTrait;
|
||||
|
||||
protected $view = 'weiwait.dcat-vue::common';
|
||||
|
||||
public function render()
|
||||
{
|
||||
/****************************** parent ************************************/
|
||||
|
||||
$this->addVariables([
|
||||
'options' => $this->formatOptions(),
|
||||
]);
|
||||
|
||||
/****************************** field ************************************/
|
||||
|
||||
if (!$this->shouldRender()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->setDefaultClass();
|
||||
|
||||
$this->callComposing();
|
||||
|
||||
$this->withScript();
|
||||
|
||||
/****************************** custom ************************************/
|
||||
|
||||
$this->withProvides();
|
||||
|
||||
$this->withUpload();
|
||||
|
||||
$this->addVariables([
|
||||
'provides' => $this->variables(),
|
||||
]);
|
||||
|
||||
return view($this->view(), $this->variables());
|
||||
}
|
||||
|
||||
protected function formatAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
protected function withProvides()
|
||||
{
|
||||
$this->addVariables([
|
||||
'component' => 'Editor',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Models\WeiwaitUpload;
|
||||
|
||||
class File extends Field\File
|
||||
@@ -49,6 +50,7 @@ class File extends Field\File
|
||||
|
||||
$this->addVariables([
|
||||
'component' => 'File',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
'multiple' => false,
|
||||
'disk' => $this->disk ?? $disk,
|
||||
'dir' => $this->getDirectory(),
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Models\WeiwaitUpload;
|
||||
|
||||
class Image extends Field\Image
|
||||
@@ -54,6 +55,7 @@ class Image extends Field\Image
|
||||
|
||||
$this->addVariables([
|
||||
'component' => 'Image',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
'multiple' => false,
|
||||
'disk' => $this->disk ?? $disk,
|
||||
'dir' => $this->getDirectory(),
|
||||
|
||||
@@ -6,6 +6,7 @@ use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Support\Str;
|
||||
use function Swoole\Coroutine\map;
|
||||
|
||||
class KeyValue extends Field\KeyValue
|
||||
@@ -143,6 +144,7 @@ class KeyValue extends Field\KeyValue
|
||||
{
|
||||
$this->addVariables([
|
||||
'component' => 'KeyValue',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ListField extends Field\ListField
|
||||
{
|
||||
@@ -54,6 +55,7 @@ class ListField extends Field\ListField
|
||||
{
|
||||
$this->addVariables([
|
||||
'component' => 'List',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Models\WeiwaitUpload;
|
||||
|
||||
class MultipleFile extends Field\MultipleFile
|
||||
@@ -49,6 +50,7 @@ class MultipleFile extends Field\MultipleFile
|
||||
|
||||
$this->addVariables([
|
||||
'component' => 'File',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
'multiple' => true,
|
||||
'disk' => $this->disk ?? $disk,
|
||||
'dir' => $this->getDirectory(),
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
use Weiwait\DcatVue\Models\WeiwaitUpload;
|
||||
|
||||
class MultipleImage extends Field\MultipleImage
|
||||
@@ -54,6 +55,7 @@ class MultipleImage extends Field\MultipleImage
|
||||
|
||||
$this->addVariables([
|
||||
'component' => 'Image',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
'multiple' => true,
|
||||
'disk' => $this->disk ?? $disk,
|
||||
'dir' => $this->getDirectory(),
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Weiwait\DcatVue\Field;
|
||||
|
||||
use Dcat\Admin\Form\Field;
|
||||
use Dcat\Admin\Support\Helper;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Tag extends Field\Tags
|
||||
{
|
||||
@@ -63,6 +64,7 @@ class Tag extends Field\Tags
|
||||
{
|
||||
$this->addVariables([
|
||||
'component' => 'Tag',
|
||||
'mountId' => 'id' . md5(Str::uuid()),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
28
src/Field/Traits/UploadTrait.php
Normal file
28
src/Field/Traits/UploadTrait.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Weiwait\DcatVue\Field\Traits;
|
||||
|
||||
trait UploadTrait
|
||||
{
|
||||
use \Dcat\Admin\Form\Field\UploadField;
|
||||
|
||||
public function withUpload()
|
||||
{
|
||||
$this->addVariables([
|
||||
'uploader' => [
|
||||
'disk' => $this->disk,
|
||||
'dir' => $this->getDirectory(),
|
||||
'uploaded_url' => route('dcat.admin.weiwait.file.uploaded'),
|
||||
'obs_config_url' => route('dcat.admin.weiwait.file.obs-config'),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function defaultDirectory()
|
||||
{
|
||||
return config('admin.upload.directory.file');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user