重构: ARC-05 project.ts 上帝 store 拆分(4 子 store+barrel 兼容零改动)

拆 stores/project/{state,projects,tasks,ideas,workflow}.ts 四领域子 store(共享 state 单例 reactive 引用一致);越层 invoke approve_human_approval/cancel_workflow_node 下沉 src/api/workflow.ts;project.ts 改 barrel 组合器(实例化四子 store+re-export 所有成员,useProjectStore 单例+ProjectStore 类型保留)。所有 view(App/Dashboard/Ideas/ProjectDetail/Projects/Tasks/ToolCard)import '../stores/project' 零改动。行为零变化(含 CR-11⑪ approveHumanApproval 签名+B-34 snake_case)。批6,vue-tsc 0
This commit is contained in:
lxy
2026-06-15 05:48:47 +08:00
parent d809cf4b18
commit 8710d6cfd1
7 changed files with 456 additions and 322 deletions
+48
View File
@@ -0,0 +1,48 @@
import { taskApi } from '../../api'
import { state } from './state'
/** 任务 CRUD 子 store(共享全局 state) */
export function createTasksStore() {
async function loadTasks(projectId?: string) {
try {
state.tasks = await taskApi.list(projectId)
} catch (e: any) {
state.error = e?.toString() ?? '加载任务失败'
}
}
async function createTask(input: { project_id: string; title: string; description?: string; priority?: number; branch_name?: string; assignee?: string }) {
try {
const record = await taskApi.create(input)
state.tasks.push(record)
return record
} catch (e: any) {
state.error = e?.toString() ?? '创建任务失败'
return null
}
}
async function updateTask(id: string, field: string, value: string) {
await taskApi.update(id, field, value)
const idx = state.tasks.findIndex(t => t.id === id)
if (idx >= 0) {
(state.tasks[idx] as any)[field] = value
}
}
async function deleteTask(id: string) {
try {
await taskApi.delete(id)
state.tasks = state.tasks.filter(t => t.id !== id)
} catch (e: any) {
state.error = e?.toString() ?? '删除任务失败'
}
}
return {
loadTasks,
createTask,
updateTask,
deleteTask,
}
}