mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 02:22:48 +08:00
增加初始化admin账号密码命令行;修改部分声明;增加表注释生成关联的功能;
This commit is contained in:
@@ -15,7 +15,7 @@ namespace app\common\command;
|
||||
|
||||
use app\admin\model\SystemNode;
|
||||
use EasyAdmin\console\CliEcho;
|
||||
use EasyAdmin\curd\BuildCurd;
|
||||
use app\common\tools\BuildCurd;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
@@ -32,26 +32,6 @@ class Curd extends Command
|
||||
->addOption('controllerFilename', 'c', Option::VALUE_REQUIRED, '控制器文件名', null)
|
||||
->addOption('modelFilename', 'm', Option::VALUE_REQUIRED, '主表模型文件名', null)
|
||||
#
|
||||
->addOption('checkboxFieldSuffix', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '复选框字段后缀', null)
|
||||
->addOption('radioFieldSuffix', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '单选框字段后缀', null)
|
||||
->addOption('imageFieldSuffix', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '单图片字段后缀', null)
|
||||
->addOption('imagesFieldSuffix', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '多图片字段后缀', null)
|
||||
->addOption('fileFieldSuffix', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '单文件字段后缀', null)
|
||||
->addOption('filesFieldSuffix', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '多文件字段后缀', null)
|
||||
->addOption('dateFieldSuffix', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '时间字段后缀', null)
|
||||
->addOption('switchFields', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '开关的字段', null)
|
||||
->addOption('selectFileds', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '下拉的字段', null)
|
||||
->addOption('editorFields', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '富文本的字段', null)
|
||||
->addOption('sortFields', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '排序的字段', null)
|
||||
->addOption('ignoreFields', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '忽略的字段', null)
|
||||
#
|
||||
->addOption('relationTable', 'r', Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '关联表名', null)
|
||||
->addOption('foreignKey', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '关联外键', null)
|
||||
->addOption('primaryKey', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '关联主键', null)
|
||||
->addOption('relationModelFilename', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '关联模型文件名', null)
|
||||
->addOption('relationOnlyFileds', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '关联模型中只显示的字段', null)
|
||||
->addOption('relationBindSelect', null, Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, '关联模型中的字段用于主表外键的表单下拉选择', null)
|
||||
#
|
||||
->addOption('force', 'f', Option::VALUE_REQUIRED, '强制覆盖模式', 0)
|
||||
->addOption('delete', 'd', Option::VALUE_REQUIRED, '删除模式', 0)
|
||||
->setDescription('一键curd命令服务');
|
||||
@@ -64,39 +44,10 @@ class Curd extends Command
|
||||
$controllerFilename = $input->getOption('controllerFilename');
|
||||
$modelFilename = $input->getOption('modelFilename');
|
||||
|
||||
$checkboxFieldSuffix = $input->getOption('checkboxFieldSuffix');
|
||||
$radioFieldSuffix = $input->getOption('radioFieldSuffix');
|
||||
$imageFieldSuffix = $input->getOption('imageFieldSuffix');
|
||||
$imagesFieldSuffix = $input->getOption('imagesFieldSuffix');
|
||||
$fileFieldSuffix = $input->getOption('fileFieldSuffix');
|
||||
$filesFieldSuffix = $input->getOption('filesFieldSuffix');
|
||||
$dateFieldSuffix = $input->getOption('dateFieldSuffix');
|
||||
$switchFields = $input->getOption('switchFields');
|
||||
$selectFileds = $input->getOption('selectFileds');
|
||||
$sortFields = $input->getOption('sortFields');
|
||||
$ignoreFields = $input->getOption('ignoreFields');
|
||||
|
||||
$relationTable = $input->getOption('relationTable');
|
||||
$foreignKey = $input->getOption('foreignKey');
|
||||
$primaryKey = $input->getOption('primaryKey');
|
||||
$relationModelFilename = $input->getOption('relationModelFilename');
|
||||
$relationOnlyFileds = $input->getOption('relationOnlyFileds');
|
||||
$relationBindSelect = $input->getOption('relationBindSelect');
|
||||
|
||||
$force = $input->getOption('force');
|
||||
$delete = $input->getOption('delete');
|
||||
|
||||
$relations = [];
|
||||
foreach ($relationTable as $key => $val) {
|
||||
$relations[] = [
|
||||
'table' => $relationTable[$key],
|
||||
'foreignKey' => isset($foreignKey[$key]) ? $foreignKey[$key] : null,
|
||||
'primaryKey' => isset($primaryKey[$key]) ? $primaryKey[$key] : null,
|
||||
'modelFilename' => isset($relationModelFilename[$key]) ? $relationModelFilename[$key] : null,
|
||||
'onlyFileds' => isset($relationOnlyFileds[$key]) ? explode(",", $relationOnlyFileds[$key]) : [],
|
||||
'relationBindSelect' => isset($relationBindSelect[$key]) ? $relationBindSelect[$key] : null,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
if (empty($table)) {
|
||||
CliEcho::error('请设置主表');
|
||||
@@ -108,23 +59,40 @@ class Curd extends Command
|
||||
->setTable($table)
|
||||
->setForce($force);
|
||||
|
||||
$columns = $build->getTableColumns();
|
||||
|
||||
|
||||
$relations = [];
|
||||
|
||||
|
||||
foreach ($columns as $field => $column) {
|
||||
|
||||
if (isset($column['formType']) && $column['formType'] == 'relation') {
|
||||
$define = $column['define'];
|
||||
|
||||
if (!isset($define['table'])) {
|
||||
CliEcho::error("关联字段{$field}没有设置关联表名称");
|
||||
return false;
|
||||
}
|
||||
|
||||
$relations[] = [
|
||||
'table' => $define['table'],
|
||||
'foreignKey' => $field,
|
||||
'primaryKey' => $define['primaryKey'] ?? null,
|
||||
'modelFilename' => $define['modelFilename'] ?? null,
|
||||
'onlyFileds' => isset($define['onlyFileds']) ? explode("|", $define['onlyFileds']) : [],
|
||||
'relationBindSelect' => $define['relationBindSelect'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
!empty($controllerFilename) && $build = $build->setControllerFilename($controllerFilename);
|
||||
!empty($modelFilename) && $build = $build->setModelFilename($modelFilename);
|
||||
|
||||
!empty($checkboxFieldSuffix) && $build = $build->setCheckboxFieldSuffix($checkboxFieldSuffix);
|
||||
!empty($radioFieldSuffix) && $build = $build->setRadioFieldSuffix($radioFieldSuffix);
|
||||
!empty($imageFieldSuffix) && $build = $build->setImageFieldSuffix($imageFieldSuffix);
|
||||
!empty($imagesFieldSuffix) && $build = $build->setImagesFieldSuffix($imagesFieldSuffix);
|
||||
!empty($fileFieldSuffix) && $build = $build->setFileFieldSuffix($fileFieldSuffix);
|
||||
!empty($filesFieldSuffix) && $build = $build->setFilesFieldSuffix($filesFieldSuffix);
|
||||
!empty($dateFieldSuffix) && $build = $build->setDateFieldSuffix($dateFieldSuffix);
|
||||
!empty($switchFields) && $build = $build->setSwitchFields($switchFields);
|
||||
!empty($selectFileds) && $build = $build->setSelectFileds($selectFileds);
|
||||
!empty($sortFields) && $build = $build->setSortFields($sortFields);
|
||||
!empty($ignoreFields) && $build = $build->setIgnoreFields($ignoreFields);
|
||||
|
||||
|
||||
foreach ($relations as $relation) {
|
||||
$build = $build->setRelation($relation['table'], $relation['foreignKey'], $relation['primaryKey'], $relation['modelFilename'], $relation['onlyFileds'],$relation['relationBindSelect']);
|
||||
$build = $build->setRelation($relation['table'], $relation['foreignKey'], $relation['primaryKey'], $relation['modelFilename'], $relation['onlyFileds'], $relation['relationBindSelect']);
|
||||
}
|
||||
|
||||
$build = $build->render();
|
||||
@@ -132,7 +100,7 @@ class Curd extends Command
|
||||
|
||||
if (!$delete) {
|
||||
$result = $build->create();
|
||||
if($force){
|
||||
if ($force) {
|
||||
$output->info(">>>>>>>>>>>>>>>");
|
||||
foreach ($fileList as $key => $val) {
|
||||
$output->info($key);
|
||||
@@ -169,6 +137,4 @@ class Curd extends Command
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user