Skip to content

Commit e1c2e56

Browse files
committed
builder
1 parent f09b9d3 commit e1c2e56

File tree

5 files changed

+127
-24
lines changed

5 files changed

+127
-24
lines changed

src/addons/Service.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function register()
5252
$this->loadLang();
5353
// 2.注册插件事件hook
5454
$this->loadEvent();
55-
55+
5656
$this->loadService();
5757
// 4.自动加载全局的插件内部第三方类库
5858

@@ -206,7 +206,7 @@ private function autoload()
206206
$config = Config::get('addons');
207207
// 读取插件目录及钩子列表
208208
$base = get_class_methods("\\fun\\Addons");
209-
$base = array_merge($base, ['init','initialize','install', 'uninstall', 'enabled', 'disabled']);
209+
$base = array_merge($base, ['init','initialize','install', 'uninstall', 'enabled', 'disabled','config']);
210210
// 读取插件目录中的php文件
211211
foreach (glob($this->getAddonsPath() . '*/*.php') as $addons_file) {
212212
// 格式化路径信息

src/builder/TableBuilder.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class TableBuilder
2626
protected $driver = 'mysql';
2727
protected $database = 'funadmin';
2828
protected $tablePrefix = 'fun_';
29+
protected $templet = ['laydate', 'colorpicker', 'time', 'tags', 'image', 'content', 'text', 'dropdown', 'selects', 'switch', 'select', 'url', 'iframe', 'open','icon','number','operat'];
30+
2931
public $fields = [];
3032
public $node = [];
3133
public $methods = [];
@@ -190,6 +192,7 @@ public function searchInput($show = true, string $tableId = 'list')
190192
return $this;
191193
}
192194

