1
0
mirror of https://github.com/cjango/dcat-vue.git synced 2025-12-06 22:40:03 +08:00

新增多选组件

This commit is contained in:
weiwait
2023-01-03 11:01:14 +08:00
parent 5f89c022a3
commit b8aeddda7f
5 changed files with 356 additions and 254 deletions

View File

@@ -85,6 +85,11 @@
->options(['123', '456', 'A' => 'aaa']) // 选项
->concatKey('separator') // 显示键
->optionsFromKeyValue('kvs'); // 用于结合vKeyValue进行选项选择
$form->vMultipleSelect('ms', '多选')
->options(['123', '456', 'A' => 'aaa']) // 选项
->concatKey('separator') // 显示键
->optionsFromKeyValue('kvs'); // 用于结合vKeyValue进行选项选择
```
[comment]: <> (### Donate)

File diff suppressed because one or more lines are too long

View File

@@ -15,6 +15,7 @@ use Weiwait\DcatVue\Field\KeyValue;
use Weiwait\DcatVue\Field\ListField;
use Weiwait\DcatVue\Field\MultipleFile;
use Weiwait\DcatVue\Field\MultipleImage;
use Weiwait\DcatVue\Field\MultipleSelect;
use Weiwait\DcatVue\Field\Select;
use Weiwait\DcatVue\Field\Tag;
use Weiwait\DcatVue\Field\Vue;
@@ -58,6 +59,7 @@ class DcatVueServiceProvider extends ServiceProvider
Form::extend('vDistpicker', Distpicker::class);
Form::extend('vDateRange', DateRange::class);
Form::extend('vSelect', Select::class);
Form::extend('vMultipleSelect', MultipleSelect::class);
Admin::requireAssets('@weiwait.dcat-vue');
}

View File

@@ -0,0 +1,91 @@
<?php
namespace Weiwait\DcatVue\Field;
use Dcat\Admin\Form\Field;
use Dcat\Admin\Support\Helper;
use Illuminate\Support\Str;
class MultipleSelect extends Field\MultipleSelect
{
protected $view = 'weiwait.dcat-vue::common';
private string $optionsFromKeyValueField = '';
private string $concatSeparator = '';
public function render()
{
/****************************** parent ************************************/
if (! $this->shouldRender()) {
return '';
}
$this->setDefaultClass();
$this->callComposing();
$this->withScript();
/****************************** field ************************************/
$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())));
/****************************** custom ************************************/
$this->withProvides();
$this->addVariables([
'provides' => $this->variables(),
]);
return view($this->view(), $this->variables());
}
protected function formatAttributes()
{
return $this->attributes;
}
protected function withProvides()
{
$this->addVariables([
'component' => 'MultipleSelect',
'mountId' => 'id' . md5(Str::uuid()),
'optionsFromKeyValueField' => $this->optionsFromKeyValueField,
'concatSeparator' => $this->concatSeparator,
]);
}
public function optionsFromKeyValue(string $field): self
{
$this->optionsFromKeyValueField = $field;
return $this;
}
public function concatKey(string $separator = ': '): self
{
$this->concatSeparator = $separator;
return $this;
}
}

View File

@@ -59,4 +59,8 @@ return [
'2.3.2' => [
'一些优化',
],
'2.4.0' => [
'一些优化',
'新增多选组件',
],
];