@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import FlowchartEditor from "shared/components/FlowchartEditor/index.vue"
|
|
||||||
import { atou } from "utils/functions"
|
import { atou } from "utils/functions"
|
||||||
|
import { useMermaid } from "shared/composables/useMermaid"
|
||||||
|
|
||||||
interface EvaluationResult {
|
interface EvaluationResult {
|
||||||
score?: number
|
score?: number
|
||||||
@@ -13,6 +13,7 @@ interface EvaluationResult {
|
|||||||
interface Props {
|
interface Props {
|
||||||
evaluationResult: EvaluationResult | null
|
evaluationResult: EvaluationResult | null
|
||||||
myFlowchartZippedStr: string
|
myFlowchartZippedStr: string
|
||||||
|
myMermaidCode: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
@@ -24,9 +25,11 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const showDetailModal = ref(false)
|
const showDetailModal = ref(false)
|
||||||
|
|
||||||
const readonlyFlowchartEditorRef = useTemplateRef<any>(
|
// mermaid 渲染相关
|
||||||
"readonlyFlowchartEditorRef",
|
const mermaidContainer = useTemplateRef<HTMLElement>("mermaidContainer")
|
||||||
)
|
|
||||||
|
// 使用 mermaid composable
|
||||||
|
const { renderError, renderFlowchart } = useMermaid()
|
||||||
|
|
||||||
// 根据分数获取标签类型
|
// 根据分数获取标签类型
|
||||||
const getScoreType = (score: number) => {
|
const getScoreType = (score: number) => {
|
||||||
@@ -39,12 +42,7 @@ const getScoreType = (score: number) => {
|
|||||||
async function openDetailModal() {
|
async function openDetailModal() {
|
||||||
showDetailModal.value = true
|
showDetailModal.value = true
|
||||||
await nextTick()
|
await nextTick()
|
||||||
const str = atou(props.myFlowchartZippedStr)
|
await renderFlowchart(mermaidContainer.value, props.myMermaidCode)
|
||||||
const json = JSON.parse(str)
|
|
||||||
readonlyFlowchartEditorRef.value.setFlowchartData({
|
|
||||||
nodes: json.nodes || [],
|
|
||||||
edges: json.edges || [],
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
@@ -87,14 +85,13 @@ function loadToEditor() {
|
|||||||
>
|
>
|
||||||
<n-grid :cols="5" :x-gap="16">
|
<n-grid :cols="5" :x-gap="16">
|
||||||
<n-gi :span="3">
|
<n-gi :span="3">
|
||||||
<n-card title="大致缩略图(有错位问题,建议加载到流程图编辑器查看)">
|
<n-card title="流程图预览">
|
||||||
<div class="flowchart">
|
<n-alert v-if="renderError" type="error" title="流程图渲染失败">
|
||||||
<FlowchartEditor
|
<template #default>
|
||||||
ref="readonlyFlowchartEditorRef"
|
{{ renderError }}
|
||||||
readonly
|
</template>
|
||||||
height="400px"
|
</n-alert>
|
||||||
/>
|
<div v-else ref="mermaidContainer" class="flowchart"></div>
|
||||||
</div>
|
|
||||||
</n-card>
|
</n-card>
|
||||||
<n-flex style="margin-top: 16px" justify="center">
|
<n-flex style="margin-top: 16px" justify="center">
|
||||||
<n-button @click="loadToEditor" type="primary">
|
<n-button @click="loadToEditor" type="primary">
|
||||||
@@ -160,9 +157,14 @@ function loadToEditor() {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.flowchart {
|
.flowchart {
|
||||||
height: 400px;
|
height: 500px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 4px;
|
display: flex;
|
||||||
overflow: hidden;
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.flowchart > svg) {
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,54 +1,24 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useProblemStore } from "oj/store/problem"
|
import { useProblemStore } from "oj/store/problem"
|
||||||
import { nanoid } from "nanoid"
|
import { useMermaid } from "shared/composables/useMermaid"
|
||||||
|
|
||||||
const problemStore = useProblemStore()
|
const problemStore = useProblemStore()
|
||||||
const { problem } = storeToRefs(problemStore)
|
const { problem } = storeToRefs(problemStore)
|
||||||
const mermaidContainer = useTemplateRef<HTMLElement>("mermaidContainer")
|
const mermaidContainer = useTemplateRef<HTMLElement>("mermaidContainer")
|
||||||
|
|
||||||
// 渲染状态
|
// 使用 mermaid composable
|
||||||
const renderError = ref<string | null>(null)
|
const { renderError, renderFlowchart } = useMermaid()
|
||||||
|
|
||||||
// 动态导入 mermaid
|
|
||||||
let mermaid: any = null
|
|
||||||
|
|
||||||
// 动态加载 Mermaid
|
|
||||||
const loadMermaid = async () => {
|
|
||||||
if (!mermaid) {
|
|
||||||
const mermaidModule = await import("mermaid")
|
|
||||||
mermaid = mermaidModule.default
|
|
||||||
mermaid.initialize({
|
|
||||||
startOnLoad: false,
|
|
||||||
securityLevel: "loose",
|
|
||||||
theme: "default",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return mermaid
|
|
||||||
}
|
|
||||||
|
|
||||||
// 渲染流程图的函数
|
// 渲染流程图的函数
|
||||||
const renderFlowchart = async () => {
|
const renderProblemFlowchart = async () => {
|
||||||
try {
|
if (problem.value?.mermaid_code) {
|
||||||
renderError.value = null
|
await renderFlowchart(mermaidContainer.value, problem.value.mermaid_code)
|
||||||
|
|
||||||
// 确保 mermaid 已加载
|
|
||||||
await loadMermaid()
|
|
||||||
|
|
||||||
// 渲染流程图
|
|
||||||
if (mermaidContainer.value && problem.value?.mermaid_code) {
|
|
||||||
const id = `mermaid-${nanoid()}`
|
|
||||||
const { svg } = await mermaid.render(id, problem.value.mermaid_code)
|
|
||||||
mermaidContainer.value.innerHTML = svg
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
renderError.value =
|
|
||||||
error instanceof Error ? error.message : "流程图渲染失败,请检查代码格式"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化Mermaid并渲染
|
// 初始化Mermaid并渲染
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
renderFlowchart()
|
renderProblemFlowchart()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useBreakpoints } from "shared/composables/breakpoints"
|
import { useBreakpoints } from "shared/composables/breakpoints"
|
||||||
import { useFlowchartSubmit } from "../composables/useFlowchartSubmit"
|
import { useFlowchartSubmission } from "../composables/useFlowchartSubmission"
|
||||||
import FlowchartEvaluationDisplay from "./FlowchartEvaluationDisplay.vue"
|
import FlowchartEvaluationDisplay from "./FlowchartEvaluationDisplay.vue"
|
||||||
|
|
||||||
const { isDesktop } = useBreakpoints()
|
const { isDesktop } = useBreakpoints()
|
||||||
@@ -14,11 +14,12 @@ const {
|
|||||||
loading,
|
loading,
|
||||||
submissionCount,
|
submissionCount,
|
||||||
myFlowchartZippedStr,
|
myFlowchartZippedStr,
|
||||||
|
myMermaidCode,
|
||||||
connect,
|
connect,
|
||||||
disconnect,
|
disconnect,
|
||||||
checkCurrentSubmissionStatus,
|
checkCurrentSubmissionStatus,
|
||||||
submitFlowchartData,
|
submitFlowchartData,
|
||||||
} = useFlowchartSubmit()
|
} = useFlowchartSubmission()
|
||||||
|
|
||||||
// 组件挂载时连接 WebSocket 并检查状态
|
// 组件挂载时连接 WebSocket 并检查状态
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -65,6 +66,7 @@ function handleLoadToEditor(data: any) {
|
|||||||
<FlowchartEvaluationDisplay
|
<FlowchartEvaluationDisplay
|
||||||
:evaluation-result="evaluationResult"
|
:evaluation-result="evaluationResult"
|
||||||
:my-flowchart-zipped-str="myFlowchartZippedStr"
|
:my-flowchart-zipped-str="myFlowchartZippedStr"
|
||||||
|
:my-mermaid-code="myMermaidCode"
|
||||||
@close="() => {}"
|
@close="() => {}"
|
||||||
@load-to-editor="handleLoadToEditor"
|
@load-to-editor="handleLoadToEditor"
|
||||||
/>
|
/>
|
||||||
|
|||||||
97
src/oj/problem/composables/useFlowchartEvaluation.ts
Normal file
97
src/oj/problem/composables/useFlowchartEvaluation.ts
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import { ref } from "vue"
|
||||||
|
import { useMessage } from "naive-ui"
|
||||||
|
import {
|
||||||
|
useFlowchartWebSocket,
|
||||||
|
type FlowchartEvaluationUpdate,
|
||||||
|
} from "shared/composables/websocket"
|
||||||
|
|
||||||
|
export interface EvaluationResult {
|
||||||
|
score?: number
|
||||||
|
grade?: string
|
||||||
|
feedback?: string
|
||||||
|
suggestions?: string
|
||||||
|
criteriaDetails?: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SubmissionStatus {
|
||||||
|
status: string
|
||||||
|
submission_id: string
|
||||||
|
created_time?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useFlowchartEvaluation() {
|
||||||
|
const message = useMessage()
|
||||||
|
|
||||||
|
const evaluationResult = ref<EvaluationResult | null>(null)
|
||||||
|
const submissionStatus = ref<SubmissionStatus | null>(null)
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
// 处理 WebSocket 消息
|
||||||
|
const handleWebSocketMessage = (data: FlowchartEvaluationUpdate) => {
|
||||||
|
console.log("收到流程图评分更新:", data)
|
||||||
|
|
||||||
|
if (data.type === "flowchart_evaluation_completed") {
|
||||||
|
loading.value = false
|
||||||
|
evaluationResult.value = {
|
||||||
|
score: data.score,
|
||||||
|
grade: data.grade,
|
||||||
|
feedback: data.feedback,
|
||||||
|
}
|
||||||
|
submissionStatus.value = null // 清除状态
|
||||||
|
message.success(`流程图评分完成!得分: ${data.score}分 (${data.grade}级)`)
|
||||||
|
} else if (data.type === "flowchart_evaluation_failed") {
|
||||||
|
console.log("处理评分失败消息")
|
||||||
|
loading.value = false
|
||||||
|
submissionStatus.value = null // 清除状态
|
||||||
|
message.error(`流程图评分失败: ${data.error}`)
|
||||||
|
} else {
|
||||||
|
console.log("未知的消息类型:", data.type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建 WebSocket 连接
|
||||||
|
const { connect, disconnect, subscribe } = useFlowchartWebSocket(
|
||||||
|
handleWebSocketMessage,
|
||||||
|
)
|
||||||
|
|
||||||
|
// 订阅提交更新
|
||||||
|
const subscribeToSubmission = (submissionId: string) => {
|
||||||
|
console.log("开始订阅WebSocket更新")
|
||||||
|
subscribe(submissionId)
|
||||||
|
|
||||||
|
// 设置评分状态显示
|
||||||
|
submissionStatus.value = {
|
||||||
|
status: "processing",
|
||||||
|
submission_id: submissionId,
|
||||||
|
created_time: new Date().toISOString(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清除结果
|
||||||
|
const clearResult = () => {
|
||||||
|
evaluationResult.value = null
|
||||||
|
submissionStatus.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置加载状态
|
||||||
|
const setLoading = (value: boolean) => {
|
||||||
|
loading.value = value
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置评估结果
|
||||||
|
const setEvaluationResult = (result: EvaluationResult) => {
|
||||||
|
evaluationResult.value = result
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
evaluationResult,
|
||||||
|
submissionStatus,
|
||||||
|
loading,
|
||||||
|
connect,
|
||||||
|
disconnect,
|
||||||
|
subscribeToSubmission,
|
||||||
|
clearResult,
|
||||||
|
setLoading,
|
||||||
|
setEvaluationResult,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,98 +1,18 @@
|
|||||||
import { ref, watch } from "vue"
|
import { ref } from "vue"
|
||||||
import { useMessage } from "naive-ui"
|
import { useMessage } from "naive-ui"
|
||||||
import {
|
import { submitFlowchart, getCurrentProblemFlowchartSubmission } from "oj/api"
|
||||||
useFlowchartWebSocket,
|
import { useProblemStore } from "oj/store/problem"
|
||||||
type FlowchartEvaluationUpdate,
|
import { utoa } from "utils/functions"
|
||||||
} from "shared/composables/websocket"
|
import { useMermaidConverter } from "./useMermaidConverter"
|
||||||
|
import { useFlowchartEvaluation } from "./useFlowchartEvaluation"
|
||||||
export interface EvaluationResult {
|
|
||||||
score?: number
|
|
||||||
grade?: string
|
|
||||||
feedback?: string
|
|
||||||
suggestions?: string
|
|
||||||
criteriaDetails?: any
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SubmissionStatus {
|
|
||||||
status: string
|
|
||||||
submission_id: string
|
|
||||||
created_time?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useFlowchartSubmission() {
|
export function useFlowchartSubmission() {
|
||||||
const message = useMessage()
|
const message = useMessage()
|
||||||
|
const problemStore = useProblemStore()
|
||||||
|
const { problem } = toRefs(problemStore)
|
||||||
|
|
||||||
const evaluationResult = ref<EvaluationResult | null>(null)
|
const { convertToMermaid } = useMermaidConverter()
|
||||||
const submissionStatus = ref<SubmissionStatus | null>(null)
|
const {
|
||||||
const loading = ref(false)
|
|
||||||
|
|
||||||
// 处理 WebSocket 消息
|
|
||||||
const handleWebSocketMessage = (data: FlowchartEvaluationUpdate) => {
|
|
||||||
console.log("收到流程图评分更新:", data)
|
|
||||||
|
|
||||||
if (data.type === "flowchart_evaluation_completed") {
|
|
||||||
loading.value = false
|
|
||||||
evaluationResult.value = {
|
|
||||||
score: data.score,
|
|
||||||
grade: data.grade,
|
|
||||||
feedback: data.feedback,
|
|
||||||
}
|
|
||||||
submissionStatus.value = null // 清除状态
|
|
||||||
message.success(`流程图评分完成!得分: ${data.score}分 (${data.grade}级)`)
|
|
||||||
} else if (data.type === "flowchart_evaluation_failed") {
|
|
||||||
console.log("处理评分失败消息")
|
|
||||||
loading.value = false
|
|
||||||
submissionStatus.value = null // 清除状态
|
|
||||||
message.error(`流程图评分失败: ${data.error}`)
|
|
||||||
} else {
|
|
||||||
console.log("未知的消息类型:", data.type)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建 WebSocket 连接
|
|
||||||
const { connect, disconnect, subscribe, status } = useFlowchartWebSocket(
|
|
||||||
handleWebSocketMessage,
|
|
||||||
)
|
|
||||||
|
|
||||||
// 监听WebSocket状态变化
|
|
||||||
watch(
|
|
||||||
status,
|
|
||||||
(newStatus) => {
|
|
||||||
console.log("WebSocket状态变化:", newStatus)
|
|
||||||
},
|
|
||||||
{ immediate: true },
|
|
||||||
)
|
|
||||||
|
|
||||||
// 订阅提交更新
|
|
||||||
const subscribeToSubmission = (submissionId: string) => {
|
|
||||||
console.log("开始订阅WebSocket更新")
|
|
||||||
subscribe(submissionId)
|
|
||||||
|
|
||||||
// 设置评分状态显示
|
|
||||||
submissionStatus.value = {
|
|
||||||
status: "processing",
|
|
||||||
submission_id: submissionId,
|
|
||||||
created_time: new Date().toISOString(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清除结果
|
|
||||||
const clearResult = () => {
|
|
||||||
evaluationResult.value = null
|
|
||||||
submissionStatus.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置加载状态
|
|
||||||
const setLoading = (value: boolean) => {
|
|
||||||
loading.value = value
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置评估结果
|
|
||||||
const setEvaluationResult = (result: EvaluationResult) => {
|
|
||||||
evaluationResult.value = result
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
evaluationResult,
|
evaluationResult,
|
||||||
submissionStatus,
|
submissionStatus,
|
||||||
loading,
|
loading,
|
||||||
@@ -102,5 +22,90 @@ export function useFlowchartSubmission() {
|
|||||||
clearResult,
|
clearResult,
|
||||||
setLoading,
|
setLoading,
|
||||||
setEvaluationResult,
|
setEvaluationResult,
|
||||||
|
} = useFlowchartEvaluation()
|
||||||
|
|
||||||
|
// 提交次数
|
||||||
|
const submissionCount = ref(0)
|
||||||
|
|
||||||
|
// 存储流程图数据
|
||||||
|
const myFlowchartZippedStr = ref("")
|
||||||
|
const myMermaidCode = ref("")
|
||||||
|
|
||||||
|
// 检查当前问题的流程图提交状态
|
||||||
|
const checkCurrentSubmissionStatus = async () => {
|
||||||
|
if (!problem.value?.id) return
|
||||||
|
|
||||||
|
const { data } = await getCurrentProblemFlowchartSubmission(
|
||||||
|
problem.value.id,
|
||||||
|
)
|
||||||
|
const submission = data.submission
|
||||||
|
submissionCount.value = data.count
|
||||||
|
if (submission && submission.status === 2) {
|
||||||
|
myFlowchartZippedStr.value = data.submission.flowchart_data.data
|
||||||
|
myMermaidCode.value = data.submission.mermaid_code
|
||||||
|
setEvaluationResult({
|
||||||
|
score: submission.ai_score,
|
||||||
|
grade: submission.ai_grade,
|
||||||
|
feedback: submission.ai_feedback,
|
||||||
|
suggestions: submission.ai_suggestions,
|
||||||
|
criteriaDetails: submission.ai_criteria_details,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交流程图
|
||||||
|
const submitFlowchartData = async (flowchartEditorRef: any) => {
|
||||||
|
if (!flowchartEditorRef?.value) return
|
||||||
|
|
||||||
|
// 获取流程图的JSON数据
|
||||||
|
const flowchartData = flowchartEditorRef.value.getFlowchartData()
|
||||||
|
|
||||||
|
if (flowchartData.nodes.length === 0 || flowchartData.edges.length === 0) {
|
||||||
|
message.error("流程图节点或边不能为空")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const mermaidCode = convertToMermaid(flowchartData)
|
||||||
|
const compressed = utoa(JSON.stringify(flowchartData))
|
||||||
|
|
||||||
|
setLoading(true)
|
||||||
|
clearResult() // 清除之前的结果
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await submitFlowchart({
|
||||||
|
problem_id: problem.value!.id,
|
||||||
|
mermaid_code: mermaidCode,
|
||||||
|
flowchart_data: {
|
||||||
|
compressed: true,
|
||||||
|
data: compressed,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// 获取提交ID并订阅更新
|
||||||
|
const submissionId = response.data.submission_id
|
||||||
|
|
||||||
|
if (submissionId) {
|
||||||
|
subscribeToSubmission(submissionId)
|
||||||
|
}
|
||||||
|
|
||||||
|
message.success("流程图已提交,请耐心等待评分")
|
||||||
|
} catch (error) {
|
||||||
|
setLoading(false)
|
||||||
|
message.error("流程图提交失败")
|
||||||
|
console.error("提交流程图失败:", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
evaluationResult,
|
||||||
|
submissionStatus,
|
||||||
|
loading,
|
||||||
|
submissionCount,
|
||||||
|
myFlowchartZippedStr,
|
||||||
|
myMermaidCode,
|
||||||
|
connect,
|
||||||
|
disconnect,
|
||||||
|
checkCurrentSubmissionStatus,
|
||||||
|
submitFlowchartData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
import { ref } from "vue"
|
|
||||||
import { useMessage } from "naive-ui"
|
|
||||||
import { submitFlowchart, getCurrentProblemFlowchartSubmission } from "oj/api"
|
|
||||||
import { useProblemStore } from "oj/store/problem"
|
|
||||||
import { atou, utoa } from "utils/functions"
|
|
||||||
import { useMermaidConverter } from "./useMermaidConverter"
|
|
||||||
import { useFlowchartSubmission } from "./useFlowchartSubmission"
|
|
||||||
|
|
||||||
export function useFlowchartSubmit() {
|
|
||||||
const message = useMessage()
|
|
||||||
const problemStore = useProblemStore()
|
|
||||||
const { problem } = toRefs(problemStore)
|
|
||||||
|
|
||||||
const { convertToMermaid } = useMermaidConverter()
|
|
||||||
const {
|
|
||||||
evaluationResult,
|
|
||||||
submissionStatus,
|
|
||||||
loading,
|
|
||||||
connect,
|
|
||||||
disconnect,
|
|
||||||
subscribeToSubmission,
|
|
||||||
clearResult,
|
|
||||||
setLoading,
|
|
||||||
setEvaluationResult,
|
|
||||||
} = useFlowchartSubmission()
|
|
||||||
|
|
||||||
// 提交次数
|
|
||||||
const submissionCount = ref(0)
|
|
||||||
|
|
||||||
// 存储流程图数据
|
|
||||||
const myFlowchartZippedStr = ref("")
|
|
||||||
|
|
||||||
// 检查当前问题的流程图提交状态
|
|
||||||
const checkCurrentSubmissionStatus = async () => {
|
|
||||||
if (!problem.value?.id) return
|
|
||||||
|
|
||||||
const { data } = await getCurrentProblemFlowchartSubmission(
|
|
||||||
problem.value.id,
|
|
||||||
)
|
|
||||||
const submission = data.submission
|
|
||||||
submissionCount.value = data.count
|
|
||||||
if (submission && submission.status === 2) {
|
|
||||||
myFlowchartZippedStr.value = data.submission.flowchart_data.data
|
|
||||||
setEvaluationResult({
|
|
||||||
score: submission.ai_score,
|
|
||||||
grade: submission.ai_grade,
|
|
||||||
feedback: submission.ai_feedback,
|
|
||||||
suggestions: submission.ai_suggestions,
|
|
||||||
criteriaDetails: submission.ai_criteria_details,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 提交流程图
|
|
||||||
const submitFlowchartData = async (flowchartEditorRef: any) => {
|
|
||||||
if (!flowchartEditorRef?.value) return
|
|
||||||
|
|
||||||
// 获取流程图的JSON数据
|
|
||||||
const flowchartData = flowchartEditorRef.value.getFlowchartData()
|
|
||||||
|
|
||||||
if (flowchartData.nodes.length === 0 || flowchartData.edges.length === 0) {
|
|
||||||
message.error("流程图节点或边不能为空")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const mermaidCode = convertToMermaid(flowchartData)
|
|
||||||
const compressed = utoa(JSON.stringify(flowchartData))
|
|
||||||
|
|
||||||
setLoading(true)
|
|
||||||
clearResult() // 清除之前的结果
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await submitFlowchart({
|
|
||||||
problem_id: problem.value!.id,
|
|
||||||
mermaid_code: mermaidCode,
|
|
||||||
flowchart_data: {
|
|
||||||
compressed: true,
|
|
||||||
data: compressed,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// 获取提交ID并订阅更新
|
|
||||||
const submissionId = response.data.submission_id
|
|
||||||
|
|
||||||
if (submissionId) {
|
|
||||||
subscribeToSubmission(submissionId)
|
|
||||||
}
|
|
||||||
|
|
||||||
message.success("流程图已提交,请耐心等待评分")
|
|
||||||
} catch (error) {
|
|
||||||
setLoading(false)
|
|
||||||
message.error("流程图提交失败")
|
|
||||||
console.error("提交流程图失败:", error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
evaluationResult,
|
|
||||||
submissionStatus,
|
|
||||||
loading,
|
|
||||||
submissionCount,
|
|
||||||
myFlowchartZippedStr,
|
|
||||||
connect,
|
|
||||||
disconnect,
|
|
||||||
checkCurrentSubmissionStatus,
|
|
||||||
submitFlowchartData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="custom-node"
|
class="custom-node"
|
||||||
:class="{
|
:class="{ 'is-hovered': isHovered, 'is-editing': isEditing }"
|
||||||
'is-hovered': isHovered,
|
|
||||||
'is-editing': isEditing,
|
|
||||||
readonly: readonly,
|
|
||||||
}"
|
|
||||||
:data-node-type="nodeType"
|
:data-node-type="nodeType"
|
||||||
:draggable="!isEditing && !readonly"
|
:draggable="!isEditing"
|
||||||
@mouseenter="!readonly ? (isHovered = true) : undefined"
|
@mouseenter="isHovered = true"
|
||||||
@mouseleave="!readonly ? handleMouseLeave : undefined"
|
@mouseleave="handleMouseLeave"
|
||||||
@dblclick="!readonly ? handleDoubleClick : undefined"
|
@dblclick="handleDoubleClick"
|
||||||
@dragstart="!readonly ? handleDragStart : undefined"
|
@dragstart="handleDragStart"
|
||||||
@mousedown="!readonly ? handleMouseDown : undefined"
|
@mousedown="handleMouseDown"
|
||||||
>
|
>
|
||||||
<!-- 连线点 - 根据节点类型动态显示 -->
|
<!-- 连线点 - 根据节点类型动态显示 -->
|
||||||
<NodeHandles :node-type="nodeType" :node-config="nodeConfig" />
|
<NodeHandles :node-type="nodeType" :node-config="nodeConfig" />
|
||||||
@@ -43,7 +39,7 @@
|
|||||||
|
|
||||||
<!-- 悬停时显示的操作按钮 -->
|
<!-- 悬停时显示的操作按钮 -->
|
||||||
<NodeActions
|
<NodeActions
|
||||||
v-if="isHovered && !readonly"
|
v-if="isHovered"
|
||||||
@delete="handleDelete"
|
@delete="handleDelete"
|
||||||
@mouseenter="handleMouseEnter"
|
@mouseenter="handleMouseEnter"
|
||||||
@mouseleave="handleMouseLeave"
|
@mouseleave="handleMouseLeave"
|
||||||
@@ -62,7 +58,6 @@ interface Props {
|
|||||||
id: string
|
id: string
|
||||||
type: string
|
type: string
|
||||||
data: any
|
data: any
|
||||||
readonly?: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
@@ -71,9 +66,7 @@ interface Emits {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Props 和 Emits
|
// Props 和 Emits
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = defineProps<Props>()
|
||||||
readonly: false,
|
|
||||||
})
|
|
||||||
const emit = defineEmits<Emits>()
|
const emit = defineEmits<Emits>()
|
||||||
|
|
||||||
// 响应式状态
|
// 响应式状态
|
||||||
@@ -222,14 +215,6 @@ onUnmounted(() => {
|
|||||||
filter: brightness(1.1);
|
filter: brightness(1.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-node.readonly {
|
|
||||||
cursor: default;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom-node.readonly .node-content {
|
|
||||||
pointer-events: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 节点内容区域 */
|
/* 节点内容区域 */
|
||||||
.node-content {
|
.node-content {
|
||||||
|
|||||||
@@ -22,12 +22,10 @@ import CustomNode from "./CustomNode.vue"
|
|||||||
import { useProblemStore } from "oj/store/problem"
|
import { useProblemStore } from "oj/store/problem"
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
readonly?: boolean
|
|
||||||
height?: string
|
height?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
withDefaults(defineProps<Props>(), {
|
withDefaults(defineProps<Props>(), {
|
||||||
readonly: false,
|
|
||||||
height: "calc(100vh - 133px)",
|
height: "calc(100vh - 133px)",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -183,12 +181,11 @@ defineExpose({
|
|||||||
<VueFlow
|
<VueFlow
|
||||||
v-model:nodes="nodes"
|
v-model:nodes="nodes"
|
||||||
v-model:edges="edges"
|
v-model:edges="edges"
|
||||||
:readonly="readonly"
|
@dragover="handleDragOver"
|
||||||
@dragover="!readonly ? handleDragOver : undefined"
|
@dragleave="handleDragLeave"
|
||||||
@dragleave="!readonly ? handleDragLeave : undefined"
|
@drop="handleDrop"
|
||||||
@drop="!readonly ? handleDrop : undefined"
|
@connect="handleConnect"
|
||||||
@connect="!readonly ? handleConnect : undefined"
|
@edge-click="handleEdgeClick"
|
||||||
@edge-click="!readonly ? handleEdgeClick : undefined"
|
|
||||||
:default-edge-options="{
|
:default-edge-options="{
|
||||||
type: 'step',
|
type: 'step',
|
||||||
style: {
|
style: {
|
||||||
@@ -211,7 +208,7 @@ defineExpose({
|
|||||||
markerEnd: 'url(#connection-arrow)',
|
markerEnd: 'url(#connection-arrow)',
|
||||||
filter: 'drop-shadow(0 2px 4px rgba(0,0,0,0.1))',
|
filter: 'drop-shadow(0 2px 4px rgba(0,0,0,0.1))',
|
||||||
}"
|
}"
|
||||||
:fit-view-on-init="readonly"
|
:fit-view-on-init="false"
|
||||||
:connect-on-click="false"
|
:connect-on-click="false"
|
||||||
:multi-selection-key-code="null"
|
:multi-selection-key-code="null"
|
||||||
:delete-key-code="null"
|
:delete-key-code="null"
|
||||||
@@ -240,17 +237,14 @@ defineExpose({
|
|||||||
:id="id"
|
:id="id"
|
||||||
:type="type"
|
:type="type"
|
||||||
:data="data"
|
:data="data"
|
||||||
:readonly="readonly"
|
|
||||||
@delete="handleNodeDelete"
|
@delete="handleNodeDelete"
|
||||||
@update="handleNodeUpdate"
|
@update="handleNodeUpdate"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<Background variant="lines" :gap="20" :size="1" />
|
<Background variant="lines" :gap="20" :size="1" />
|
||||||
<Controls v-if="!readonly" />
|
<Controls />
|
||||||
<Toolbar
|
<Toolbar
|
||||||
v-if="!readonly"
|
|
||||||
r
|
|
||||||
:can-undo="canUndo"
|
:can-undo="canUndo"
|
||||||
:can-redo="canRedo"
|
:can-redo="canRedo"
|
||||||
:is-saving="isSaving"
|
:is-saving="isSaving"
|
||||||
|
|||||||
54
src/shared/composables/useMermaid.ts
Normal file
54
src/shared/composables/useMermaid.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { nanoid } from "nanoid"
|
||||||
|
|
||||||
|
export function useMermaid() {
|
||||||
|
// 渲染状态
|
||||||
|
const renderError = ref<string | null>(null)
|
||||||
|
|
||||||
|
// 动态导入 mermaid
|
||||||
|
let mermaid: any = null
|
||||||
|
|
||||||
|
// 动态加载 Mermaid
|
||||||
|
const loadMermaid = async () => {
|
||||||
|
if (!mermaid) {
|
||||||
|
const mermaidModule = await import("mermaid")
|
||||||
|
mermaid = mermaidModule.default
|
||||||
|
mermaid.initialize({
|
||||||
|
startOnLoad: false,
|
||||||
|
securityLevel: "loose",
|
||||||
|
theme: "default",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return mermaid
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染流程图的函数
|
||||||
|
const renderFlowchart = async (container: HTMLElement | null, mermaidCode: string) => {
|
||||||
|
try {
|
||||||
|
renderError.value = null
|
||||||
|
|
||||||
|
// 确保 mermaid 已加载
|
||||||
|
await loadMermaid()
|
||||||
|
|
||||||
|
// 渲染流程图
|
||||||
|
if (container && mermaidCode) {
|
||||||
|
const id = `mermaid-${nanoid()}`
|
||||||
|
const { svg } = await mermaid.render(id, mermaidCode)
|
||||||
|
container.innerHTML = svg
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
renderError.value =
|
||||||
|
error instanceof Error ? error.message : "流程图渲染失败,请检查代码格式"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清除渲染错误
|
||||||
|
const clearError = () => {
|
||||||
|
renderError.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
renderError: readonly(renderError),
|
||||||
|
renderFlowchart,
|
||||||
|
clearError,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user