195+
193196
/**
194197
* @param $column
195198
* @return $this
@@ -199,10 +202,15 @@ public function col(array $column = [], string $tableId = 'list')
199202
if(!$this->options[$tableId]){
200203
$this->options();
201204
}
205+
foreach ($column as $key=>&$v){
206+
if(!empty($v['templet']) && strpos($v['templet'],'Table.templet')===false){
207+
$v['templet'] = $this->getColTemplet($v['templet']);
208+
}
209+
}
210+
unset($v);
202211
array_push($this->options[$tableId]['cols'][0], $column);
203212
return $this;
204213
}
205-
206214
/**
207215
* @param $columns
208216
* @return $this
@@ -607,4 +615,11 @@ public function view(string $template = '')
607615
$template = $template ?: $this->template;
608616
return view($template);
609617
}
618+
619+
protected function getColTemplet($templet){
620+
if($templet && in_array($templet,$this->templet)){
621+
return 'templet:Table.templet.'+templet;
622+
}
623+
return $templet;
624+
}
610625
}

src/curd/service/CurdService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CurdService
3131
'fileSuffix' => ['file', 'files', 'path', 'paths'],//识别为文件字段
3232
'priSuffix' => ['_id', '_ids'],//识别为别的表的主键
3333
'sortSuffix' => ['sort','orderby','weight'],//排序
34-
'imageSuffix' => ['image', 'images', 'thumb', 'thumbs', 'avatar', 'avatars','picture', 'pictures',''],//识别为图片字段
34+
'imageSuffix' => ['image', 'images', 'thumb', 'thumbs', 'avatar', 'avatars','picture', 'pictures'],//识别为图片字段
3535
'editorSuffix' => ['editor', 'content', 'detail', 'details', 'description'],//识别为编辑器字段
3636
'iconSuffix' => ['icon'],//识别为图标字段
3737
'colorSuffix' => ['color'],//颜色
@@ -971,13 +971,13 @@ protected function getCols()
971971
if (in_array($v['name'], ['update_time', 'delete_time'])) {
972972
break;
973973
}
974-
$this->jsCols .= $space . "{field:'{$v['name']}',title: __('{$name}'),align: 'center',timeType:'datetime',dateformat:'yyyy-MM-dd HH:mm:ss',searchdateformat:'yyyy-MM-dd HH:mm:ss',search:'timerange',templet: Table.templet.time,sort:true}," . PHP_EOL;;
974+
$this->jsCols .= $space . "{field:'{$v['name']}',title: __('{$name}'),align: 'center',timeType:'datetime',dateformat:'yyyy-MM-dd HH:mm:ss',searchdateformat:'yyyy-MM-dd HH:mm:ss',search:'timerange',templet: Table.templet.time,sort:true,searchOp:'daterange'}," . PHP_EOL;;
975975
break;
976976
case 'year':
977-
$this->jsCols .= $space . "{field:'{$v['name']}',title: __('{$name}'),align: 'center',dateformat:'yyyy',searchdateformat:'yyyy',timeType:'year',search:'timerange',templet: Table.templet.time,sort:true}," . PHP_EOL;;
977+
$this->jsCols .= $space . "{field:'{$v['name']}',title: __('{$name}'),align: 'center',dateformat:'yyyy',searchdateformat:'yyyy',timeType:'year',search:'timerange',templet: Table.templet.time,sort:true,searchOp:'daterange'}," . PHP_EOL;;
978978
break;
979979
case 'time':
980-
$this->jsCols .= $space . "{field:'{$v['name']}',title: __('{$name}'),align: 'center',dateformat:'HH:mm:ss',searchdateformat:'HH:mm:ss',timeType:'time',search:'timerange',templet: Table.templet.time,sort:true}," . PHP_EOL;;
980+
$this->jsCols .= $space . "{field:'{$v['name']}',title: __('{$name}'),align: 'center',dateformat:'HH:mm:ss',searchdateformat:'HH:mm:ss',timeType:'time',search:'timerange',templet: Table.templet.time,sort:true,searchOp:'daterange'}," . PHP_EOL;;
981981
break;
982982
default :
983983
$this->jsCols .= $space . "{field:'{$v['name']}', title: __('{$name}'),align: 'center'}," . PHP_EOL;

src/helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ function get_addons_autoload_config($chunk = false)
398398
$route = [];
399399
// 读取插件目录及钩子列表
400400
$base = get_class_methods("\\fun\\Addons");
401-
$base = array_merge($base, ['init','initialize','install', 'uninstall', 'enabled', 'disabled']);
401+
$base = array_merge($base, ['init','initialize','install', 'uninstall', 'enabled', 'disabled','config']);
402402

403403
$url_domain_deploy = Config::get('route.url_domain_deploy');
404404
$addons = get_addons_list();

src/helper/FormHelper.php

Lines changed: 104 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,11 @@ public function switchs($name = '', $switch=[], $options = [], $value = '')
484484
{
485485
$switchArr = $this->getArray($name,$switch);
486486
$switchStr = $switchArr ? $this->__($switchArr[1]) . '|' . $this->__($switchArr[0]) : $this->__('open') . '|' . 'close';
487+
$checked = $value?'checked="true"':'';
487488
$str = <<<EOF
488489
<div class="layui-form-item"> {$this->label($name, $options)}
489490
<div class="layui-input-block">
490-
<input {$this->getDataPropAttr($name,$value,$options)} class="{$this->getClass($options)}" type="checkbox" checked="" lay-skin="switch" lay-text="{$switchStr}" data-text="{$this->__($value)}"/>
491+
<input {$this->getDataPropAttr($name,$value,$options)} class="{$this->getClass($options)}" type="checkbox" {$checked} lay-skin="switch" lay-text="{$switchStr}" data-text="{$this->__($value)}"/>
491492
{$this->tips($options)}
492493
</div>
493494
</div>'
@@ -688,7 +689,7 @@ public function selectn($name = '', $select= [], $options=[], $attr=[], $value=
688689
<div class="layui-form-item layui-form" lay-filter="{$name}">{$this->label($name,$options)}
689690
<div class="layui-input-block">
690691
<div data-verify ="{$this->labelRequire($options)}"
691-
{$this->getDataPropAttr($name, $value, $options)} class="{$this->getClass($options)}" {$this->search($options)} {$this->readonlyOrdisabled($options)} >
692+
{$this->getDataPropAttr($name, $value, $options)} class="{$this->getClass($options)}" {$this->laysearch($options)} {$this->readonlyOrdisabled($options)} >
692693
</div>
693694
{$this->tips($options)}
694695
</div>
@@ -752,6 +753,19 @@ public function autocomplete($name='',$list=[],$options=[],$attr=[],$value=''){
752753
EOF;
753754
return $str;
754755
}
756+
757+
/**
758+
* @param $name
759+
* @param $select
760+
* @param $options
761+
* @param $attr
762+
* @param $value
763+
* @return string
764+
*/
765+
public function select($name = '', $select=[], $options=[], $attr=[], $value='')
766+
{
767+
return $this->multiselect($name,$select,$options,$attr,$value);
768+
}
755769
/**
756770
* @param $name
757771
* @param $select
@@ -947,8 +961,8 @@ public function color($name = '', $options = [], $value = '')
947961
public function icon($name = '', $options = [], $value = '')
948962
{
949963
list($name,$id) = $this->getNameId($name,$options);
950-
$value = $value ?: 'layui-icon-app';
951-
$options['filter'] = 'iconPickers';
964+
$value = $value ?: 'layui-icon layui-icon-app';
965+
$options['filter'] = 'iconPicker';
952966
$str = <<<EOF
953967
<div class="layui-form-item">{$this->label($name,$options)}
954968
<div class="layui-input-block">
@@ -1057,10 +1071,17 @@ public function editor($name = 'container', $options = [], $value = '')
10571071

10581072
$text = '';
10591073
if (isset($options['textarea'])) {
1060-
$text= <<<EOF
1061-
<textarea {$this->getNameValueAttr($name,$value,$options)} </textarea>
1074+
$verify = '';
1075+
if(!empty($options['verify'])){
1076+
$verify = 'lay-verify ="'.$options['verify'].'"';
1077+
}
1078+
$text= <<<EOF
1079+
<textarea {$verify} {$this->getNameValueAttr($name,$value,$options)} </textarea>
10621080
EOF;
10631081
}
1082+
if(!empty($options['verify'])){
1083+
unset($options['verify']);
1084+
}
10641085
$content = <<<EOF
10651086
<div {$this->getDataPropAttr($name,$value,$options)} lay-editor type="text/plain" >
10661087
{$text}
@@ -1122,21 +1143,25 @@ public function upload($name = 'avatar', $options = [], $value = '')
11221143
if ($k + 1 <= $options['num']) {
11231144
switch ($options['mime']) {
11241145
case 'video':
1146+
$v = $v?:'/static/backend/images/filetype/video.png';
11251147
$li .= <<<EOF
11261148
<li><video lay-event="" class="layui-upload-img fl" width="150" src="{$v}"></video> <i class="layui-icon layui-icon-close" lay-event="filedelete" data-fileurl="$v"></i></li>
11271149
EOF;
11281150
break;
11291151
case 'audio':
1152+
$v = $v?:'/static/backend/images/filetype/audio.jpg';
11301153
$li .= <<<EOF
11311154
<li><audio lay-event="" class="layui-upload-img fl" width="150" src="'{$v}"></audio> <i class="layui-icon layui-icon-close" lay-event="filedelete" data-fileurl="{$v}"></i></li>
11321155
EOF;
11331156
break;
11341157
case 'images':
1158+
$v = $v?:'/static/backend/images/filetype/image.jpg';
11351159
$li .= <<<EOF
11361160
<li><img lay-event="photos" class="layui-upload-img fl" width="150" src="{$v}"></img> <i class="layui-icon layui-icon-close" lay-event="filedelete" data-fileurl="{$v}"></i></li>
11371161
EOF;
11381162
break;
11391163
case 'image':
1164+
$v = $v?:'/static/backend/images/filetype/image.jpg';
11401165
$li .= <<<EOF
11411166
<li><img lay-event="photos" class="layui-upload-img fl" width="150" src="{$v}"></img> <i class="layui-icon layui-icon-close" lay-event="filedelete" data-fileurl="{$v}"></i></li>
11421167
EOF;
@@ -1396,7 +1421,7 @@ protected function tips($options = [])
13961421
* @ 验证
13971422
* @return string
13981423
*/
1399-
protected function verify($options = [])
1424+
protected function layverify($options = [])
14001425
{
14011426
$verify = '';
14021427
if (isset($options['verify'])) {
@@ -1417,26 +1442,74 @@ protected function verify($options = [])
14171442
* @param $options
14181443
* @return string
14191444
*/
1420-
protected function filter($options = [])
1445+
protected function layfilter($options = [])
14211446
{
14221447
$filter = '';
14231448
if (isset($options['filter'])) {
14241449
$filter = ' lay-filter="' . $options['filter'] . '"';
14251450
}
14261451
return $filter;
14271452
}
1428-
1453+
protected function layaffix($options = [])
1454+
{
1455+
$affix = '';
1456+
if (isset($options['affix'])) {
1457+
$affix = ' lay-affix="' . $options['affix'] . '"';
1458+
}
1459+
return $affix;
1460+
}
1461+
protected function layautocomplete($options = [])
1462+
{
1463+
$affix = ' ';
1464+
if (isset($options['affix'])) {
1465+
$affix = ' autocomplete="'.$options['autocomplete'] .'"';
1466+
}
1467+
return $affix;
1468+
}
1469+
protected function laysubmit($options = [])
1470+
{
1471+
$affix = ' ';
1472+
if (isset($options['submit'])) {
1473+
$affix = ' lay-submit="'.$options['submit'] .'"';
1474+
}
1475+
return $affix;
1476+
}
1477+
protected function layignore($options = [])
1478+
{
1479+
$affix = ' ';
1480+
if (isset($options['ignore'])) {
1481+
$affix = ' lay-ignore="'.$options['ignore'] .'"';
1482+
}
1483+
return $affix;
1484+
}
1485+
protected function laystep($options = [])
1486+
{
1487+
$str = ' ';
1488+
if (isset($options['step'])) {
1489+
$str = ' step="' . $options['step'] . '"';
1490+
}
1491+
return $str;
1492+
}
14291493
/**搜索
14301494
* @return string
14311495
*/
1432-
protected function search($options = [])
1496+
protected function laysearch($options = [])
14331497
{
14341498
$search = '';
14351499
if (!isset($options['search']) || $options['search'] == true) {
14361500
$search = ' lay-search';
14371501
}
14381502
return $search;
14391503
}
1504+
1505+
protected function layskin($options = [])
1506+
{
1507+
$search = '';
1508+
if (isset($options['skin'])) {
1509+
$affix = ' lay-skin="'.$options['skin'] .'"';
1510+
}
1511+
return $search;
1512+
}
14401513
/**
14411514
* @param $ops
14421515
* @param $val
@@ -1541,10 +1614,25 @@ public function getOptionsAttr($name='',$options=[]){
15411614
$attr.= $key.'="'. $this->__($val).'" ';
15421615
break;
15431616
case 'verify':
1544-
$attr.= $this->verify($options);
1617+
$attr.= $this->layverify($options);
15451618
break;
15461619
case 'filter':
1547-
$attr.= $this->filter($options);
1620+
$attr.= $this->layfilter($options);
1621+
break;
1622+
case 'step':
1623+
$attr.= $this->laystep($options);
1624+
break;
1625+
case 'affix':
1626+
$attr.= $this->layaffix($options);
1627+
break;
1628+
case 'autocomplete':
1629+
$attr.= $this->layautocomplete($options);
1630+
break;
1631+
case 'submit':
1632+
$attr.= $this->laysubmit($options);
1633+
break;
1634+
case 'ignore':
1635+
$attr.= $this->layignore($options);
15481636
break;
15491637
case 'style':
15501638
$attr.= $this->getStyle($options);
@@ -1553,7 +1641,10 @@ public function getOptionsAttr($name='',$options=[]){
15531641
$attr.= $this->readonlyOrdisabled($options);
15541642
break;
15551643
case 'search':
1556-
$attr.= $this->search($options);
1644+
$attr.= $this->laysearch($options);
1645+
break;
1646+
case 'skin':
1647+
$attr.= $this->layskin($options);
15571648
break;
15581649
case 'value':
15591650
$attr .= $key."='".$this->entities($val) ."' data-".$key."='".$this->entities($val)."' ";
@@ -1565,9 +1656,6 @@ public function getOptionsAttr($name='',$options=[]){
15651656
}
15661657
$attr .= " data-".$key."='".$val."' ";
15671658
break;
1568-
case 'skin':
1569-
$attr.= " lay-'".$key.'"="'. $val.'" ';
1570-
break;
15711659
default:
15721660
if(is_object($val) || is_array($val)){
15731661
$val = (array)$val;

0 commit comments

Comments
 (0)