fetch(); } /** * @NodeAnnotation(title="操作") * @throws TableException */ public function save(Request $request, string $type = ''): ?Json { if (!$request->isAjax()) $this->error(); $tb_prefix = $request->param('tb_prefix/s', ''); $tb_name = $request->param('tb_name/s', ''); if (empty($tb_name)) $this->error('参数错误'); switch ($type) { case "search": try { $list = Db::query("SHOW FULL COLUMNS FROM {$tb_prefix}{$tb_name}"); $data = []; foreach ($list as $value) { $data[] = [ 'name' => $value['Field'], 'type' => $value['Type'], 'key' => $value['Key'], 'extra' => $value['Extra'], 'null' => $value['Null'], 'desc' => $value['Comment'], ]; } $this->success('查询成功', compact('data', 'list')); }catch (PDOException $exception) { $this->error($exception->getMessage()); } break; case "add": $force = $request->post('force/d', 0); try { $build = (new BuildCurd())->setTablePrefix($tb_prefix)->setTable($tb_name); $build->setForce($force); // 强制覆盖 $build = $build->render(); $fileList = $build->getFileList(); if (empty($fileList)) $this->error('这里什么都没有'); $result = $build->create(); $_file = $result[0] ?? ''; $link = ''; if (!empty($_file)) { $_fileExp = explode(DIRECTORY_SEPARATOR, $_file); $_fileExp_last = array_slice($_fileExp, -2); $_fileExp_last_0 = $_fileExp_last[0] . '.'; if ($_fileExp_last[0] == 'controller') $_fileExp_last_0 = ''; $link = '/' . env('EASYADMIN.ADMIN', 'admin') . '/' . $_fileExp_last_0 . Str::snake(explode('.php', end($_fileExp_last))[0] ?? '') . '/index'; } $this->success('生成成功', compact('result', 'link')); }catch (FileException $exception) { return json(['code' => -1, 'msg' => $exception->getMessage()]); } break; case "delete": try { $build = (new BuildCurd())->setTablePrefix($tb_prefix)->setTable($tb_name); $build = $build->render(); $fileList = $build->getFileList(); if (empty($fileList)) $this->error('这里什么都没有'); $result = $build->delete(); $this->success('删除自动生成CURD文件成功', compact('result')); }catch (FileException $exception) { return json(['code' => -1, 'msg' => $exception->getMessage()]); } break; default: $this->error('参数错误'); break; } } }