Skip to content

Commit

Permalink
fix: 代码生成器, 切换保存路径时更新对应文件路径
Browse files Browse the repository at this point in the history
  • Loading branch information
slowlyo committed Jun 11, 2024
1 parent 002a00f commit fe8e0b0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
'input_config_name' => 'Please Input Config Name',
'same_name_tips' => 'Configurations with the same name will be overwritten',
'save_path_dir' => 'Primary application',
'save_path_select' => 'Select Directory',
'save_path_select' => 'Toggle Directory',
'save_path_select_tips' => 'Project root directory or plugin root directory can be selected',
'save_path_label_prefix' => 'Plugins -> ',
'clear_code' => 'Clear Code',
Expand Down
2 changes: 1 addition & 1 deletion lang/zh_CN/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
'input_config_name' => '请填写配置名称',
'same_name_tips' => '相同名称的配置将会被覆盖',
'save_path_dir' => '主应用',
'save_path_select' => '选择目录',
'save_path_select' => '切换目录',
'save_path_select_tips' => '可选择项目根目录或插件根目录',
'save_path_label_prefix' => '插件 -> ',
'clear_code' => '清除代码',
Expand Down
17 changes: 0 additions & 17 deletions src/Console/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,6 @@ public function version323()
}
}

public function version325()
{
$this->output->title('Update to version v3.2.5');
if (!$this->schema()->hasColumn('admin_code_generators', 'save_path')) {
$this->schema()->table('admin_code_generators', function ($table) {
$table->text('save_path')->nullable()->comment('保存位置');
});
}

if (!$this->updateAll) {
$this->call('admin:publish', [
'--lang' => true,
'--force' => true,
]);
}
}

public function version341()
{
$this->output->title('Update to version v3.4.1');
Expand Down
53 changes: 20 additions & 33 deletions src/Controllers/DevTools/CodeGeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ public function form($isEdit = false)
{
// 下划线的表名处理成驼峰文件名
$nameHandler = 'JOIN(ARRAYMAP(SPLIT(IF(ENDSWITH(table_name, "s"), LEFT(table_name, LEN(table_name) - 1), table_name), "_"), item=>CAPITALIZE(item)))';
// 填充路径
$fillPathAction = [
'actionType' => 'setValue',
'componentId' => 'code_generator_form',
'args' => [
'value' => [
'model_name' => '${model_path}${' . $nameHandler . '}',
'controller_name' => '${controller_path}${' . $nameHandler . '}Controller',
'service_name' => '${service_path}${' . $nameHandler . '}Service',
],
],
];

return amis()->Form()
->promptPageLeave()
Expand All @@ -143,9 +155,7 @@ public function form($isEdit = false)
[
'actionType' => 'setValue',
'componentId' => 'gen_menu_title',
'args' => [
'value' => '${value}',
],
'args' => ['value' => '${value}'],
],
],
],
Expand All @@ -161,26 +171,15 @@ public function form($isEdit = false)
[
'actionType' => 'setValue',
'componentId' => 'gen_menu_route',
'args' => [
'value' => '/${value}',
],
],
[
'actionType' => 'setValue',
'componentId' => 'code_generator_form',
'args' => [
'value' => [
'model_name' => '${model_path}${' . $nameHandler . '}',
'controller_name' => '${controller_path}${' . $nameHandler . '}Controller',
'service_name' => '${service_path}${' . $nameHandler . '}Service',
],
],
'args' => ['value' => '/${value}'],
],
$fillPathAction,
],
],
]),
amis()
->SelectControl('exists_table', admin_trans('admin.code_generators.exists_table'))
->inputClassName('bg-gray-100')
->searchable()
->clearable()
->selectMode('group')
Expand All @@ -203,21 +202,9 @@ public function form($isEdit = false)
[
'actionType' => 'setValue',
'componentId' => 'gen_menu_route',
'args' => [
'value' => '/${SPLIT(event.data.value, "-")[0]}',
],
],
[
'actionType' => 'setValue',
'componentId' => 'code_generator_form',
'args' => [
'value' => [
'model_name' => '${model_path}${' . $nameHandler . '}',
'controller_name' => '${controller_path}${' . $nameHandler . '}Controller',
'service_name' => '${service_path}${' . $nameHandler . '}Service',
],
],
'args' => ['value' => '/${SPLIT(event.data.value, "-")[0]}'],
],
$fillPathAction,
],
],
]),
Expand All @@ -236,8 +223,7 @@ public function form($isEdit = false)
->SelectControl('save_path', admin_trans('admin.code_generators.save_path_select'))
->searchable()
->description(admin_trans('admin.code_generators.save_path_select_tips'))
->clearable()
->value('${default_path}')
->inputClassName('bg-gray-100')
->selectMode('group')
->source('${save_path_options}')
->onEvent([
Expand All @@ -255,6 +241,7 @@ public function form($isEdit = false)
],
],
],
$fillPathAction,
],
],
]),
Expand Down
1 change: 0 additions & 1 deletion src/Models/AdminCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ class AdminCodeGenerator extends BaseModel
'needs' => 'array',
'menu_info' => 'array',
'page_info' => 'array',
'save_path' => 'array',
];
}
1 change: 0 additions & 1 deletion src/Support/Cores/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public function up()
$table->text('needs')->nullable()->comment('需要生成的代码');
$table->text('menu_info')->nullable()->comment('菜单信息');
$table->text('page_info')->nullable()->comment('页面信息');
$table->text('save_path')->nullable()->comment('保存位置');
$table->timestamps();
});

Expand Down

0 comments on commit fe8e0b0

Please sign in to comment.