feat: 初始化 Claude Code 管理平台项目

实现了基于 Web 的 Claude Code 实例管理功能:

## 功能特性
- 🔐 用户认证:JWT 登录验证
- 🚀 实例管理:创建、启动、停止、删除 Claude Code 实例
- 📊 实时监控:CPU、内存、运行时间统计
- 📝 日志管理:Winston 日志系统
- 🔌 PM2 集成:稳定的进程管理
- 🌐 Web 界面:Vue 3 + Element Plus

## 技术栈
- 后端:Node.js + Express + TypeScript + PM2
- 前端:Vue 3 + TypeScript + Vite + Element Plus
- 认证:JWT
- 存储:文件系统(JSON)

## 项目结构
- Monorepo 结构,前后端分离
- 完整的类型定义
- 模块化设计
- 详细的开发文档

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
hughhuangandClaude Sonnet 4.5 committed 2026-01-02 22:57:33 +08:00
commit ed626e74dc
46 files changed
+11882

No files matched your search

+110
View File
@@ -0,0 +1,110 @@
<template>
<div class="dashboard">
<h1>仪表盘</h1>
<el-row :gutter="20">
<el-col :span="6">
<el-card>
<div class="stat-card">
<el-icon class="stat-icon" color="#409eff"><Server /></el-icon>
<div class="stat-content">
<div class="stat-value">{{ stats.totalInstances }}</div>
<div class="stat-label">总实例数</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="6">
<el-card>
<div class="stat-card">
<el-icon class="stat-icon" color="#67c23a"><CircleCheck /></el-icon>
<div class="stat-content">
<div class="stat-value">{{ stats.runningInstances }}</div>
<div class="stat-label">运行中</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="6">
<el-card>
<div class="stat-card">
<el-icon class="stat-icon" color="#e6a23c"><VideoPause /></el-icon>
<div class="stat-content">
<div class="stat-value">{{ stats.stoppedInstances }}</div>
<div class="stat-label">已停止</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="6">
<el-card>
<div class="stat-card">
<el-icon class="stat-icon" color="#f56c6c"><Warning /></el-icon>
<div class="stat-content">
<div class="stat-value">{{ stats.erroredInstances }}</div>
<div class="stat-label">异常</div>
</div>
</div>
</el-card>
</el-col>
</el-row>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useInstanceStore } from '@/stores/instance';
const instanceStore = useInstanceStore();
const stats = ref({
totalInstances: 0,
runningInstances: 0,
stoppedInstances: 0,
erroredInstances: 0,
});
onMounted(async () => {
await instanceStore.fetchInstances();
const instances = instanceStore.instances;
stats.value = {
totalInstances: instances.length,
runningInstances: instances.filter((i) => i.status === 'running').length,
stoppedInstances: instances.filter((i) => i.status === 'stopped').length,
erroredInstances: instances.filter((i) => i.status === 'errored').length,
};
});
</script>
<style scoped>
.dashboard h1 {
margin-bottom: 20px;
color: #303133;
}
.stat-card {
display: flex;
align-items: center;
gap: 16px;
}
.stat-icon {
font-size: 48px;
}
.stat-content {
flex: 1;
}
.stat-value {
font-size: 32px;
font-weight: bold;
color: #303133;
}
.stat-label {
margin-top: 8px;
font-size: 14px;
color: #909399;
}
</style>
+205
View File
@@ -0,0 +1,205 @@
<template>
<div class="instance-detail">
<h1>实例详情</h1>
<p>实例 ID: {{ $route.params.id }}</p>
<el-tabs>
<el-tab-pane label="交互">
<div class="interaction-panel">
<el-input
v-model="userMessage"
type="textarea"
:rows="4"
placeholder="输入消息..."
@keydown.ctrl.enter="handleSend"
/>
<el-button type="primary" @click="handleSend" :loading="sending">
发送 (Ctrl+Enter)
</el-button>
<div v-if="messages.length" class="messages">
<div v-for="(msg, index) in messages" :key="index" class="message" :class="msg.role">
<div class="message-role">{{ msg.role === 'user' ? '用户' : 'Claude' }}</div>
<div class="message-content">{{ msg.content }}</div>
</div>
</div>
</div>
</el-tab-pane>
<el-tab-pane label="日志">
<div class="log-viewer">
<pre>{{ logs }}</pre>
</div>
</el-tab-pane>
<el-tab-pane label="监控">
<div class="monitor-panel">
<el-descriptions :column="2" border>
<el-descriptions-item label="CPU">{{ monitorData.cpu }}%</el-descriptions-item>
<el-descriptions-item label="内存">{{ formatMemory(monitorData.memory) }}</el-descriptions-item>
<el-descriptions-item label="运行时间">{{ formatUptime(monitorData.uptime) }}</el-descriptions-item>
<el-descriptions-item label="重启次数">{{ monitorData.restarts }}</el-descriptions-item>
</el-descriptions>
</div>
</el-tab-pane>
</el-tabs>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue';
import { useRoute } from 'vue-router';
import { ElMessage } from 'element-plus';
import axios from 'axios';
const route = useRoute();
const instanceId = route.params.id as string;
const userMessage = ref('');
const sending = ref(false);
const messages = ref<Array<{ role: string; content: string }>>([]);
const logs = ref('暂无日志');
const monitorData = ref({
cpu: 0,
memory: 0,
uptime: 0,
restarts: 0,
});
let logInterval: NodeJS.Timeout;
let monitorInterval: NodeJS.Timeout;
onMounted(() => {
// 启动日志轮询
logInterval = setInterval(fetchLogs, 2000);
// 启动监控轮询
monitorInterval = setInterval(fetchMonitor, 3000);
fetchLogs();
fetchMonitor();
});
onUnmounted(() => {
clearInterval(logInterval);
clearInterval(monitorInterval);
});
const handleSend = async () => {
if (!userMessage.value.trim()) {
return;
}
sending.value = true;
try {
// 添加用户消息
messages.value.push({
role: 'user',
content: userMessage.value,
});
// 发送到后端
const response = await axios.post(`/api/interactions/${instanceId}/chat`, {
messages: messages.value,
});
// 添加 AI 响应
messages.value.push({
role: 'assistant',
content: response.data.content,
});
userMessage.value = '';
} catch (error: any) {
ElMessage.error(error.message || '发送失败');
} finally {
sending.value = false;
}
};
const fetchLogs = async () => {
try {
const response = await axios.get(`/api/logs/${instanceId}`);
logs.value = response.data.logs.join('\n');
} catch (error) {
// 静默失败
}
};
const fetchMonitor = async () => {
try {
const response = await axios.get(`/api/monitor/${instanceId}`);
monitorData.value = response.data;
} catch (error) {
// 静默失败
}
};
const formatMemory = (bytes: number) => {
return (bytes / 1024 / 1024).toFixed(2) + ' MB';
};
const formatUptime = (seconds: number) => {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
return `${hours}h ${minutes}m`;
};
</script>
<style scoped>
.instance-detail h1 {
margin-bottom: 20px;
color: #303133;
}
.interaction-panel {
display: flex;
flex-direction: column;
gap: 16px;
}
.messages {
border: 1px solid #e6e6e6;
border-radius: 4px;
padding: 16px;
max-height: 500px;
overflow-y: auto;
}
.message {
margin-bottom: 16px;
padding: 12px;
border-radius: 4px;
}
.message.user {
background-color: #f0f9ff;
}
.message.assistant {
background-color: #f5f5f5;
}
.message-role {
font-weight: bold;
margin-bottom: 8px;
font-size: 14px;
color: #606266;
}
.message-content {
white-space: pre-wrap;
word-break: break-word;
}
.log-viewer {
background-color: #1e1e1e;
color: #d4d4d4;
padding: 16px;
border-radius: 4px;
max-height: 600px;
overflow-y: auto;
}
.log-viewer pre {
margin: 0;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 14px;
line-height: 1.6;
}
</style>
+200
View File
@@ -0,0 +1,200 @@
<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 {
await instanceStore.createInstance(createForm.value);
ElMessage.success('创建成功');
showCreateDialog.value = false;
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>
+126
View File
@@ -0,0 +1,126 @@
<template>
<el-container class="layout-container">
<el-aside width="200px">
<div class="logo">
<h2>CC Cloud</h2>
</div>
<el-menu
:default-active="currentRoute"
router
background-color="#545c64"
text-color="#fff"
active-text-color="#ffd04b"
>
<el-menu-item index="/dashboard">
<el-icon><Monitor /></el-icon>
<span>仪表盘</span>
</el-menu-item>
<el-menu-item index="/instances">
<el-icon><List /></el-icon>
<span>实例管理</span>
</el-menu-item>
<el-menu-item index="/settings">
<el-icon><Setting /></el-icon>
<span>设置</span>
</el-menu-item>
</el-menu>
</el-aside>
<el-container>
<el-header>
<div class="header-content">
<span>{{ currentTitle }}</span>
<el-dropdown @command="handleCommand">
<span class="user-dropdown">
<el-icon><User /></el-icon>
{{ username }}
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="logout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</el-header>
<el-main>
<router-view />
</el-main>
</el-container>
</el-container>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { ElMessage } from 'element-plus';
import { useAuthStore } from '@/stores/auth';
const router = useRouter();
const route = useRoute();
const authStore = useAuthStore();
const username = computed(() => authStore.user?.username || '');
const currentRoute = computed(() => route.path);
const currentTitle = computed(() => route.meta.title || 'CC Cloud');
const handleCommand = (command: string) => {
if (command === 'logout') {
authStore.logout();
ElMessage.success('已退出登录');
router.push('/login');
}
};
</script>
<style scoped>
.layout-container {
height: 100vh;
}
.el-aside {
background-color: #545c64;
}
.logo {
padding: 20px;
text-align: center;
color: #fff;
}
.logo h2 {
margin: 0;
font-size: 20px;
}
.el-header {
background-color: #fff;
border-bottom: 1px solid #e6e6e6;
display: flex;
align-items: center;
justify-content: space-between;
}
.header-content {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 18px;
font-weight: 500;
}
.user-dropdown {
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
}
.el-main {
background-color: #f5f5f5;
padding: 20px;
}
</style>
+114
View File
@@ -0,0 +1,114 @@
<template>
<div class="login-container">
<el-card class="login-card">
<template #header>
<div class="card-header">
<h2>CC Cloud</h2>
<p>Claude Code 管理平台</p>
</div>
</template>
<el-form :model="loginForm" :rules="rules" ref="formRef" @submit.prevent="handleLogin">
<el-form-item prop="username">
<el-input
v-model="loginForm.username"
placeholder="用户名"
prefix-icon="User"
size="large"
/>
</el-form-item>
<el-form-item prop="password">
<el-input
v-model="loginForm.password"
type="password"
placeholder="密码"
prefix-icon="Lock"
size="large"
@keyup.enter="handleLogin"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" size="large" style="width: 100%" :loading="loading" @click="handleLogin">
登录
</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</template>
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { useAuthStore } from '@/stores/auth';
const router = useRouter();
const authStore = useAuthStore();
const formRef = ref<FormInstance>();
const loading = ref(false);
const loginForm = reactive({
username: '',
password: '',
});
const rules: FormRules = {
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
};
const handleLogin = async () => {
if (!formRef.value) return;
await formRef.value.validate(async (valid) => {
if (!valid) return;
loading.value = true;
try {
await authStore.login(loginForm);
ElMessage.success('登录成功');
router.push('/');
} catch (error: any) {
ElMessage.error(error.message || '登录失败');
} finally {
loading.value = false;
}
});
};
</script>
<style scoped>
.login-container {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-card {
width: 400px;
}
.card-header {
text-align: center;
}
.card-header h2 {
margin: 0;
font-size: 24px;
color: #303133;
}
.card-header p {
margin: 8px 0 0;
font-size: 14px;
color: #909399;
}
</style>
+33
View File
@@ -0,0 +1,33 @@
<template>
<div class="settings">
<h1>设置</h1>
<el-card>
<el-form label-width="120px">
<el-form-item label="用户名">
<el-input :value="username" disabled />
</el-form-item>
<el-form-item label="API 端点">
<el-input value="/api" disabled />
</el-form-item>
<el-form-item label="WebSocket">
<el-input value="/socket" disabled />
</el-form-item>
</el-form>
</el-card>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { useAuthStore } from '@/stores/auth';
const authStore = useAuthStore();
const username = computed(() => authStore.user?.username || '');
</script>
<style scoped>
.settings h1 {
margin-bottom: 20px;
color: #303133;
}
</style>