在陪玩系统源码开发过程中,需要实现的列表页面还是非常多的,如何保证列表页面的流畅、整洁很重要,接下来我们一起来看看具体的实现代码吧。route.php<?phpusethink\Route;Route::get('test','api/test/index');Route::put('test/:id','api/test/update');Route::delete('test/:id','api/test/delete');Route::resource('test','api/test');Route::get('api/:ver/cat','api/:ver.cat/read');Route::get('api/:ver/index','api/:ver.index/index');Route::resource('api/:ver/news','api/:ver.news');News.php(Model)<?php/CreatedbyPhpStorm.User:tongDate:2017/11/20Time:16:34/namespaceapp\common\model;classNewsextendsBase{publicfunctiongetNews($data=[]){$data['status']=['neq',config('code.status_delete'),];$order=['id'=>'desc'];$result=$this->where($data)->order($order)->paginate();return$result;}publicfunctiongetNewsByCondition($condition=[],$from,$size=5){if(!isset($condition['status'])){$condition['status']=['neq',config('code.status_delete')];}$order=['id'=>'desc'];$result=$this->where($condition)->field($this->getListField())->limit($from,$size)->order($order)->select();return$result;}publicfunctiongetNewsByCountCondition($condition=[]){if(!isset($condition['status'])){$condition['status']=['neq',config('code.status_delete')];}return$this->where($condition)->count();}publicfunctiongetIndexHadNormalNews($num=4){$data=['status'=>1,'is_head_figure'=>1,];$order=['id'=>'desc',];return$this->where($data)->field($this->getListField())->order($order)->limit($num)->select();}publicfunctiongetPositionNormalNews($num=20){$data=['status'=>1,'is_position'=>1,];$order=['id'=>'desc',];return$this->where($data)->field($this->getListField())->order($order)->limit($num)->select();}privatefunctiongetListField(){return['id','catid','image','title','read_count','status','is_position','update_time','create_time',];}}->field($this->getListField())privatefunctiongetListField(){return['id','catid','image','title','read_count','status','is_position','update_time','create_time',];}Common.php<?php/CreatedbyPhpStorm.User:tongDate:2017/11/23Time:11:30/namespaceapp\api\controller;useapp\common\lib\Aes;useapp\common\lib\exception\ApiException;useapp\common\lib\IAuth;useapp\common\lib\Time;usethink\Cache;usethink\Controller;classCommonextendsController{public$headers='';public$page=1;public$size=5;public$from=0;protectedfunction_initialize(){$this->checkRequestAuth();//$this->testAes();}publicfunctioncheckRequestAuth(){$headers=request()->header();if(empty($headers['sign'])){thrownewApiException('sign不存在',400);}if(!in_array($headers['app_type'],config('app.apptypes'))){thrownewApiException('app_type不合法',400);}if(!IAuth::checkSignPass($headers)){thrownewApiException('授权码sign失败',401);}Cache::set($headers['sign'],config('app.app_sign_cache_time'));$headers=$this->headers;}publicfunctiontestAes(){$data=['did'=>'12345dg','version'=>1,'time'=>Time::get13TimeStamp(),];//$str='sRCvj52mZ8G+u2OdHYwmysvczmCw+RrAYWiEaXFI/5A=';//echo(newAes())->decrypt($str);//exit;echoIAuth::setSign($data);exit;}publicfunctiongetDealNews($news=[]){if(empty($news)){return[];}$cats=config('cat.list');foreach($newsas$key=>$new){$news[$key]['catname']=$cats[$new['catid']]?$cats[$new['catid']]:'-