From 528d8a7f79398448f3b6084670c723fb0c43fd5b Mon Sep 17 00:00:00 2001 From: dark Date: Thu, 25 Apr 2024 00:33:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMutation=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E5=90=8E=EF=BC=8CinvalidateQueries=E7=9A=84?= =?UTF-8?q?=E4=BC=A0=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/system/menus/store.ts | 4 ++-- src/pages/system/roles/index.tsx | 6 +++--- src/pages/system/roles/store.ts | 2 +- src/store/user.ts | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/pages/system/menus/store.ts b/src/pages/system/menus/store.ts index 5a32a6d..7b9abff 100644 --- a/src/pages/system/menus/store.ts +++ b/src/pages/system/menus/store.ts @@ -70,7 +70,7 @@ export const saveOrUpdateMenuAtom = atomWithMutation>((get) => //更新列表 // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore fix - get(queryClientAtom).invalidateQueries([ 'menus', get(menuPageAtom) ]).then() + get(queryClientAtom).invalidateQueries({ queryKey: [ 'menus', get(menuPageAtom) ]}).then() } } }) @@ -86,7 +86,7 @@ export const deleteMenuAtom = atomWithMutation((get) => { onSuccess: () => { message.success(t('message.deleteSuccess', '删除成功')) store.set(batchIdsAtom, []) - get(queryClientAtom).invalidateQueries([ 'menus', get(menuPageAtom) ]).then() + get(queryClientAtom).invalidateQueries({ queryKey: [ 'menus', get(menuPageAtom) ]}).then() } } }) \ No newline at end of file diff --git a/src/pages/system/roles/index.tsx b/src/pages/system/roles/index.tsx index b34dbdd..aa96e5d 100644 --- a/src/pages/system/roles/index.tsx +++ b/src/pages/system/roles/index.tsx @@ -7,7 +7,7 @@ import { } from '@ant-design/pro-components' import { createLazyFileRoute } from '@tanstack/react-router' import { useStyle } from './style.ts' -import { useEffect, useMemo, useRef, useState } from 'react' +import { memo, useEffect, useMemo, useRef, useState } from 'react' import { useAtom, useAtomValue, useSetAtom } from 'jotai' import { pageAtom, roleAtom, rolesAtom, saveOrUpdateRoleAtom, searchAtom } from './store.ts' import { useTranslation } from '@/i18n.ts' @@ -38,7 +38,7 @@ const MenuTree = (props: any) => { } -const Roles = () => { +const Roles = memo(() => { const { t } = useTranslation() const { styles } = useStyle() @@ -196,7 +196,7 @@ const Roles = () => { columns={columns}/> ) -} +}) export const Route = createLazyFileRoute('/system/roles')({ component: Roles diff --git a/src/pages/system/roles/store.ts b/src/pages/system/roles/store.ts index 2dfdacf..0725fac 100644 --- a/src/pages/system/roles/store.ts +++ b/src/pages/system/roles/store.ts @@ -49,7 +49,7 @@ export const saveOrUpdateRoleAtom = atomWithMutation>((get) => //更新列表 // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore fix - get(queryClientAtom).invalidateQueries([ 'roles', get(searchAtom) ]).then() + get(queryClientAtom).invalidateQueries({ queryKey: [ 'roles', get(searchAtom) ] }) return res } diff --git a/src/store/user.ts b/src/store/user.ts index d2901eb..a6648ad 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -54,5 +54,6 @@ export const userMenuDataAtom = atomWithQuery((get) => ({ select: (data: AxiosResponse) => { return formatMenuData(data.data.rows as any ?? []) }, + cacheTime: 1000 * 60, retry: false, }))