Skip to content

Commit

Permalink
builder
Browse files Browse the repository at this point in the history
  • Loading branch information
funadmin committed Sep 23, 2023
1 parent f09b9d3 commit e1c2e56
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/addons/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function register()
$this->loadLang();
// 2.注册插件事件hook
$this->loadEvent();

$this->loadService();
// 4.自动加载全局的插件内部第三方类库

Expand Down Expand Up @@ -206,7 +206,7 @@ private function autoload()
$config = Config::get('addons');
// 读取插件目录及钩子列表
$base = get_class_methods("\\fun\\Addons");
$base = array_merge($base, ['init','initialize','install', 'uninstall', 'enabled', 'disabled']);
$base = array_merge($base, ['init','initialize','install', 'uninstall', 'enabled', 'disabled','config']);
// 读取插件目录中的php文件
foreach (glob($this->getAddonsPath() . '*/*.php') as $addons_file) {
// 格式化路径信息
Expand Down
17 changes: 16 additions & 1 deletion src/builder/TableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class TableBuilder
protected $driver = 'mysql';
protected $database = 'funadmin';
protected $tablePrefix = 'fun_';
protected $templet = ['laydate', 'colorpicker', 'time', 'tags', 'image', 'content', 'text', 'dropdown', 'selects', 'switch', 'select', 'url', 'iframe', 'open','icon','number','operat'];

public $fields = [];
public $node = [];
public $methods = [];
Expand Down Expand Up @@ -190,6 +192,7 @@ public function searchInput($show = true, string $tableId = 'list')
return $this;
}


