Auto commit: 2026-03-19 01:46

This commit is contained in:
xiongxiao
2026-03-19 01:46:16 +08:00
committed by cnb
parent bc9ce9e5df
commit 469d23b0b9
8 changed files with 850 additions and 192 deletions

View File

@@ -2,13 +2,143 @@ import { useMarkStore } from '@kevisual/api/store-mark';
export { useMarkStore }
import { create } from 'zustand';
import { queryApi } from '@/modules/mark-api';
import { toast } from 'sonner';
type WorkspaceItem = {
id: string;
name: string;
created_at: string;
updated_at: string;
data?: any;
}
type WorkspaceState = {
edit: boolean;
setEdit: (edit: boolean) => void;
list: WorkspaceItem[];
loading: boolean;
setLoading: (loading: boolean) => void;
// 弹窗状态
showCreateDialog: boolean;
setShowCreateDialog: (show: boolean) => void;
showEditDialog: boolean;
setShowEditDialog: (show: boolean) => void;
editingItem: WorkspaceItem | null;
setEditingItem: (item: WorkspaceItem | null) => void;
// 数据操作
getList: (params?: { search?: string, page?: number, pageSize?: number }) => Promise<void>;
createItem: (data: { name: string, data?: any }) => Promise<void>;
updateItem: (id: string, data: { name?: string, data?: any }) => Promise<void>;
deleteItem: (id: string) => Promise<void>;
getItem: (id: string) => Promise<WorkspaceItem | null>;
}
export const useWorkspaceStore = create<WorkspaceState>((set) => ({
export type { WorkspaceState, WorkspaceItem };
export const useWorkspaceStore = create<WorkspaceState>((set, get) => ({
edit: false,
setEdit: (edit) => set({ edit }),
}));
list: [],
loading: false,
setLoading: (loading) => set({ loading }),
showCreateDialog: false,
setShowCreateDialog: (show) => set({ showCreateDialog: show }),
showEditDialog: false,
setShowEditDialog: (show) => set({ showEditDialog: show }),
editingItem: null,
setEditingItem: (item) => set({ editingItem: item }),
getList: async (params = {}) => {
const { page = 1, pageSize = 20, search } = params;
set({ loading: true });
try {
const res = await queryApi.mark.list({
markType: 'cnb',
page,
pageSize,
search,
sort: 'DESC'
});
if (res.code === 200) {
set({ list: res.data?.list || [] });
} else {
toast.error(res.message || '获取列表失败');
}
} catch (e) {
console.error('获取workspace列表失败', e);
toast.error('获取列表失败');
} finally {
set({ loading: false });
}
},
createItem: async (data) => {
try {
const res = await queryApi.mark.create({
name: data.name,
markType: 'cnb',
data: data.data || {}
});
if (res.code === 200) {
toast.success('创建成功');
get().getList();
set({ showCreateDialog: false });
} else {
toast.error(res.message || '创建失败');
}
} catch (e) {
console.error('创建失败', e);
toast.error('创建失败');
}
},
updateItem: async (id, data) => {
try {
const res = await queryApi.mark.update({
id,
...data
});
if (res.code === 200) {
toast.success('更新成功');
get().getList();
set({ showEditDialog: false, editingItem: null });
} else {
toast.error(res.message || '更新失败');
}
} catch (e) {
console.error('更新失败', e);
toast.error('更新失败');
}
},
deleteItem: async (id) => {
try {
const res = await queryApi.mark.delete({ id });
if (res.code === 200) {
toast.success('删除成功');
get().getList();
} else {
toast.error(res.message || '删除失败');
}
} catch (e) {
console.error('删除失败', e);
toast.error('删除失败');
}
},
getItem: async (id) => {
try {
const res = await queryApi.mark.get({ id });
if (res.code === 200) {
return res.data;
} else {
toast.error(res.message || '获取详情失败');
return null;
}
} catch (e) {
console.error('获取详情失败', e);
return null;
}
}
}));