fix(CRUD):修复在多数据库场景中远程下拉组件的 pk 属性可能错误的问题

This commit is contained in:
妙码生花 2024-09-23 20:27:25 +08:00
parent b8ce675ae8
commit 3783cd1d2f

View File

@ -196,7 +196,7 @@ class Crud extends Backend
// 表单项
if (in_array($field['name'], $table['formFields'])) {
$this->formVueData['formFields'][] = $this->getFormField($field, $columnDict);
$this->formVueData['formFields'][] = $this->getFormField($field, $columnDict, $table['databaseConnection']);
}
// 表格列
@ -653,8 +653,14 @@ class Crud extends Backend
$columns[$relationField]['table']['show'] = 'false';
$columns[$relationField]['table']['operator'] = 'FIND_IN_SET';
$columns[$relationField]['table']['comSearchRender'] = 'remoteSelect';
$pk = $field['form']['remote-pk'] ?? 'id';
if (!str_contains($pk, '.')) {
$pk = TableManager::tableName($field['form']['remote-table'], true, $table['databaseConnection']) . '.' . $pk;
}
$columns[$relationField]['table']['remote'] = [
'pk' => TableManager::tableName($field['form']['remote-table']) . '.' . ($field['form']['remote-pk'] ?? 'id'),
'pk' => $pk,
'field' => $field['form']['remote-field'] ?? 'name',
'remoteUrl' => $this->getRemoteSelectUrl($field),
'multiple' => 'true',
@ -753,7 +759,7 @@ class Crud extends Backend
* 组装前台表单的数据
* @throws Throwable
*/
private function getFormField($field, $columnDict): array
private function getFormField($field, $columnDict, ?string $dbConnection = null): array
{
// 表单项属性
$formField = [
@ -771,7 +777,12 @@ class Crud extends Backend
$formField['@keyup.enter.stop'] = '';
$formField['@keyup.ctrl.enter'] = 'baTable.onSubmit(formRef)';
} elseif ($field['designType'] == 'remoteSelect' || $field['designType'] == 'remoteSelects') {
$formField[':input-attr']['pk'] = TableManager::tableName($field['form']['remote-table']) . '.' . ($field['form']['remote-pk'] ?? 'id');
$pk = $field['form']['remote-pk'] ?? 'id';
if (!str_contains($pk, '.')) {
$pk = TableManager::tableName($field['form']['remote-table'], true, $dbConnection) . '.' . $pk;
}
$formField[':input-attr']['pk'] = $pk;
$formField[':input-attr']['field'] = $field['form']['remote-field'] ?? 'name';
$formField[':input-attr']['remoteUrl'] = $this->getRemoteSelectUrl($field);
} elseif ($field['designType'] == 'number') {