You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.6 KiB
58 lines
1.6 KiB
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<IPage>({
|
|
page: 1,
|
|
pageSize: 10,
|
|
})
|
|
|
|
type LogSearch = {
|
|
key?: string,
|
|
}
|
|
|
|
export const loginLogSearchAtom = atom<LogSearch>({
|
|
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<number[]>([])
|
|
|
|
export const deleteLoginLogAtom = atomWithMutation<any, number[]>((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<any, { start: string, end: string }>((get) => ({
|
|
mutationKey: [ 'clearLoginLog' ],
|
|
mutationFn: async (params) => {
|
|
return await systemServ.logs.login.clear(params)
|
|
},
|
|
onSuccess: () => {
|
|
message.success(t('message.deleteSuccess', '删除成功'))
|
|
get(loginLogsAtom).refetch()
|
|
}
|
|
}))
|