🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 操作栏 > 图片示例: ![](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>`openTab`打开子页面、<br>`openPopup`打开弹出层页面<br>其他情况默认为`asyncEvent`异步事件 | | title | string | 否 | 标题 | | class | string | 否 | 额外的class,可含图标的`class` | | url | string | 否 | 触发事件执行的url,默认当前地址。<br>当`type=openTab或openPopup`时,会自动携带上id参数。 | | confirmText | string | 否 | 触发事件前,弹出确认弹窗,确认时间执行的提示 | | dropdown | bool | 否 | 是否下拉操作,默认`false` | > 提示:触发事件名为配置项key,主要用于type=asyncEvent的异步请求。 > 代码示例: ~~~ $builder=YT('general_example')->state([...]) ->cols(function($state){ $cols=[ 'id'=>['type'=>'checkbox'], // 字段name_cn,对应中文姓名表头 'name_cn'=>['title'=>'中文姓名'], // 操作栏 'action'=>[ 'title'=>'操作', 'templet'=>'action', // 避免和系统action函数名冲突 'options'=>[ 'edit'=>['type'=>'openPopup','title'=>'详情','icon'=>'layui-icon layui-icon-survey','url'=>url('edit')] ] ], ]; switch ($state){ case 11: $cols['action']['options']+=[ 22=>['type'=>'asyncEvent','title'=>'移入回收站','dropdown'=>true], ]; break; case 22: $cols['action']['options']+=[ 11=>['type'=>'asyncEvent','title'=>'还原','dropdown'=>true], 99=>['type'=>'asyncEvent','title'=>'永久删除','dropdown'=>true] ]; break; } return $cols; }) ->event(function ($event,$ids){ switch ($event){ case 11: foreach ($ids as $id){ Db::name('example')->where([ ['id','eq',$id], ['state','eq',22], ])->update(['update_time'=>time(),'state'=>11]); } return success_json(); case 22: foreach ($ids as $id){ Db::name('example')->where([ ['id','eq',$id], ['state','eq',11], ])->update(['update_time'=>time(),'state'=>22]); } return success_json(); case 99: foreach ($ids as $id){ Db::name('example')->where([ ['id','eq',$id], ['state','eq',22], ])->update(['update_time'=>time(),'state'=>99]); } return success_json(); default: return error_json(); } }) ~~~