fixed 代码生成预览bug

This commit is contained in:
JaguarJack 2021-06-18 16:50:16 +08:00
parent d53e8c46af
commit 99e53be3e4
2 changed files with 10 additions and 40 deletions

View File

@ -92,9 +92,7 @@ class Generator
*/
public function preview($params)
{
$params = \json_decode($params['data'], true);
[$controller, $model] = $this->parseParams($params);
[$controller, $model] = $this->parseParams(\json_decode($params['data'], true));
switch ($params['type']) {
case 'controller':

View File

@ -55,7 +55,7 @@ class Model extends Factory
// 如果填写了表名并且没有填写模型名称 使用表名作为模型名称
if (!$modelName && $table) {
$modelName = ucfirst(Str::camel($table));
$params['model'] = $params['model'] . $modelName;
$params['model'] .= $modelName;
}
if (!$modelName) {
@ -68,17 +68,19 @@ class Model extends Factory
->class($modelName, function (Class_ $class, Generator $generator) use ($table){
$class->extend('Model');
$class->setDocComment($this->buildClassComment($table));
$generator->property('name', function (Property $property) use ($table){
return $property->setDefault(Utils::tableWithoutPrefix($table));
});
if ($this->hasTableExists($table)) {
// 设置 class comment
$class->setDocComment($this->buildClassComment($table));
// 设置 name 属性
$generator->property('field', function (Property $property) use ($table){
return $property->setDefault(array_column(Db::getFields($table), 'name'));
});
}
$generator->property('name', function (Property $property) use ($table){
return $property->setDefault(Utils::tableWithoutPrefix($table));
});
})
->uses([
$softDelete ? 'catcher\base\CatchModel as Model' : 'think\Model'
@ -90,36 +92,6 @@ class Model extends Factory
]);
})
->print();
/**
return (new CatchBuild)->namespace($namespace)
->use((new Uses())->name('catcher\base\CatchModel', 'Model'))
->when(!$softDelete, function (CatchBuild $build){
$build->use((new Uses())->name(BaseOptionsTrait::class));
$build->use((new Uses())->name(ScopeTrait::class));
})
->class((new Classes($modelName))
->extend('Model')
->docComment($this->buildClassComment($table)),
function (Classes $class) use ($softDelete, $table) {
if (!$softDelete) {
$class->addTrait(
(new Traits())->use('BaseOptionsTrait', 'ScopeTrait')
);
}
$class->addProperty(
(new Property('name'))->default(
Utils::tableWithoutPrefix($table)
)->docComment('// 表名')
);
$class->when($this->hasTableExists($table), function ($class) use ($table){
$class->addProperty(
(new Property('field'))->default(
(new Arr)->build(Db::getFields($table))
)->docComment('// 数据库字段映射'));
});
})->getContent();*/
}
/**