fix
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
2025-10-13 12:51:23 +08:00
parent 41819b6d9b
commit eda470cb78
2 changed files with 33 additions and 11 deletions

View File

@@ -6,6 +6,9 @@ const problemStore = useProblemStore()
const { problem } = storeToRefs(problemStore)
const mermaidContainer = useTemplateRef<HTMLElement>("mermaidContainer")
// 渲染状态
const renderError = ref<string | null>(null)
// 动态导入 mermaid
let mermaid: any = null
@@ -23,8 +26,11 @@ const loadMermaid = async () => {
return mermaid
}
// 初始化Mermaid并渲染
onMounted(async () => {
// 渲染流程图的函数
const renderFlowchart = async () => {
try {
renderError.value = null
// 确保 mermaid 已加载
await loadMermaid()
@@ -34,11 +40,27 @@ onMounted(async () => {
const { svg } = await mermaid.render(id, problem.value.mermaid_code)
mermaidContainer.value.innerHTML = svg
}
} catch (error) {
renderError.value =
error instanceof Error ? error.message : "流程图渲染失败,请检查代码格式"
}
}
// 初始化Mermaid并渲染
onMounted(() => {
renderFlowchart()
})
</script>
<template>
<div ref="mermaidContainer" class="container"></div>
<div>
<n-alert v-if="renderError" type="error" title="流程图渲染失败">
<template #default>
{{ renderError }}
</template>
</n-alert>
<div v-else ref="mermaidContainer" class="container"></div>
</div>
</template>
<style scoped>

View File

@@ -122,7 +122,7 @@ watch(isMobile, (value) => {
<ProblemContent />
</n-tab-pane>
<n-tab-pane
v-if="problem.show_flowchart"
v-if="problem.show_flowchart && problem.mermaid_code"
name="flowchart"
tab="流程图表"
>