diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index d52179f..b223beb 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -41,12 +41,14 @@ import { Mail, Palette, Plus, + Search, Settings, Trash2, Tv, UserPlus, Users, Video, + X, } from 'lucide-react'; import { GripVertical } from 'lucide-react'; import { @@ -512,8 +514,10 @@ interface UserConfigProps { userPage: number; userTotalPages: number; userTotal: number; - fetchUsersV2: (page: number) => Promise; + fetchUsersV2: (page: number, search?: string) => Promise; userListLoading: boolean; + userSearch: string; + setUserSearch: (value: string) => void; } const UserConfig = ({ @@ -526,6 +530,8 @@ const UserConfig = ({ userTotal, fetchUsersV2, userListLoading, + userSearch, + setUserSearch, }: UserConfigProps) => { const { alertModal, showAlert, hideAlert } = useAlertModal(); const { isLoading, withLoading } = useLoadingState(); @@ -582,6 +588,7 @@ const UserConfig = ({ } | null>(null); const [showDeleteUserModal, setShowDeleteUserModal] = useState(false); const [deletingUser, setDeletingUser] = useState(null); + const trimmedUserSearch = userSearch.trim(); // 当前登录用户名 const currentUsername = getAuthInfoFromBrowserCookie()?.username || null; @@ -887,7 +894,7 @@ const UserConfig = ({ if (checked) { // 只选择自己有权限操作的用户 const selectableUsernames = - config?.UserConfig?.Users?.filter( + displayUsers?.filter( (user) => role === 'owner' || (role === 'admin' && @@ -898,7 +905,7 @@ const UserConfig = ({ setSelectedUsers(new Set()); } }, - [config?.UserConfig?.Users, role, currentUsername] + [displayUsers, role, currentUsername] ); // 批量设置用户组 @@ -1240,15 +1247,87 @@ const UserConfig = ({ {/* 用户列表 */}
-
-

- 用户列表 -

-
+
+
+

+ 用户列表 +

+ +
+
+ {!hasOldUserData && usersV2 && ( +
{ + e.preventDefault(); + setSelectedUsers(new Set()); + fetchUsersV2(1, trimmedUserSearch); + }} + className='ml-auto flex min-w-0 items-center gap-2' + > +
+ + setUserSearch(e.target.value)} + placeholder='按用户名搜索' + className='w-full pl-9 pr-3 py-1.5 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent' + /> +
+ {trimmedUserSearch && ( + + )} + +
+ )} {/* 批量操作按钮 */} {selectedUsers.size > 0 && ( <> -
+
已选择 {selectedUsers.size} 个用户 @@ -1259,23 +1338,9 @@ const UserConfig = ({ 批量设置用户组
-
+
)} -
@@ -1448,7 +1513,7 @@ const UserConfig = ({ {(() => { // 检查是否有权限操作任何用户 - const hasAnyPermission = config?.UserConfig?.Users?.some( + const hasAnyPermission = displayUsers?.some( (user) => role === 'owner' || (role === 'admin' && @@ -1516,7 +1581,7 @@ const UserConfig = ({ 加载中... @@ -1536,6 +1601,23 @@ const UserConfig = ({ }; return priority(a) - priority(b); }); + if (sortedUsers.length === 0) { + return ( + + + + {trimmedUserSearch + ? `未找到用户名包含“${trimmedUserSearch}”的用户` + : '暂无用户'} + + + + ); + } + return ( {sortedUsers.map((user) => { @@ -1778,11 +1860,14 @@ const UserConfig = ({ {!hasOldUserData && usersV2 && userTotalPages > 1 && (
- 共 {userTotal} 个用户,第 {userPage} / {userTotalPages} 页 + {trimmedUserSearch + ? `搜索结果 ${userTotal} 个用户` + : `共 ${userTotal} 个用户`} + ,第 {userPage} / {userTotalPages} 页