|
@ -1,5 +1,5 @@ |
|
|
import { atom } from 'jotai' |
|
|
import { atom } from 'jotai' |
|
|
import { IApiResult, IPage } from '@/global' |
|
|
|
|
|
|
|
|
import { IApiResult, IPage, IPageResult } from '@/global' |
|
|
import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' |
|
|
import { atomWithMutation, atomWithQuery, queryClientAtom } from 'jotai-tanstack-query' |
|
|
import { message } from 'antd' |
|
|
import { message } from 'antd' |
|
|
import { t } from 'i18next' |
|
|
import { t } from 'i18next' |
|
@ -32,13 +32,12 @@ export const modelPageAtom = atom<IPage>({ |
|
|
page: 1, |
|
|
page: 1, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
export const modelCURDAtom = atomWithQuery<IApiResult<XForm.IModelCURD>, any, any>((get) => { |
|
|
|
|
|
const api = get(apiAtom) |
|
|
|
|
|
console.log('api', api) |
|
|
|
|
|
|
|
|
export const modelCURDAtom = atomWithQuery<IApiResult<XForm.IModelCURD>, any, any, any>((get) => { |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
enabled: !!api, |
|
|
|
|
|
queryKey: [ 'modelCURD' ], |
|
|
|
|
|
queryFn: async () => { |
|
|
|
|
|
|
|
|
enabled: !!get(apiAtom), |
|
|
|
|
|
queryKey: [ 'modelCURD', get(apiAtom) ], |
|
|
|
|
|
queryFn: async ({ queryKey: [ , api ] }) => { |
|
|
return await modelServ.model(api).proxy() |
|
|
return await modelServ.model(api).proxy() |
|
|
}, |
|
|
}, |
|
|
select: (res) => { |
|
|
select: (res) => { |
|
@ -47,14 +46,13 @@ export const modelCURDAtom = atomWithQuery<IApiResult<XForm.IModelCURD>, any, an |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
export const modelsAtom = atomWithQuery((get) => { |
|
|
|
|
|
const api = get(apiAtom) |
|
|
|
|
|
const curd = get(modelCURDAtom) |
|
|
|
|
|
|
|
|
export const modelsAtom = atomWithQuery<IApiResult<IPageResult<any>>, any, any, any>((get) => { |
|
|
|
|
|
|
|
|
|
|
|
const curd = get(modelCURDAtom) |
|
|
return { |
|
|
return { |
|
|
enabled: curd.isSuccess && !!api, |
|
|
|
|
|
queryKey: [ 'models', get(modelSearchAtom) ], |
|
|
|
|
|
queryFn: async ({ queryKey: [ , params ] }) => { |
|
|
|
|
|
|
|
|
enabled: curd.isSuccess && !!get(apiAtom), |
|
|
|
|
|
queryKey: [ 'models', get(modelSearchAtom), get(apiAtom) ], |
|
|
|
|
|
queryFn: async ({ queryKey: [ , params, api ] }) => { |
|
|
|
|
|
|
|
|
if (api.startsWith('http')) { |
|
|
if (api.startsWith('http')) { |
|
|
return await modelServ.model(api).proxy<XForm.IModel>({ |
|
|
return await modelServ.model(api).proxy<XForm.IModel>({ |
|
@ -81,7 +79,7 @@ export const modelsAtom = atomWithQuery((get) => { |
|
|
export const saveOrUpdateModelAtom = atomWithMutation<IApiResult, XForm.IModel>((get) => { |
|
|
export const saveOrUpdateModelAtom = atomWithMutation<IApiResult, XForm.IModel>((get) => { |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
mutationKey: [ 'updateModel' ], |
|
|
|
|
|
|
|
|
mutationKey: [ 'updateModel', get(apiAtom) ], |
|
|
mutationFn: async (data) => { |
|
|
mutationFn: async (data) => { |
|
|
const api = get(apiAtom) |
|
|
const api = get(apiAtom) |
|
|
if (!api) { |
|
|
if (!api) { |
|
@ -119,8 +117,9 @@ export const saveOrUpdateModelAtom = atomWithMutation<IApiResult, XForm.IModel>( |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
export const deleteModelAtom = atomWithMutation((get) => { |
|
|
export const deleteModelAtom = atomWithMutation((get) => { |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
mutationKey: [ 'deleteModel' ], |
|
|
|
|
|
|
|
|
mutationKey: [ 'deleteModel', get(apiAtom) ], |
|
|
mutationFn: async (ids: number[]) => { |
|
|
mutationFn: async (ids: number[]) => { |
|
|
const api = get(apiAtom) |
|
|
const api = get(apiAtom) |
|
|
if (api.startsWith('http')) { |
|
|
if (api.startsWith('http')) { |
|
|