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.

57 lines
1.6 KiB

  1. import { atomWithMutation, atomWithQuery } from 'jotai-tanstack-query'
  2. import { atom } from 'jotai/index'
  3. import { IPage } from '@/global'
  4. import systemServ from '@/service/system.ts'
  5. import { message } from 'antd'
  6. import { t } from '@/i18n.ts'
  7. export const loginLogPageAtom = atom<IPage>({
  8. page: 1,
  9. pageSize: 10,
  10. })
  11. type LogSearch = {
  12. key?: string,
  13. }
  14. export const loginLogSearchAtom = atom<LogSearch>({
  15. key: ''
  16. })
  17. export const loginLogsAtom = atomWithQuery((get) => ({
  18. queryKey: [ 'loginLogs', get(loginLogPageAtom), get(loginLogSearchAtom) ],
  19. queryFn: async ({ queryKey: [ , page, search ] }) => {
  20. return await systemServ.logs.login.list({
  21. ...page as any,
  22. ...search as any,
  23. })
  24. },
  25. select: (data) => {
  26. return data.data
  27. },
  28. }))
  29. export const loginLogIdsAtom = atom<number[]>([])
  30. export const deleteLoginLogAtom = atomWithMutation<any, number[]>((get) => ({
  31. mutationKey: [ 'deleteLoginLog' ],
  32. mutationFn: async (ids) => {
  33. return await systemServ.logs.login.batchDelete(ids)
  34. },
  35. onSuccess: () => {
  36. message.success(t('message.deleteSuccess', '删除成功'))
  37. get(loginLogsAtom).refetch()
  38. },
  39. }))
  40. //clear
  41. export const clearLoginLogAtom = atomWithMutation<any, { start: string, end: string }>((get) => ({
  42. mutationKey: [ 'clearLoginLog' ],
  43. mutationFn: async (params) => {
  44. return await systemServ.logs.login.clear(params)
  45. },
  46. onSuccess: () => {
  47. message.success(t('message.deleteSuccess', '删除成功'))
  48. get(loginLogsAtom).refetch()
  49. }
  50. }))