ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 操作栏 > 图片示例: ![](https://img.kancloud.cn/92/82/9282f509b92a6f2569f3af35474a7ebd_1920x903.png) > 配置项 | key | 类型 | 是否必须 | 说明 | | --- | --- | --- | --- | | templet | string | 是 | 固定值:`action` | | 通用配置... | | title | string | 否 | 表头标题,默认`操作` | | align | string | 否 | 排列方式,可选值`left`、`center`、`right`,默认`center` | | fixed | bool或string | 否 | 列固定,可选值`left`、`right`、`(bool)false`,默认`right` | | options | array | 是 | 操作项,详见下面`操作项配置` | > 操作项配置 | key | 类型 | 是否必须 | 说明 | | --- | --- | --- | --- | | type | string | 是 | 触发事件类型,可选值:<br>`open_tab`打开子页面、<br>`open_popup`打开弹出层页面、<br>`async_event`异步事件 | | title | string | 否 | 标题 | | event | string | 否 | 触发事件名,主要用于type=async_event的异步请求。默认为当前设置项的`key`值 | | icon | string | 否 | 显示图标的`class` | | url | string | 否 | 触发事件执行的url,默认当前表格地址 | | confirm_text | string | 否 | 触发事件前,弹出确认弹窗,确认时间执行的提示 | | dropdown | bool | 否 | 是否下拉操作,默认`false` | > 代码示例: ~~~ $builder=YT('general_example')->state(DbRowState::state()) ->cols(function($state){ $cols=[ 'id'=>['type'=>'checkbox'], // 字段name_cn,对应中文姓名表头 'name_cn'=>['title'=>'中文姓名'], // 操作栏 'action'=>[ 'title'=>'操作', 'templet'=>'action', // 避免和系统action函数名冲突 'options'=>[ 'edit'=>['type'=>'open_popup','title'=>'详情','icon'=>'layui-icon layui-icon-survey','url'=>url('edit')] ] ], ]; switch ($state){ case DbRowState::ACTIVE: $cols['action']['options']+=[ DbRowState::TRASH=>['type'=>'async_event','title'=>'移入回收站','dropdown'=>true], ]; break; case DbRowState::TRASH: $cols['action']['options']+=[ DbRowState::ACTIVE=>['type'=>'async_event','title'=>'还原','dropdown'=>true], DbRowState::REMOVED=>['type'=>'async_event','title'=>'永久删除','dropdown'=>true] ]; break; } return $cols; }) ->event(function ($event,$ids){ switch ($event){ case DbRowState::ACTIVE: foreach ($ids as $id){ Db::name('example')->where([ ['id','eq',$id], ['state','eq',DbRowState::TRASH], ])->update(['update_time'=>time(),'state'=>DbRowState::ACTIVE]); } return success_json(); case DbRowState::TRASH: foreach ($ids as $id){ Db::name('example')->where([ ['id','eq',$id], ['state','eq',DbRowState::ACTIVE], ])->update(['update_time'=>time(),'state'=>DbRowState::TRASH]); } return success_json(); case DbRowState::REMOVED: foreach ($ids as $id){ Db::name('example')->where([ ['id','eq',$id], ['state','eq',DbRowState::TRASH], ])->update(['update_time'=>time(),'state'=>DbRowState::REMOVED]); } return success_json(); default: return error_json(); } }) ~~~