fix: clear stale split result on code edit, show error on submit failure

This commit is contained in:
2026-03-29 09:28:41 -06:00
parent 5f95b88914
commit 1744c405a5

View File

@@ -31,7 +31,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue" import { ref, watch } from "vue"
import { useMessage } from "naive-ui" import { useMessage } from "naive-ui"
import { html, css, js } from "../store/editors" import { html, css, js } from "../store/editors"
import { Submission } from "../api" import { Submission } from "../api"
@@ -44,6 +44,10 @@ const rawCode = ref("")
const splitResult = ref<{ html: string; css: string; js: string } | null>(null) const splitResult = ref<{ html: string; css: string; js: string } | null>(null)
const submitting = ref(false) const submitting = ref(false)
watch(rawCode, () => {
splitResult.value = null
})
function splitHtml(raw: string): { html: string; css: string; js: string } { function splitHtml(raw: string): { html: string; css: string; js: string } {
let result = raw let result = raw
const cssBlocks: string[] = [] const cssBlocks: string[] = []
@@ -90,7 +94,7 @@ async function submit() {
rawCode.value = "" rawCode.value = ""
splitResult.value = null splitResult.value = null
} catch { } catch {
// 静默失败,保留表单内容以便重试 message.error("提交失败,请重试")
} finally { } finally {
submitting.value = false submitting.value = false
} }