mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 03:22:51 +08:00
refactor: 优化后台兼容接口请求的判断
This commit is contained in:
@@ -44,7 +44,7 @@ class AdminBase extends AdminController
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
if ($this->request->isJson()) {
|
if ($this->request->isAjax()) {
|
||||||
if (input('selectFields')) {
|
if (input('selectFields')) {
|
||||||
return $this->selectList();
|
return $this->selectList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ class AdminControllerBase extends BaseController
|
|||||||
public function checkParseApi()
|
public function checkParseApi()
|
||||||
{
|
{
|
||||||
if (Config::get('app.auto_parse_api')) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,35 +10,34 @@ class RequestBase extends \think\Request
|
|||||||
protected $filter = [];
|
protected $filter = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前是否JSON请求
|
* 当前是否Ajax请求
|
||||||
|
* @access public
|
||||||
|
* @param bool $ajax true 获取原始ajax请求
|
||||||
* @return bool
|
* @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 (true === $ajax) {
|
||||||
if (!$is_json) {
|
return $result;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$is_ajax = $this->param($this->varAjax) ? true : $result;
|
||||||
|
|
||||||
if (!Config::get('app.auto_parse_api')) {
|
if (!Config::get('app.auto_parse_api')) {
|
||||||
|
return $is_ajax;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->isJson()){
|
||||||
|
if ($this->has('get_page_data')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
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