fix
This commit is contained in:
@@ -36,8 +36,13 @@ interface Evaluation extends Rating {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ==================== 组合式函数和响应式变量 ====================
|
// ==================== 组合式函数和响应式变量 ====================
|
||||||
|
interface FlowchartEditorInstance {
|
||||||
|
getFlowchartData: () => { nodes: unknown[]; edges: unknown[] }
|
||||||
|
setFlowchartData: (data: { nodes: unknown[]; edges: unknown[] }) => void
|
||||||
|
}
|
||||||
|
|
||||||
// 通过inject获取FlowchartEditor组件的引用
|
// 通过inject获取FlowchartEditor组件的引用
|
||||||
const flowchartEditorRef = inject<any>("flowchartEditorRef")
|
const flowchartEditorRef = inject<Ref<FlowchartEditorInstance | null>>("flowchartEditorRef")
|
||||||
const mermaidContainer = useTemplateRef<HTMLElement>("mermaidContainer")
|
const mermaidContainer = useTemplateRef<HTMLElement>("mermaidContainer")
|
||||||
|
|
||||||
// 基础组合式函数
|
// 基础组合式函数
|
||||||
@@ -94,7 +99,7 @@ function subscribeToSubmission(submissionId: string) {
|
|||||||
|
|
||||||
// ==================== 提交相关函数 ====================
|
// ==================== 提交相关函数 ====================
|
||||||
// 提交流程图
|
// 提交流程图
|
||||||
async function submitFlowchartData(flowchartEditorRef: any) {
|
async function submitFlowchartData() {
|
||||||
if (!flowchartEditorRef?.value) return
|
if (!flowchartEditorRef?.value) return
|
||||||
|
|
||||||
// 获取流程图的JSON数据
|
// 获取流程图的JSON数据
|
||||||
@@ -138,7 +143,7 @@ async function submitFlowchartData(flowchartEditorRef: any) {
|
|||||||
|
|
||||||
// 提交函数
|
// 提交函数
|
||||||
function submit() {
|
function submit() {
|
||||||
submitFlowchartData(flowchartEditorRef)
|
submitFlowchartData()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== 数据获取和处理函数 ====================
|
// ==================== 数据获取和处理函数 ====================
|
||||||
|
|||||||
@@ -269,6 +269,7 @@ async function loadMermaid() {
|
|||||||
export function useMermaid() {
|
export function useMermaid() {
|
||||||
const renderError = ref<string | null>(null)
|
const renderError = ref<string | null>(null)
|
||||||
const renderSuccess = ref(false)
|
const renderSuccess = ref(false)
|
||||||
|
let renderGeneration = 0
|
||||||
|
|
||||||
const renderFlowchart = async (
|
const renderFlowchart = async (
|
||||||
container: HTMLElement | null,
|
container: HTMLElement | null,
|
||||||
@@ -281,14 +282,17 @@ export function useMermaid() {
|
|||||||
|
|
||||||
if (!container || !mermaidCode?.trim()) return
|
if (!container || !mermaidCode?.trim()) return
|
||||||
|
|
||||||
|
const gen = ++renderGeneration
|
||||||
try {
|
try {
|
||||||
const m = await loadMermaid()
|
const m = await loadMermaid()
|
||||||
const id = `mermaid-${getRandomId()}`
|
const id = `mermaid-${getRandomId()}`
|
||||||
const { svg } = await m.render(id, mermaidCode)
|
const { svg } = await m.render(id, mermaidCode)
|
||||||
|
if (gen !== renderGeneration) return
|
||||||
container.innerHTML = svg
|
container.innerHTML = svg
|
||||||
applyFlowchartDisplayStyle(container)
|
applyFlowchartDisplayStyle(container)
|
||||||
renderSuccess.value = true
|
renderSuccess.value = true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (gen !== renderGeneration) return
|
||||||
renderError.value =
|
renderError.value =
|
||||||
error instanceof Error
|
error instanceof Error
|
||||||
? error.message
|
? error.message
|
||||||
|
|||||||
Reference in New Issue
Block a user