Feat: 后台用户列表增加金币/魅力列,表头支持点击排序(等级/经验/金币/魅力)
This commit is contained in:
@@ -23,7 +23,7 @@ use Illuminate\View\View;
|
||||
class UserManagerController extends Controller
|
||||
{
|
||||
/**
|
||||
* 显示拥护列表及搜索
|
||||
* 显示用户列表及搜索(支持按等级/经验/金币/魅力排序)
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
@@ -33,13 +33,17 @@ class UserManagerController extends Controller
|
||||
$query->where('username', 'like', '%'.$request->input('username').'%');
|
||||
}
|
||||
|
||||
// 分页获取用户
|
||||
$users = $query->orderBy('id', 'desc')->paginate(20);
|
||||
// 排序:允许的字段白名单,防止 SQL 注入
|
||||
$sortable = ['user_level', 'exp_num', 'jjb', 'meili', 'id'];
|
||||
$sortBy = in_array($request->input('sort_by'), $sortable) ? $request->input('sort_by') : 'id';
|
||||
$sortDir = $request->input('sort_dir') === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
$users = $query->orderBy($sortBy, $sortDir)->paginate(20)->withQueryString();
|
||||
|
||||
// VIP 等级选项列表(供编辑弹窗使用)
|
||||
$vipLevels = \App\Models\VipLevel::orderBy('sort_order')->get();
|
||||
|
||||
return view('admin.users.index', compact('users', 'vipLevels'));
|
||||
return view('admin.users.index', compact('users', 'vipLevels', 'sortBy', 'sortDir'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,22 @@
|
||||
|
||||
<!-- 用户表格 -->
|
||||
<div class="overflow-x-auto">
|
||||
@php
|
||||
/**
|
||||
* 生成排序链接:点击同一列切换方向,点击新列默认倒序
|
||||
*/
|
||||
$sortLink = function (string $col) use ($sortBy, $sortDir, $request): string {
|
||||
$newDir = $sortBy === $col && $sortDir === 'desc' ? 'asc' : 'desc';
|
||||
$qs = http_build_query(
|
||||
array_merge($request->except(['sort_by', 'sort_dir', 'page']), [
|
||||
'sort_by' => $col,
|
||||
'sort_dir' => $newDir,
|
||||
]),
|
||||
);
|
||||
return url('/admin/users?' . $qs);
|
||||
};
|
||||
$arrow = fn(string $col): string => $sortBy === $col ? ($sortDir === 'desc' ? ' ↓' : ' ↑') : '';
|
||||
@endphp
|
||||
<table class="w-full text-left border-collapse">
|
||||
<thead>
|
||||
<tr
|
||||
@@ -29,8 +45,26 @@
|
||||
<th class="p-4">ID</th>
|
||||
<th class="p-4">注册名</th>
|
||||
<th class="p-4">性别</th>
|
||||
<th class="p-4">等级</th>
|
||||
<th class="p-4">经验</th>
|
||||
<th class="p-4">
|
||||
<a href="{{ $sortLink('user_level') }}" class="hover:text-indigo-600 flex items-center gap-1">
|
||||
等级<span class="text-indigo-500">{{ $arrow('user_level') }}</span>
|
||||
</a>
|
||||
</th>
|
||||
<th class="p-4">
|
||||
<a href="{{ $sortLink('exp_num') }}" class="hover:text-indigo-600 flex items-center gap-1">
|
||||
经验<span class="text-indigo-500">{{ $arrow('exp_num') }}</span>
|
||||
</a>
|
||||
</th>
|
||||
<th class="p-4">
|
||||
<a href="{{ $sortLink('jjb') }}" class="hover:text-yellow-600 flex items-center gap-1">
|
||||
金币<span class="text-yellow-500">{{ $arrow('jjb') }}</span>
|
||||
</a>
|
||||
</th>
|
||||
<th class="p-4">
|
||||
<a href="{{ $sortLink('meili') }}" class="hover:text-pink-600 flex items-center gap-1">
|
||||
魅力<span class="text-pink-500">{{ $arrow('meili') }}</span>
|
||||
</a>
|
||||
</th>
|
||||
<th class="p-4">注册时间</th>
|
||||
<th class="p-4 text-right">管理操作</th>
|
||||
</tr>
|
||||
@@ -60,6 +94,12 @@
|
||||
<td class="p-4 text-sm font-mono text-gray-600">
|
||||
{{ number_format($user->exp_num ?? 0) }}
|
||||
</td>
|
||||
<td class="p-4 text-sm font-mono text-yellow-700">
|
||||
{{ number_format($user->jjb ?? 0) }}
|
||||
</td>
|
||||
<td class="p-4 text-sm font-mono text-pink-600">
|
||||
{{ number_format($user->meili ?? 0) }}
|
||||
</td>
|
||||
<td class="p-4 text-sm font-mono text-gray-500">{{ $user->created_at->format('Y/m/d H:i') }}
|
||||
</td>
|
||||
<td class="p-4 text-right space-x-2 relative" x-data>
|
||||
|
||||
Reference in New Issue
Block a user