改进 处理
This commit is contained in:
parent
915682af20
commit
b170717c7b
10
app/Exceptions/EmqxSupportException.php
Normal file
10
app/Exceptions/EmqxSupportException.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class EmqxSupportException extends Exception
|
||||
{
|
||||
//
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\EmqxSupport;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
|
||||
class DeviceController extends Controller
|
||||
{
|
||||
@ -14,8 +15,13 @@ public function index(Request $request)
|
||||
{
|
||||
$emqx = new EmqxSupport();
|
||||
|
||||
$clients = $emqx->clients($request->all());
|
||||
$clients = $emqx->clients([
|
||||
'clientid' => $request->client_id,
|
||||
'username' => $request->username,
|
||||
'page' => $request->page,
|
||||
]);
|
||||
|
||||
// dd($clients);
|
||||
return view('admin.device.index', compact('clients'));
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Exceptions\EmqxSupportException;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
@ -12,6 +13,9 @@ private function api(): PendingRequest
|
||||
return Http::baseUrl(config('emqx.api_url'))->withBasicAuth(config('emqx.api_key'), config('emqx.api_secret'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws EmqxSupportException
|
||||
*/
|
||||
public function clients($params = [])
|
||||
{
|
||||
// merge params
|
||||
@ -25,7 +29,7 @@ public function clients($params = [])
|
||||
if ($response->successful()) {
|
||||
return $response->json();
|
||||
} else {
|
||||
return false;
|
||||
throw new EmqxSupportException('无法获取客户端列表。');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,4 +84,22 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="d-none flex-sm-fill d-sm-flex align-items-sm-center justify-content-sm-end">
|
||||
<div>
|
||||
<ul class="pagination">
|
||||
@if ($clients['meta']['page'] > 1)
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ $clients['meta']['page'] - 1 }}">上一页</a>
|
||||
</li>
|
||||
@endif
|
||||
|
||||
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?page={{ $clients['meta']['page'] + 1}}" rel="next"
|
||||
aria-label="下一页 »">下一页</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
Loading…
Reference in New Issue
Block a user