改进 处理

This commit is contained in:
iVampireSP.com 2022-11-28 23:14:48 +08:00
parent 915682af20
commit b170717c7b
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
4 changed files with 40 additions and 2 deletions

View File

@ -0,0 +1,10 @@
<?php
namespace App\Exceptions;
use Exception;
class EmqxSupportException extends Exception
{
//
}

View File

@ -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'));
}

View File

@ -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('无法获取客户端列表。');
}
}

View File

@ -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="下一页 &raquo;">下一页</a>
</li>
</ul>
</div>
</div>
@endsection