feat: Day 8-9 - Project Management API completed
Backend: - Create project routes (GET, POST, PUT, DELETE) - Implement projectController with CRUD operations - Create projectService for database operations - Add validation middleware for request validation - Update Prisma schema (add background, researchType, deletedAt fields) - Implement soft delete for projects Frontend: - Create projectApi service module - Update useProjectStore with fetchProjects and loading state - Connect ProjectSelector to real API with loading indicator - Connect CreateProjectDialog to real API with error handling - Connect EditProjectDialog to real API with loading state - Add comprehensive error handling and user feedback Build: Both frontend and backend build successfully
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { create } from 'zustand';
|
||||
import { projectApi } from '../api/projectApi';
|
||||
import { message } from 'antd';
|
||||
|
||||
export interface Project {
|
||||
id: string;
|
||||
@@ -16,6 +18,9 @@ interface ProjectState {
|
||||
// 所有项目列表
|
||||
projects: Project[];
|
||||
|
||||
// 加载状态
|
||||
loading: boolean;
|
||||
|
||||
// 是否显示创建项目对话框
|
||||
showCreateDialog: boolean;
|
||||
|
||||
@@ -30,11 +35,14 @@ interface ProjectState {
|
||||
deleteProject: (id: string) => void;
|
||||
setShowCreateDialog: (show: boolean) => void;
|
||||
setShowEditDialog: (show: boolean) => void;
|
||||
setLoading: (loading: boolean) => void;
|
||||
fetchProjects: () => Promise<void>;
|
||||
}
|
||||
|
||||
export const useProjectStore = create<ProjectState>((set) => ({
|
||||
currentProject: null,
|
||||
projects: [],
|
||||
loading: false,
|
||||
showCreateDialog: false,
|
||||
showEditDialog: false,
|
||||
|
||||
@@ -65,5 +73,25 @@ export const useProjectStore = create<ProjectState>((set) => ({
|
||||
setShowCreateDialog: (show) => set({ showCreateDialog: show }),
|
||||
|
||||
setShowEditDialog: (show) => set({ showEditDialog: show }),
|
||||
|
||||
setLoading: (loading) => set({ loading }),
|
||||
|
||||
// 获取项目列表
|
||||
fetchProjects: async () => {
|
||||
try {
|
||||
set({ loading: true });
|
||||
const response = await projectApi.getProjects();
|
||||
if (response.success && response.data) {
|
||||
set({ projects: response.data });
|
||||
} else {
|
||||
message.error(response.message || '获取项目列表失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取项目列表失败:', error);
|
||||
message.error('获取项目列表失败');
|
||||
} finally {
|
||||
set({ loading: false });
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user