更新
This commit is contained in:
@@ -10,9 +10,9 @@ declare (strict_types = 1);
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
class Api{
|
||||
use app\services\auth\UsersLogService;
|
||||
|
||||
public $data = ['code' => 1, 'data' => '', 'message' => ''];
|
||||
class Api{
|
||||
|
||||
/**
|
||||
* 处理请求
|
||||
@@ -22,22 +22,18 @@ class Api{
|
||||
* @return Response
|
||||
*/
|
||||
public function handle($request, \Closure $next){
|
||||
$request->pageConfig = array(
|
||||
'list_rows' => $request->param('pageSize', 30),
|
||||
'page' => $request->param('page', 1),
|
||||
);
|
||||
$response = $next($request);
|
||||
|
||||
if (is_array($response->getData())) {
|
||||
$this->data = array_merge($this->data, $response->getData());
|
||||
|
||||
//记录用户操作记录
|
||||
app()->make(UsersLogService::class)->record($request, $response->getCode());
|
||||
if ($request->isAjax() || is_array($response->getData())) {
|
||||
return json($response->getData());
|
||||
} else {
|
||||
$this->data = $response->getData();
|
||||
}
|
||||
|
||||
if ($request->isAjax()) {
|
||||
return json($this->data);
|
||||
} else {
|
||||
if (\is_string($this->data) && $this->data != '') {
|
||||
return $response;
|
||||
} else {
|
||||
return json($this->data);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user