From da2ae8122b2cc26b2ee68825f5ad7336964bbec7 Mon Sep 17 00:00:00 2001 From: "2368302435@qq.com" <2368302435@qq.com> Date: Fri, 1 Mar 2024 19:14:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E8=8E=B7=E5=8F=96=E8=A1=A8=E4=B8=BB?= =?UTF-8?q?=E9=94=AE=E5=AD=97=E6=AE=B5=E6=8E=A5=E5=8F=A3=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Ajax.php | 11 +++++++---- web/src/api/common.ts | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/admin/controller/Ajax.php b/app/admin/controller/Ajax.php index 20368ef2..d0297ff0 100644 --- a/app/admin/controller/Ajax.php +++ b/app/admin/controller/Ajax.php @@ -86,20 +86,23 @@ class Ajax extends Backend /** * 获取表主键字段 * @param ?string $table + * @param ?string $connection * @throws Throwable */ - public function getTablePk(?string $table = null): void + public function getTablePk(?string $table = null, ?string $connection = null): void { if (!$table) { $this->error(__('Parameter error')); } - $table = TableManager::tableName($table); - if (!TableManager::phinxAdapter(false)->hasTable($table)) { + $table = TableManager::tableName($table, true, $connection); + if (!TableManager::phinxAdapter(false, $connection)->hasTable($table)) { $this->error(__('Data table does not exist')); } - $tablePk = Db::table($table)->getPk(); + $tablePk = Db::connect(TableManager::getConnection($connection)) + ->table($table) + ->getPk(); $this->success('', ['pk' => $tablePk]); } diff --git a/web/src/api/common.ts b/web/src/api/common.ts index 12ab3047..3b4392e8 100644 --- a/web/src/api/common.ts +++ b/web/src/api/common.ts @@ -245,12 +245,13 @@ export function checkClickCaptcha(id: string, info: string, unset: boolean) { ) } -export function getTablePk(table: string) { +export function getTablePk(table: string, connection = '') { return createAxios({ url: getTablePkUrl, method: 'get', params: { table: table, + connection: connection, }, }) }