feat: add version history and AI diff highlighting in editor
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, nextTick } from 'vue'
|
||||
import { ref, nextTick, onMounted } from 'vue'
|
||||
import { useEditorStore } from '../stores/editorStore'
|
||||
import { sendAIRequest } from '../composables/useAI'
|
||||
|
||||
@@ -40,13 +40,19 @@ async function send() {
|
||||
messages.value.push({ role: 'user', content: userInput })
|
||||
loading.value = true
|
||||
|
||||
if (mode.value === 'json') {
|
||||
await store.saveVersion('AI 修改前')
|
||||
}
|
||||
|
||||
const oldGameData = mode.value === 'json' ? JSON.parse(JSON.stringify(store.gameData)) : undefined
|
||||
|
||||
try {
|
||||
const { result, sessionId: newSid } = await sendAIRequest(fullMessage, mode.value, store.deepseekKey, store.aiSessionId || undefined)
|
||||
if (newSid) store.setAISessionId(newSid)
|
||||
|
||||
if (mode.value === 'json') {
|
||||
messages.value.push({ role: 'assistant', content: result || '已完成' })
|
||||
await store.reloadFromDisk()
|
||||
await store.reloadFromDisk(oldGameData)
|
||||
} else {
|
||||
messages.value.push({ role: 'assistant', content: result || '已完成' })
|
||||
}
|
||||
@@ -68,6 +74,10 @@ function newSession() {
|
||||
messages.value = []
|
||||
errorMsg.value = ''
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
store.loadVersions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -83,6 +93,16 @@ function newSession() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="store.versions.length > 0 || store.aiChanges" class="ai-toolbar">
|
||||
<select v-if="store.versions.length > 0" class="ai-version-select" @change="store.restoreVersion(($event.target as HTMLSelectElement).selectedIndex)">
|
||||
<option disabled selected>历史版本</option>
|
||||
<option v-for="v in store.versions" :key="v.timestamp">
|
||||
{{ new Date(v.timestamp).toLocaleString('zh-CN') }} {{ v.label }}
|
||||
</option>
|
||||
</select>
|
||||
<button v-if="store.aiChanges" class="ai-clear-btn" @click="store.clearAIMarkers()">清除高亮</button>
|
||||
</div>
|
||||
|
||||
<div class="ai-chat" ref="chatRef">
|
||||
<div v-if="!store.deepseekKey" class="ai-key-setup">
|
||||
<span class="key-label">DeepSeek API Key</span>
|
||||
@@ -289,4 +309,36 @@ function newSession() {
|
||||
font-size: 11px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.ai-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 16px;
|
||||
border-bottom: 1px solid rgba(255,255,255,0.06);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ai-version-select {
|
||||
flex: 1;
|
||||
padding: 4px 8px;
|
||||
font-size: 11px;
|
||||
background: rgba(255,255,255,0.05);
|
||||
border: 1px solid rgba(255,255,255,0.1);
|
||||
border-radius: 3px;
|
||||
color: #ccc;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.ai-clear-btn {
|
||||
padding: 4px 10px;
|
||||
font-size: 11px;
|
||||
color: #ccc;
|
||||
background: rgba(255,255,255,0.05);
|
||||
border: 1px solid rgba(255,255,255,0.1);
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ai-clear-btn:hover { color: #fff; border-color: rgba(255,255,255,0.2); }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user