|
@ -1,14 +1,12 @@ |
|
|
import { appAtom, setToken } from '@/store/system.ts' |
|
|
import { appAtom, setToken } from '@/store/system.ts' |
|
|
import { IMenu } from '@/types/menus' |
|
|
|
|
|
import { IUser, IUserInfo } from '@/types/user' |
|
|
|
|
|
import { atom } from 'jotai/index' |
|
|
import { atom } from 'jotai/index' |
|
|
import { IApiResult, IAuth, IPage, IPageResult, MenuItem } from '@/global' |
|
|
import { IApiResult, IAuth, IPage, IPageResult, MenuItem } from '@/global' |
|
|
import { LoginRequest } from '@/types/login' |
|
|
|
|
|
import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' |
|
|
import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' |
|
|
import systemServ from '@/service/system.ts' |
|
|
import systemServ from '@/service/system.ts' |
|
|
import { formatMenuData, isDev } from '@/utils' |
|
|
import { formatMenuData, isDev } from '@/utils' |
|
|
import { message } from 'antd' |
|
|
import { message } from 'antd' |
|
|
import { t } from 'i18next' |
|
|
import { t } from 'i18next' |
|
|
|
|
|
import { System } from '@/types' |
|
|
|
|
|
|
|
|
export const authAtom = atom<IAuth>({ |
|
|
export const authAtom = atom<IAuth>({ |
|
|
isLogin: false, |
|
|
isLogin: false, |
|
@ -20,11 +18,11 @@ const devLogin = { |
|
|
password: 'kk123456', |
|
|
password: 'kk123456', |
|
|
code: '123456' |
|
|
code: '123456' |
|
|
} |
|
|
} |
|
|
export const loginFormAtom = atom<LoginRequest>({ |
|
|
|
|
|
|
|
|
export const loginFormAtom = atom<System.LoginRequest>({ |
|
|
...(isDev ? devLogin : {}) |
|
|
...(isDev ? devLogin : {}) |
|
|
} as LoginRequest) |
|
|
|
|
|
|
|
|
} as System.LoginRequest) |
|
|
|
|
|
|
|
|
export const loginAtom = atomWithMutation<any, LoginRequest>((get) => ({ |
|
|
|
|
|
|
|
|
export const loginAtom = atomWithMutation<any, System.LoginRequest>((get) => ({ |
|
|
mutationKey: [ 'login' ], |
|
|
mutationKey: [ 'login' ], |
|
|
mutationFn: async (params) => { |
|
|
mutationFn: async (params) => { |
|
|
return await systemServ.login(params) |
|
|
return await systemServ.login(params) |
|
@ -46,7 +44,7 @@ export const logoutAtom = atomWithMutation(() => ({ |
|
|
}, |
|
|
}, |
|
|
})) |
|
|
})) |
|
|
|
|
|
|
|
|
export const currentUserAtom = atomWithQuery<IApiResult<IUserInfo>, any, IUserInfo>((get) => { |
|
|
|
|
|
|
|
|
export const currentUserAtom = atomWithQuery<IApiResult<System.IUserInfo>, any, System.IUserInfo>((get) => { |
|
|
return { |
|
|
return { |
|
|
queryKey: [ 'user_info', get(appAtom).token ], |
|
|
queryKey: [ 'user_info', get(appAtom).token ], |
|
|
queryFn: async () => { |
|
|
queryFn: async () => { |
|
@ -58,7 +56,7 @@ export const currentUserAtom = atomWithQuery<IApiResult<IUserInfo>, any, IUserIn |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
export const userMenuDataAtom = atomWithQuery<IApiResult<IPageResult<IMenu[]>>, any, MenuItem[]>((get) => ({ |
|
|
|
|
|
|
|
|
export const userMenuDataAtom = atomWithQuery<IApiResult<IPageResult<System.IMenu[]>>, any, MenuItem[]>((get) => ({ |
|
|
enabled: false, |
|
|
enabled: false, |
|
|
queryKey: [ 'user_menus', get(appAtom).token ], |
|
|
queryKey: [ 'user_menus', get(appAtom).token ], |
|
|
queryFn: async () => { |
|
|
queryFn: async () => { |
|
@ -102,16 +100,16 @@ export const userListAtom = atomWithQuery((get) => { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// user selected
|
|
|
// user selected
|
|
|
export const userSelectedAtom = atom<IUser>({} as IUser) |
|
|
|
|
|
|
|
|
export const userSelectedAtom = atom<System.IUser>({} as System.IUser) |
|
|
|
|
|
|
|
|
export const defaultUserData = { |
|
|
export const defaultUserData = { |
|
|
id: 0, |
|
|
id: 0, |
|
|
dept_id: 0, |
|
|
dept_id: 0, |
|
|
role_id: 0, |
|
|
role_id: 0, |
|
|
} as IUser |
|
|
|
|
|
|
|
|
} as System.IUser |
|
|
|
|
|
|
|
|
//save or update user
|
|
|
//save or update user
|
|
|
export const saveOrUpdateUserAtom = atomWithMutation<IApiResult, IUser>((get) => ({ |
|
|
|
|
|
|
|
|
export const saveOrUpdateUserAtom = atomWithMutation<IApiResult, System.IUser>((get) => ({ |
|
|
mutationKey: [ 'save_user' ], |
|
|
mutationKey: [ 'save_user' ], |
|
|
mutationFn: async (params) => { |
|
|
mutationFn: async (params) => { |
|
|
params.status = params.status ? '1' : '0' |
|
|
params.status = params.status ? '1' : '0' |