[fix]:[FL-170][角色管理页面输入关键字时不要直接触发查询]
将角色管理页面的搜索行为从输入时自动触发改为手动触发(点击搜索按钮或按回车键)。 主要改动: - 修改 loadData 函数接收可选的 keyword 参数,不再依赖 searchKeyword 状态 - 移除 searchKeyword 从 loadData 的依赖数组,避免每次输入都触发请求 - 更新搜索按钮和回车事件处理,显式传入 searchKeyword 参数 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -87,7 +87,7 @@ export default function AdminRolesPage() {
|
||||
return new Map(menus.map((menu) => [menu.id, `${menu.name} (${menu.code})`]));
|
||||
}, [menus]);
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
const loadData = useCallback(async (keyword?: string) => {
|
||||
if (!canRead) {
|
||||
setLoading(false);
|
||||
return;
|
||||
@@ -96,9 +96,9 @@ export default function AdminRolesPage() {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
try {
|
||||
const keyword = searchKeyword.trim();
|
||||
const url = keyword
|
||||
? `/api/v1/admin/roles-with-menus?keyword=${encodeURIComponent(keyword)}`
|
||||
const searchTerm = (keyword ?? "").trim();
|
||||
const url = searchTerm
|
||||
? `/api/v1/admin/roles-with-menus?keyword=${encodeURIComponent(searchTerm)}`
|
||||
: "/api/v1/admin/roles-with-menus";
|
||||
|
||||
const response = await fetchWithAuth(url);
|
||||
@@ -116,7 +116,7 @@ export default function AdminRolesPage() {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [canRead, fetchWithAuth, searchKeyword]);
|
||||
}, [canRead, fetchWithAuth]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!user || !canRead) {
|
||||
@@ -430,11 +430,11 @@ export default function AdminRolesPage() {
|
||||
placeholder="搜索角色编码、名称或菜单"
|
||||
value={searchKeyword}
|
||||
onChange={(event) => setSearchKeyword(event.currentTarget.value)}
|
||||
onPressEnter={() => void loadData()}
|
||||
onPressEnter={() => void loadData(searchKeyword)}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" onClick={() => void loadData()}>搜索</Button>
|
||||
<Button type="primary" onClick={() => void loadData(searchKeyword)}>搜索</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user