Skip to content

Commit 9779168

Browse files
committed
fix builder
1 parent 1e769c2 commit 9779168

File tree

8 files changed

+110
-85
lines changed

8 files changed

+110
-85
lines changed

src/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* @method static string switchs(string $name, array $list = [], array $options = [], string $value = null) 切换组件
5656
* @method static string checkbox(string $name, array $list = [], array $options = [],string $value = '1', ) 单个复选框
5757
* @method static string radio(string $name, array $list = [], array $options = []) 单个单选框
58-
* @method static string css(string $name = null,array $options = []) css
58+
* @method static string link(string $name = null,array $options = []) css
5959
* @method static string style(string $name = null, array $options = []) 上传文件组件(多文件))
6060
* @method static string js(string $name = null, array $options = []) 表单button
6161
* @method static string script(string $name = null, array $options = []) 表单button

src/builder/FormBuilder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class FormBuilder
3131
* css
3232
* @var array
3333
*/
34-
protected $css = [];
34+
protected $link = [];
3535
/**
3636
* js
3737
* @var array
@@ -533,11 +533,11 @@ public function js($name=[],$options=[]){
533533
}
534534
return $this;
535535
}
536-
public function css($name=[],$options=[]){
536+
public function link($name=[],$options=[]){
537537
if($options['merge']){
538-
$this->formHtml[] = Form::css($name,$options);
538+
$this->formHtml[] = Form::link($name,$options);
539539
}else{
540-
$this->css[] = Form::css($name,$options);
540+
$this->link[] = Form::link($name,$options);
541541
}
542542

543543
return $this;
@@ -567,7 +567,7 @@ public function assign($data=[]){
567567
View::assign([
568568
'formBuilder'=>$form,
569569
'formStyle'=>implode('',$this->style),
570-
'formCss'=>implode('',$this->css),
570+
'formLink'=>implode('',$this->link),
571571
'formScript'=>implode('',$this->script),
572572
'formJs'=>implode('',$this->js),
573573
'formHtml'=>implode('',$this->formHtml),

src/builder/TableBuilder.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace fun\builder;
1616

17+
use fun\Form;
1718
use think\facade\Config;
1819
use think\facade\Db;
1920
use think\facade\View;
@@ -29,9 +30,9 @@ class TableBuilder
2930
protected $node = [];
3031
protected $methods = [];
3132
protected $script = '';
32-
protected $extraScript = '';
33+
protected $js = '';
3334
protected $style = '';
34-
protected $extraStyle = '';
35+
protected $link = '';
3536
protected $html = '';
3637
protected $requests = [
3738
'index_url' => 'index',
@@ -454,25 +455,21 @@ public function style($style = '', string $action = 'index')
454455
$this->style = $style;
455456
return $this;
456457
}
457-
458-
public function script($script = '', string $action = 'index')
458+
public function link(string|array $link = '', string $action = 'index')
459459
{
460-
$this->script = $script;
460+
$this->link = Form::link($link,[]);
461461
return $this;
462462
}
463-
464-
public function extraStyle($style = '', string $action = 'index')
463+
public function js(string|array$js = '', string $action = 'index')
465464
{
466-
$this->extraStyle = $style;
465+
$this->js = Form::js($js,[]);
467466
return $this;
468467
}
469-
470-
public function extraScript($script = '', string $action = 'index')
468+
public function script(string$script = '', string $action = 'index')
471469
{
472-
$this->extraScript = $script;
470+
$this->script = $script;
473471
return $this;
474472
}
475-
476473
/**
477474
* 设置额外HTML代码
478475
* @param string $html 额外HTML代码
@@ -565,9 +562,9 @@ public function assign(array $data = [])
565562
'requests' => $this->requests,
566563
'html' => $this->html,
567564
'tableScript' => $this->script,
568-
'extraScript' => $this->extraScript,
565+
'tableJs' => $this->js,
569566
'tableStyle' => $this->style,
570-
'extraStyle' => $this->extraStyle,
567+
'tableLink' => $this->link,
571568
'data' => $data,
572569
]);
573570
return $this;

src/builder/layout/add.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
{$formCss}
2-
{$formStyle}
3-
{$formJs}
1+
{if $formLink}{$formLink|raw}{/if}
2+
{if $formStyle}{$formStyle|raw}}{/if}
3+
{if $formJs}{$formJs|raw}}{/if}
4+
45
<form class="layui-form" lay-filter="form">
56
{$formHtml|raw}
67
</form>
@@ -9,5 +10,3 @@
910
<script>
1011
var formData = {:json_encode($formData)};
1112
</script>
12-
13-
{$formScript}

src/builder/layout/edit.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
{$formCss}
2-
{$formStyle}
3-
{$formJs}
1+
{if $formLink}{$formLink|raw}{/if}
2+
{if $formStyle}{$formStyle|raw}}{/if}
3+
{if $formJs}{$formJs|raw}}{/if}
4+
45
<form class="layui-form" lay-filter="form">
56
{$formHtml|raw}
67
</form>
@@ -9,5 +10,3 @@
910
<script>
1011
var formData = {:json_encode($formData)};
1112
</script>
12-
13-
{$formScript}

src/builder/layout/table.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
{$extraStyle}
1+
{if $tableLink}{$tableLink|raw}}{/if}
2+
{if $tableStyle}{$tableStyle|raw}}{/if}
3+
{if $tableJs}{$tableJs}{/if}
24
{$html|raw}
35

4-
<table class="layui-table" id="list" lay-filter="list" data-primaryKey="id"
6+
<table class="layui-table" id="{$options[$ACTION]['id']}" lay-filter="{$options[$ACTION]['elem']}" data-primaryKey="{$options[$ACTION]['primaryKey']}"
57
data-node-add="{:auth(__u('add'))}"
68
data-node-edit="{:auth(__u('edit'))}"
79
data-node-delete="{:auth(__u('delete'))}"
@@ -18,4 +20,3 @@
1820
var requests = {:json_encode($requests)};
1921
var data = {:json_encode($data)};
2022
</script>
21-
{$extraScript}

src/helper.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,17 +623,17 @@ function form_js($name=[], array $options=[])
623623
return Form::js($name, $options);
624624
}
625625
}
626-
if (!function_exists('form_css')) {
626+
if (!function_exists('form_link')) {
627627
/**
628628
* @param string $name
629629
* @param string $type
630630
* @param array $options
631631
* @param '' $value
632632
* @return string
633633
*/
634-
function form_css($name=[],$options=[])
634+
function form_link($name=[],$options=[])
635635
{
636-
return Form::css($name, $options);
636+
return Form::link($name, $options);
637637
}
638638
}
639639
if (!function_exists('form_config')) {
@@ -863,6 +863,17 @@ function form_arrays($name='', $list = [], $option = [])
863863
}
864864
}
865865

