diff --git a/app/admin/service/curd/BuildCurdService.php b/app/admin/service/curd/BuildCurdService.php index 0073f3d..d8ca245 100644 --- a/app/admin/service/curd/BuildCurdService.php +++ b/app/admin/service/curd/BuildCurdService.php @@ -225,7 +225,7 @@ class BuildCurdService * 表单类型 * @var array */ - protected $formTypeArray = ['text', 'image', 'images', 'file', 'files', 'select', 'switch', 'date', 'editor', 'textarea', 'checkbox', 'radio', 'relation']; + protected $formTypeArray = ['text', 'image', 'images', 'file', 'files', 'select', 'switch', 'date', 'editor', 'textarea', 'checkbox', 'radio', 'relation', 'table']; /** * 初始化 @@ -285,19 +285,8 @@ class BuildCurdService throw new TableException($e->getMessage()); } - // 初始化默认控制器名 - $nodeArray = explode('_', $this->table); - if (count($nodeArray) == 1) { - $this->controllerFilename = ucfirst($nodeArray[0]); - } else { - foreach ($nodeArray as $k => $v) { - if ($k == 0) { - $this->controllerFilename = "{$v}{$this->DS}"; - } else { - $this->controllerFilename .= ucfirst($v); - } - } - } + + $this->controllerFilename = $this->getTableControllerName($this->table); // 初始化默认模型名 $this->modelFilename = Str::studly($this->table); @@ -310,6 +299,26 @@ class BuildCurdService return $this; } + public function getTableControllerName($table) + { + $controllerFilename = ''; + // 初始化默认控制器名 + $nodeArray = explode('_', $table); + if (count($nodeArray) == 1) { + $controllerFilename = ucfirst($nodeArray[0]); + } else { + foreach ($nodeArray as $k => $v) { + if ($k == 0) { + $controllerFilename = "{$v}{$this->DS}"; + } else { + $controllerFilename .= ucfirst($v); + } + } + } + + return $controllerFilename; + } + /** * 设置关联表 * @param $relationTable @@ -570,6 +579,8 @@ class BuildCurdService return $this->fileList; } + + /** * 构建基础视图、JS、URL * @return $this @@ -654,9 +665,9 @@ class BuildCurdService preg_match('/\([\s\S]*?\)/i', $string, $defineMatch); if (!empty($formTypeMatch) && isset($defineMatch[0])) { $colum['comment'] = str_replace($defineMatch[0], '', $colum['comment']); - if (isset($colum['formType']) && in_array($colum['formType'], ['images', 'files', 'select', 'switch', 'radio', 'checkbox', 'date', 'relation'])) { + if (isset($colum['formType']) && in_array($colum['formType'], ['images', 'files', 'select', 'switch', 'radio', 'checkbox', 'date', 'relation', 'table'])) { $define = str_replace(')', '', str_replace('(', '', $defineMatch[0])); - if (in_array($colum['formType'], ['select', 'switch', 'radio', 'checkbox', 'relation'])) { + if (in_array($colum['formType'], ['select', 'switch', 'radio', 'checkbox', 'relation', 'table'])) { $formatDefine = []; $explodeArray = explode(',', $define); foreach ($explodeArray as $vo) { @@ -784,6 +795,45 @@ class BuildCurdService ); return $optionCode; } + /** + * 构建表格选择器视图 + * @param $field + * @param string $select + * @return mixed + */ + protected function buildTableView($field, $options, $value) + { + $default_define = [ + 'type' => 'checkbox', + 'value_filed' => 'id', + 'comment' => $options['comment'], + 'field' => $field, + 'required' => $options['required'], + 'value' => $value, + ]; + + $define = array_merge($default_define, $options['define']); + + $table_controller_name = $this->getTableControllerName($define['table']); + + + $nodeArray = explode($this->DS, $table_controller_name); + $formatArray = []; + foreach ($nodeArray as $vo) { + $formatArray[] = Str::snake($vo); + } + $controller_url = implode('.', $formatArray); + + $define['controller_url'] = $controller_url; + + + $table_main_code = $this->replaceTemplate( + $this->getTemplate("view{$this->DS}module{$this->DS}tableMain"), + $define + ); + + return $table_main_code; + } /** * 构建单选框视图 @@ -1194,7 +1244,7 @@ class BuildCurdService if (!in_array($define, ['year', 'month', 'date', 'time', 'datetime'])) { $define = 'datetime'; } - } elseif ($val['formType'] == 'radio') { + } elseif ($val['formType'] == 'radio' || $val['formType'] == 'switch') { $templateFile = "view{$this->DS}module{$this->DS}radio"; if (isset($val['define']) && !empty($val['define'])) { $define = $this->buildRadioView($field, '{in name="k" value="' . $val['default'] . '"}checked=""{/in}'); @@ -1221,6 +1271,9 @@ class BuildCurdService } elseif (isset($val['define']) && !empty($val['define'])) { $define = $this->buildOptionView($field); } + } elseif ($val['formType'] == 'table') { + $templateFile = "view{$this->DS}module{$this->DS}table"; + $define = $this->buildTableView($field, $val, $val['default']); } @@ -1280,7 +1333,7 @@ class BuildCurdService if (!in_array($define, ['year', 'month', 'date', 'time', 'datetime'])) { $define = 'datetime'; } - } elseif ($val['formType'] == 'radio') { + } elseif ($val['formType'] == 'radio' || $val['formType'] == 'switch') { $templateFile = "view{$this->DS}module{$this->DS}radio"; if (isset($val['define']) && !empty($val['define'])) { $define = $this->buildRadioView($field, '{in name="k" value="$row.' . $field . '"}checked=""{/in}'); @@ -1300,6 +1353,9 @@ class BuildCurdService } elseif (in_array($field, ['remark']) || $val['formType'] == 'textarea') { $templateFile = "view{$this->DS}module{$this->DS}textarea"; $value = '{$row.' . $field . '|raw|default=\'\'}'; + } elseif ($val['formType'] == 'table') { + $templateFile = "view{$this->DS}module{$this->DS}table"; + $define = $this->buildTableView($field, $val, $value); } $editFormList .= $this->replaceTemplate( diff --git a/app/admin/service/curd/templates/view/module/table.code b/app/admin/service/curd/templates/view/module/table.code new file mode 100644 index 0000000..502d8da --- /dev/null +++ b/app/admin/service/curd/templates/view/module/table.code @@ -0,0 +1,6 @@ +
+ +
+{{define}} +
+
\ No newline at end of file diff --git a/app/admin/service/curd/templates/view/module/tableMain.code b/app/admin/service/curd/templates/view/module/tableMain.code new file mode 100644 index 0000000..3fdf4e0 --- /dev/null +++ b/app/admin/service/curd/templates/view/module/tableMain.code @@ -0,0 +1,3 @@ +
+ +
\ No newline at end of file diff --git a/public/static/plugs/lay-module/tableData/tableData.css b/public/static/plugs/lay-module/tableData/tableData.css index 8529ba6..11d9a57 100644 --- a/public/static/plugs/lay-module/tableData/tableData.css +++ b/public/static/plugs/lay-module/tableData/tableData.css @@ -11,4 +11,7 @@ } .table-data-container .layui-input .layui-btn i { pointer-events: all; +} +.table-data-container .layui-form-danger + .layui-input { + border-color: #ff5722 !important; } \ No newline at end of file diff --git a/public/static/plugs/lay-module/tableData/tableData.html b/public/static/plugs/lay-module/tableData/tableData.html index 8311f25..687c130 100644 --- a/public/static/plugs/lay-module/tableData/tableData.html +++ b/public/static/plugs/lay-module/tableData/tableData.html @@ -1,5 +1,5 @@ -
- +
+
{{setting.placeholder}}
diff --git a/public/static/plugs/lay-module/tableData/tableData.js b/public/static/plugs/lay-module/tableData/tableData.js index 4c0d7a9..71e9d6c 100644 --- a/public/static/plugs/lay-module/tableData/tableData.js +++ b/public/static/plugs/lay-module/tableData/tableData.js @@ -76,7 +76,9 @@ define(['jquery', 'vue'], function ($, Vue) { }, created() { this.value = options.selectValue; - + if(typeof this.value != 'string') { + this.value = this.value.toString(); + } var valueLength = this.value.split(',').length; loading.show(); $.get(options.index,{ @@ -90,6 +92,11 @@ define(['jquery', 'vue'], function ($, Vue) { }) }, + mounted() { + if(options.required == 1){ + $(this.$refs['tableData']).closest('.layui-form-item').children('.layui-form-label').addClass('required'); + } + }, template: tableDataTemplate, methods: { diff --git a/public/static/plugs/lay-module/tableData/tableData.scss b/public/static/plugs/lay-module/tableData/tableData.scss index 2c0b77b..3ed8758 100644 --- a/public/static/plugs/lay-module/tableData/tableData.scss +++ b/public/static/plugs/lay-module/tableData/tableData.scss @@ -16,4 +16,9 @@ } } } + + + .layui-form-danger+.layui-input { + border-color: #ff5722 !important; + } } \ No newline at end of file