/**
* @param $column
* @return $this
Expand All @@ -199,10 +202,15 @@ public function col(array $column = [], string $tableId = 'list')
if(!$this->options[$tableId]){
$this->options();
}
foreach ($column as $key=>&$v){
if(!empty($v['templet']) && strpos($v['templet'],'Table.templet')===false){
$v['templet'] = $this->getColTemplet($v['templet']);
}
}
unset($v);
array_push($this->options[$tableId]['cols'][0], $column);
return $this;
}

/**
* @param $columns
* @return $this
Expand Down Expand Up @@ -607,4 +615,11 @@ public function view(string $template = '')
$template = $template ?: $this->template;
return view($template);
}

protected function getColTemplet($templet){
if($templet && in_array($templet,$this->templet)){
return 'templet:Table.templet.'+templet;
}
return $templet;
}
}
8 changes: 4 additions & 4 deletions src/curd/service/CurdService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CurdService
'fileSuffix' => ['file', 'files', 'path', 'paths'],//识别为文件字段
'priSuffix' => ['_id', '_ids'],//识别为别的表的主键
'sortSuffix' => ['sort','orderby','weight'],//排序
'imageSuffix' => ['image', 'images', 'thumb', 'thumbs', 'avatar', 'avatars','picture', 'pictures',''],//识别为图片字段
'imageSuffix' => ['image', 'images', 'thumb', 'thumbs', 'avatar', 'avatars','picture', 'pictures'],//识别为图片字段
'editorSuffix' => ['editor', 'content', 'detail', 'details', 'description'],//识别为编辑器字段
'iconSuffix' => ['icon'],//识别为图标字段
'colorSuffix' => ['color'],//颜色
Expand Down Expand Up @@ -971,13 +971,13 @@ protected function getCols()
if (in_array($v['name'], ['update_time', 'delete_time'])) {
break;
}
$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;;
$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;;
break;
case 'year':
$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;;
$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;;
break;
case 'time':
$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;;
$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;;
break;
default :
$this->jsCols .= $space . "{field:'{$v['name']}', title: __('{$name}'),align: 'center'}," . PHP_EOL;
Expand Down
2 changes: 1 addition & 1 deletion src/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ function get_addons_autoload_config($chunk = false)
$route = [];
// 读取插件目录及钩子列表
$base = get_class_methods("\\fun\\Addons");
$base = array_merge($base, ['init','initialize','install', 'uninstall', 'enabled', 'disabled']);
$base = array_merge($base, ['init','initialize','install', 'uninstall', 'enabled', 'disabled','config']);

$url_domain_deploy = Config::get('route.url_domain_deploy');
$addons = get_addons_list();
Expand Down
120 changes: 104 additions & 16 deletions src/helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,11 @@ public function switchs($name = '', $switch=[], $options = [], $value = '')
{
$switchArr = $this->getArray($name,$switch);
$switchStr = $switchArr ? $this->__($switchArr[1]) . '|' . $this->__($switchArr[0]) : $this->__('open') . '|' . 'close';
$checked = $value?'checked="true"':'';
$str = <<<EOF
<div class="layui-form-item"> {$this->label($name, $options)}
<div class="layui-input-block">
<input {$this->getDataPropAttr($name,$value,$options)} class="{$this->getClass($options)}" type="checkbox" checked="" lay-skin="switch" lay-text="{$switchStr}" data-text="{$this->__($value)}"/>
<input {$this->getDataPropAttr($name,$value,$options)} class="{$this->getClass($options)}" type="checkbox" {$checked} lay-skin="switch" lay-text="{$switchStr}" data-text="{$this->__($value)}"/>
{$this->tips($options)}
</div>
</div>'
Expand Down Expand Up @@ -688,7 +689,7 @@ public function selectn($name = '', $select= [], $options=[], $attr=[], $value=
<div class="layui-form-item layui-form" lay-filter="{$name}">{$this->label($name,$options)}
<div class="layui-input-block">
<div data-verify ="{$this->labelRequire($options)}"
{$this->getDataPropAttr($name, $value, $options)} class="{$this->getClass($options)}" {$this->search($options)} {$this->readonlyOrdisabled($options)} >
{$this->getDataPropAttr($name, $value, $options)} class="{$this->getClass($options)}" {$this->laysearch($options)} {$this->readonlyOrdisabled($options)} >
</div>
{$this->tips($options)}
</div>
Expand Down Expand Up @@ -752,6 +753,19 @@ public function autocomplete($name='',$list=[],$options=[],$attr=[],$value=''){
EOF;
return $str;
}

/**
* @param $name
* @param $select
* @param $options
* @param $attr
* @param $value
* @return string
*/
public function select($name = '', $select=[], $options=[], $attr=[], $value='')
{
return $this->multiselect($name,$select,$options,$attr,$value);
}
/**
* @param $name
* @param $select
Expand Down Expand Up @@ -947,8 +961,8 @@ public function color($name = '', $options = [], $value = '')
public function icon($name = '', $options = [], $value = '')
{
list($name,$id) = $this->getNameId($name,$options);
$value = $value ?: 'layui-icon-app';
$options['filter'] = 'iconPickers';
$value = $value ?: 'layui-icon layui-icon-app';
$options['filter'] = 'iconPicker';
$str = <<<EOF
<div class="layui-form-item">{$this->label($name,$options)}
<div class="layui-input-block">
Expand Down Expand Up @@ -1057,10 +1071,17 @@ public function editor($name = 'container', $options = [], $value = '')

$text = '';
if (isset($options['textarea'])) {
$text= <<<EOF
<textarea {$this->getNameValueAttr($name,$value,$options)} </textarea>
$verify = '';
if(!empty($options['verify'])){
$verify = 'lay-verify ="'.$options['verify'].'"';
}
$text= <<<EOF
<textarea {$verify} {$this->getNameValueAttr($name,$value,$options)} </textarea>
EOF;
}
if(!empty($options['verify'])){
unset($options['verify']);
}
$content = <<<EOF
<div {$this->getDataPropAttr($name,$value,$options)} lay-editor type="text/plain" >
{$text}
Expand Down Expand Up @@ -1122,21 +1143,25 @@ public function upload($name = 'avatar', $options = [], $value = '')
if ($k + 1 <= $options['num']) {
switch ($options['mime']) {
case 'video':
$v = $v?:'/static/backend/images/filetype/video.png';
$li .= <<<EOF
<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>
EOF;
break;
case 'audio':
$v = $v?:'/static/backend/images/filetype/audio.jpg';
$li .= <<<EOF
<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>
EOF;
break;
case 'images':
$v = $v?:'/static/backend/images/filetype/image.jpg';
$li .= <<<EOF
<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>
EOF;
break;
case 'image':
$v = $v?:'/static/backend/images/filetype/image.jpg';
$li .= <<<EOF
<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>
EOF;
Expand Down Expand Up @@ -1396,7 +1421,7 @@ protected function tips($options = [])
* @ 验证
* @return string
*/
protected function verify($options = [])
protected function layverify($options = [])
{
$verify = '';
if (isset($options['verify'])) {
Expand All @@ -1417,26 +1442,74 @@ protected function verify($options = [])
* @param $options
* @return string
*/
protected function filter($options = [])
protected function layfilter($options = [])
{
$filter = '';
if (isset($options['filter'])) {
$filter = ' lay-filter="' . $options['filter'] . '"';
}
return $filter;
}

protected function layaffix($options = [])
{
$affix = '';
if (isset($options['affix'])) {
$affix = ' lay-affix="' . $options['affix'] . '"';
}
return $affix;
}
protected function layautocomplete($options = [])
{
$affix = ' ';
if (isset($options['affix'])) {
$affix = ' autocomplete="'.$options['autocomplete'] .'"';
}
return $affix;
}
protected function laysubmit($options = [])
{
$affix = ' ';
if (isset($options['submit'])) {
$affix = ' lay-submit="'.$options['submit'] .'"';
}
return $affix;
}
protected function layignore($options = [])
{
$affix = ' ';
if (isset($options['ignore'])) {
$affix = ' lay-ignore="'.$options['ignore'] .'"';
}
return $affix;
}
protected function laystep($options = [])
{
$str = ' ';
if (isset($options['step'])) {
$str = ' step="' . $options['step'] . '"';
}
return $str;
}
/**搜索
* @return string
*/
protected function search($options = [])
protected function laysearch($options = [])
{
$search = '';
if (!isset($options['search']) || $options['search'] == true) {
$search = ' lay-search';
}
return $search;
}

protected function layskin($options = [])
{
$search = '';
if (isset($options['skin'])) {
$affix = ' lay-skin="'.$options['skin'] .'"';
}
return $search;
}
/**
* @param $ops
* @param $val
Expand Down Expand Up @@ -1541,10 +1614,25 @@ public function getOptionsAttr($name='',$options=[]){
$attr.= $key.'="'. $this->__($val).'" ';
break;
case 'verify':
$attr.= $this->verify($options);
$attr.= $this->layverify($options);
break;
case 'filter':
$attr.= $this->filter($options);
$attr.= $this->layfilter($options);
break;
case 'step':
$attr.= $this->laystep($options);
break;
case 'affix':
$attr.= $this->layaffix($options);
break;
case 'autocomplete':
$attr.= $this->layautocomplete($options);
break;
case 'submit':
$attr.= $this->laysubmit($options);
break;
case 'ignore':
$attr.= $this->layignore($options);
break;
case 'style':
$attr.= $this->getStyle($options);
Expand All @@ -1553,7 +1641,10 @@ public function getOptionsAttr($name='',$options=[]){
$attr.= $this->readonlyOrdisabled($options);
break;
case 'search':
$attr.= $this->search($options);
$attr.= $this->laysearch($options);
break;
case 'skin':
$attr.= $this->layskin($options);
break;
case 'value':
$attr .= $key."='".$this->entities($val) ."' data-".$key."='".$this->entities($val)."' ";
Expand All @@ -1565,9 +1656,6 @@ public function getOptionsAttr($name='',$options=[]){
}
$attr .= " data-".$key."='".$val."' ";
break;
case 'skin':
$attr.= " lay-'".$key.'"="'. $val.'" ';
break;
default:
if(is_object($val) || is_array($val)){
$val = (array)$val;
Expand Down

0 comments on commit e1c2e56

Please sign in to comment.