866+
if (!function_exists('form_array')) {
867+
/**
868+
* @param $name
869+
* @return string
870+
*/
871+
function form_array($name='', $list = [], $option = [])
872+
{
873+
return Form::arrays($name, $list, $option);
874+
}
875+
}
876+
866877

867878
if (!function_exists('form_textarea')) {
868879
/**

src/helper/FormHelper.php

Lines changed: 67 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public function config($name='',$options=[],$value='')
179179
$form = $this->slider($name,$options,$value);
180180
break;
181181
case 'arrays':
182+
case 'array':
182183
$attr = $options['attr']??['id','title'];
183184
$list = ($options['list']??$extra);
184185
$form = $this->arrays($name,$list,$options);
@@ -568,60 +569,77 @@ public function arrays($name = '', $list = [], $options = [])
568569
{
569570
list($name,$id) = $this->getNameId($name,$options);
570571
$arr = '';
571-
$i = 0;
572-
if (empty($list)) {
572+
$tr = '';
573+
if(!empty($list)){
574+
foreach($list as $key=>$val){
575+
$tr.=<<<EOF
576+
<tr class="tr sortable">
577+
<td>
578+
<div><input type="text" {$this->getDataPropAttr("{$name}[key][]",$key,$options)} placeholder="{$this->__('Key')}" class="layui-input key">
579+
</div>
580+
</td>
581+
<td>
582+
<div><input type="text" {$this->getDataPropAttr("{$name}[value][]",$val,$options)} placeholder="{$this->__('Value')}" class="layui-input value">
583+
</div>
584+
</td>
585+
<th>
586+
<div class="btn">
587+
<span class="add">
588+
<i class="layui-icon layui-icon-addition"></i>
589+
</span><span class="del">
590+
<i class="layui-icon layui-icon-delete"></i></span>
591+
</div>
592+
</th>
593+
</tr>
594+
EOF;
595+
596+
}
597+
598+
}else{
599+
$tr.=<<<EOF
600+
601+
<tr class="tr sortable">
602+
<td>
603+
<div><input type="text" name="{$name}[key][]" value="" placeholder="{$this->__('Key')}" class="layui-input key">
604+
</div>
605+
</td>
606+
<td>
607+
<div><input type="text" name="{$name}[value][]" value="" placeholder="{$this->__('Value')}" class="layui-input value">
608+
</div>
609+
</td>
610+
<th>
611+
<div class="btn">
612+
<span class="add">
613+
<i class="layui-icon layui-icon-addition"></i>
614+
</span><span class="del">
615+
<i class="layui-icon layui-icon-delete"></i></span>
616+
</div>
617+
</th>
618+
</tr>
619+
EOF;
620+
}
573621
$arr .=<<<EOF
574-
<div class="layui-form-item" >
575-
{$this->label($name,$options)}
576-
<div class="layui-input-inline">
577-
<input {$this->verify($options)} type="text" name="{$name}[key][]" value="" placeholder="{$this->__('key')}" autocomplete="off" class="layui-input input-double-width">
622+
<div class="layui-form-item" >
623+
{$this->label($name,$options)}
624+
<div class="layui-input-block">
625+
<table class="layui-table" filter="array">
626+
<thead>
627+
<tr>
628+
<th>{$this->__('Key')}</th>
629+
<th>{$this->__('Value')}</th>
630+
<td>{$this->__('Oprate')}</td>
631+
</tr>
632+
</thead>
633+
<tbody class="form-sortable layui-table-tr">
634+
{$tr}
635+
</tbody>
636+
</table>
578637
</div>
579-
<div class="layui-input-inline">
580-
<input {$this->verify($options)} type="text" name="{$name}[value][]" value="" placeholder="{$this->__('value')}" autocomplete="off" class="layui-input input-double-width">
581-
</div><div class="layui-input-inline" >
582-
<button data-name="{$name}" type="button" class="layui-btn layui-btn-warm layui-btn-sm addInput" lay-event="addInput">
583-
<i class="layui-icon">&#xe654;</i>
584-
</button>
585638
</div>
586-
</div>
587639
EOF;
588-
}
589-
foreach ($list as $key => $value) {
590-
if ($i == 0) {
591-
$arr .= <<<EOF
592-
<div class="layui-form-item" >{$this->label($name, $options)}<div class="layui-input-inline">
593-
<input {$this->getDataPropAttr("{$name}[key][]",$key,$options)} type="text" autocomplete="off" class="layui-input input-double-width">
594-
</div>
595-
<div class="layui-input-inline">
596-
<input {$this->getDataPropAttr("{$name}[value][]",$value,$options)} type="text" placeholder="{$this->__('value')}" autocomplete="off" class="layui-input input-double-width">
597-
</div><div class="layui-input-inline" >
598-
<button data-name="{$name}" type="button" class="layui-btn layui-btn-warm layui-btn-sm addInput" lay-event="addInput">
599-
<i class="layui-icon">&#xe654;</i>
600-
</button>
601-
</div>
602-
</div>
603-
EOF;
604-
} else {
605-
$arr .=<<<EOF
606-
<div class="layui-form-item">{$this->label($name, $options)}
607-
<div class="layui-input-inline">
608-
<input {$this->verify($options)} type="text" {$this->getDataPropAttr("{$name}[key][]",$key,$options)} placeholder="' . $this->__('key') . '" autocomplete="off" class="layui-input input-double-width">
609-
</div><div class="layui-input-inline">
610-
<input {$this->verify($options)} type="text" {$this->getDataPropAttr("{$name}[value][]",$value,$options)} placeholder="' . $this->__('value') . '" autocomplete="off" class="layui-input input-double-width">
611-
</div><div class="layui-input-inline">
612-
<button data-name="' . $name . '" type="button" class="layui-btn layui-btn-danger layui-btn-sm removeInupt" lay-event="removeInupt">
613-
<i class="layui-icon">&#xe67e;</i>
614-
</button>
615-
</div></div>
616-
EOF;
617-
}
618-
$i++;
619-
}
620-
$str = '<div id="' . $name . '">' . $arr . '</div>';
621-
640+
$str = '<div class="form-array" id="' . $name . '">' . $arr . '</div>';
622641
return $str;
623642
}
624-
625643
/**
626644
* 文本
627645
* @param null $name
@@ -1303,7 +1321,7 @@ public function js($name=[],$options=[]){
13031321
* @param $options
13041322
* @return string
13051323
*/
1306-
public function css($name=[],$options=[]){
1324+
public function link($name=[],$options=[]){
13071325
if(is_string($name)){
13081326
$name = explode(',',$name);
13091327
}

0 commit comments

Comments
 (0)