Files
cc-cloud/frontend/src/views/Instances.vue
T
hughhuangandClaude Sonnet 4.5 56db593f96 feat: 完善项目文档和功能验证
## 新增功能

### 核心功能完善
- 添加实例交互服务(interaction.service.ts)
- 添加日志查询服务(log.service.ts)
- 添加监控数据服务(monitor.service.ts)
- 完善开发模式进程管理
- 优化实例列表展示

### API 接口
- POST /api/interactions/:id/chat - 实例交互
- GET /api/logs/:id - 查询实例日志
- GET /api/monitor/:id - 获取监控数据

## 文档完善

### 开发文档
- CLAUDE_GUIDE.md - Claude Code 开发指南
  - 完整的项目架构说明
  - 核心概念和业务流程详解
  - API 接口文档
  - 功能扩展指南

- PROJECT_SUMMARY.md - 项目总结文档
  - 已完成工作列表
  - 文档结构说明
  - 核心亮点总结

### 测试文档
- FUNCTIONALITY_TEST_REPORT.md - 功能验证报告
  - 测试通过的功能列表
  - 发现的问题和改进建议
  - 测试覆盖率分析(93%)

- PLAYWRIGHT_MCP_TESTING.md - 测试指南
  - Playwright MCP 使用教程
  - 测试用例详解
  - 快速开始指南

- FINAL_SUMMARY.md - 最终总结
  - 项目完成状态
  - 核心功能验证
  - 后续改进建议

## 功能验证

使用 Playwright MCP 完成端到端测试:
- ✅ 应用启动和认证
- ✅ 实例管理(启动/停止/查看)
- ✅ 日志和监控数据展示
- ✅ 实例详情页功能

测试通过率:82%(9/11 完全通过)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-03 13:25:34 +08:00

220 lines
6.1 KiB
Vue

<template>
<div class="instances">
<div class="page-header">
<h1>实例管理</h1>
<el-button type="primary" @click="showCreateDialog = true">
<el-icon><Plus /></el-icon>
创建实例
</el-button>
</div>
<el-card>
<el-table :data="instances" v-loading="loading">
<el-table-column prop="name" label="实例名称" />
<el-table-column prop="status" label="状态">
<template #default="{ row }">
<el-tag :type="getStatusType(row.status)">
{{ getStatusText(row.status) }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="config.workingDir" label="工作目录" />
<el-table-column prop="stats.port" label="端口" />
<el-table-column label="操作" width="300">
<template #default="{ row }">
<el-button
v-if="row.status === 'stopped'"
type="success"
size="small"
@click="handleStart(row.id)"
>
启动
</el-button>
<el-button
v-if="row.status === 'running'"
type="warning"
size="small"
@click="handleStop(row.id)"
>
停止
</el-button>
<el-button type="primary" size="small" @click="handleView(row.id)">
查看
</el-button>
<el-button type="danger" size="small" @click="handleDelete(row.id)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
<!-- 创建实例对话框 -->
<el-dialog v-model="showCreateDialog" title="创建实例" width="600px">
<el-form :model="createForm" label-width="120px">
<el-form-item label="实例名称">
<el-input v-model="createForm.name" placeholder="请输入实例名称" />
</el-form-item>
<el-form-item label="工作目录">
<el-input v-model="createForm.workingDir" placeholder="请输入工作目录路径" />
</el-form-item>
<el-form-item label="模型">
<el-select v-model="createForm.model" placeholder="请选择模型">
<el-option label="Claude Sonnet 4.5" value="claude-sonnet-4-5" />
<el-option label="Claude Opus 4.5" value="claude-opus-4-5" />
</el-select>
</el-form-item>
<el-form-item label="API Key">
<el-input v-model="createForm.apiKey" type="password" placeholder="可选,留空使用默认" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="showCreateDialog = false">取消</el-button>
<el-button type="primary" @click="handleCreate">创建</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
import { useInstanceStore } from '@/stores/instance';
const router = useRouter();
const instanceStore = useInstanceStore();
const loading = ref(false);
const showCreateDialog = ref(false);
const instances = ref(instanceStore.instances);
const createForm = ref({
name: '',
workingDir: '',
model: 'claude-sonnet-4-5',
apiKey: '',
});
onMounted(async () => {
loading.value = true;
try {
await instanceStore.fetchInstances();
instances.value = instanceStore.instances;
} finally {
loading.value = false;
}
});
const getStatusType = (status: string) => {
const map: Record<string, any> = {
running: 'success',
stopped: 'info',
errored: 'danger',
offline: 'warning',
};
return map[status] || 'info';
};
const getStatusText = (status: string) => {
const map: Record<string, string> = {
running: '运行中',
stopped: '已停止',
errored: '异常',
offline: '离线',
};
return map[status] || status;
};
const handleCreate = async () => {
try {
// 构建请求数据,符合后端 API 格式
const requestData = {
name: createForm.value.name,
config: {
model: createForm.value.model,
workingDir: createForm.value.workingDir,
...(createForm.value.apiKey && { apiKey: createForm.value.apiKey }),
},
};
await instanceStore.createInstance(requestData);
ElMessage.success('创建成功');
showCreateDialog.value = false;
// 重置表单
createForm.value = {
name: '',
workingDir: '',
model: 'claude-sonnet-4-5',
apiKey: '',
};
await instanceStore.fetchInstances();
instances.value = instanceStore.instances;
} catch (error: any) {
ElMessage.error(error.message || '创建失败');
}
};
const handleStart = async (id: string) => {
try {
await instanceStore.startInstance(id);
ElMessage.success('启动成功');
await instanceStore.fetchInstances();
instances.value = instanceStore.instances;
} catch (error: any) {
ElMessage.error(error.message || '启动失败');
}
};
const handleStop = async (id: string) => {
try {
await instanceStore.stopInstance(id);
ElMessage.success('停止成功');
await instanceStore.fetchInstances();
instances.value = instanceStore.instances;
} catch (error: any) {
ElMessage.error(error.message || '停止失败');
}
};
const handleDelete = async (id: string) => {
try {
await ElMessageBox.confirm('确定要删除这个实例吗?', '提示', {
type: 'warning',
});
await instanceStore.deleteInstance(id);
ElMessage.success('删除成功');
await instanceStore.fetchInstances();
instances.value = instanceStore.instances;
} catch (error: any) {
if (error !== 'cancel') {
ElMessage.error(error.message || '删除失败');
}
}
};
const handleView = (id: string) => {
router.push(`/instances/${id}`);
};
</script>
<style scoped>
.instances {
height: 100%;
}
.page-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.page-header h1 {
margin: 0;
color: #303133;
}
</style>