import { api } from './client.js' const q = (params) => { const s = new URLSearchParams() Object.entries(params || {}).forEach(([k, v]) => { if (v !== undefined && v !== null && v !== '') s.set(k, v) }) const str = s.toString() return str ? '?' + str : '' } // 项目 export const projectApi = { list: () => api('/projects'), detail: (id) => api(`/projects/${id}`), create: (body) => api('/projects', { method: 'POST', body }), update: (id, body) => api(`/projects/${id}`, { method: 'PUT', body }), remove: (id) => api(`/projects/${id}`, { method: 'DELETE' }), addMember: (id, body) => api(`/projects/${id}/members`, { method: 'POST', body }), removeMember: (id, uid) => api(`/projects/${id}/members/${uid}`, { method: 'DELETE' }), } // 看板列 export const columnApi = { list: (projectId) => api(`/projects/${projectId}/columns`), add: (projectId, body) => api(`/projects/${projectId}/columns`, { method: 'POST', body }), update: (id, body) => api(`/columns/${id}`, { method: 'PUT', body }), remove: (id, moveToColumnId) => api(`/columns/${id}${q({ moveToColumnId })}`, { method: 'DELETE' }), order: (projectId, ids) => api(`/projects/${projectId}/columns/order`, { method: 'PUT', body: { ids } }), } // 任务 export const taskApi = { list: (projectId) => api(`/projects/${projectId}/tasks`), create: (projectId, body) => api(`/projects/${projectId}/tasks`, { method: 'POST', body }), detail: (id) => api(`/tasks/${id}`), update: (id, body) => api(`/tasks/${id}`, { method: 'PUT', body }), reorder: (projectId, ids) => api(`/projects/${projectId}/tasks/reorder`, { method: 'POST', body: { ids } }), remove: (id) => api(`/tasks/${id}`, { method: 'DELETE' }), copy: (id, projectId) => api(`/tasks/${id}/copy`, { method: 'POST', body: { projectId } }), archive: (id) => api(`/tasks/${id}/archive`, { method: 'POST', body: {} }), unarchive: (id) => api(`/tasks/${id}/unarchive`, { method: 'POST', body: {} }), archivedList: (projectId, params) => api(`/projects/${projectId}/tasks/archived` + q(params)), }