改进 分页
This commit is contained in:
parent
c306393a19
commit
3342cf8d8d
@ -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());
|
||||
|
@ -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'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -35,103 +35,66 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
@if(isset($clients))
|
||||
@foreach($clients['data'] as $c)
|
||||
<tr>
|
||||
<td>
|
||||
{{ $c['clientid'] }}
|
||||
</td>
|
||||
<td>
|
||||
<a href="?username={{ $c['username'] }}">{{ $c['username'] }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ $c['node'] }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $c['proto_name'] . ' v' . $c['proto_ver'] }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $c['ip_address'] }}
|
||||
</td>
|
||||
<td>
|
||||
@if ($c['clean_start'])
|
||||
<span class="badge text-success">干净启动</span>
|
||||
@endif
|
||||
@if ($c['recv_oct'])
|
||||
<br/>
|
||||
<span class="badge text-success">接收字节: {{ $c['recv_oct'] }}</span>
|
||||
@endif
|
||||
@if ($c['send_oct'])
|
||||
<br/>
|
||||
<span class="badge text-success">发送字节: {{ $c['send_oct'] }}</span>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($c['subscriptions_cnt'] > 0)
|
||||
<span class="text-success">{{ $c['subscriptions_cnt'] }} 个</span>
|
||||
@else
|
||||
<span class="text-danger">没有订阅</span>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<form action="{{ route('admin.devices.destroy') }}" method="post">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<input type="hidden" name="client_id" value="{{ $c['clientid'] }}">
|
||||
<button type="submit" class="btn btn-danger btn-sm">踢出</button>
|
||||
</form>
|
||||
@foreach($clients as $c)
|
||||
<tr>
|
||||
<td>
|
||||
{{ $c['clientid'] }}
|
||||
</td>
|
||||
<td>
|
||||
<a href="?username={{ $c['username'] }}">{{ $c['username'] }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ $c['node'] }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $c['proto_name'] . ' v' . $c['proto_ver'] }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $c['ip_address'] }}
|
||||
</td>
|
||||
<td>
|
||||
@if ($c['clean_start'])
|
||||
<span class="badge text-success">干净启动</span>
|
||||
@endif
|
||||
@if ($c['recv_oct'])
|
||||
<br/>
|
||||
<span class="badge text-success">接收字节: {{ $c['recv_oct'] }}</span>
|
||||
@endif
|
||||
@if ($c['send_oct'])
|
||||
<br/>
|
||||
<span class="badge text-success">发送字节: {{ $c['send_oct'] }}</span>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($c['subscriptions_cnt'] > 0)
|
||||
<span class="text-success">{{ $c['subscriptions_cnt'] }} 个</span>
|
||||
@else
|
||||
<span class="text-danger">没有订阅</span>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<form action="{{ route('admin.devices.destroy') }}" method="post">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<input type="hidden" name="client_id" value="{{ $c['clientid'] }}">
|
||||
<button type="submit" class="btn btn-danger btn-sm">踢出</button>
|
||||
</form>
|
||||
|
||||
<form class="mt-2" action="{{ route('admin.devices.destroy') }}" method="post"
|
||||
onsubmit="return confirm('将踢出此模块以及它的所有客户端。')">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<input type="hidden" name="username" value="{{ $c['username'] }}">
|
||||
<input type="hidden" name="like_username" value="1"/>
|
||||
<button type="submit" class="btn btn-danger btn-sm">踢出所有</button>
|
||||
</form>
|
||||
<form class="mt-2" action="{{ route('admin.devices.destroy') }}" method="post"
|
||||
onsubmit="return confirm('将踢出此模块以及它的所有客户端。')">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<input type="hidden" name="username" value="{{ $c['username'] }}">
|
||||
<input type="hidden" name="like_username" value="1"/>
|
||||
<button type="submit" class="btn btn-danger btn-sm">踢出所有</button>
|
||||
</form>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@if(isset($clients))
|
||||
<div class="d-none flex-sm-fill d-sm-flex align-items-sm-center justify-content-sm-between">
|
||||
<div>
|
||||
<p class="small text-muted">
|
||||
共 {{ $clients['meta']['count'] }} 个设备,当前在第 {{ Request::input('page', 1) }} 页。
|
||||
</p>
|
||||
</div>
|
||||
{{ $clients->links() }}
|
||||
|
||||
<div>
|
||||
<ul class="pagination">
|
||||
<li class="page-item @if (!($clients['meta']['page'] > 1)) disabled @endif">
|
||||
<a class="page-link" href="?page={{ $clients['meta']['page'] - 1 }}"
|
||||
aria-label="上一页 »">‹</a>
|
||||
</li>
|
||||
|
||||
@for($i = 1; $i <= ceil($clients['meta']['count'] / $clients['meta']['limit']); $i++)
|
||||
@if ($i == Request::input('page', 1))
|
||||
<li class="page-item @if ($i == Request::input('page', 1)) active @endif">
|
||||
<span class="page-link" href="?page={{ $i }}">{{ $i }}</span>
|
||||
</li>
|
||||
@else
|
||||
<li class="page-item @if ($i == Request::input('page', 1)) active @endif">
|
||||
<a class="page-link" href="?page={{ $i }}">{{ $i }}</a>
|
||||
</li>
|
||||
@endif
|
||||
@endfor
|
||||
|
||||
|
||||
<li class="page-item @if ($clients['meta']['count'] == Request::input('page', 1) * count($clients['data'])) disabled @endif">
|
||||
<a class="page-link" href="?page={{ $clients['meta']['page'] + 1}}" rel="next"
|
||||
aria-label="下一页 »">›</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@endsection
|
||||
|
Loading…
Reference in New Issue
Block a user