重构: 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:
@@ -0,0 +1,63 @@
|
||||
import { ideaApi } from '../../api'
|
||||
import { state } from './state'
|
||||
|
||||
/** 灵感 CRUD 子 store(共享全局 state) */
|
||||
export function createIdeasStore() {
|
||||
async function loadIdeas() {
|
||||
try {
|
||||
state.ideas = await ideaApi.list()
|
||||
} catch (e: any) {
|
||||
state.error = e?.toString() ?? '加载灵感失败'
|
||||
}
|
||||
}
|
||||
|
||||
async function createIdea(input: { title: string; description?: string; priority?: number; tags?: string; source?: string }) {
|
||||
try {
|
||||
const record = await ideaApi.create(input)
|
||||
state.ideas.push(record)
|
||||
return record
|
||||
} catch (e: any) {
|
||||
state.error = e?.toString() ?? '创建灵感失败'
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function updateIdea(id: string, field: string, value: string) {
|
||||
await ideaApi.update(id, field, value)
|
||||
const idx = state.ideas.findIndex(i => i.id === id)
|
||||
if (idx >= 0) {
|
||||
(state.ideas[idx] as any)[field] = value
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteIdea(id: string) {
|
||||
try {
|
||||
await ideaApi.delete(id)
|
||||
state.ideas = state.ideas.filter(i => i.id !== id)
|
||||
} catch (e: any) {
|
||||
state.error = e?.toString() ?? '删除灵感失败'
|
||||
}
|
||||
}
|
||||
|
||||
async function evaluateIdea(id: string) {
|
||||
const record = await ideaApi.evaluate(id)
|
||||
const idx = state.ideas.findIndex(i => i.id === id)
|
||||
if (idx >= 0) state.ideas[idx] = record
|
||||
return record
|
||||
}
|
||||
|
||||
async function promoteIdea(id: string) {
|
||||
const res = await ideaApi.promote(id)
|
||||
await loadIdeas() // 后端已回写 status=promoted/promoted_to,刷新列表
|
||||
return res
|
||||
}
|
||||
|
||||
return {
|
||||
loadIdeas,
|
||||
createIdea,
|
||||
updateIdea,
|
||||
deleteIdea,
|
||||
evaluateIdea,
|
||||
promoteIdea,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user