优化HasWhen,使用fields包围下级
This commit is contained in:
parent
80d9729a51
commit
c05035b485
|
@ -396,7 +396,7 @@ class Search extends SWrapper implements Renderable
|
|||
|
||||
$this->hidden('__page__')->value(1);
|
||||
$this->hidden('__pagesize__');
|
||||
$this->hidden('__search__')->value($this->id);
|
||||
$this->hidden('__search__')->value($this->getFormId());
|
||||
$this->hidden('__table__')->value($this->tableId);
|
||||
$this->hidden('__sort__');
|
||||
$this->hidden('__columns__')->value(implode(',', $this->chooseColumns));
|
||||
|
|
|
@ -139,7 +139,6 @@ class Map extends Text
|
|||
{
|
||||
return [
|
||||
'maptype' => $this->type,
|
||||
'textTempl' => Module::getInstance()->getViewsPath() . 'displayer' . DIRECTORY_SEPARATOR . 'text.html',
|
||||
'mapStyle' => 'style="width: ' . $this->width . ';height: ' . $this->height . ';max-width: 100%;"',
|
||||
];
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ class Matche extends Raw
|
|||
|
||||
public function renderValue()
|
||||
{
|
||||
$this->checked = '' . $this->value;
|
||||
|
||||
if (isset($this->options[$this->value])) {
|
||||
$this->value = $this->options[$this->value];
|
||||
} else if (isset($this->options['__default__'])) {
|
||||
|
@ -35,6 +33,8 @@ class Matche extends Raw
|
|||
|
||||
public function customVars()
|
||||
{
|
||||
$this->checked = (string)$this->value;
|
||||
|
||||
return array_merge(parent::customVars(), [
|
||||
'checked' => $this->checked,
|
||||
]);
|
||||
|
|
|
@ -43,8 +43,6 @@ class Matches extends Raw
|
|||
|
||||
public function renderValue()
|
||||
{
|
||||
$this->checked = is_array($this->value) ? implode(',', $this->value) : '' . $this->value;
|
||||
|
||||
$values = explode(',', $this->value);
|
||||
$texts = [];
|
||||
|
||||
|
@ -61,8 +59,10 @@ class Matches extends Raw
|
|||
|
||||
public function customVars()
|
||||
{
|
||||
return array_merge(parent::customVars(), [
|
||||
$this->checked = is_array($this->value) ? implode(',', $this->value) : (string)$this->value;
|
||||
|
||||
return [
|
||||
'checked' => $this->checked,
|
||||
]);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ class Select extends Field
|
|||
*/
|
||||
public function disabledOptions($val)
|
||||
{
|
||||
$this->disabledOptions = $val;
|
||||
$this->disabledOptions = is_array($val) ? $val : explode(',', $val);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -305,9 +305,7 @@ EOT;
|
|||
EOT;
|
||||
}
|
||||
|
||||
if (empty($prev)) {
|
||||
$this->script[] = $script;
|
||||
}
|
||||
$this->script[] = $script;
|
||||
|
||||
return $script;
|
||||
}
|
||||
|
@ -429,10 +427,7 @@ EOT;
|
|||
if (!$this->group && !isset($this->options[''])) {
|
||||
$this->options = ['' => $this->jsOptions['placeholder']] + $this->options;
|
||||
}
|
||||
|
||||
if ($this->disabledOptions && !is_array($this->disabledOptions)) {
|
||||
$this->disabledOptions = explode(',', $this->disabledOptions);
|
||||
}
|
||||
|
||||
foreach ($this->disabledOptions as &$di) {
|
||||
$di = '-' . $di;
|
||||
}
|
||||
|
@ -450,4 +445,10 @@ EOT;
|
|||
|
||||
return $viewshow->assign($vars)->getContent();
|
||||
}
|
||||
|
||||
public function destroy()
|
||||
{
|
||||
$this->prevSelect = null;
|
||||
parent::destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class SelectTree extends Tree
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function s2ztreeScript()
|
||||
protected function ztreeScript()
|
||||
{
|
||||
if (!($this->value === '' || $this->value === null || $this->value === [])) {
|
||||
$this->checked = is_array($this->value) ? $this->value : explode(',', $this->value);
|
||||
|
@ -90,7 +90,7 @@ EOT;
|
|||
|
||||
public function beforRender()
|
||||
{
|
||||
$this->s2ztreeScript();
|
||||
$this->ztreeScript();
|
||||
|
||||
return parent::beforRender();
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ class UEditor extends Field
|
|||
protected $minify = false;
|
||||
|
||||
protected $js = [
|
||||
'/assets/builderueditor/ueditor.config.js',
|
||||
'/assets/builderueditor/ueditor.all.min.js',
|
||||
];
|
||||
|
||||
protected $configJsPath = '/assets/builderueditor/ueditor.all.min.js';
|
||||
protected $configJsPath = '/assets/builderueditor/ueditor.config.js';
|
||||
|
||||
protected $uploadUrl = '';
|
||||
|
||||
|
@ -68,7 +68,7 @@ EOT;
|
|||
|
||||
public function beforRender()
|
||||
{
|
||||
$this->js[] = $this->configJsPath;
|
||||
$this->js = array_merge([$this->configJsPath], $this->js);
|
||||
|
||||
if (!$this->readonly) {
|
||||
$this->editorScript();
|
||||
|
|
|
@ -23,11 +23,13 @@ trait HasWhen
|
|||
*/
|
||||
protected $__when__ = null;
|
||||
|
||||
protected $whenWrapper = false;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string|int|array $cases 如:'1' 或 '1 + 2' 或 ['1 + 2', '2 + 3']
|
||||
* @param mixed ...$toggleFields
|
||||
* @param array|\Closure|mixed ...$toggleFields
|
||||
* @return $this
|
||||
*/
|
||||
public function when($cases, ...$toggleFields)
|
||||
|
@ -41,8 +43,15 @@ trait HasWhen
|
|||
if (count($toggleFields)) {
|
||||
|
||||
if ($toggleFields[0] instanceof \Closure) { //如果是匿名回调
|
||||
$toggleFields[0]($when);
|
||||
//fields包围优化
|
||||
$this->makeWhenWrapper();
|
||||
$toggleFields[0]($form, $when);
|
||||
} else {
|
||||
//->when('1',$field1,$field2)
|
||||
//或
|
||||
//->when('1',[$field1,$field2])
|
||||
|
||||
//无法fields包围优化,无多层次when时不影响
|
||||
if (is_array($toggleFields[0])) {
|
||||
$toggleFields = $toggleFields[0];
|
||||
}
|
||||
|
@ -54,11 +63,26 @@ trait HasWhen
|
|||
$form->whenEnd();
|
||||
$this->whenEnd();
|
||||
//如果此处传入[toggleFields]参数,那么就结束,后面就不要再调用with($toggleFields)方法了。否则,后面可以继续调用with($toggleFields)方法;
|
||||
} else {
|
||||
//fields包围优化
|
||||
$this->makeWhenWrapper();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function makeWhenWrapper()
|
||||
{
|
||||
//创建一个fields把后面的 toggleFields装进去,解决多层when的嵌套的一些问题
|
||||
$form = $this->getForm();
|
||||
$whenWrapper = $form->fields(preg_replace('/\W/', '', $this->getName()) . '_when_' . count($this->whens))
|
||||
->showLabel(false)
|
||||
->addClass('when-wrapper')
|
||||
->size(0, 12);
|
||||
$this->__when__->toggle($whenWrapper);
|
||||
$this->whenWrapper = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
|
@ -72,7 +96,7 @@ trait HasWhen
|
|||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param mixed ...$toggleFields
|
||||
* @param array|\Closure|mixed ...$toggleFields
|
||||
* @return $this
|
||||
*/
|
||||
public function with(...$toggleFields)
|
||||
|
@ -86,18 +110,23 @@ trait HasWhen
|
|||
if (count($toggleFields)) {
|
||||
if ($toggleFields[0] instanceof \Closure) {
|
||||
$toggleFields[0]($form);
|
||||
} else {
|
||||
if (is_array($toggleFields[0])) {
|
||||
$toggleFields = $toggleFields[0];
|
||||
}
|
||||
foreach ($toggleFields as $field) {
|
||||
$this->__when__->toggle($field);
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// if (is_array($toggleFields[0])) {
|
||||
// $toggleFields = $toggleFields[0];
|
||||
// }
|
||||
// foreach ($toggleFields as $field) {
|
||||
// $this->__when__->toggle($field);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
$form->whenEnd();
|
||||
|
||||
if ($this->whenWrapper) {
|
||||
$form->fieldsEnd();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue