实现了基于 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>
206 lines
4.7 KiB
Vue
206 lines
4.7 KiB
Vue
<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>
|