>[danger] layui 相关功能封装
```php
<?php
// 获取类的实例
// function layui()
// {
// return Layui::getInstance();
// }
/**
* layui接口数据格式规范封装
* @last modify time 2020-07-20
*/
class Layui
{
private static $obj;
// 禁止类在外部被克隆
private function __construct(){}
/**
* 获取类的实例
*/
public static function getInstance()
{
if (! self::$obj instanceof self) {
self::$obj = new self;
}
return self::$obj;
}
/**
* 数据表格接口数据规范
* layui()->table('', $count, $data)
*/
public function table($msg, $count, $data, $code = 0)
{
return json(compact('code', 'msg', 'count', 'data'));
}
/**
* 增删改
* layui()->res(200, '添加成功', $data)
*/
public function res($status, $msg, $data, $code = 0)
{
return json(compact('status', 'msg', 'data', 'code'));
}
public function rpsData($msg, $data, $code = 0)
{
return json(compact('code', 'msg', 'data'));
}
/**
* 分页参数
* list($page, $limit) = layui()->pageLimit();
*/
public function pageLimit()
{
return [input('get.page/d', 1), input('get.limit/d', 10)];
}
/**
* 数据表格搜索的字段
* list($field, $search) = layui()->search('id,name');
*/
public function search($fields)
{
$arr = explode(',', $fields);
$build = [];
foreach ($arr as $v) {
$key = trim($v);
if (empty($key)) continue;
$build[$key] = input('get.' . $key, '', 'trim');
}
return [array_keys($build), $build];
}
public function debug($data, $code = 0)
{
return json(compact('code', 'data'));
}
private function __clone(){}
}
```