From 34e5b974f9039f92a95e6f7be973ea5d6d69a08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=99=E7=A0=81=E7=94=9F=E8=8A=B1?= <18523774412@qq.com> Date: Mon, 26 Feb 2024 04:30:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E6=9B=B4=E6=96=B0=E8=A1=A8=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E5=92=8C=E5=88=A0=E9=99=A4=E8=A1=A8=E5=9D=87=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E5=8F=AF=E4=BB=A5=E4=BD=BF=E7=94=A8=20phinx=20?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/crud/Crud.php | 12 ++++++++---- app/admin/library/crud/Helper.php | 12 ++---------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/admin/controller/crud/Crud.php b/app/admin/controller/crud/Crud.php index 078f23bf..c1d16fe8 100644 --- a/app/admin/controller/crud/Crud.php +++ b/app/admin/controller/crud/Crud.php @@ -88,17 +88,17 @@ class Crud extends Backend 'status' => 'start', ]); + // 表名称 + $tableName = TableManager::tableName($table['name'], false); + if ($type == 'create' || $table['rebuild'] == 'Yes') { // 数据表存在则删除 - Helper::delTable($table['name']); + TableManager::phinxTable($tableName)->drop()->save(); } // 处理表设计 [$tablePk] = Helper::handleTableDesign($table, $fields); - // 表名称 - $tableName = TableManager::tableName($table['name'], false); - // 表注释 $tableComment = mb_substr($table['comment'], -1) == '表' ? mb_substr($table['comment'], 0, -1) . '管理' : $table['comment']; @@ -757,6 +757,10 @@ class Crud extends Backend } } + /** + * 组装前台表单的数据 + * @throws Throwable + */ private function getFormField($field, $columnDict): array { // 表单项属性 diff --git a/app/admin/library/crud/Helper.php b/app/admin/library/crud/Helper.php index c22c0aa4..d5243e39 100644 --- a/app/admin/library/crud/Helper.php +++ b/app/admin/library/crud/Helper.php @@ -480,9 +480,9 @@ class Helper if ($adapter->hasTable($name)) { // 更新表 - TableManager::changeComment($name, $comment); if ($designChange) { $table = TableManager::phinxTable($name, [], false); + $table->changeComment($comment)->update(); // 改名和删除操作优先 $priorityOpt = false; @@ -727,17 +727,9 @@ class Helper return str_pad('', 4 * $num); } - /** - * 删除数据表 - */ - public static function delTable(string $table): void - { - $sql = 'DROP TABLE IF EXISTS `' . TableManager::tableName($table) . '`'; - Db::execute($sql); - } - /** * 根据数据表解析字段数据 + * @throws Throwable */ public static function parseTableColumns(string $table, bool $analyseField = false): array {