1、行添加自定义按钮
<?phpnamespace app\controller;use app\BaseController;class User extends BaseController{ use \tpScriptVueCurd\base\controller\Controller; public function init(): void { $this->title='人员信息'; $this->md=\app\model\User::make($this); } /** * 列表按钮组左侧 (--模型中同样存在此方法--) * @param BaseModel $info 当前行信息 * @param FieldCollection $fields * @param BaseModel|null $parentInfo * @param \think\model\Collection $list 列表信息 * @return RowBtn[]|OpenBtn[] */ public function getListRowBeforeBtns(BaseModel $info, FieldCollection $fields, ?BaseModel $parentInfo, \think\model\Collection $list): array { $btn=new RowBtn(); $btn->btnTitle='作废'; $btn->btnColor='#fa541c'; $btn->modalTitle='填写作废信息'; $btn->modalH='300px'; //打开页面后要填写的字段信息。!!!如果没有字段信息,将会弹出一个确认操作,点击确认后直接执行saveUrl $btn->modalFields=FieldCollection::make([ TextField::init('remark','作废理由') ->required(true), DateField::init('date_time','作废时间') ->showTime(true) ->editExplain('不填写默认为当前时间') ]); $btn->saveUrl=url('doNullify')->build();//处理填写信息的操作地址 $btn->saveBtnTitle='确定作废'; $btn2=new OpenBtn(); $btn2->btnTitle='按钮2'; $btn2->modalTitle='按钮2标题'; //可以在新打开的页面中操作列表页面,根据JS对象window.listVue //比如操作成功后刷新列表(ajax请求结束后): //window.listVue.refreshTable();//刷新(父页面)列表 //document.body.dispatchEvent(new Event('closeIframe'));//关闭当前页面 $btn2->modalUrl='/index'; $btn2->btnType='warning'; return [ $btn,$btn2,$btn3 ]; } /** * 列表按钮组右侧 (--模型中同样存在此方法--) * @param BaseModel $info 当前行信息 * @param FieldCollection $fields * @param BaseModel|null $parentInfo * @param \think\model\Collection $list 列表信息 * @return RowBtn[]|OpenBtn[] */ public function getListRowAfterBtns(BaseModel $info, FieldCollection $fields, ?BaseModel $parentInfo, \think\model\Collection $list): array { return []; }}
2、修改详情、编辑按钮文字与打开窗口信息
<?php
namespace app\controller;
use app\BaseController;
class User extends BaseController
{
use \tpScriptVueCurd\base\controller\Controller;
public function init(): void
{
$this->title='人员信息';
$this->md=\app\model\User::make($this);
}
/**
* 对列表给到前端的数据进行处理
* @param FunControllerIndexData $option
* @return void
*/
protected function indexData(FunControllerIndexData $option): void
{
foreach ($option->data as $v){
//更改详情按钮
/**
* @var OpenBtn $showBtn
*/
$showBtn=$v['showBtn'];
$showBtn->btnTitle='详情';
$showBtn->modalTitle='查看 '.$this->title.' 相关信息';
$showBtn->modalUrl=url('show',[
'base_id'=>$option->parentInfo&&!empty($option->parentInfo->id)?$option->parentInfo->id:0,
'id'=>$v['id']
])->build();
//更改修改按钮
/**
* @var OpenBtn $editBtn
*/
$editBtn=$v['editBtn'];
//更改添加下级按钮
/**
* @var OpenBtn $childAddBtn
*/
$childAddBtn=$v['childAddBtn'];
}
}
}