fixed 代码生成预览bug
This commit is contained in:
parent
d53e8c46af
commit
99e53be3e4
@ -92,9 +92,7 @@ class Generator
|
|||||||
*/
|
*/
|
||||||
public function preview($params)
|
public function preview($params)
|
||||||
{
|
{
|
||||||
$params = \json_decode($params['data'], true);
|
[$controller, $model] = $this->parseParams(\json_decode($params['data'], true));
|
||||||
|
|
||||||
[$controller, $model] = $this->parseParams($params);
|
|
||||||
|
|
||||||
switch ($params['type']) {
|
switch ($params['type']) {
|
||||||
case 'controller':
|
case 'controller':
|
||||||
|
@ -55,7 +55,7 @@ class Model extends Factory
|
|||||||
// 如果填写了表名并且没有填写模型名称 使用表名作为模型名称
|
// 如果填写了表名并且没有填写模型名称 使用表名作为模型名称
|
||||||
if (!$modelName && $table) {
|
if (!$modelName && $table) {
|
||||||
$modelName = ucfirst(Str::camel($table));
|
$modelName = ucfirst(Str::camel($table));
|
||||||
$params['model'] = $params['model'] . $modelName;
|
$params['model'] .= $modelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$modelName) {
|
if (!$modelName) {
|
||||||
@ -68,17 +68,19 @@ class Model extends Factory
|
|||||||
->class($modelName, function (Class_ $class, Generator $generator) use ($table){
|
->class($modelName, function (Class_ $class, Generator $generator) use ($table){
|
||||||
$class->extend('Model');
|
$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)) {
|
if ($this->hasTableExists($table)) {
|
||||||
|
// 设置 class comment
|
||||||
|
$class->setDocComment($this->buildClassComment($table));
|
||||||
|
|
||||||
|
// 设置 name 属性
|
||||||
$generator->property('field', function (Property $property) use ($table){
|
$generator->property('field', function (Property $property) use ($table){
|
||||||
return $property->setDefault(array_column(Db::getFields($table), 'name'));
|
return $property->setDefault(array_column(Db::getFields($table), 'name'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$generator->property('name', function (Property $property) use ($table){
|
||||||
|
return $property->setDefault(Utils::tableWithoutPrefix($table));
|
||||||
|
});
|
||||||
})
|
})
|
||||||
->uses([
|
->uses([
|
||||||
$softDelete ? 'catcher\base\CatchModel as Model' : 'think\Model'
|
$softDelete ? 'catcher\base\CatchModel as Model' : 'think\Model'
|
||||||
@ -90,36 +92,6 @@ class Model extends Factory
|
|||||||
]);
|
]);
|
||||||
})
|
})
|
||||||
->print();
|
->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();*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user