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 {