From 49e96fda628ed451db24c18dc585047ecd5f19d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=99=E7=A0=81=E7=94=9F=E8=8A=B1?= <18523774412@qq.com> Date: Thu, 28 Apr 2022 03:24:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(CRUD):=E7=94=9F=E6=88=90=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=99=A8=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/command/Crud.php | 26 ++++++++++-------- app/admin/command/Crud/stubs/validate.stub | 31 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 app/admin/command/Crud/stubs/validate.stub diff --git a/app/admin/command/Crud.php b/app/admin/command/Crud.php index 23f6fe46..fe6a5c40 100644 --- a/app/admin/command/Crud.php +++ b/app/admin/command/Crud.php @@ -480,17 +480,17 @@ class Crud extends Command $this->langPrefix = implode('.', $viewArr) . '.'; // 最终将生成的文件路径 - $formFile = $viewDir . 'form.vue'; - $indexFile = $viewDir . 'index.vue'; - $serverLangZhCnFile = $adminPath . 'lang' . DIRECTORY_SEPARATOR . 'zh-cn' . DIRECTORY_SEPARATOR . $controllerBaseName . '.php'; - $serverLangEnFile = $adminPath . 'lang' . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . $controllerBaseName . '.php'; - $webLangZhCnFile = $webLangPath . 'zh-cn' . DIRECTORY_SEPARATOR . $viewPath . '.ts'; - $webLangEnFile = $webLangPath . 'en' . DIRECTORY_SEPARATOR . $viewPath . '.ts'; + $formFile = $viewDir . 'form.vue'; + $indexFile = $viewDir . 'index.vue'; + // $serverLangZhCnFile = $adminPath . 'lang' . DIRECTORY_SEPARATOR . 'zh-cn' . DIRECTORY_SEPARATOR . $controllerBaseName . '.php'; + // $serverLangEnFile = $adminPath . 'lang' . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . $controllerBaseName . '.php'; + $webLangZhCnFile = $webLangPath . 'zh-cn' . DIRECTORY_SEPARATOR . $viewPath . '.ts'; + $webLangEnFile = $webLangPath . 'en' . DIRECTORY_SEPARATOR . $viewPath . '.ts'; - // 是否为删除模式-待测 + // 是否为删除模式 $delete = $this->getOption('delete'); if ($delete) { - $readyFiles = [$controllerFile, $modelFile, $validateFile, $formFile, $indexFile, $serverLangZhCnFile, $serverLangEnFile, $webLangZhCnFile, $webLangEnFile]; + $readyFiles = [$controllerFile, $modelFile, $validateFile, $formFile, $indexFile, $webLangZhCnFile, $webLangEnFile]; foreach ($readyFiles as $k => $v) { $output->warning($v); } @@ -941,18 +941,22 @@ class Crud extends Command // 生成模型文件 $modelContent = $stub->getReplacedStub('model', $modelData); Stub::writeToFile($modelFile, $modelContent); + + // 生成关联模型文件 if ($relations) { foreach ($relations as $i => $relation) { if (!is_file($relation['relationFile'])) { - // 生成关联模型文件 $relationFileContent = $stub->getReplacedStub('relationModel', $relation); Stub::writeToFile($relation['relationFile'], $relationFileContent); } } } - return; + // 生成验证器文件 - $this->writeToFile('validate', $data, $validateFile); + Stub::writeToFile($validateFile, $stub->getReplacedStub('validate', [ + 'validateNamespace' => $validateNamespace, + 'validateName' => $validateName + ])); // TODO 生成server端语言包文件备用 } catch (ErrorException $e) { diff --git a/app/admin/command/Crud/stubs/validate.stub b/app/admin/command/Crud/stubs/validate.stub new file mode 100644 index 00000000..580fd998 --- /dev/null +++ b/app/admin/command/Crud/stubs/validate.stub @@ -0,0 +1,31 @@ + [], + 'edit' => [], + ]; + +}