@@ -48,7 +48,7 @@ const router = useRouter()
|
|||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const codeStore = useCodeStore()
|
const codeStore = useCodeStore()
|
||||||
const problemStore = useProblemStore()
|
const problemStore = useProblemStore()
|
||||||
const { problem } = storeToRefs(problemStore)
|
const { problem, languages } = storeToRefs(problemStore)
|
||||||
|
|
||||||
const { isMobile, isDesktop } = useBreakpoints()
|
const { isMobile, isDesktop } = useBreakpoints()
|
||||||
|
|
||||||
@@ -72,15 +72,7 @@ const menu = computed<DropdownOption[]>(() => [
|
|||||||
{ label: "重置代码", key: "reset" },
|
{ label: "重置代码", key: "reset" },
|
||||||
])
|
])
|
||||||
|
|
||||||
const flowchartAndLanguages = computed(
|
const languageOptions: DropdownOption[] = languages.value.map(
|
||||||
() =>
|
|
||||||
[
|
|
||||||
...(problem.value!.allow_flowchart ? ["Flowchart"] : []),
|
|
||||||
...problem.value!.languages,
|
|
||||||
] as LANGUAGE[],
|
|
||||||
)
|
|
||||||
|
|
||||||
const languageOptions: DropdownOption[] = flowchartAndLanguages.value.map(
|
|
||||||
(it) => ({
|
(it) => ({
|
||||||
label: () =>
|
label: () =>
|
||||||
h(NFlex, { align: "center" }, () => [
|
h(NFlex, { align: "center" }, () => [
|
||||||
@@ -150,7 +142,7 @@ defineExpose({
|
|||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (!problem.value!.languages.includes(codeStore.code.language)) {
|
if (!languages.value.includes(codeStore.code.language)) {
|
||||||
codeStore.code.language = "Python3"
|
codeStore.code.language = "Python3"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ import storage from "utils/storage"
|
|||||||
import { LANGUAGE } from "utils/types"
|
import { LANGUAGE } from "utils/types"
|
||||||
import Form from "./Form.vue"
|
import Form from "./Form.vue"
|
||||||
|
|
||||||
|
const FlowchartEditor = defineAsyncComponent(
|
||||||
|
() => import("shared/components/FlowchartEditor/index.vue"),
|
||||||
|
)
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const formRef = useTemplateRef<InstanceType<typeof Form>>("formRef")
|
const formRef = useTemplateRef<InstanceType<typeof Form>>("formRef")
|
||||||
|
|
||||||
@@ -85,7 +89,9 @@ const handleSyncStatusChange = (status: {
|
|||||||
@change-language="changeLanguage"
|
@change-language="changeLanguage"
|
||||||
@toggle-sync="toggleSync"
|
@toggle-sync="toggleSync"
|
||||||
/>
|
/>
|
||||||
|
<FlowchartEditor v-if="codeStore.code.language === 'Flowchart'" />
|
||||||
<SyncCodeEditor
|
<SyncCodeEditor
|
||||||
|
v-else
|
||||||
v-model:value="codeStore.code.value"
|
v-model:value="codeStore.code.value"
|
||||||
:sync="sync"
|
:sync="sync"
|
||||||
:problem="problem!._id"
|
:problem="problem!._id"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from "pinia"
|
import { defineStore } from "pinia"
|
||||||
import { Problem } from "utils/types"
|
import { LANGUAGE, Problem } from "utils/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 题目状态管理 Store
|
* 题目状态管理 Store
|
||||||
@@ -10,17 +10,12 @@ export const useProblemStore = defineStore("problem", () => {
|
|||||||
const problem = ref<Problem | null>(null)
|
const problem = ref<Problem | null>(null)
|
||||||
|
|
||||||
// ==================== 计算属性 ====================
|
// ==================== 计算属性 ====================
|
||||||
const hasProblem = computed(() => problem.value !== null)
|
const languages = computed<LANGUAGE[]>(() => {
|
||||||
|
if (problem.value?.allow_flowchart) {
|
||||||
const problemId = computed(() => problem.value?._id ?? null)
|
return ["Flowchart", ...problem.value?.languages]
|
||||||
|
}
|
||||||
const problemTitle = computed(() => problem.value?.title ?? "")
|
return problem.value?.languages ?? []
|
||||||
|
})
|
||||||
const difficulty = computed(() => problem.value?.difficulty ?? "")
|
|
||||||
|
|
||||||
const languages = computed(() => problem.value?.languages ?? [])
|
|
||||||
|
|
||||||
const isACed = computed(() => problem.value?.my_status === 0)
|
|
||||||
|
|
||||||
// ==================== 操作 ====================
|
// ==================== 操作 ====================
|
||||||
/**
|
/**
|
||||||
@@ -51,12 +46,7 @@ export const useProblemStore = defineStore("problem", () => {
|
|||||||
problem,
|
problem,
|
||||||
|
|
||||||
// 计算属性
|
// 计算属性
|
||||||
hasProblem,
|
|
||||||
problemId,
|
|
||||||
problemTitle,
|
|
||||||
difficulty,
|
|
||||||
languages,
|
languages,
|
||||||
isACed,
|
|
||||||
|
|
||||||
// 操作
|
// 操作
|
||||||
setProblem,
|
setProblem,
|
||||||
|
|||||||
14
src/shared/components/FlowchartEditor/index.vue
Normal file
14
src/shared/components/FlowchartEditor/index.vue
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="container">可拖拽的流程图编辑器</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.container {
|
||||||
|
width: 100%;
|
||||||
|
height: calc(100vh - 133px);
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user