From 3342cf8d8d1da1c8c6c1e7757c542fa66c59e997 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Thu, 19 Jan 2023 23:24:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/DeviceController.php | 3 +- app/Support/EmqxSupport.php | 27 +++- resources/views/admin/device/index.blade.php | 149 +++++++----------- 3 files changed, 83 insertions(+), 96 deletions(-) diff --git a/app/Http/Controllers/Admin/DeviceController.php b/app/Http/Controllers/Admin/DeviceController.php index 710130c..14922bf 100644 --- a/app/Http/Controllers/Admin/DeviceController.php +++ b/app/Http/Controllers/Admin/DeviceController.php @@ -17,10 +17,9 @@ public function index(Request $request): RedirectResponse|View $emqx = new EmqxSupport(); try { - $clients = $emqx->clients([ + $clients = $emqx->pagination([ 'clientid' => $request->input('client_id'), 'username' => $request->input('username'), - 'page' => $request->input('page'), ]); } catch (EmqxSupportException $e) { return back()->with('error', $e->getMessage()); diff --git a/app/Support/EmqxSupport.php b/app/Support/EmqxSupport.php index d4e7e8a..39bc210 100644 --- a/app/Support/EmqxSupport.php +++ b/app/Support/EmqxSupport.php @@ -6,11 +6,15 @@ use App\Jobs\Support\EMQXKickClientJob; use Illuminate\Http\Client\ConnectionException; use Illuminate\Http\Client\PendingRequest; +use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Request; class EmqxSupport { + private int $limit_per_page = 50; + /** * 移除客户端 */ @@ -42,7 +46,7 @@ public function clients($params = []) { // merge params $params = array_merge([ - 'limit' => 100, + 'limit' => $this->limit_per_page, 'isTrusted' => true, ], $params); @@ -59,4 +63,25 @@ public function clients($params = []) throw new EmqxSupportException('无法获取客户端列表。'); } } + + /** + * @throws EmqxSupportException + */ + public function pagination($params = []): LengthAwarePaginator + { + $page = Request::input('page', 1); + $params = array_merge([ + 'page' => $page, + ], $params); + + $clients = $this->clients($params); + + $data = $clients['data']; + $total = $clients['meta']['count']; + $limit = $clients['meta']['limit']; + + return new LengthAwarePaginator($data, $total, $limit, $page, [ + 'path' => route('admin.devices.index'), + ]); + } } diff --git a/resources/views/admin/device/index.blade.php b/resources/views/admin/device/index.blade.php index 41c34a9..bd17a73 100644 --- a/resources/views/admin/device/index.blade.php +++ b/resources/views/admin/device/index.blade.php @@ -35,103 +35,66 @@ - @if(isset($clients)) - @foreach($clients['data'] as $c) - - - {{ $c['clientid'] }} - - - {{ $c['username'] }} - - - {{ $c['node'] }} - - - {{ $c['proto_name'] . ' v' . $c['proto_ver'] }} - - - {{ $c['ip_address'] }} - - - @if ($c['clean_start']) - 干净启动 - @endif - @if ($c['recv_oct']) -
- 接收字节: {{ $c['recv_oct'] }} - @endif - @if ($c['send_oct']) -
- 发送字节: {{ $c['send_oct'] }} - @endif - - - @if ($c['subscriptions_cnt'] > 0) - {{ $c['subscriptions_cnt'] }} 个 - @else - 没有订阅 - @endif - - -
- @csrf - @method('DELETE') - - -
+ @foreach($clients as $c) + + + {{ $c['clientid'] }} + + + {{ $c['username'] }} + + + {{ $c['node'] }} + + + {{ $c['proto_name'] . ' v' . $c['proto_ver'] }} + + + {{ $c['ip_address'] }} + + + @if ($c['clean_start']) + 干净启动 + @endif + @if ($c['recv_oct']) +
+ 接收字节: {{ $c['recv_oct'] }} + @endif + @if ($c['send_oct']) +
+ 发送字节: {{ $c['send_oct'] }} + @endif + + + @if ($c['subscriptions_cnt'] > 0) + {{ $c['subscriptions_cnt'] }} 个 + @else + 没有订阅 + @endif + + +
+ @csrf + @method('DELETE') + + +
-
- @csrf - @method('DELETE') - - - -
+
+ @csrf + @method('DELETE') + + + +
- - - @endforeach - @endif + + + @endforeach - @if(isset($clients)) -
-
-

- 共 {{ $clients['meta']['count'] }} 个设备,当前在第 {{ Request::input('page', 1) }} 页。 -

-
+ {{ $clients->links() }} -
-
    -
  • - -
  • - - @for($i = 1; $i <= ceil($clients['meta']['count'] / $clients['meta']['limit']); $i++) - @if ($i == Request::input('page', 1)) -
  • - {{ $i }} -
  • - @else -
  • - {{ $i }} -
  • - @endif - @endfor - - -
  • - -
  • - -
-
-
- @endif @endsection