From ac6f656aefb747aa497769ceba54b0bc554b7d4a Mon Sep 17 00:00:00 2001 From: funadmin <994927909@qq.com> Date: Sat, 16 Mar 2024 21:54:25 +0800 Subject: [PATCH] v5.5 --- src/addons/Controller.php | 2 +- src/addons/Service.php | 4 +- src/builder/FormBuilder.php | 15 ++- src/curd/Install.php | 7 +- src/curd/service/CurdService.php | 203 ++++++++++++++++--------------- src/curd/tpl/addon/plugin.tpl | 19 --- src/curd/tpl/join.tpl | 2 +- src/helper/FormHelper.php | 136 ++++++++++++++------- 8 files changed, 218 insertions(+), 170 deletions(-) diff --git a/src/addons/Controller.php b/src/addons/Controller.php index c44afb9..ad0c9b0 100644 --- a/src/addons/Controller.php +++ b/src/addons/Controller.php @@ -58,7 +58,7 @@ public function __construct(App $app) $this->action = $this->request->action(); $this->addon = $this->addon ? call_user_func($filter, $this->addon) : app()->http->getName(); $this->addon_path = $app->addons->getAddonsPath() . $this->addon; - $this->controller = $controller ? call_user_func($filter, $controller) : 'index'; + $this->controller = $this->controller ? call_user_func($filter, $this->controller) : 'index'; $this->action = $this->action ? call_user_func($filter, $this->action) : 'index'; // 父类的调用必须放在设置模板路径之后 $this->_initialize(); diff --git a/src/addons/Service.php b/src/addons/Service.php index 753b394..bb0f9c7 100644 --- a/src/addons/Service.php +++ b/src/addons/Service.php @@ -178,7 +178,8 @@ private function loadEvent() $values = (array)$values; } $hooks[$key] = array_filter(array_map(function ($v) use ($key) { - return [get_addons_class($v),$key]; + $addon = get_addons_class($v); + return $addon?[$addon,$key]:[]; }, $values)); } Cache::set('hooks', $hooks); @@ -192,7 +193,6 @@ private function loadEvent() } } - /** * 自动载入钩子插件 * @return bool diff --git a/src/builder/FormBuilder.php b/src/builder/FormBuilder.php index 087c5b5..f305930 100644 --- a/src/builder/FormBuilder.php +++ b/src/builder/FormBuilder.php @@ -504,7 +504,16 @@ public function closebtn($reset = true, $options = []) return $this; } - + /** + * @param bool $reset + * @param array $options + * @return string + */ + public function close($reset = true, $options = []) + { + $this->formHtml[] = Form::closebtn($reset,$options); + return $this; + } /** * @param bool $reset * @param array $options @@ -559,8 +568,8 @@ public function script(string $name,$options=[]){ */ public function extrajs($js,$options=[]){ $reg = '/([\s\S]*?)<\/script>/im'; - preg_match($reg, $script,$match); - $this->extraJs = empty($match)?$script:$match[1]; + preg_match($reg, $js,$match); + $this->extraJs = empty($match)?$js:$match[1]; return $this; } public function style(string $name,$options=[]){ diff --git a/src/curd/Install.php b/src/curd/Install.php index 582433f..42b9ad4 100644 --- a/src/curd/Install.php +++ b/src/curd/Install.php @@ -5,7 +5,7 @@ * 版权所有 2017-2028 FunAdmin,并保留所有权利。 * 网站地址: https://www.FunAdmin.com * ---------------------------------------------------------------------------- - * 采用最新Thinkphp6实现 + * 采用最新Thinkphp8实现 * ============================================================================ * Author: yuege * Date: 2020/9/21 @@ -30,7 +30,7 @@ class Install extends Command //sql 文件 protected $sqlFile = ''; //mysql版本 - protected $mysqlVersion = '5.6'; + protected $mysqlVersion = '5.7'; //database模板 protected $databaseTpl = ''; @@ -160,10 +160,11 @@ protected function install($input): void{ $db["username"] = $env['DATABASE']['USERNAME'] ; $db["password"] = $env['DATABASE']['PASSWORD'] ; } + $prefix = env('DB_PREFIX'); $db["host"] = strtolower($this->output->ask($this->input, '👉 Set mysql hostname default(127.0.01)'))?:$db["host"]; $db["port"] = strtolower($this->output->ask($this->input, '👉 Set mysql hostport default (3306)'))?:$db["port"] ; $db['database'] = strtolower($this->output->ask($this->input, '👉 Set mysql database default (funadmin)'))?:$db["database"]; - $db['prefix'] = strtolower($this->output->ask($this->input, '👉 Set mysql table prefix default (fun_)'))?:$db["prefix"]; + $db['prefix'] = strtolower($this->output->ask($this->input, "👉 Set mysql table prefix default( $prefix )"))?:$db["prefix"]; $db["charset"] = strtolower($this->output->ask($this->input, '👉 Set mysql table charset default (utf8mb4)'))?:$db["charset"]; $db['username'] = strtolower($this->output->ask($this->input, '👉 Set mysql username default (root)'))?:$db["username"]; $db['password'] = strtolower($this->output->ask($this->input, '👉 Set mysql password required'))?: $db["password"]; diff --git a/src/curd/service/CurdService.php b/src/curd/service/CurdService.php index 7db7794..bf5c3a9 100644 --- a/src/curd/service/CurdService.php +++ b/src/curd/service/CurdService.php @@ -5,7 +5,7 @@ * 版权所有 2017-2028 FunAdmin,并保留所有权利。 * 网站地址: http://www.FunAdmin.com * ---------------------------------------------------------------------------- - * 采用最新Thinkphp6实现 + * 采用最新Thinkphp8实现 * ============================================================================ * Author: yuege * Date: 2017/8/2 @@ -25,6 +25,7 @@ class CurdService protected $config = [ 'keepField' => ['admin_id', 'member_id'],//保留字段 'fields' => [],//显示的字段 + 'formFields' => [],//添加的字段 'ignoreFields' => ['create_time', 'status', 'update_time', 'delete_time'],//忽略字段 'tagsSuffix' => ['tags', 'tag'],//识别为tag类型 'urlSuffix' => ['url', 'urls'],//识别为url类型 @@ -48,7 +49,7 @@ class CurdService * 表前缀 * @var string */ - protected $tablePrefix = 'fun_'; + protected $tablePrefix = ''; /** * 数据库名 * @var string @@ -85,9 +86,9 @@ class CurdService protected $joinName; protected $joinModel; protected $joinTable; - protected $joinForeignKey; + protected $joinForeignKey = []; protected $primaryKey = 'id'; - protected $joinPrimaryKey; + protected $joinPrimaryKey = [] ; protected $selectFields; protected $jsCols; protected $jsColsRecycle; @@ -109,11 +110,12 @@ class CurdService public function __construct(array $config) { + $config['driver'] = $config['driver']??$this->driver; $this->tablePrefix = config('database.connections.' . $config['driver'] . '.prefix'); $this->database = Config::get('database.connections' . '.' . $config['driver'] . '.database'); $this->rootPath = root_path(); $this->dir = __DIR__; - $this->tplPath = $this->rootPath . 'vendor' . '/' . 'funadmin' . '/' . 'fun-addons' . '/' . 'src' . '/' . 'curd' . '/' . 'tpl' . '/'; + $this->tplPath = $this->rootPath . 'vendor/funadmin/fun-addons/src/curd/tpl/'; $this->setParam($config); $this->driver = $config['driver']; return $this; @@ -159,36 +161,36 @@ public function setParam($config) */ protected function setArg() { - $this->table = $this->config['table']; + $this->table = !empty($this->config['table'])?$this->config['table']:''; $this->table = str_replace($this->tablePrefix, '', $this->table); - $this->addon = isset($this->config['addon']) && $this->config['addon'] ? $this->config['addon'] : ''; - $this->force = $this->config['force']; - $this->app = $this->config['app']; - $this->title = $this->config['title']?:$this->addon; - $this->description = $this->config['description']?:$this->addon; - $this->requires = $this->config['requires']?:3.0; - $this->author = $this->config['author']?:$this->addon; - $this->version = $this->config['version']?:1.0; - $this->jump = $this->config['jump']; - $this->limit = $this->config['limit'] ?: 15; - $this->page = ($this->config['page']==null || $this->config['page'] == 1) ? "true" : 'false'; - $this->joinTable = $this->config['joinTable']; + $this->addon = $this->config['addon']?? ''; + $this->force = $this->config['force']??$this->force; + $this->app = $this->config['app']??$this->app; + $this->title = $this->config['title']??$this->addon; + $this->description = $this->config['description']??$this->addon; + $this->requires = $this->config['requires']??'3.0'; + $this->author = $this->config['author']??$this->addon; + $this->version = $this->config['version']??'1.0'; + $this->jump = $this->config['jump']??$this->jump; + $this->limit = $this->config['limit']?? 15; + $this->page = (!isset($this->config['page']) || $this->config['page']==null || $this->config['page'] == 1 ) ? "true" : 'false'; + $this->joinTable = $this->config['joinTable']??[]; foreach ($this->joinTable as $k => $v) { $this->joinTable[$k] = str_replace($this->tablePrefix, '', $v); } - $this->joinName = $this->config['joinName'] ?: $this->joinTable; - $this->joinModel = $this->config['joinModel'] ?: $this->joinTable; - $this->joinMethod = $this->config['joinMethod']; - $this->joinForeignKey = $this->config['joinForeignKey']; - if ($this->joinForeignKey && count($this->joinForeignKey) == 1 && strpos($this->joinForeignKey[0], ',')) { + $this->joinName = empty($this->config['joinName']) ? $this->joinTable:$this->config['joinName']; + $this->joinModel = empty( $this->config['joinModel']) ? $this->joinTable: $this->config['joinModel']; + $this->joinMethod = $this->config['joinMethod']??''; + $this->joinForeignKey = $this->config['joinForeignKey']??[]; + if (!empty($this->joinForeignKey) && count($this->joinForeignKey) == 1 && strpos($this->joinForeignKey[0], ',')) { $this->joinForeignKey = array_filter(explode(',', ($this->joinForeignKey[0]))); } - $this->joinPrimaryKey = $this->config['joinPrimaryKey']; - if ($this->joinForeignKey && count($this->joinPrimaryKey) == 1 && strpos($this->joinPrimaryKey[0], ',')) { + $this->joinPrimaryKey = $this->config['joinPrimaryKey']??[]; + if (!empty($this->joinPrimaryKey) && count($this->joinPrimaryKey) == 1 && strpos($this->joinPrimaryKey[0], ',')) { $this->joinPrimaryKey = array_filter(explode(',', ($this->joinPrimaryKey[0]))); } - $this->selectFields = $this->config['selectFields']; - $controllerStr = $this->config['controller'] ?: Str::studly($this->table); + $this->selectFields = !empty($this->config['selectFields'])?$this->config['selectFields']:''; + $controllerStr = !empty($this->config['controller']) ? $this->config['controller'] : Str::studly($this->table); $controllerArr = explode('/', $controllerStr); foreach ($controllerArr as $k => &$v) { $v = ucfirst(Str::studly($v)); @@ -196,7 +198,7 @@ protected function setArg() unset($v); $this->controllerName = array_pop($controllerArr); $this->controllerArr = $controllerArr; - $modelStr = $this->config['model'] ?: Str::studly($this->table); + $modelStr = !empty($this->config['model']) ?$this->config['model']: Str::studly($this->table); $modelArr = explode('/', $modelStr); foreach ($modelArr as $k => &$v) { $v = ucfirst(Str::studly($v)); @@ -205,7 +207,7 @@ protected function setArg() $this->modelName = array_pop($modelArr); $modelArr ? $modelArr[0] = Str::lower($modelArr[0]) : ''; $this->modelArr = $modelArr; - $this->validateName = $this->config['validate'] ?: $this->modelName; + $this->validateName = !empty($this->config['validate']) ? $this->config['validate'] : $this->modelName; $this->validateName = Str::studly($this->validateName); $this->controllerUrl = $controllerArr ? Str::lower($controllerArr[0]) . '.' . Str::camel($this->controllerName) : Str::camel($this->controllerName); if (isset($this->config['method']) and $this->config['method']) { @@ -303,12 +305,13 @@ protected function makeController() $controllerTpl = $this->tplPath . 'controller.tpl'; $modelTpl = $this->tplPath . 'model.tpl'; $attrTpl = $this->tplPath . 'attr.tpl'; + $joinTpl = $this->tplPath . 'join.tpl'; $indexTpl = ''; $recycleTpl = ''; $relationSearch = ''; $statusResult = Db::connect($this->driver)->query("SELECT COUNT(*) FROM information_schema.columns WHERE table_name ='" . $this->tablePrefix . $this->table . "' AND column_name ='status'"); $status = $statusResult[0]['COUNT(*)']; - if ($this->joinTable) { + if (!empty($this->joinTable)) { $relationSearch = '$this->relationSearch = true;'; $joinIndexMethod = "withJoin(["; foreach ($this->joinTable as $k => $v) { @@ -333,21 +336,21 @@ protected function makeController() $joinclass = str_replace(DS, '\\', $joinclass); if (file_exists($joinModelFile)) include_once $joinModelFile; if ($assign) { - foreach ($assign as $key => $val) { - $kk = Str::studly($key); - if (!$this->hasSuffix($k, $this->config['priSuffix'])) { + foreach ($assign as $k => $v) { + $kk = Str::studly($k); + $tempKey = $k; + if(Str::endsWith($k,'List')){ + $tempKey = substr($k, 0, strlen($k) - 4); + } + if ($v) { $joinMethod = 'get' . $kk; if (class_exists($joinclass)) { $joinClassMethods = get_class_methods($joinclass); if(!in_array($joinMethod,$joinClassMethods)){ - $joinTplStr .= str_replace(['{{$method}}', '{{$values}}'], - ['get' . $kk, $val], - file_get_contents($attrTpl)) . PHP_EOL; + $joinTplStr .= str_replace(['{{$method}}', '{{$values}}'], ['get' . $kk, $v], file_get_contents($attrTpl)) . PHP_EOL; } }else{ - $joinTplStr .= str_replace(['{{$method}}', '{{$values}}'], - ['get' . $kk, $val], - file_get_contents($attrTpl)) . PHP_EOL; + $joinTplStr .= str_replace(['{{$method}}', '{{$values}}'], ['get' . $kk, $v], file_get_contents($attrTpl)) . PHP_EOL; } } } @@ -355,7 +358,7 @@ protected function makeController() $attrStr = $this->modifyAttr($fieldsList); //生成关联表的模型 $connection = $this->driver == 'mysql' ? "" : "protected \$connection = '" . $this->driver . "';"; - if (!$this->force && class_exists($joinclass) && $joinTplStr) { + if (class_exists($joinclass) && $joinTplStr) { $content = str_replace('?>','',file_get_contents($joinModelFile)); $content = substr($content,0,strrpos($content,'}',0)).$joinTplStr .PHP_EOL .'}'; file_put_contents($joinModelFile,$content); @@ -418,13 +421,14 @@ protected function makeController() $scriptStr = '')){ + return $name; + } if (is_string($name)) { $name = explode(',', $name); } @@ -1376,6 +1401,9 @@ public function js($name = [], $options = []) */ public function link($name = [], $options = []) { + if(Str::contains($name,'layignore($options); break; + case 'precision': + $attr .= $this->layprecision($options); + break; case 'style': $attr .= $this->getStyle($options); case 'readonly': @@ -1692,6 +1741,9 @@ public function getOptionsAttr($name = '', $options = []) case 'search': $attr .= $this->laysearch($options); break; + case 'creatable': + $attr .= $this->laycreatable($options); + break; case 'skin': $attr .= $this->layskin($options); break;