feat: add layout and org
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
import { create } from 'zustand';
|
||||
import { query } from '@/modules';
|
||||
import { message } from 'antd';
|
||||
import { isObjectNull } from '@/utils/is-null';
|
||||
|
||||
type AppVersionStore = {
|
||||
showEdit: boolean;
|
||||
setShowEdit: (showEdit: boolean) => void;
|
||||
formData: any;
|
||||
setFormData: (formData: any) => void;
|
||||
updateByFromData: () => void;
|
||||
loading: boolean;
|
||||
setLoading: (loading: boolean) => void;
|
||||
key: string;
|
||||
setKey: (key: string) => void;
|
||||
list: any[];
|
||||
getList: () => Promise<void>;
|
||||
app: any;
|
||||
getApp: (key: string, force?: boolean) => Promise<void>;
|
||||
updateData: (data: any) => Promise<void>;
|
||||
deleteData: (id: string) => Promise<void>;
|
||||
publishVersion: (data: any) => Promise<void>;
|
||||
};
|
||||
export const useAppVersionStore = create<AppVersionStore>((set, get) => {
|
||||
return {
|
||||
@@ -22,6 +27,16 @@ export const useAppVersionStore = create<AppVersionStore>((set, get) => {
|
||||
setShowEdit: (showEdit) => set({ showEdit }),
|
||||
formData: {},
|
||||
setFormData: (formData) => set({ formData }),
|
||||
updateByFromData: () => {
|
||||
const { formData, list } = get();
|
||||
const data = list.map((item) => {
|
||||
if (item.id === formData.id) {
|
||||
return formData;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
set({ list: data });
|
||||
},
|
||||
loading: false,
|
||||
setLoading: (loading) => set({ loading }),
|
||||
key: '',
|
||||
@@ -38,6 +53,7 @@ export const useAppVersionStore = create<AppVersionStore>((set, get) => {
|
||||
key,
|
||||
},
|
||||
});
|
||||
get().getApp(key);
|
||||
set({ loading: false });
|
||||
if (res.code === 200) {
|
||||
set({ list: res.data });
|
||||
@@ -45,6 +61,25 @@ export const useAppVersionStore = create<AppVersionStore>((set, get) => {
|
||||
message.error(res.message || 'Request failed');
|
||||
}
|
||||
},
|
||||
app: {},
|
||||
getApp: async (key, force) => {
|
||||
const { app } = get();
|
||||
if (!force && !isObjectNull(app)) {
|
||||
return;
|
||||
}
|
||||
const res = await query.post({
|
||||
path: 'user-app',
|
||||
key: 'get',
|
||||
data: {
|
||||
key,
|
||||
},
|
||||
});
|
||||
if (res.code === 200) {
|
||||
set({ app: res.data });
|
||||
} else {
|
||||
message.error(res.message || 'Request failed');
|
||||
}
|
||||
},
|
||||
updateData: async (data) => {
|
||||
const { getList } = get();
|
||||
const res = await query.post({
|
||||
@@ -74,5 +109,22 @@ export const useAppVersionStore = create<AppVersionStore>((set, get) => {
|
||||
message.error(res.message || 'Request failed');
|
||||
}
|
||||
},
|
||||
publishVersion: async (data) => {
|
||||
const { getList } = get();
|
||||
const loaded = message.loading('Publishing...', 0);
|
||||
const res = await query.post({
|
||||
path: 'app',
|
||||
key: 'publish',
|
||||
data,
|
||||
});
|
||||
loaded();
|
||||
if (res.code === 200) {
|
||||
message.success('Success');
|
||||
// getList();
|
||||
get().getApp(get().key, true);
|
||||
} else {
|
||||
message.error(res.message || 'Request failed');
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user