arch-design-agent-skill-das.../frontend/src/modules/project/composables/useProject.ts
openclaw d8071bc9f3 feat(fe-project): add project management UI — list, create, delete
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 17:16:32 +00:00

60 lines
1.6 KiB
TypeScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { Project } from '@/shared/types/api'
import * as projectApi from '../api'
export const useProjectStore = defineStore('project', () => {
const projects = ref<Project[]>([])
const currentProject = ref<Project | null>(null)
const loading = ref(false)
const error = ref<string | null>(null)
async function fetchProjects() {
loading.value = true
error.value = null
try {
projects.value = await projectApi.listProjects()
} catch (e: any) {
error.value = e.message
} finally {
loading.value = false
}
}
async function createProject(name: string, designDir: string, codeDir?: string) {
loading.value = true
error.value = null
try {
const project = await projectApi.createProject(name, designDir, codeDir)
projects.value.push(project)
return project
} catch (e: any) {
error.value = e.response?.data?.detail || e.message
throw e
} finally {
loading.value = false
}
}
async function selectProject(id: string) {
loading.value = true
try {
currentProject.value = await projectApi.getProject(id)
} catch (e: any) {
error.value = e.message
} finally {
loading.value = false
}
}
async function removeProject(id: string) {
await projectApi.deleteProject(id)
projects.value = projects.value.filter(p => p.id !== id)
if (currentProject.value?.id === id) {
currentProject.value = null
}
}
return { projects, currentProject, loading, error, fetchProjects, createProject, selectProject, removeProject }
})