方法:addToparea($default=[],$custom=[],$items=[],$form=[])

参数 含义 类型
default 默认按钮 array
custom 自定义按钮 array
items 搜索表单项 array
form 搜索表单form array

返回:Widget

default参数如下

['add'=>[$href,$is_pop],'delete','disable','enable'] 可以是其中1个按钮或多个按钮,其中add按钮可以设置是否弹窗

custom数组元素结构,数见button,须为关联数组


## items数组元素结构 第一个参数是表单项的标识符,其他为该表单项的参数,参数顺序与标识符所代表的表单项参数顺序一致。比如下面的标识符是text,那么标识该表单项为单行文本框,参数顺序要按单行文本框的写。 > 注意:部分表单项attr有'is_formgroup'属性的需要设置为**false**

form参数

参数 含义 类型
href form的url string
class form的样式 string
id form的id string
    /**
     * 文章列表
     */
	public function newsIndex()
	{
		$keytype=input('keytype','title');
		$key=input('key','');
		$lang=input('lang','');
		$status=input('status','');
		$cid=input('cid','');
		$diyflag=input('diyflag','');
		//查询:时间格式过滤 获取格式 2015-11-12 - 2015-11-18
		$sldate=input('reservation','');
		$arr = explode(" - ",$sldate);
        $map=[];
        if(count($arr)==2){
            $arrdateone=strtotime($arr[0]);
            $arrdatetwo=strtotime($arr[1].' 23:55:55');
            $map[] =['a.create_time','between',[$arrdateone,$arrdatetwo]];
        }
		//map架构查询条件数组
		$map[]= ['is_back','=',0];
		if(!empty($key)){
			if($keytype=='title'){
				$map[]= ['a.title','like',"%".$key."%"];
			}elseif($keytype=='username'){
				$map[]= array('b.username','like',"%".$key."%");
			}else{
				$map[]= [$keytype,'=',$key];
			}
		}
		if ($status!=''){
			$map[]= array('a.status','=',$status);
		}
		if (!empty($lang)){
			$map[]= array('a.lang','=',$lang);
		}
        if(!config('lang_switch_on')){
            $map[]=['a.lang','=',$this->lang];
        }
		if ($cid){
			$ids=get_menu_byid($cid,1,2);
			$map[]= array('a.cid','in',implode(",", $ids));
		}
        if($diyflag){
		    $map[]=['','exp',Db::raw("FIND_IN_SET('$diyflag',flags)")];;
        }
		$news_model=new NewsModel;
		$news=$news_model->alias("a")->field('a.*,b.username,c.name')
				->join(config('database.prefix').'user b','a.author =b.id')
				->join(config('database.prefix').'menu c','a.cid =c.id')
				->where($map)->order('a.create_time desc')->paginate(config('paginate.list_rows'),false,['query'=>get_query()]);
        $page = $news->render();
        $page=preg_replace("(]*page[=|/](\d+).+?>(.+?)<\/a>)","$2",$page);
        $data=$news->items();
		//文章属性数据
        $common_model=new CommonModel();
        $diyflag_list=Cache::get('flags');
        if(!$diyflag_list){
            $diyflag_list=$common_model->setTable(config('database.prefix').'flags')->setPk('id')->column('name','value');
            Cache::set('flags',$diyflag_list);
        }
		//栏目数据
		$menu_text=menu_text($this->lang);
        //表格字段
        $fields=[
            ['title'=>'排序','field'=>'sort','type'=>'input'],
            ['title'=>'ID','field'=>'id'],
            ['title'=>'作者','field'=>'username'],
            ['title'=>'文章标题','field'=>'title'],
            ['title'=>'所属栏目','field'=>'name'],
            ['title'=>'状态','field'=>'status','type'=>'switch','url'=>url('newsState')],
            ['title'=>'发布时间','field'=>'create_time','type'=>'date']
        ];
        $pk='id';
        //右侧操作按钮
        $right_action=[
            'edit'=>['href'=>url('newsEdit'),'is_pop'=>1],
            'delete'=>url('newsDel')
        ];
        $order=url('newsOrder');
        $delall=url('newsAlldel');
        $search=[
            ['select','keytype','',['title'=>'按标题','author'=>'按发布人ID','username'=>'按发布人名'],$keytype,'','',['is_formgroup'=>false],'class'=>''],
            ['select','cid','',$menu_text,$cid,'','',['is_formgroup'=>false,'default'=>'按栏目'],'class'=>'ajax_change'],
            ['select','lang','',['zh-cn'=>'中文','en-us'=>'英语'],$lang,'','',['is_formgroup'=>false,'default'=>'按语言'],'ajax_change'],
            ['select','diyflag','',$diyflag_list,$diyflag,'','',['is_formgroup'=>false,'default'=>'按属性'],'ajax_change'],
            ['select','status','',['1'=>'已启用','0'=>'未启用'],$status,'','',['is_formgroup'=>false,'default'=>'按状态'],'ajax_change'],
            ['daterange','reservation','',$sldate,'',['is_formgroup'=>false,'placeholder'=>'点击选择日期范围'],'','height:30px;margin:auto 2px;'],
            ['text','key','',$key,'','','text',['placeholder'=>'输入需查询的关键字','is_formgroup'=>false],'search-query'],
            ['button','搜索',['class'=>'btn btn-purple btn-sm search-query ajax-search-form','type'=>'submit','icon_l'=>'ace-icon fa fa-search icon-on-right bigger-110']]
        ];
        $form=[
            'href'=>url('newsIndex'),
            'class'=>'form-search',
            'id'=>'list-filter'
        ];
        //实例化表单类
        $widget=new Widget();
		if(request()->isAjax()){
            return $widget
                ->form('table',$fields,$pk,$data,$right_action,$page,$order,$delall,1);
		}else{
            return $widget
                ->addToparea(['add'=>['href'=>url('newsAdd'),'is_pop'=>1]],[],$search,$form)
                ->addtable($fields,$pk,$data,$right_action,$page,$order,$delall)
                ->setButton()
                ->fetch();
		}

顶部按钮及搜索