如果你使用还是dcat-admin , 非dcat-plus版。请使用以下代码,去修正。
把 使用以下代码去修正, use DcatInteractsWithApi
加到你的每一个图表 Card中
重写了 InteractsWithApi 中的两个方法, 只有在 图表Card id, 在页面中存在时才会触发异步请求
<?php
namespace App\Helpers;
use Illuminate\Http\Request;
/**
* Trait InteractsWithApi.
*
*
* @method mixed handle(Request $request)
* @method mixed valueResult()
*/
trait DcatInteractsWithApi
{
/**
* 构建请求数据js代码.
*
* @return null|string
*/
public function buildRequestScript()
{
if (! $this->allowBuildRequest()) {
return;
}
$fetching = implode(';', $this->requestScripts['fetching']);
$fetched = implode(';', $this->requestScripts['fetched']);
$id = $this->id();
return <<<JS
(function () {
if($("#{$id}").length >= 1) {
var loading;
function request(data) {
if (loading) {
return;
}
loading = 1;
data = $.extend({$this->formatRequestData()}, data || {});
{$fetching};
$.ajax({
url: '{$this->getRequestUrl()}',
dataType: 'json',
method: '{$this->method}',
data: data,
success: function (response) {
loading = 0;
{$fetched};
},
error: function (a, b, c) {
loading = 0;
Dcat.handleAjaxError(a, b, c)
},
});
}
request();
{$this->buildBindingScript()}
}
})();
JS;
}
private function formatRequestData()
{
$data = [
'_key' => $this->getUriKey(),
'_token' => csrf_token(),
];
return json_encode(
array_merge($this->parameters(), $data)
);
}
}