feat: add query-login
This commit is contained in:
53
src/pages/config/store/config.ts
Normal file
53
src/pages/config/store/config.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { create } from 'zustand';
|
||||
import { query } from '@/modules/query';
|
||||
import { toast } from 'react-toastify';
|
||||
import { QueryConfig } from '@kevisual/query-config';
|
||||
|
||||
export const queryConfig = new QueryConfig({ query });
|
||||
|
||||
interface ConfigStore {
|
||||
list: any[];
|
||||
getConfig: () => Promise<void>;
|
||||
updateData: (data: any, opts?: { refresh?: boolean }) => Promise<any>;
|
||||
showEdit: boolean;
|
||||
setShowEdit: (showEdit: boolean) => void;
|
||||
formData: any;
|
||||
setFormData: (formData: any) => void;
|
||||
deleteConfig: (id: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export const useConfigStore = create<ConfigStore>((set, get) => ({
|
||||
list: [],
|
||||
getConfig: async () => {
|
||||
const res = await queryConfig.listConfig();
|
||||
if (res.code === 200) {
|
||||
set({ list: res.data?.list || [] });
|
||||
}
|
||||
},
|
||||
updateData: async (data: any, opts?: { refresh?: boolean }) => {
|
||||
const res = await queryConfig.updateConfig(data);
|
||||
if (res.code === 200) {
|
||||
get().setFormData(res.data);
|
||||
if (opts?.refresh ?? true) {
|
||||
get().getConfig();
|
||||
}
|
||||
toast.success('保存成功');
|
||||
} else {
|
||||
toast.error('保存失败');
|
||||
}
|
||||
return res;
|
||||
},
|
||||
showEdit: false,
|
||||
setShowEdit: (showEdit: boolean) => set({ showEdit }),
|
||||
formData: {},
|
||||
setFormData: (formData: any) => set({ formData }),
|
||||
deleteConfig: async (id: string) => {
|
||||
const res = await queryConfig.deleteConfig(id);
|
||||
if (res.code === 200) {
|
||||
get().getConfig();
|
||||
toast.success('删除成功');
|
||||
} else {
|
||||
toast.error('删除失败');
|
||||
}
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user