fix: 修复 schema 切换时 generator 被旧 config 调用导致白板

根因: activeSchemaId 变化后,ConfigForm 还没 emit 新默认值,generator 就用旧 config 执行了
修复: 在 App.vue 中 watch activeSchemaId,切换时立即用新 schema 默认值重置 config
同时修复 bind.js 中 forwarders.split() 的防御性空值处理
This commit is contained in:
cnbugs
2026-07-19 16:25:07 +08:00
parent 14f02df58d
commit b951e29c00
3 changed files with 12 additions and 2 deletions
+6 -1
View File
@@ -15,7 +15,7 @@
</template>
<script setup>
import { ref, computed } from 'vue'
import { ref, computed, watch } from 'vue'
import Sidebar from './components/Sidebar.vue'
import ConfigForm from './components/ConfigForm.vue'
import CodePreview from './components/CodePreview.vue'
@@ -26,6 +26,11 @@ const currentConfig = ref({})
const currentSchema = computed(() => schemas[activeSchemaId.value])
// 当 schema 切换时,立即用新 schema 的默认值重置 config
watch(activeSchemaId, (newId) => {
currentConfig.value = getDefaultValues(schemas[newId])
})
const generatedCode = computed(() => {
const gen = generators[activeSchemaId.value]
if (!gen) return ''
+5
View File
@@ -5,6 +5,11 @@ import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import App from './App.vue'
const app = createApp(App)
app.config.errorHandler = (err, instance, info) => {
console.error('Vue Error:', err, info)
}
app.use(ElementPlus, { size: 'default' })
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
+1 -1
View File
@@ -174,7 +174,7 @@ export function generateBindConf(config) {
lines.push(` recursion ${config.recursion ? 'yes' : 'no'};`)
lines.push(``)
lines.push(` forwarders {`)
const forwarders = config.forwarders.split(';').map((s) => s.trim()).filter(Boolean)
const forwarders = (config.forwarders || '').split(';').map((s) => s.trim()).filter(Boolean)
forwarders.forEach((f) => {
lines.push(` ${f};`)
})