mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 03:22:51 +08:00
增加生成模型字段注解
This commit is contained in:
@@ -5,7 +5,9 @@ namespace app\admin\model;
|
|||||||
|
|
||||||
|
|
||||||
use app\common\model\TimeModel;
|
use app\common\model\TimeModel;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
class MallCate extends TimeModel
|
class MallCate extends TimeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -265,13 +265,14 @@ class BuildCurdService
|
|||||||
|
|
||||||
// 获取表列注释
|
// 获取表列注释
|
||||||
$colums = Db::query("SHOW FULL COLUMNS FROM {$this->tablePrefix}{$this->table}");
|
$colums = Db::query("SHOW FULL COLUMNS FROM {$this->tablePrefix}{$this->table}");
|
||||||
foreach ($colums as $vo) {
|
|
||||||
|
|
||||||
|
foreach ($colums as $vo) {
|
||||||
$colum = [
|
$colum = [
|
||||||
'type' => $vo['Type'],
|
'type' => $vo['Type'],
|
||||||
'comment' => !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'],
|
'comment' => !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'],
|
||||||
'required' => $vo['Null'] == "NO" ? true : false,
|
'required' => $vo['Null'] == "NO" ? true : false,
|
||||||
'default' => $vo['Default'],
|
'default' => $vo['Default'],
|
||||||
|
'field' => $vo['Field']
|
||||||
];
|
];
|
||||||
|
|
||||||
// 格式化列数据
|
// 格式化列数据
|
||||||
@@ -297,6 +298,11 @@ class BuildCurdService
|
|||||||
// 初始化默认模型名
|
// 初始化默认模型名
|
||||||
$this->modelFilename = Str::studly($this->table);
|
$this->modelFilename = Str::studly($this->table);
|
||||||
|
|
||||||
|
// 主表模型命名
|
||||||
|
$modelArray = explode($this->DS, $this->modelFilename);
|
||||||
|
|
||||||
|
$this->modelName = array_pop($modelArray);
|
||||||
|
|
||||||
$this->buildViewJsUrl();
|
$this->buildViewJsUrl();
|
||||||
|
|
||||||
// 构建数据
|
// 构建数据
|
||||||
@@ -362,6 +368,7 @@ class BuildCurdService
|
|||||||
'type' => $vo['Type'],
|
'type' => $vo['Type'],
|
||||||
'comment' => $vo['Comment'],
|
'comment' => $vo['Comment'],
|
||||||
'default' => $vo['Default'],
|
'default' => $vo['Default'],
|
||||||
|
'field' => $vo['Field']
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->buildColum($colum);
|
$this->buildColum($colum);
|
||||||
@@ -608,10 +615,7 @@ class BuildCurdService
|
|||||||
$namespaceSuffix = implode('\\', $namespaceArray);
|
$namespaceSuffix = implode('\\', $namespaceArray);
|
||||||
$this->controllerNamespace = empty($namespaceSuffix) ? "app\admin\controller" : "app\admin\controller\\{$namespaceSuffix}";
|
$this->controllerNamespace = empty($namespaceSuffix) ? "app\admin\controller" : "app\admin\controller\\{$namespaceSuffix}";
|
||||||
|
|
||||||
// 主表模型命名
|
|
||||||
$modelArray = explode($this->DS, $this->modelFilename);
|
|
||||||
|
|
||||||
$this->modelName = array_pop($modelArray);
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -691,6 +695,29 @@ class BuildCurdService
|
|||||||
|
|
||||||
$colum['comment'] = trim($colum['comment']);
|
$colum['comment'] = trim($colum['comment']);
|
||||||
|
|
||||||
|
$colum['property_type'] = $this->fieldTypeToVarType($colum['type']);
|
||||||
|
|
||||||
|
$colum['property_name'] = $colum['field'];
|
||||||
|
|
||||||
|
$colum['data_list'] = '';
|
||||||
|
|
||||||
|
if (isset($colum['formType'])) {
|
||||||
|
if ($colum['formType'] == 'relation') {
|
||||||
|
$relation_model_name = '\\app\\admin\\model\\' . Str::studly($colum['define']['table']);
|
||||||
|
$colum['property_type'] = $relation_model_name;
|
||||||
|
$colum['property_name'] = Str::camel($colum['define']['table']);
|
||||||
|
} else if (in_array($colum['formType'], ['select', 'switch', 'radio', 'checkbox',])) {
|
||||||
|
$data_list = '';
|
||||||
|
|
||||||
|
foreach ($colum['define'] as $define_key => $define_value) {
|
||||||
|
$data_list .= $define_key . ':' . $define_value . ',';
|
||||||
|
}
|
||||||
|
$data_list = substr($data_list, 0, -1);
|
||||||
|
$colum['data_list'] = $data_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return $colum;
|
return $colum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -816,10 +843,12 @@ class BuildCurdService
|
|||||||
protected function buildTableView($field, $options, $value)
|
protected function buildTableView($field, $options, $value)
|
||||||
{
|
{
|
||||||
$default_define = [
|
$default_define = [
|
||||||
'table' => '', // 必填
|
'table' => '',
|
||||||
|
// 必填
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'valueField' => 'id',
|
'valueField' => 'id',
|
||||||
'fieldName' => 'title', // 必填
|
'fieldName' => 'title',
|
||||||
|
// 必填
|
||||||
'comment' => $options['comment'],
|
'comment' => $options['comment'],
|
||||||
'field' => $field,
|
'field' => $field,
|
||||||
'required' => $options['required'],
|
'required' => $options['required'],
|
||||||
@@ -1145,12 +1174,19 @@ class BuildCurdService
|
|||||||
|
|
||||||
$selectList = '';
|
$selectList = '';
|
||||||
|
|
||||||
|
$doc_content = '';
|
||||||
|
|
||||||
foreach ($this->tableColumns as $field => $val) {
|
foreach ($this->tableColumns as $field => $val) {
|
||||||
if (isset($val['formType']) && in_array($val['formType'], ['select', 'switch', 'radio', 'checkbox']) && isset($val['define'])) {
|
if (isset($val['formType']) && in_array($val['formType'], ['select', 'switch', 'radio', 'checkbox']) && isset($val['define'])) {
|
||||||
$selectList .= $this->buildSelectModel($field, $val['define']);
|
$selectList .= $this->buildSelectModel($field, $val['define']);
|
||||||
}
|
}
|
||||||
|
$doc_content .= " * @property {$val['property_type']} \${$val['property_name']} {$val['comment']} {$val['data_list']}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$doc_content = substr($doc_content, 0, -1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$extendNamespaceArray = explode($this->DS, $this->modelFilename);
|
$extendNamespaceArray = explode($this->DS, $this->modelFilename);
|
||||||
$extendNamespace = null;
|
$extendNamespace = null;
|
||||||
if (count($extendNamespaceArray) > 1) {
|
if (count($extendNamespaceArray) > 1) {
|
||||||
@@ -1167,6 +1203,7 @@ class BuildCurdService
|
|||||||
'deleteTime' => $this->delete ? '"delete_time"' : 'false',
|
'deleteTime' => $this->delete ? '"delete_time"' : 'false',
|
||||||
'relationList' => $relationList,
|
'relationList' => $relationList,
|
||||||
'selectList' => $selectList,
|
'selectList' => $selectList,
|
||||||
|
'doc_content' => $doc_content,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->fileList[$modelFile] = $modelValue;
|
$this->fileList[$modelFile] = $modelValue;
|
||||||
@@ -1648,4 +1685,53 @@ class BuildCurdService
|
|||||||
}
|
}
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function fieldTypeToVarType($type)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$type_prefix_map = [
|
||||||
|
'BIT' => 'bool',
|
||||||
|
'TINYINT' => 'int',
|
||||||
|
'BOOL' => 'bool',
|
||||||
|
'BOOLEAN' => 'bool',
|
||||||
|
'SMALLINT' => 'int',
|
||||||
|
'MEDIUMINT' => 'int',
|
||||||
|
'INT' => 'int',
|
||||||
|
'INTEGER' => 'int',
|
||||||
|
'BIGINT' => 'int',
|
||||||
|
'FLOAT' => 'float|double',
|
||||||
|
'DOUBLE' => 'float|double',
|
||||||
|
'DECIMAL' => 'float|double',
|
||||||
|
'DATE' => 'string',
|
||||||
|
'DATETIME' => 'string',
|
||||||
|
'TIMESTAMP' => 'int',
|
||||||
|
'TIME' => 'string',
|
||||||
|
'YEAR' => 'int',
|
||||||
|
'CHAR' => 'string',
|
||||||
|
'VARCHAR' => 'string',
|
||||||
|
'BINARY' => 'string',
|
||||||
|
'VARBINARY' => 'string',
|
||||||
|
'TINYBLOB' => 'string',
|
||||||
|
'BLOB' => 'string',
|
||||||
|
'MEDIUMBLOB' => 'string',
|
||||||
|
'LONGBLOB' => 'string',
|
||||||
|
'TINYTEXT' => 'string',
|
||||||
|
'TEXT' => 'string',
|
||||||
|
'MEDIUMTEXT' => 'string',
|
||||||
|
'LONGTEXT' => 'string',
|
||||||
|
'ENUM' => 'string',
|
||||||
|
'SET' => 'string',
|
||||||
|
'JSON' => 'string',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($type_prefix_map as $sql_type => $var_type) {
|
||||||
|
if (Str::startsWith(strtolower($type), strtolower($sql_type))) {
|
||||||
|
return $var_type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'mixed';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,9 @@ namespace {{modelNamespace}};
|
|||||||
|
|
||||||
use app\common\model\TimeModel;
|
use app\common\model\TimeModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
{{doc_content}}
|
||||||
|
*/
|
||||||
class {{modelName}} extends TimeModel
|
class {{modelName}} extends TimeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user