fetch();'; } $action=<<$rows['field'], 'title'=>$rows['title'] ]; if($table){ if($rows['visible']==='none'){ return ''; } if($rows['visible']===false){ $arr['visible']=false; } if(!empty($rows['sortable'])){ $arr['sortable']=true; } if($rows['operate']){ $operate=parseJson($rows['operate']); if($operate!='='){ $arr['operate']=$operate; } if(is_array($operate) && isset($operate['value'])){ if(str_starts_with($operate['value'],'[') && str_ends_with($operate['value'],']')){ $arr['operate']['value']=json_decode($operate['value'],true); } //通过正则表达式判断$operate['value']是否为整数 if(preg_match('/^\d+$/',$operate['value'])){ $arr['operate']['value']=intval($operate['value']); } } }else{ $arr['operate']=false; } } if($form){ if($rows['visible']==='none'){ return ''; } if($rows['edit']){ $arr['edit']=parseJson($rows['edit']); if(is_array($arr['edit']) && isset($arr['edit']['value'])){ if(str_starts_with($arr['edit']['value'],'[') && str_ends_with($arr['edit']['value'],']')){ $arr['edit']['value']=json_decode($arr['edit']['value'],true); } //通过正则表达式判断$operate['value']是否为整数 if(is_string($arr['edit']['value']) && preg_match('/^\d+$/',$arr['edit']['value'])){ $arr['edit']['value']=intval($arr['edit']['value']); } } } if($rows['rules']){ $arr['rules']=parseJson($rows['rules']); } } if($rows['searchList']){ $arr['searchList']=parseJson($rows['searchList']); } $json=json_encode($arr,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); if($table){ $json=substr($json,0,-1).getFormatter($rows,$isTree,$treeTitle).'},'; } if($form){ $json.=','; } $str=<<
{$title}插槽内容
EOF; return $str; } function getFormslot($rows,$istree=false,$treetitle='') { $edit=parseJson($rows['edit']); $isslot=false; if(is_string($edit) && $edit=='slot'){ $isslot=true; } if(is_array($edit) && $edit['form']=='slot'){ $isslot=true; } if(!$isslot){ return ''; } $field=$rows['field']; $title=$rows['title']; if($field=='pid' && $istree){ $str=<< {foreach name="parentList" item="vo"} {/foreach} EOF; }else{ $str=<< 插槽内容 EOF; } return $str; } function parseJson($str) { $str=trim($str); if(str_starts_with($str,'{') && str_ends_with($str,'}')){ $jsonarr=json_decode($str,true); //如果是非关联数组 if(array_keys($jsonarr) === range(0, count($jsonarr) - 1)){ $r=[]; for($i=count($jsonarr);$i>0;$i--){ $r[$i-1]=$jsonarr[$i-1]; } return $r; } return $jsonarr; } return $str; } function getRelationMethods($field,$relation) { $table=$relation['table']; $config = Db::getConfig(); $default=$config['default']; $prefix=$config['connections'][$default]['prefix']; $table=str_replace($prefix,'',$table); $funcname=parse_name($table,1); $tableModelName=str_replace(' ','',ucwords(str_replace('_',' ',$table))); $selectfields=implode(',',array_unique([$relation['relationField'],$relation['showField'],$relation['filterField']])); if($relation['ralationType']=='one'){ $action=<<hasOne({$tableModelName}::class,'{$relation['relationField']}','{$field}')->field('{$selectfields}'); } EOF; return $action; } if($relation['ralationType']=='many'){ $action=<<hasMany({$tableModelName}::class,'{$relation['relationField']}','{$field}')->field('{$selectfields}'); } EOF; return $action; } } function getRecyclebinField($field){ if(empty($field)){ return ''; } $str=''; foreach ($field as $value){ $str.=<<"{$value['title']}", EOF; } return $str; } function getRecyclebinType($field){ if(empty($field)){ return ''; } $str=''; foreach ($field as $value){ $str.=<<"{$value['type']}", EOF; } return $str; } function getFormatter($rows,$isTree,$treeTitle) { if($rows['visible']==='relation'){ $relation=json_decode($rows['relation'],true); $table=str_replace(CurdService::$prefix,'',$relation['table']); $arrfieldtype="''"; if($rows['formatter']=='tags' || $rows['formatter']=='images'){ $arrfieldtype="[]"; } $str=<<