feat: 生成表单时在添加页面默认读取get参数预设值

This commit is contained in:
augushong
2025-03-21 13:20:45 +08:00
parent 3f98cf0b5b
commit d85f98a869
2 changed files with 11 additions and 8 deletions

View File

@@ -1266,6 +1266,9 @@ class BuildCurdServiceBase
continue;
}
$defaultFromRequestComponent = '{$Request.param.' . $field . '|default=\'' . $val['default'] . '\'}';
$defaultFromRequestVar = '$Request.param.' . $field;
$templateFile = "view{$this->DS}module{$this->DS}input";
$define = '';
@@ -1295,12 +1298,12 @@ class BuildCurdServiceBase
} elseif ($val['formType'] == 'radio' || $val['formType'] == 'switch') {
$templateFile = "view{$this->DS}module{$this->DS}radio";
if (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildRadioView($field, '{in name="k" value="' . $val['default'] . '"}checked=""{/in}');
$define = $this->buildRadioView($field, '{in name="k" value="' . $defaultFromRequestVar . '"}checked=""{/in}');
}
} elseif ($val['formType'] == 'checkbox') {
$templateFile = "view{$this->DS}module{$this->DS}checkbox";
if (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildCheckboxView($field, '{in name="k" value="' . $val['default'] . '"}checked=""{/in}');
$define = $this->buildCheckboxView($field, '{in name="k" value="' . $defaultFromRequestVar . '"}checked=""{/in}');
}
} elseif ($val['formType'] == 'select') {
$templateFile = "view{$this->DS}module{$this->DS}select";
@@ -1308,7 +1311,7 @@ class BuildCurdServiceBase
// TODO:这里的兼容关联不知道还有没有用,可能是技术债务,需要清理
$define = $this->buildOptionView($val['bindRelation']);
} elseif (isset($val['define']) && !empty($val['define'])) {
$define = $this->buildOptionView($field);
$define = $this->buildOptionView($field, '{in name="k" value="' . $defaultFromRequestVar . '"}selected=""{/in}');
}
} elseif (in_array($field, ['remark']) || $val['formType'] == 'textarea') {
$templateFile = "view{$this->DS}module{$this->DS}textarea";
@@ -1319,13 +1322,13 @@ class BuildCurdServiceBase
$templateFile = "view{$this->DS}module{$this->DS}table";
$define = $this->buildTableView($field, $val, $val['default']);
$define = $this->buildTableView($field, $val, $defaultFromRequestComponent);
} elseif ($val['formType'] == 'table') {
$templateFile = "view{$this->DS}module{$this->DS}table";
$define = $this->buildTableView($field, $val, $val['default']);
$define = $this->buildTableView($field, $val, $defaultFromRequestComponent);
} elseif ($val['formType'] == 'city') {
$templateFile = "view{$this->DS}module{$this->DS}city";
$define = $this->buildCityView($field, $val, $val['default']);
$define = $this->buildCityView($field, $val, $defaultFromRequestComponent);
} elseif ($val['formType'] == 'tag') {
$templateFile = "view{$this->DS}module{$this->DS}tag";
}
@@ -1337,7 +1340,7 @@ class BuildCurdServiceBase
'field' => $field,
'required' => $this->buildRequiredHtml($val['required']),
'required_text' => $val['required'] ? '1' : '',
'value' => $val['default'],
'value' => $defaultFromRequestComponent,
'define' => $define,
]
);

View File

@@ -2,7 +2,7 @@ var init = {
tableElem: '#currentTable',
tableRenderId: 'currentTableRenderId',
indexUrl: '{{controllerUrl}}/index',
addUrl: '{{controllerUrl}}/add',
addUrl: '{{controllerUrl}}/add' + location.search,
editUrl: '{{controllerUrl}}/edit',
deleteUrl: '{{controllerUrl}}/delete',
exportUrl: '{{controllerUrl}}/export',