mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
refactor: 优化后台兼容接口请求的判断
This commit is contained in:
@@ -44,7 +44,7 @@ class AdminBase extends AdminController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isJson()) {
|
||||
if ($this->request->isAjax()) {
|
||||
if (input('selectFields')) {
|
||||
return $this->selectList();
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ class AdminControllerBase extends BaseController
|
||||
public function checkParseApi()
|
||||
{
|
||||
if (Config::get('app.auto_parse_api')) {
|
||||
if ($this->request->isJsonPure() && $this->request->param('get_page_data')) {
|
||||
if ($this->request->isJson() && $this->request->param('get_page_data')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,35 +10,34 @@ class RequestBase extends \think\Request
|
||||
protected $filter = [];
|
||||
|
||||
/**
|
||||
* 当前是否JSON请求
|
||||
* 当前是否Ajax请求
|
||||
* @access public
|
||||
* @param bool $ajax true 获取原始ajax请求
|
||||
* @return bool
|
||||
*/
|
||||
public function isJson(): bool
|
||||
public function isAjax(bool $ajax = false): bool
|
||||
{
|
||||
$acceptType = $this->type();
|
||||
$value = $this->server('HTTP_X_REQUESTED_WITH');
|
||||
$result = $value && 'xmlhttprequest' == strtolower($value) ? true : false;
|
||||
|
||||
$is_json = str_contains($acceptType, 'json');
|
||||
if (!$is_json) {
|
||||
return false;
|
||||
if (true === $ajax) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$is_ajax = $this->param($this->varAjax) ? true : $result;
|
||||
|
||||
if (!Config::get('app.auto_parse_api')) {
|
||||
return $is_ajax;
|
||||
}
|
||||
|
||||
if($this->isJson()){
|
||||
if ($this->has('get_page_data')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ($this->has('get_page_data')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return $is_ajax;
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅通过实际请求参数判断请求
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isJsonPure()
|
||||
{
|
||||
return parent::isJson();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user