Skip to content

Commit

Permalink
fix builder
Browse files Browse the repository at this point in the history
  • Loading branch information
funadmin committed Aug 20, 2023
1 parent 1e769c2 commit 9779168
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/builder/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FormBuilder
* css
* @var array
*/
protected $css = [];
protected $link = [];
/**
* js
* @var array
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
25 changes: 11 additions & 14 deletions src/builder/TableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace fun\builder;

use fun\Form;
use think\facade\Config;
use think\facade\Db;
use think\facade\View;
Expand All @@ -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',
Expand Down Expand Up @@ -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代码
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/builder/layout/add.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{$formCss}
{$formStyle}
{$formJs}
{if $formLink}{$formLink|raw}{/if}
{if $formStyle}{$formStyle|raw}}{/if}
{if $formJs}{$formJs|raw}}{/if}

<form class="layui-form" lay-filter="form">
{$formHtml|raw}
</form>
Expand All @@ -9,5 +10,3 @@
<script>
var formData = {:json_encode($formData)};
</script>

{$formScript}
9 changes: 4 additions & 5 deletions src/builder/layout/edit.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{$formCss}
{$formStyle}
{$formJs}
{if $formLink}{$formLink|raw}{/if}
{if $formStyle}{$formStyle|raw}}{/if}
{if $formJs}{$formJs|raw}}{/if}

<form class="layui-form" lay-filter="form">
{$formHtml|raw}
</form>
Expand All @@ -9,5 +10,3 @@
<script>
var formData = {:json_encode($formData)};
</script>

{$formScript}
7 changes: 4 additions & 3 deletions src/builder/layout/table.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{$extraStyle}
{if $tableLink}{$tableLink|raw}}{/if}
{if $tableStyle}{$tableStyle|raw}}{/if}
{if $tableJs}{$tableJs}{/if}
{$html|raw}

<table class="layui-table" id="list" lay-filter="list" data-primaryKey="id"
<table class="layui-table" id="{$options[$ACTION]['id']}" lay-filter="{$options[$ACTION]['elem']}" data-primaryKey="{$options[$ACTION]['primaryKey']}"
data-node-add="{:auth(__u('add'))}"
data-node-edit="{:auth(__u('edit'))}"
data-node-delete="{:auth(__u('delete'))}"
Expand All @@ -18,4 +20,3 @@
var requests = {:json_encode($requests)};
var data = {:json_encode($data)};
</script>
{$extraScript}
17 changes: 14 additions & 3 deletions src/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,17 +623,17 @@ 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
* @param 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')) {
Expand Down Expand Up @@ -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')) {
/**
Expand Down
116 changes: 67 additions & 49 deletions src/helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
<tr class="tr sortable">
<td>
<div><input type="text" {$this->getDataPropAttr("{$name}[key][]",$key,$options)} placeholder="{$this->__('Key')}" class="layui-input key">
</div>
</td>
<td>
<div><input type="text" {$this->getDataPropAttr("{$name}[value][]",$val,$options)} placeholder="{$this->__('Value')}" class="layui-input value">
</div>
</td>
<th>
<div class="btn">
<span class="add">
<i class="layui-icon layui-icon-addition"></i>
</span><span class="del">
<i class="layui-icon layui-icon-delete"></i></span>
</div>
</th>
</tr>
EOF;

}

}else{
$tr.=<<<EOF
<tr class="tr sortable">
<td>
<div><input type="text" name="{$name}[key][]" value="" placeholder="{$this->__('Key')}" class="layui-input key">
</div>
</td>
<td>
<div><input type="text" name="{$name}[value][]" value="" placeholder="{$this->__('Value')}" class="layui-input value">
</div>
</td>
<th>
<div class="btn">
<span class="add">
<i class="layui-icon layui-icon-addition"></i>
</span><span class="del">
<i class="layui-icon layui-icon-delete"></i></span>
</div>
</th>
</tr>
EOF;
}
$arr .=<<<EOF
<div class="layui-form-item" >
{$this->label($name,$options)}
<div class="layui-input-inline">
<input {$this->verify($options)} type="text" name="{$name}[key][]" value="" placeholder="{$this->__('key')}" autocomplete="off" class="layui-input input-double-width">
<div class="layui-form-item" >
{$this->label($name,$options)}
<div class="layui-input-block">
<table class="layui-table" filter="array">
<thead>
<tr>
<th>{$this->__('Key')}</th>
<th>{$this->__('Value')}</th>
<td>{$this->__('Oprate')}</td>
</tr>
</thead>
<tbody class="form-sortable layui-table-tr">
{$tr}
</tbody>
</table>
</div>
<div class="layui-input-inline">
<input {$this->verify($options)} type="text" name="{$name}[value][]" value="" placeholder="{$this->__('value')}" autocomplete="off" class="layui-input input-double-width">
</div><div class="layui-input-inline" >
<button data-name="{$name}" type="button" class="layui-btn layui-btn-warm layui-btn-sm addInput" lay-event="addInput">
<i class="layui-icon">&#xe654;</i>
</button>
</div>
</div>
EOF;
}
foreach ($list as $key => $value) {
if ($i == 0) {
$arr .= <<<EOF
<div class="layui-form-item" >{$this->label($name, $options)}<div class="layui-input-inline">
<input {$this->getDataPropAttr("{$name}[key][]",$key,$options)} type="text" autocomplete="off" class="layui-input input-double-width">
</div>
<div class="layui-input-inline">
<input {$this->getDataPropAttr("{$name}[value][]",$value,$options)} type="text" placeholder="{$this->__('value')}" autocomplete="off" class="layui-input input-double-width">
</div><div class="layui-input-inline" >
<button data-name="{$name}" type="button" class="layui-btn layui-btn-warm layui-btn-sm addInput" lay-event="addInput">
<i class="layui-icon">&#xe654;</i>
</button>
</div>
</div>
EOF;
} else {
$arr .=<<<EOF
<div class="layui-form-item">{$this->label($name, $options)}
<div class="layui-input-inline">
<input {$this->verify($options)} type="text" {$this->getDataPropAttr("{$name}[key][]",$key,$options)} placeholder="' . $this->__('key') . '" autocomplete="off" class="layui-input input-double-width">
</div><div class="layui-input-inline">
<input {$this->verify($options)} type="text" {$this->getDataPropAttr("{$name}[value][]",$value,$options)} placeholder="' . $this->__('value') . '" autocomplete="off" class="layui-input input-double-width">
</div><div class="layui-input-inline">
<button data-name="' . $name . '" type="button" class="layui-btn layui-btn-danger layui-btn-sm removeInupt" lay-event="removeInupt">
<i class="layui-icon">&#xe67e;</i>
</button>
</div></div>
EOF;
}
$i++;
}
$str = '<div id="' . $name . '">' . $arr . '</div>';

$str = '<div class="form-array" id="' . $name . '">' . $arr . '</div>';
return $str;
}

/**
* 文本
* @param null $name
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 9779168

Please sign in to comment.