feat(curd):支持CURD自动生成回收站功能 add recycle functionality for soft deleted items

- Add recycle method to Curd trait for restoring or permanently deleting items
- Implement recycle view and update index view to include recycle button-Add recycle URL and functionality to JavaScript table initialization
- Create new recycle template files for view and JavaScript
This commit is contained in:
wolfcode
2025-04-08 10:43:27 +08:00
parent 74122885f1
commit b8ccf1542b
7 changed files with 136 additions and 34 deletions

View File

@@ -132,35 +132,4 @@ EOF;
$this->success('success', compact('choices'));
}
#[NodeAnnotation(title: '回收站', auth: true)]
public function recycle(Request $request): Json|string
{
if (!$request->isAjax()) {
return $this->fetch();
}
$id = $request->param('id', []);
$type = $request->param('type', '');
switch ($type) {
case 'restore':
self::$model::withTrashed()->whereIn('id', $id)->update(['delete_time' => null, 'update_time' => time()]);
$this->success('success');
break;
case 'delete':
self::$model::destroy($id, true);
$this->success('success');
break;
default:
list($page, $limit, $where) = $this->buildTableParams();
$count = self::$model::withTrashed()->whereNotNull('delete_time')->count();
$list = self::$model::withTrashed()->with(['cate'])->where($where)->page($page, $limit)->order($this->sort)->whereNotNull('delete_time')->select()->toArray();
$data = [
'code' => 0,
'msg' => '',
'count' => $count,
'data' => $list,
];
return json($data);
}
}
}