import { atomWithMutation, atomWithQuery } from 'jotai-tanstack-query' import { atom } from 'jotai/index' import { IPage } from '@/global' import systemServ from '@/service/system.ts' import { message } from 'antd' import { t } from '@/i18n.ts' export const loginLogPageAtom = atom({ page: 1, pageSize: 10, }) type LogSearch = { key?: string, } export const loginLogSearchAtom = atom({ key: '' }) export const loginLogsAtom = atomWithQuery((get) => ({ queryKey: [ 'loginLogs', get(loginLogPageAtom), get(loginLogSearchAtom) ], queryFn: async ({ queryKey: [ , page, search ] }) => { return await systemServ.logs.login.list({ ...page as any, ...search as any, }) }, select: (data) => { return data.data }, })) export const loginLogIdsAtom = atom([]) export const deleteLoginLogAtom = atomWithMutation((get) => ({ mutationKey: [ 'deleteLoginLog' ], mutationFn: async (ids) => { return await systemServ.logs.login.batchDelete(ids) }, onSuccess: () => { message.success(t('message.deleteSuccess', '删除成功')) get(loginLogsAtom).refetch() }, })) //clear export const clearLoginLogAtom = atomWithMutation((get) => ({ mutationKey: [ 'clearLoginLog' ], mutationFn: async (params) => { return await systemServ.logs.login.clear(params) }, onSuccess: () => { message.success(t('message.deleteSuccess', '删除成功')) get(loginLogsAtom).refetch() } }))