This commit is contained in:
walkor 2022-12-08 11:48:50 +08:00
parent b2b669856b
commit 5782855513
2 changed files with 12 additions and 12 deletions

View File

@ -3,7 +3,7 @@ namespace plugin\admin\app\common;
use support\exception\BusinessException; use support\exception\BusinessException;
class LayuiForm class Layui
{ {
/** /**
@ -681,16 +681,16 @@ EOF;
* 构建表单 * 构建表单
* @param $table * @param $table
* @param string $type * @param string $type
* @return LayuiForm * @return Layui
* @throws BusinessException * @throws BusinessException
*/ */
static public function buildForm($table, string $type = 'insert'): LayuiForm static public function buildForm($table, string $type = 'insert'): Layui
{ {
if (!in_array($type, ['insert', 'update', 'search'])) { if (!in_array($type, ['insert', 'update', 'search'])) {
$type = 'insert'; $type = 'insert';
} }
$filter = $type === 'search' ? 'searchable' : 'form_show'; $filter = $type === 'search' ? 'searchable' : 'form_show';
$form = new LayuiForm(); $form = new Layui();
$schema = Util::getSchema($table); $schema = Util::getSchema($table);
$forms = $schema['forms']; $forms = $schema['forms'];
$columns = $schema['columns']; $columns = $schema['columns'];

View File

@ -4,7 +4,7 @@ namespace plugin\admin\app\controller;
use Doctrine\Inflector\InflectorFactory; use Doctrine\Inflector\InflectorFactory;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use plugin\admin\app\common\LayuiForm; use plugin\admin\app\common\Layui;
use plugin\admin\app\common\Util; use plugin\admin\app\common\Util;
use plugin\admin\app\model\Role; use plugin\admin\app\model\Role;
use plugin\admin\app\model\Rule; use plugin\admin\app\model\Rule;
@ -40,7 +40,7 @@ class TableController extends Base
{ {
$table = $request->get('table'); $table = $request->get('table');
$table = Util::filterAlphaNum($table); $table = Util::filterAlphaNum($table);
$form = LayuiForm::buildForm($table, 'search'); $form = Layui::buildForm($table, 'search');
$table_info = Util::getSchema($table, 'table'); $table_info = Util::getSchema($table, 'table');
$primary_key = $table_info['primary_key'][0] ?? null; $primary_key = $table_info['primary_key'][0] ?? null;
return view("table/view", [ return view("table/view", [
@ -704,7 +704,7 @@ EOF;
$this->mkdir($template_file_path . '/index.html'); $this->mkdir($template_file_path . '/index.html');
$code_base = Util::controllerToUrlPath($controller_class_with_namespace); $code_base = Util::controllerToUrlPath($controller_class_with_namespace);
$code_base = str_replace('/', '.', trim($code_base, '/')); $code_base = str_replace('/', '.', trim($code_base, '/'));
$form = LayuiForm::buildForm($table, 'search'); $form = Layui::buildForm($table, 'search');
$html = $form->html(3); $html = $form->html(3);
$html = $html ? <<<EOF $html = $html ? <<<EOF
<div class="layui-card"> <div class="layui-card">
@ -731,7 +731,7 @@ EOF
: ''; : '';
$html = str_replace("\n", "\n" . str_repeat(' ', 2), $html); $html = str_replace("\n", "\n" . str_repeat(' ', 2), $html);
$js = $form->js(3); $js = $form->js(3);
$table_js = LayuiForm::buildTable($table, 4); $table_js = Layui::buildTable($table, 4);
$template_content = <<<EOF $template_content = <<<EOF
<!DOCTYPE html> <!DOCTYPE html>
@ -919,7 +919,7 @@ EOF
EOF; EOF;
file_put_contents("$template_file_path/index.html", $template_content); file_put_contents("$template_file_path/index.html", $template_content);
$form = LayuiForm::buildForm($table); $form = Layui::buildForm($table);
$html = $form->html(5); $html = $form->html(5);
$js = $form->js(3); $js = $form->js(3);
$template_content = <<<EOF $template_content = <<<EOF
@ -995,7 +995,7 @@ EOF;
file_put_contents("$template_file_path/insert.html", $template_content); file_put_contents("$template_file_path/insert.html", $template_content);
$form = LayuiForm::buildForm($table, 'update'); $form = Layui::buildForm($table, 'update');
$html = $form->html(5); $html = $form->html(5);
$js = $form->js(6); $js = $form->js(6);
$template_content = <<<EOF $template_content = <<<EOF
@ -1194,7 +1194,7 @@ EOF;
{ {
if ($request->method() === 'GET') { if ($request->method() === 'GET') {
$table = $request->get('table'); $table = $request->get('table');
$form = LayuiForm::buildForm($table); $form = Layui::buildForm($table);
return view("table/insert", [ return view("table/insert", [
'form' => $form, 'form' => $form,
'table' => $table 'table' => $table
@ -1248,7 +1248,7 @@ EOF;
$table_info = Util::getSchema($table, 'table'); $table_info = Util::getSchema($table, 'table');
$primary_key = $table_info['primary_key'][0] ?? null; $primary_key = $table_info['primary_key'][0] ?? null;
$value = htmlspecialchars($request->get($primary_key, '')); $value = htmlspecialchars($request->get($primary_key, ''));
$form = LayuiForm::buildForm($table,'update'); $form = Layui::buildForm($table,'update');
return view("table/update", [ return view("table/update", [
'primary_key' => $primary_key, 'primary_key' => $primary_key,
'value' => $value, 'value' => $value,