From 977916886b4967e12d1ebca0549796e5b30bd8d9 Mon Sep 17 00:00:00 2001 From: funadmin <994927909@qq.com> Date: Sun, 20 Aug 2023 16:38:24 +0800 Subject: [PATCH] fix builder --- src/Form.php | 2 +- src/builder/FormBuilder.php | 10 +-- src/builder/TableBuilder.php | 25 ++++---- src/builder/layout/add.html | 9 ++- src/builder/layout/edit.html | 9 ++- src/builder/layout/table.html | 7 +- src/helper.php | 17 ++++- src/helper/FormHelper.php | 116 ++++++++++++++++++++-------------- 8 files changed, 110 insertions(+), 85 deletions(-) diff --git a/src/Form.php b/src/Form.php index 3949b80..ba43e8e 100644 --- a/src/Form.php +++ b/src/Form.php @@ -55,7 +55,7 @@ * @method static string switchs(string $name, array $list = [], array $options = [], string $value = null) 切换组件 * @method static string checkbox(string $name, array $list = [], array $options = [],string $value = '1', ) 单个复选框 * @method static string radio(string $name, array $list = [], array $options = []) 单个单选框 - * @method static string css(string $name = null,array $options = []) css + * @method static string link(string $name = null,array $options = []) css * @method static string style(string $name = null, array $options = []) 上传文件组件(多文件)) * @method static string js(string $name = null, array $options = []) 表单button * @method static string script(string $name = null, array $options = []) 表单button diff --git a/src/builder/FormBuilder.php b/src/builder/FormBuilder.php index 579d500..a8ddf9c 100644 --- a/src/builder/FormBuilder.php +++ b/src/builder/FormBuilder.php @@ -31,7 +31,7 @@ class FormBuilder * css * @var array */ - protected $css = []; + protected $link = []; /** * js * @var array @@ -533,11 +533,11 @@ public function js($name=[],$options=[]){ } return $this; } - public function css($name=[],$options=[]){ + public function link($name=[],$options=[]){ if($options['merge']){ - $this->formHtml[] = Form::css($name,$options); + $this->formHtml[] = Form::link($name,$options); }else{ - $this->css[] = Form::css($name,$options); + $this->link[] = Form::link($name,$options); } return $this; @@ -567,7 +567,7 @@ public function assign($data=[]){ View::assign([ 'formBuilder'=>$form, 'formStyle'=>implode('',$this->style), - 'formCss'=>implode('',$this->css), + 'formLink'=>implode('',$this->link), 'formScript'=>implode('',$this->script), 'formJs'=>implode('',$this->js), 'formHtml'=>implode('',$this->formHtml), diff --git a/src/builder/TableBuilder.php b/src/builder/TableBuilder.php index af2215b..d6527b8 100644 --- a/src/builder/TableBuilder.php +++ b/src/builder/TableBuilder.php @@ -14,6 +14,7 @@ namespace fun\builder; +use fun\Form; use think\facade\Config; use think\facade\Db; use think\facade\View; @@ -29,9 +30,9 @@ class TableBuilder protected $node = []; protected $methods = []; protected $script = ''; - protected $extraScript = ''; + protected $js = ''; protected $style = ''; - protected $extraStyle = ''; + protected $link = ''; protected $html = ''; protected $requests = [ 'index_url' => 'index', @@ -454,25 +455,21 @@ public function style($style = '', string $action = 'index') $this->style = $style; return $this; } - - public function script($script = '', string $action = 'index') + public function link(string|array $link = '', string $action = 'index') { - $this->script = $script; + $this->link = Form::link($link,[]); return $this; } - - public function extraStyle($style = '', string $action = 'index') + public function js(string|array$js = '', string $action = 'index') { - $this->extraStyle = $style; + $this->js = Form::js($js,[]); return $this; } - - public function extraScript($script = '', string $action = 'index') + public function script(string$script = '', string $action = 'index') { - $this->extraScript = $script; + $this->script = $script; return $this; } - /** * 设置额外HTML代码 * @param string $html 额外HTML代码 @@ -565,9 +562,9 @@ public function assign(array $data = []) 'requests' => $this->requests, 'html' => $this->html, 'tableScript' => $this->script, - 'extraScript' => $this->extraScript, + 'tableJs' => $this->js, 'tableStyle' => $this->style, - 'extraStyle' => $this->extraStyle, + 'tableLink' => $this->link, 'data' => $data, ]); return $this; diff --git a/src/builder/layout/add.html b/src/builder/layout/add.html index 23f8ce4..8d23b73 100644 --- a/src/builder/layout/add.html +++ b/src/builder/layout/add.html @@ -1,6 +1,7 @@ -{$formCss} -{$formStyle} -{$formJs} +{if $formLink}{$formLink|raw}{/if} +{if $formStyle}{$formStyle|raw}}{/if} +{if $formJs}{$formJs|raw}}{/if} +
{$formHtml|raw}
@@ -9,5 +10,3 @@ - -{$formScript} diff --git a/src/builder/layout/edit.html b/src/builder/layout/edit.html index 23f8ce4..8d23b73 100644 --- a/src/builder/layout/edit.html +++ b/src/builder/layout/edit.html @@ -1,6 +1,7 @@ -{$formCss} -{$formStyle} -{$formJs} +{if $formLink}{$formLink|raw}{/if} +{if $formStyle}{$formStyle|raw}}{/if} +{if $formJs}{$formJs|raw}}{/if} +
{$formHtml|raw}
@@ -9,5 +10,3 @@ - -{$formScript} diff --git a/src/builder/layout/table.html b/src/builder/layout/table.html index 483b445..cb0d5ea 100644 --- a/src/builder/layout/table.html +++ b/src/builder/layout/table.html @@ -1,7 +1,9 @@ -{$extraStyle} +{if $tableLink}{$tableLink|raw}}{/if} +{if $tableStyle}{$tableStyle|raw}}{/if} +{if $tableJs}{$tableJs}{/if} {$html|raw} - -{$extraScript} diff --git a/src/helper.php b/src/helper.php index 939eb4e..a5c9abd 100644 --- a/src/helper.php +++ b/src/helper.php @@ -623,7 +623,7 @@ function form_js($name=[], array $options=[]) return Form::js($name, $options); } } -if (!function_exists('form_css')) { +if (!function_exists('form_link')) { /** * @param string $name * @param string $type @@ -631,9 +631,9 @@ function form_js($name=[], array $options=[]) * @param '' $value * @return string */ - function form_css($name=[],$options=[]) + function form_link($name=[],$options=[]) { - return Form::css($name, $options); + return Form::link($name, $options); } } if (!function_exists('form_config')) { @@ -863,6 +863,17 @@ function form_arrays($name='', $list = [], $option = []) } } +if (!function_exists('form_array')) { + /** + * @param $name + * @return string + */ + function form_array($name='', $list = [], $option = []) + { + return Form::arrays($name, $list, $option); + } +} + if (!function_exists('form_textarea')) { /** diff --git a/src/helper/FormHelper.php b/src/helper/FormHelper.php index f4810bf..75f0634 100644 --- a/src/helper/FormHelper.php +++ b/src/helper/FormHelper.php @@ -179,6 +179,7 @@ public function config($name='',$options=[],$value='') $form = $this->slider($name,$options,$value); break; case 'arrays': + case 'array': $attr = $options['attr']??['id','title']; $list = ($options['list']??$extra); $form = $this->arrays($name,$list,$options); @@ -568,60 +569,77 @@ public function arrays($name = '', $list = [], $options = []) { list($name,$id) = $this->getNameId($name,$options); $arr = ''; - $i = 0; - if (empty($list)) { + $tr = ''; + if(!empty($list)){ + foreach($list as $key=>$val){ + $tr.=<< + + + + +EOF; + + } + +}else{ + $tr.=<< + + + + +EOF; + } $arr .=<< -{$this->label($name,$options)} -
- verify($options)} type="text" name="{$name}[key][]" value="" placeholder="{$this->__('key')}" autocomplete="off" class="layui-input input-double-width"> +
+ {$this->label($name,$options)} +
+
+
getDataPropAttr("{$name}[key][]",$key,$options)} placeholder="{$this->__('Key')}" class="layui-input key"> +
+
+
getDataPropAttr("{$name}[value][]",$val,$options)} placeholder="{$this->__('Value')}" class="layui-input value"> +
+
+
+ + + + +
+
+
+
+
+
+
+
+
+ + + + +
+
+ + + + + + + + + {$tr} + +
{$this->__('Key')}{$this->__('Value')}{$this->__('Oprate')}
-
- verify($options)} type="text" name="{$name}[value][]" value="" placeholder="{$this->__('value')}" autocomplete="off" class="layui-input input-double-width"> -
-
- EOF; - } - foreach ($list as $key => $value) { - if ($i == 0) { - $arr .= <<{$this->label($name, $options)}
- getDataPropAttr("{$name}[key][]",$key,$options)} type="text" autocomplete="off" class="layui-input input-double-width"> -
-
- getDataPropAttr("{$name}[value][]",$value,$options)} type="text" placeholder="{$this->__('value')}" autocomplete="off" class="layui-input input-double-width"> -
- -
- -EOF; - } else { - $arr .=<<{$this->label($name, $options)} -
- verify($options)} type="text" {$this->getDataPropAttr("{$name}[key][]",$key,$options)} placeholder="' . $this->__('key') . '" autocomplete="off" class="layui-input input-double-width"> -
- verify($options)} type="text" {$this->getDataPropAttr("{$name}[value][]",$value,$options)} placeholder="' . $this->__('value') . '" autocomplete="off" class="layui-input input-double-width"> -
- -
-EOF; - } - $i++; - } - $str = '
' . $arr . '
'; - + $str = '
' . $arr . '
'; return $str; } - /** * 文本 * @param null $name @@ -1303,7 +1321,7 @@ public function js($name=[],$options=[]){ * @param $options * @return string */ - public function css($name=[],$options=[]){ + public function link($name=[],$options=[]){ if(is_string($name)){ $name = explode(',',$name); }