|
@ -1,5 +1,5 @@ |
|
|
import systemServ from '@/service/system.ts' |
|
|
import systemServ from '@/service/system.ts' |
|
|
import { IPage, IPageResult, MenuItem } from '@/types' |
|
|
|
|
|
|
|
|
import { IApiResult, IPage, MenuItem } from '@/types' |
|
|
import { IMenu } from '@/types/menus' |
|
|
import { IMenu } from '@/types/menus' |
|
|
import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' |
|
|
import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' |
|
|
import { atom, createStore } from 'jotai' |
|
|
import { atom, createStore } from 'jotai' |
|
@ -24,15 +24,15 @@ export const menuPageAtom = atom<IPage>({}) |
|
|
|
|
|
|
|
|
const store = createStore() |
|
|
const store = createStore() |
|
|
|
|
|
|
|
|
export const menuDataAtom = atomWithQuery<any, IPageResult<IMenu>>((get) => { |
|
|
|
|
|
|
|
|
export const menuDataAtom = atomWithQuery((get) => { |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
queryKey: [ 'menus', get(menuPageAtom) ], |
|
|
queryKey: [ 'menus', get(menuPageAtom) ], |
|
|
queryFn: async ({ queryKey: [ , page ] }) => { |
|
|
queryFn: async ({ queryKey: [ , page ] }) => { |
|
|
return await systemServ.menus.list(page) |
|
|
return await systemServ.menus.list(page) |
|
|
}, |
|
|
}, |
|
|
select: (data) => { |
|
|
|
|
|
return data.rows ?? [] |
|
|
|
|
|
|
|
|
select: (res) => { |
|
|
|
|
|
return res.data.rows ?? [] |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
@ -49,7 +49,7 @@ export const byIdMenuAtom = atomWithQuery((get) => ({ |
|
|
})) |
|
|
})) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const saveOrUpdateMenuAtom = atomWithMutation<any, IMenu>((get) => { |
|
|
|
|
|
|
|
|
export const saveOrUpdateMenuAtom = atomWithMutation<IApiResult, IMenu>((get) => { |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
mutationKey: [ 'updateMenu', get(selectedMenuIdAtom) ], |
|
|
mutationKey: [ 'updateMenu', get(selectedMenuIdAtom) ], |
|
|