diff --git a/src/plugin/admin/app/common/LayuiForm.php b/src/plugin/admin/app/common/LayuiForm.php index f66297a..8721372 100644 --- a/src/plugin/admin/app/common/LayuiForm.php +++ b/src/plugin/admin/app/common/LayuiForm.php @@ -703,7 +703,7 @@ EOF; $info['control_args'] = ''; } - $props = Util::getProps($control, $info['control_args']); + $props = Util::getControlProps($control, $info['control_args']); // 增加修改记录验证必填项 if ($filter == 'form_show' && !isset($props['lay-verify']) && !$columns[$key]['nullable'] && $default === null && ($field !== 'password' || $type === 'insert')) { $props['lay-verify'] = 'required'; @@ -762,7 +762,7 @@ EOF; $control = strtolower($info['control']); switch ($control) { case 'switch': - $props = Util::getProps($info['control'], $info['control_args']); + $props = Util::getControlProps($info['control'], $info['control_args']); $lay_text = $props['lay-text'] ?? ''; $templet = <<getPdo()->quote($var, \PDO::PARAM_STR); + } + + /** + * 检查表名是否合法 * @param string $table * @return string * @throws BusinessException @@ -78,15 +111,7 @@ class Util } /** - * @param $var - * @return false|string - */ - static public function pdoQuote($var) - { - return Util::db()->getPdo()->quote($var, \PDO::PARAM_STR); - } - - /** + * 检测是否是合法URL Path * @param $var * @return string * @throws BusinessException @@ -98,9 +123,13 @@ class Util } return $var; } - - static public function camel($value) + /** + * 转换为驼峰 + * @param string $value + * @return string + */ + static public function camel(string $value): string { static $cache = []; $key = $value; @@ -114,11 +143,21 @@ class Util return $cache[$key] = str_replace(' ', '', $value); } - static public function smCamel($value) + /** + * 转换为小驼峰 + * @param $value + * @return string + */ + static public function smCamel($value): string { return lcfirst(static::camel($value)); } + /** + * 获取注释中第一行 + * @param $comment + * @return false|mixed|string + */ static public function getCommentFirstLine($comment) { if ($comment === false) { @@ -132,7 +171,11 @@ class Util return $comment; } - static public function methodControlMap() + /** + * 表单类型到插件的映射 + * @return \string[][] + */ + static public function methodControlMap(): array { return [ //method=>[控件] @@ -171,7 +214,12 @@ class Util ]; } - static public function typeToControl($type) + /** + * 数据库类型到插件的转换 + * @param $type + * @return string + */ + static public function typeToControl($type): string { if (stripos($type, 'int') !== false) { return 'InputNumber'; @@ -188,6 +236,12 @@ class Util return 'Input'; } + /** + * 数据库类型到表单类型的转换 + * @param $type + * @param $unsigned + * @return string + */ static public function typeToMethod($type, $unsigned = false) { if (stripos($type, 'int') !== false) { @@ -206,10 +260,10 @@ class Util /** * 按表获取摘要 - * * @param $table - * @param $section + * @param null $section * @return array|mixed + * @throws BusinessException */ static public function getSchema($table, $section = null) { @@ -282,6 +336,11 @@ class Util return $section ? $data[$section] : $data; } + /** + * 获取字段长度或默认值 + * @param $schema + * @return mixed|string + */ static public function getLengthValue($schema) { $type = $schema->DATA_TYPE; @@ -302,7 +361,13 @@ class Util return ''; } - static public function getProps($control, $control_args) + /** + * 获取控件参数 + * @param $control + * @param $control_args + * @return array + */ + static public function getControlProps($control, $control_args): array { if (!$control_args) { return []; @@ -339,8 +404,7 @@ class Util /** - * reload webman - * + * reload webman (不支持windows) * @return bool */ static public function reloadWebman() diff --git a/src/plugin/admin/app/controller/TableController.php b/src/plugin/admin/app/controller/TableController.php index 020c7e6..bd732b9 100644 --- a/src/plugin/admin/app/controller/TableController.php +++ b/src/plugin/admin/app/controller/TableController.php @@ -699,7 +699,7 @@ EOF; * @param $controller_class_with_namespace * @return void */ - protected function createTemplate($template_file_path, $table, $template_path, $url_path_base, $primary_key, $controller_class_with_namespace) + protected function createTemplate($template_file_path, $table, $template_path, $url_path_base, $primary_key) { $this->mkdir($template_file_path . '/index.html'); $form = LayuiForm::buildForm($table, 'search'); @@ -730,7 +730,6 @@ EOF $html = str_replace("\n", "\n" . str_repeat(' ', 2), $html); $js = $form->js(3); $table_js = LayuiForm::buildTable($table, 4); - $controller_class_with_namespace = str_replace('\\', '\\\\', $controller_class_with_namespace); $template_content = << @@ -776,7 +775,6 @@ EOF // 相关常量 const PRIMARY_KEY = "$primary_key"; - const CONTROLLER = "$controller_class_with_namespace"; const SELECT_API = "$url_path_base/$template_path/select"; const UPDATE_API = "$url_path_base/$template_path/update"; const DELETE_API = "$url_path_base/$template_path/delete"; diff --git a/src/plugin/admin/app/view/table/index.html b/src/plugin/admin/app/view/table/index.html index df8c51f..a20ff7e 100644 --- a/src/plugin/admin/app/view/table/index.html +++ b/src/plugin/admin/app/view/table/index.html @@ -219,7 +219,7 @@ // 获取选择组件配置项 - function getProps(control_args) + function getControlProps(control_args) { if (!control_args) { return {}; diff --git a/src/plugin/admin/app/view/table/view.html b/src/plugin/admin/app/view/table/view.html index e6ec760..d051224 100644 --- a/src/plugin/admin/app/view/table/view.html +++ b/src/plugin/admin/app/view/table/view.html @@ -98,7 +98,7 @@ let control = item.control.toLowerCase(); // switch 可以直接编辑 if (control === "switch") { - let props = getProps(item.control_args); + let props = getControlProps(item.control_args); let layText = props["lay-text"] || ""; schema.templet = function (d) { form.on("switch("+field+")", function (data) { @@ -133,7 +133,7 @@ return ''; }; } else if (["select", "selectmulti", "treeselect", "treeselectmulti"].indexOf(control) !== -1) { - let props = getProps(item.control_args); + let props = getControlProps(item.control_args); apiResults[field] = []; if (props.url) { apis.push([field, props.url]); @@ -327,7 +327,7 @@ // 获取选择组件配置项 - function getProps(control_args) + function getControlProps(control_args) { if (!control_args) { return {};