在**应用根目录/common/model**下面,新建**Common.php**,封装layui需要返回的数据格式 ``` <?php // +---------------------------------------------------------------------- // | najing [ 通用后台管理系统 ] // +---------------------------------------------------------------------- // | Copyright (c) 2020 http://www.najingquan.com All rights reserved. // +---------------------------------------------------------------------- // | Author: 救火队队长 // +---------------------------------------------------------------------- namespace app\common\model; use think\Model; class Common extends Model { /** * 格式化返回layui需要的格式化数据 * @author 救火队队长 */ public function tableData($post) { if (isset($post['limit'])) { $limit = $post['limit']; } else { $limit = config('paginate.list_rows'); } $tableWhere = $this->tableWhere($post); $list = $this->field($tableWhere['field'])->where($tableWhere['where'])->order($tableWhere['order'])->paginate($limit); $data = $this->tableFormat($list->getCollection()); //返回的数据格式化,并渲染成table所需要的最终的显示数据类型 $re['code'] = 0; $re['msg'] = ''; $re['count'] = $list->total(); $re['data'] = $data; return $re; } /** * 根据输入的查询条件,返回所需要的where * @author 救火队队长 */ protected function tableWhere($post) { $result['where'] = []; $result['field'] = "*"; $result['order'] = []; return $result; } /** * 根据查询结果,格式化数据 * @author 救火队队长 */ protected function tableFormat($list) { return $list; } } ```