first commit
This commit is contained in:
314
src/renderer/views/chat/ChatView.vue
Normal file
314
src/renderer/views/chat/ChatView.vue
Normal file
@@ -0,0 +1,314 @@
|
||||
<template>
|
||||
<div class="chat-page">
|
||||
<!-- 服务状态栏 -->
|
||||
<div class="status-bar">
|
||||
<div class="status-indicator">
|
||||
<span class="dot" :class="serviceStatus" />
|
||||
<span class="status-text">{{ statusText }}</span>
|
||||
</div>
|
||||
<div class="status-actions">
|
||||
<el-button v-if="!isRunning" size="small" type="primary" :loading="isStarting" @click="startService">
|
||||
启动服务
|
||||
</el-button>
|
||||
<el-button v-else size="small" type="danger" plain @click="stopService">
|
||||
停止服务
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 消息列表 -->
|
||||
<div ref="messagesRef" class="messages">
|
||||
<div v-if="messages.length === 0" class="empty-hint">
|
||||
<el-icon :size="40" color="#c0c4cc"><ChatDotRound /></el-icon>
|
||||
<p>启动服务后开始对话</p>
|
||||
</div>
|
||||
<div
|
||||
v-for="msg in messages"
|
||||
:key="msg.id"
|
||||
class="bubble-wrap"
|
||||
:class="msg.role"
|
||||
>
|
||||
<div class="bubble">
|
||||
<pre class="bubble-text">{{ msg.text }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 输入区 -->
|
||||
<div class="input-area">
|
||||
<el-input
|
||||
v-model="inputText"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 2, maxRows: 5 }"
|
||||
placeholder="输入消息,Ctrl+Enter 发送"
|
||||
:disabled="!isRunning || isSending"
|
||||
resize="none"
|
||||
@keydown.ctrl.enter.prevent="send"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
:disabled="!isRunning || isSending || !inputText.trim()"
|
||||
:loading="isSending"
|
||||
@click="send"
|
||||
>
|
||||
发送
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onUnmounted, nextTick } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ChatDotRound } from '@element-plus/icons-vue'
|
||||
import { createEventSource } from '@/http/api.js'
|
||||
|
||||
const isRunning = ref(false)
|
||||
const isStarting = ref(false)
|
||||
const isSending = ref(false)
|
||||
const inputText = ref('')
|
||||
const messages = ref([])
|
||||
const messagesRef = ref(null)
|
||||
const currentSessionId = ref(null)
|
||||
let eventSource = null
|
||||
|
||||
const serviceStatus = computed(() => {
|
||||
if (isStarting.value) return 'starting'
|
||||
return isRunning.value ? 'running' : 'stopped'
|
||||
})
|
||||
|
||||
const statusText = computed(() => {
|
||||
if (isStarting.value) return '正在启动...'
|
||||
return isRunning.value ? '服务运行中' : '服务未启动'
|
||||
})
|
||||
|
||||
function scrollToBottom() {
|
||||
nextTick(() => {
|
||||
if (messagesRef.value) {
|
||||
messagesRef.value.scrollTop = messagesRef.value.scrollHeight
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function upsertAssistantBubble(msgId, text) {
|
||||
const existing = messages.value.find(m => m.id === msgId)
|
||||
if (existing) {
|
||||
existing.text = text
|
||||
} else {
|
||||
messages.value.push({ id: msgId, role: 'assistant', text })
|
||||
}
|
||||
scrollToBottom()
|
||||
}
|
||||
|
||||
function connectSSE() {
|
||||
if (eventSource) eventSource.close()
|
||||
eventSource = createEventSource()
|
||||
|
||||
eventSource.onmessage = (e) => {
|
||||
try {
|
||||
const data = JSON.parse(e.data)
|
||||
const props = data.properties || {}
|
||||
|
||||
if (data.type === 'message.part.updated') {
|
||||
const part = props.part
|
||||
if (!part || part.type !== 'text') return
|
||||
if (part.sessionID !== currentSessionId.value) return
|
||||
upsertAssistantBubble(part.messageID, part.text || '')
|
||||
}
|
||||
|
||||
if (data.type === 'message.completed') {
|
||||
isSending.value = false
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
eventSource.onerror = () => {
|
||||
isSending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function startService() {
|
||||
isStarting.value = true
|
||||
try {
|
||||
const info = await window.opencode.start()
|
||||
isRunning.value = info.running
|
||||
// 更新 baseUrl 供 http 层使用
|
||||
if (info.url) window.__opencodeBaseUrl = info.url
|
||||
connectSSE()
|
||||
ElMessage.success('服务已启动')
|
||||
} catch (err) {
|
||||
ElMessage.error(`启动失败: ${err.message}`)
|
||||
} finally {
|
||||
isStarting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function stopService() {
|
||||
await window.opencode.stop()
|
||||
isRunning.value = false
|
||||
currentSessionId.value = null
|
||||
messages.value = []
|
||||
if (eventSource) { eventSource.close(); eventSource = null }
|
||||
ElMessage.info('服务已停止')
|
||||
}
|
||||
|
||||
async function send() {
|
||||
const text = inputText.value.trim()
|
||||
if (!text || isSending.value) return
|
||||
|
||||
// 首次发送时创建会话
|
||||
if (!currentSessionId.value) {
|
||||
try {
|
||||
const session = await window.opencode.createSession()
|
||||
currentSessionId.value = session.id
|
||||
} catch (err) {
|
||||
ElMessage.error(`创建会话失败: ${err.message}`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
messages.value.push({ id: Date.now(), role: 'user', text })
|
||||
inputText.value = ''
|
||||
isSending.value = true
|
||||
scrollToBottom()
|
||||
|
||||
try {
|
||||
await window.opencode.sendMessage(currentSessionId.value, text)
|
||||
} catch (err) {
|
||||
ElMessage.error(`发送失败: ${err.message}`)
|
||||
isSending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化时同步服务状态
|
||||
window.opencode?.info().then((info) => {
|
||||
isRunning.value = info.running
|
||||
if (info.running) {
|
||||
if (info.url) window.__opencodeBaseUrl = info.url
|
||||
connectSSE()
|
||||
}
|
||||
}).catch(() => {})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (eventSource) eventSource.close()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.chat-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.status-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 16px;
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #e4e7ed;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dot.stopped { background: #c0c4cc; }
|
||||
.dot.starting { background: #e6a23c; animation: pulse 1s infinite; }
|
||||
.dot.running { background: #67c23a; }
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.3; }
|
||||
}
|
||||
|
||||
.messages {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 8px 4px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.empty-hint {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
color: #c0c4cc;
|
||||
font-size: 14px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.bubble-wrap {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.bubble-wrap.user { justify-content: flex-end; }
|
||||
.bubble-wrap.assistant { justify-content: flex-start; }
|
||||
|
||||
.bubble {
|
||||
max-width: 75%;
|
||||
padding: 10px 14px;
|
||||
border-radius: 12px;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.bubble-wrap.user .bubble {
|
||||
background: #409eff;
|
||||
color: #fff;
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
|
||||
.bubble-wrap.assistant .bubble {
|
||||
background: #f0f2f5;
|
||||
color: #303133;
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
|
||||
.bubble-text {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.input-area {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: flex-end;
|
||||
padding: 12px 16px;
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #e4e7ed;
|
||||
}
|
||||
|
||||
.input-area .el-textarea {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.input-area .el-button {
|
||||
height: 60px;
|
||||
padding: 0 20px;
|
||||
}
|
||||
</style>
|
||||
425
src/renderer/views/home/HomeView.vue
Normal file
425
src/renderer/views/home/HomeView.vue
Normal file
@@ -0,0 +1,425 @@
|
||||
<template>
|
||||
<div class="home-container">
|
||||
<!-- 顶部欢迎区 -->
|
||||
<div class="welcome-section">
|
||||
<div class="welcome-content">
|
||||
<h1 class="welcome-title">
|
||||
<span class="greeting">你好,开发者</span>
|
||||
<span class="emoji">👋</span>
|
||||
</h1>
|
||||
<p class="welcome-subtitle">准备好开始今天的创作了吗?</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 统计卡片区 -->
|
||||
<el-row :gutter="16" class="stats-row">
|
||||
<el-col :span="8" v-for="(stat, index) in stats" :key="index">
|
||||
<el-card class="stat-card" shadow="hover">
|
||||
<div class="stat-content">
|
||||
<div class="stat-icon" :style="{ background: stat.color + '20' }">
|
||||
<el-icon :size="24" :color="stat.color">
|
||||
<component :is="stat.icon" />
|
||||
</el-icon>
|
||||
</div>
|
||||
<div class="stat-info">
|
||||
<p class="stat-value">{{ stat.value }}</p>
|
||||
<p class="stat-label">{{ stat.label }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-trend" :class="stat.trend > 0 ? 'up' : 'down'">
|
||||
<el-icon><component :is="stat.trend > 0 ? Top : Bottom" /></el-icon>
|
||||
<span>{{ Math.abs(stat.trend) }}% 较上周</span>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 主要内容区 -->
|
||||
<el-row :gutter="16" class="main-content">
|
||||
<!-- 快捷操作区 -->
|
||||
<el-col :span="12">
|
||||
<el-card class="action-card" shadow="hover">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<el-icon><Grid /></el-icon>
|
||||
<span>快捷操作</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="action-grid">
|
||||
<div
|
||||
v-for="action in actions"
|
||||
:key="action.label"
|
||||
class="action-item"
|
||||
@click="action.onClick"
|
||||
>
|
||||
<div class="action-icon" :style="{ background: action.color + '20' }">
|
||||
<el-icon :size="28" :color="action.color">
|
||||
<component :is="action.icon" />
|
||||
</el-icon>
|
||||
</div>
|
||||
<span class="action-label">{{ action.label }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
|
||||
<!-- 最近文件区 -->
|
||||
<el-col :span="12">
|
||||
<el-card class="recent-card" shadow="hover">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<el-icon><Clock /></el-icon>
|
||||
<span>最近访问</span>
|
||||
</div>
|
||||
</template>
|
||||
<el-scrollbar height="280px">
|
||||
<div class="recent-list">
|
||||
<div
|
||||
v-for="(item, index) in recents"
|
||||
:key="index"
|
||||
class="recent-item"
|
||||
@click="handleFileClick(item)"
|
||||
>
|
||||
<div class="file-icon">
|
||||
<el-icon :size="20"><Document /></el-icon>
|
||||
</div>
|
||||
<div class="file-info">
|
||||
<p class="file-name">{{ item.name }}</p>
|
||||
<p class="file-path">{{ item.path }}</p>
|
||||
</div>
|
||||
<span class="file-time">{{ item.time }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useRouter } from 'vue-router'
|
||||
import {
|
||||
Document,
|
||||
Plus,
|
||||
FolderOpened,
|
||||
Setting,
|
||||
Upload,
|
||||
Top,
|
||||
Bottom,
|
||||
Grid,
|
||||
Clock,
|
||||
Timer,
|
||||
VideoCamera
|
||||
} from '@element-plus/icons-vue'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const stats = [
|
||||
{
|
||||
label: '文件总数',
|
||||
value: '128',
|
||||
trend: 12,
|
||||
icon: Document,
|
||||
color: '#409EFF'
|
||||
},
|
||||
{
|
||||
label: '今日编辑',
|
||||
value: '24',
|
||||
trend: -3,
|
||||
icon: Timer,
|
||||
color: '#67C23A'
|
||||
},
|
||||
{
|
||||
label: '运行次数',
|
||||
value: '56',
|
||||
trend: 8,
|
||||
icon: VideoCamera,
|
||||
color: '#E6A23C'
|
||||
},
|
||||
]
|
||||
|
||||
const actions = [
|
||||
{
|
||||
label: '新建文件',
|
||||
icon: Plus,
|
||||
color: '#409EFF',
|
||||
onClick: () => router.push('/editor')
|
||||
},
|
||||
{
|
||||
label: '打开文件',
|
||||
icon: FolderOpened,
|
||||
color: '#67C23A',
|
||||
onClick: () => {}
|
||||
},
|
||||
{
|
||||
label: '导入项目',
|
||||
icon: Upload,
|
||||
color: '#E6A23C',
|
||||
onClick: () => {}
|
||||
},
|
||||
{
|
||||
label: '系统设置',
|
||||
icon: Setting,
|
||||
color: '#F56C6C',
|
||||
onClick: () => {}
|
||||
},
|
||||
]
|
||||
|
||||
const recents = [
|
||||
{ name: 'main.js', path: '/src/main', time: '2 分钟前' },
|
||||
{ name: 'App.vue', path: '/src/renderer', time: '1 小时前' },
|
||||
{ name: 'index.css', path: '/src/renderer', time: '昨天' },
|
||||
{ name: 'forge.config.js', path: '/', time: '3 天前' },
|
||||
{ name: 'package.json', path: '/', time: '5 天前' },
|
||||
]
|
||||
|
||||
const handleFileClick = (item) => {
|
||||
console.log('点击文件:', item)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.home-container {
|
||||
padding: 24px;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
||||
}
|
||||
|
||||
/* 欢迎区样式 */
|
||||
.welcome-section {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.welcome-content {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.welcome-title {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.greeting {
|
||||
background: linear-gradient(90deg, #409EFF 0%, #67C23A 100%);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.emoji {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.welcome-subtitle {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
margin: 8px 0 0 0;
|
||||
}
|
||||
|
||||
/* 统计卡片区 */
|
||||
.stats-row {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
border-radius: 12px;
|
||||
border: none;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
transform: translateY(-4px);
|
||||
}
|
||||
|
||||
.stat-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.stat-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 32px;
|
||||
font-weight: 700;
|
||||
color: #303133;
|
||||
margin: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
margin: 6px 0 0 0;
|
||||
}
|
||||
|
||||
.stat-trend {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 12px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.stat-trend.up {
|
||||
color: #67C23A;
|
||||
}
|
||||
|
||||
.stat-trend.down {
|
||||
color: #F56C6C;
|
||||
}
|
||||
|
||||
/* 主要内容区 */
|
||||
.main-content {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.action-card,
|
||||
.recent-card {
|
||||
border-radius: 12px;
|
||||
border: none;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
/* 快捷操作区 */
|
||||
.action-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 16px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.action-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 20px 16px;
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
.action-item:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.action-item:hover .action-icon {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.action-label {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* 最近文件区 */
|
||||
.recent-list {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.recent-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.recent-item:hover {
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
.file-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 8px;
|
||||
background: #ecf5ff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
color: #409EFF;
|
||||
}
|
||||
|
||||
.file-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.file-name {
|
||||
font-size: 14px;
|
||||
color: #303133;
|
||||
margin: 0;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.file-path {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin: 4px 0 0 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.file-time {
|
||||
font-size: 12px;
|
||||
color: #C0C4CC;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user