Owl Admin 中文文档


<h2><strong>删除按钮</strong></h2> <ul> <li>控制器中的 <code>list</code> 方法负责构建数据列表</li> </ul> <pre><code class="language-php">public function list() { $crud = $this-&amp;gt;baseCRUD() // 配置 CRUD 组件的批量操作 -&amp;gt;bulkActions([ $this-&amp;gt;bulkDeleteButton() // 批量删除按钮 // 批量删除按钮会携带选中的主键字段, 发起 ajax 请求, 实现删除功能 ]) -&amp;gt;columns([ amis()-&amp;gt;TableColumn()-&amp;gt;label('ID')-&amp;gt;name('id')-&amp;gt;sortable(), // ... // 这里是列表的行内操作按钮 $this-&amp;gt;rowActions([ $this-&amp;gt;rowEditButton(true), // 编辑按钮 $this-&amp;gt;rowDeleteButton(), // 删除按钮 // 删除按钮会携带主键字段, 发起 ajax 请求, 实现删除功能 ]), ]); return $this-&amp;gt;baseList($crud); }</code></pre> <p>&lt;br&gt;</p> <h2><strong>删除逻辑</strong></h2> <ul> <li>通过列表上的操作按钮, 请求到 <code>AdminController</code> 中的 <code>destroy</code> 方法, 实现删除功能</li> <li>如果有自定义删除逻辑的需求, 可以在对应的 <code>service</code> 中, 重写 <code>delete</code> 方法</li> </ul> <pre><code class="language-php">/** * 删除 * * @param $ids * * @return JsonResponse|JsonResource */ public function destroy($ids) { $rows = $this-&amp;gt;service-&amp;gt;delete($ids); return $this-&amp;gt;autoResponse($rows, __('admin.delete')); } /** * service 中实际处理删除逻辑的方法, 可以在自己的 service 中重写该方法 * * @param string $ids * * @return mixed */ public function delete(string $ids): mixed { return $this-&amp;gt;query()-&amp;gt;whereIn($this-&amp;gt;primaryKey(), explode(',', $ids))-&amp;gt;delete(); }</code></pre>

页面列表

ITEM_HTML