增加查看crud接口

This commit is contained in:
liaofei 2023-04-12 16:59:17 +08:00
parent 70659e5cc9
commit da9bacdc9f
5 changed files with 48 additions and 4 deletions

View File

@ -136,6 +136,42 @@ class SystemCrud extends AuthController
return app('json')->success(compact('makePath', 'tableField'));
}
/**
* @param $id
* @return \think\Response
* @author 等风来
* @email 136327134@qq.com
* @date 2023/4/12
*/
public function read($id)
{
if (!$id) {
return app('json')->fail('缺少参数');
}
$info = $this->services->get($id);
if (!$info) {
return app('json')->fail('查看的生成的文件不存在');
}
$routeName = 'crud/' . Str::snake($info->table_name);
$make = $this->services->makeFile($info->table_name, $routeName, false, [
'menuName' => $info->name,
'fromField' => $info->field['fromField'] ?? [],
'columnField' => $info->field['columnField'] ?? [],
]);
$data = [];
foreach ($make as $item) {
$item['name'] = pathinfo($item['path'])['basename'] ?? '';
$data[] = $item;
}
return app('json')->success($data);
}
/**
* 获取tree菜单
* @return \think\Response

View File

@ -141,6 +141,8 @@ Route::group('system', function () {
Route::post('crud/file_path', 'v1.setting.SystemCrud/getFilePath')->option(['real_name' => '获取CRUD文件存放']);
//删除CRUD
Route::delete('crud/:id', 'v1.setting.SystemCrud/delete')->option(['real_name' => '删除CRUD']);
//查看CRUD
Route::get('crud/:id', 'v1.setting.SystemCrud/read')->option(['real_name' => '查看CRUD']);
//获取CRUD列表
Route::get('crud', 'v1.setting.SystemCrud/index')->option(['real_name' => '获取CRUD列表']);
//保存生成CRUD

View File

@ -35,4 +35,9 @@ class SystemCrud extends BaseModel
* @var string
*/
protected $pk = 'id';
public function getAddTimeAttr($value)
{
return date('Y-m-d H:i:s', $value);
}
}

View File

@ -72,7 +72,7 @@ class SystemCrudServices extends BaseServices
public function getList()
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->selectList([], '*', $page, $limit, 'id desc');
$list = $this->dao->selectList([], 'add_time,id,name,table_name', $page, $limit, 'id desc');
$count = $this->dao->count();
return compact('list', 'count');

View File

@ -422,14 +422,15 @@ abstract class Make
$pathname = $this->filePathName ?: $pathname;
if (is_file($pathname)) {
throw new CrudException($this->name . ':' . $pathname . ' already exists!');
}
$content = str_replace('', '', $content);
if ($this->isMake) {
if (is_file($pathname)) {
throw new CrudException($this->name . ':' . $pathname . ' already exists!');
}
try {
if (!is_dir(dirname($pathname))) {
mkdir(dirname($pathname), 0755, true);