diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemCrud.php b/crmeb/app/adminapi/controller/v1/setting/SystemCrud.php index 198e8515e..219e1f959 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemCrud.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemCrud.php @@ -110,8 +110,11 @@ class SystemCrud extends AuthController } $tableField = []; - if (!$isTable) { + if ($isTable) { $field = $this->services->getColumnNamesList($tableName); + if (!$field) { + return app('json')->fail('表不存在'); + } foreach ($field as $item) { $tableField[] = ['value' => $item['name'], 'comment' => $item['comment'], 'label' => $item['name']]; } diff --git a/crmeb/app/services/system/SystemCrudServices.php b/crmeb/app/services/system/SystemCrudServices.php index b8c97b6b1..e8efc38bc 100644 --- a/crmeb/app/services/system/SystemCrudServices.php +++ b/crmeb/app/services/system/SystemCrudServices.php @@ -18,6 +18,7 @@ use app\dao\system\SystemCrudDao; use app\services\BaseServices; use crmeb\services\crud\Controller; use crmeb\services\crud\Dao; +use crmeb\services\crud\Make; use crmeb\services\crud\Model; use crmeb\services\crud\Route; use crmeb\services\crud\Service; @@ -318,6 +319,8 @@ class SystemCrudServices extends BaseServices */ public function makeFile(string $tableName, string $routeName, bool $isMake = false, array $options = [], array $filePath = []) { + $options['fromField'] = is_array($options['fromField']) ? $options['fromField'] : []; + $options['columnField'] = is_array($options['columnField']) ? $options['columnField'] : []; //生成控制器 $controller = app()->make(Controller::class); [$controllerContent, $controllerPath] = $controller->setFilePathName($filePath['controller'] ?? '')->isMake($isMake)->handle($tableName, '/'); @@ -336,7 +339,7 @@ class SystemCrudServices extends BaseServices //生成service $service = app()->make(Service::class); [$serviceContent, $servicePath] = $service->setFilePathName($filePath['service'] ?? '')->isMake($isMake)->handle($tableName, '/', [ - 'field' => $options['fromField'] + 'field' => $options['fromField'], ]); //生成验证器 $validate = app()->make(Validate::class); @@ -351,6 +354,7 @@ class SystemCrudServices extends BaseServices [$apiContent, $apiPath] = $viewApi->setFilePathName($filePath['api'] ?? '')->isMake($isMake)->handle($tableName, '/', [ 'route' => $routeName, ]); + //生成前台页面 $viewPages = app()->make(ViewPages::class); [$pagesContent, $pagesPath] = $viewPages->setFilePathName($filePath['pages'] ?? '')->isMake($isMake)->handle($tableName, '/', [ @@ -359,44 +363,49 @@ class SystemCrudServices extends BaseServices return [ 'controller' => [ - 'path' => $controllerContent, - 'content' => $controllerPath + 'path' => $this->replace($controllerPath), + 'content' => $controllerContent ], 'model' => [ - 'path' => $modelPath, + 'path' => $this->replace($modelPath), 'content' => $modelContent ], 'dao' => [ - 'path' => $daoPath, + 'path' => $this->replace($daoPath), 'content' => $daoContent ], 'route' => [ - 'path' => $routePath, + 'path' => $this->replace($routePath), 'content' => $routeContent ], 'service' => [ - 'path' => $servicePath, + 'path' => $this->replace($servicePath), 'content' => $serviceContent ], 'validate' => [ - 'path' => $validatePath, + 'path' => $this->replace($validatePath), 'content' => $validateContent ], 'router' => [ - 'path' => $routerPath, + 'path' => $this->replace($routerPath), 'content' => $routerContent ], 'api' => [ - 'path' => $apiPath, + 'path' => $this->replace($apiPath), 'content' => $apiContent ], 'pages' => [ - 'path' => $pagesPath, + 'path' => $this->replace($pagesPath), 'content' => $pagesContent ], ]; } + protected function replace(string $path) + { + return str_replace([app()->getRootPath(), Make::adminTemplatePath()], '', $path); + } + /** * @param string $tableName * @param bool $fullName diff --git a/crmeb/config/app.php b/crmeb/config/app.php index af4b2bcb0..8421d6758 100644 --- a/crmeb/config/app.php +++ b/crmeb/config/app.php @@ -48,4 +48,6 @@ return [ 'console_remind' => true, // admin路由前缀 'admin_prefix' => 'admin', + //后台前端模板根路径 + 'admin_template_path' => dirname(app()->getRootPath()) . DS . 'template' . DS . 'admin' . DS . 'src' . DS, ]; diff --git a/crmeb/crmeb/services/crud/Make.php b/crmeb/crmeb/services/crud/Make.php index 700dce8bd..a69813615 100644 --- a/crmeb/crmeb/services/crud/Make.php +++ b/crmeb/crmeb/services/crud/Make.php @@ -99,7 +99,7 @@ abstract class Make public function __construct(App $app) { $this->app = $app; - $this->adminTemplatePath = dirname($this->app->getRootPath()) . DS . 'template' . DS . 'admin' . DS . 'src' . DS; + $this->adminTemplatePath = self::adminTemplatePath(); $this->basePath = $this->app->getRootPath(); $this->baseDir = $this->setBaseDir(); $this->var = $this->authDrawVar(); @@ -107,6 +107,17 @@ abstract class Make $this->setDefaultValue(); } + /** + * @return string + * @author 等风来 + * @email 136327134@qq.com + * @date 2023/4/11 + */ + public static function adminTemplatePath() + { + return config('app.admin_template_path'); + } + /** * 设置默认保存目录 * @author 等风来 diff --git a/crmeb/crmeb/services/crud/Route.php b/crmeb/crmeb/services/crud/Route.php index 921493c61..e4ce0f438 100644 --- a/crmeb/crmeb/services/crud/Route.php +++ b/crmeb/crmeb/services/crud/Route.php @@ -85,6 +85,21 @@ class Route extends Make return [$this->makeFile($filePath, $contentStr), $filePath]; } + /** + * @author 等风来 + * @email 136327134@qq.com + * @date 2023/4/11 + * @param string $path + * @param string $name + * @return string + */ + protected function getFilePathName(string $path, string $name): string + { + $path = ltrim(str_replace('\\', '/', $path), '/'); + + return $this->getBasePath($path) . $name . '.' . $this->fileMime; + } + /** * 设置模板 * @param string $type diff --git a/crmeb/crmeb/services/crud/Validate.php b/crmeb/crmeb/services/crud/Validate.php index 706525dc3..0bcf3b099 100644 --- a/crmeb/crmeb/services/crud/Validate.php +++ b/crmeb/crmeb/services/crud/Validate.php @@ -45,6 +45,6 @@ class Validate extends Make */ protected function getStub(string $type = '') { - return __DIR__ . DS . 'stubs' . DS . 'validate' . DS . 'CrudValidate.stub'; + return __DIR__ . DS . 'stubs' . DS . 'validate' . DS . 'crudValidate.stub'; } } diff --git a/crmeb/crmeb/services/crud/stubs/validate/CrudValidate.stubs b/crmeb/crmeb/services/crud/stubs/validate/crudValidate.stub similarity index 100% rename from crmeb/crmeb/services/crud/stubs/validate/CrudValidate.stubs rename to crmeb/crmeb/services/crud/stubs/validate/crudValidate.stub