mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +00:00
feat(CRUD):关联表指定远程select下拉字段 !11
This commit is contained in:
parent
74bfd23f5a
commit
6f90fb0035
@ -37,6 +37,8 @@ class Crud extends Command
|
||||
'relationmodel' => ['name' => 'relationmodel', 'shortcut' => 'e', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation model name', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
|
||||
'relationforeignkey' => ['name' => 'relationforeignkey', 'shortcut' => 'k', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation foreign key', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
|
||||
'relationprimarykey' => ['name' => 'relationprimarykey', 'shortcut' => 'p', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation primary key', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
|
||||
'remoteselectfield' => ['name' => 'remoteselectfield', 'shortcut' => 's', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'Remote select table field', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
|
||||
|
||||
'relationfields' => ['name' => 'relationfields', 'shortcut' => 'l', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation table fields', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
|
||||
'relationmode' => ['name' => 'relationmode', 'shortcut' => 'a', 'mode' => Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'description' => 'relation table mode,hasone or belongsto', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
|
||||
'delete' => ['name' => 'delete', 'shortcut' => 'd', 'mode' => Option::VALUE_OPTIONAL, 'description' => 'delete all files generated by CRUD', 'default' => null, 'solveArray' => false, 'setInputRule' => false],
|
||||
@ -407,6 +409,8 @@ class Crud extends Command
|
||||
$relationForeignKey = $this->getOption('relationforeignkey');
|
||||
// 主键
|
||||
$relationPrimaryKey = $this->getOption('relationprimarykey');
|
||||
// 远程下拉字段
|
||||
$remoteSelectField = $this->getOption('remoteselectfield');
|
||||
// 关联表显示字段
|
||||
$relationFields = $this->getOption('relationfields');
|
||||
|
||||
@ -500,6 +504,8 @@ class Crud extends Command
|
||||
'relationForeignKey' => $relationForeignKey[$index] ?? parse_name($relationName) . '_id',
|
||||
// 关联表主键
|
||||
'relationPrimaryKey' => $relationPrimaryKey[$index] ?? 'id',
|
||||
// 远程下拉字段
|
||||
'remoteSelectField' => $remoteSelectField[$index] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -766,7 +772,7 @@ class Crud extends Command
|
||||
$formFieldList[$field]['@keyup.enter.stop'] = '';
|
||||
$formFieldList[$field]['@keyup.ctrl.enter'] = 'baTable.onSubmit(formRef)';
|
||||
} elseif ($inputType == 'remoteSelect' || $inputType == 'remoteSelects') {
|
||||
$formFieldList[$field][':input-attr']['field'] = $this->getRemoteSelectField($field);
|
||||
$formFieldList[$field][':input-attr']['field'] = $this->getRemoteSelectField($field, $relations);
|
||||
$remoteUrl = $this->getRemoteSelectUrl($field, $relations, $webControllerUrls);
|
||||
$formFieldList[$field][':input-attr']['remote-url'] = $remoteUrl['url'];
|
||||
$formFieldList[$field][':input-attr']['pk'] = $remoteUrl['pk'];
|
||||
@ -1388,8 +1394,14 @@ class Crud extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getRemoteSelectField($fieldName)
|
||||
protected function getRemoteSelectField($fieldName, $relations=[])
|
||||
{
|
||||
$field = explode('_', $fieldName);
|
||||
foreach($relations as $relation){
|
||||
if($relation['remoteSelectField'] && $relation['relationTableTypeName'] == $field[0]){
|
||||
return $relation['remoteSelectField'];
|
||||
}
|
||||
}
|
||||
foreach ($this->remoteSelectFieldMap as $field => $item) {
|
||||
if (in_array($fieldName, $item)) {
|
||||
return $field;
|
||||
|
Loading…
Reference in New Issue
Block a user