feat: AI assistant panel, editor improvements, vite and package config

This commit is contained in:
2026-06-15 10:24:27 +08:00
parent 80b361813e
commit 33357650c7
10 changed files with 721 additions and 5 deletions

View File

@@ -17,6 +17,29 @@ const store = useEditorStore()
const jsonText = ref('')
const errorMsg = ref('')
const saved = ref(false)
const showAcceptReject = ref(false)
const preAIValue = ref('')
watch(() => store.aiResult, (result) => {
if (!result) return
preAIValue.value = jsonText.value
jsonText.value = result
showAcceptReject.value = true
errorMsg.value = ''
})
function acceptAI() {
showAcceptReject.value = false
jsonText.value = jsonText.value
store.setAIResult('')
onBlur()
}
function rejectAI() {
jsonText.value = preAIValue.value
showAcceptReject.value = false
store.setAIResult('')
}
watch(() => [props.scene, store.gameData] as const, () => {
errorMsg.value = ''
@@ -56,10 +79,15 @@ function onBlur() {
<div class="editor-header">
<h3>{{ scene ? scene.id : '全局配置' }}</h3>
<div class="header-actions">
<span v-if="saved" class="saved-hint">已保存</span>
<span v-if="showAcceptReject" class="ai-actions">
<button class="ai-accept-btn" @click.stop="acceptAI">接受</button>
<button class="ai-reject-btn" @click.stop="rejectAI">撤销</button>
</span>
<span v-else-if="saved" class="saved-hint">已保存</span>
<span v-if="errorMsg" class="error-hint">JSON 错误: {{ errorMsg }}</span>
<button v-if="scene" class="icon-btn danger" @click="emit('deleteScene', scene.id)" title="删除场景">删除场景</button>
<button v-if="scene" class="icon-btn" @click="emit('close')" title="关闭">关闭</button>
<button class="icon-btn" @click="store.showAIPanel = true" title="AI 助手">🤖</button>
<button v-if="scene" class="icon-btn danger" @click="emit('deleteScene', scene.id)" title="删除场景">🗑</button>
<button v-if="scene" class="icon-btn" @click="emit('close')" title="关闭"></button>
</div>
</div>
@@ -147,6 +175,33 @@ function onBlur() {
.icon-btn:hover { color: #ddd; border-color: rgba(255,255,255,0.25); }
.icon-btn.danger:hover { color: #e74c3c; border-color: #e74c3c; }
.ai-actions {
display: flex;
gap: 4px;
}
.ai-accept-btn {
padding: 3px 8px;
font-size: 11px;
color: #fff;
background: #4caf50;
border: none;
border-radius: 3px;
cursor: pointer;
}
.ai-accept-btn:hover { background: #388e3c; }
.ai-reject-btn {
padding: 3px 8px;
font-size: 11px;
color: #fff;
background: #e74c3c;
border: none;
border-radius: 3px;
cursor: pointer;
}
.ai-reject-btn:hover { background: #c62828; }
.json-area {
flex: 1;
padding: 14px 16px;