refactor: 一批名不副实的命名改掉(只动一端,不碰契约)
后端: - getUserByToken → authenticateToken:它会删会话、续 TTL、记在线,不是纯读 - todayStart → dayStart(instant):本来就接受任意时刻,不只是「今天」 - objectValue → asRecord,删掉 4 份一模一样的私有拷贝和 `as toObject` 别名 - 报错文案 "does not exists" / "Already be a public problem" 改通顺 前端: - utils/types 里 Contest / User / Problem 三个别名删掉:Contest 原来指后台 比赛、契约里同名的却是学生侧。现在 Contest = 学生侧、AdminContest = 后台, 后台用户表单叫 AdminUserForm,题目详情直接用 ProblemDetail - SubmissionInfo → ContestSubmissionInfo,免得和 submission.info 撞名 - utoa / atou → compressToBase64 / decompressFromBase64(实际是 zlib + base64), encode / decode → base64EncodeUtf8 / base64DecodeUtf8 - filterResult → toProblemRow、toProblemListItem → toAdminProblemRow, 行字段 submission / rate → submissionCount / acRate - 组件:Modal → AddFromLibraryModal、Form → EditorToolbar、 ContestEditor → BasicEditor(题单也在用它)、rank 的 Index → RankMedal、 Name → UserNameCell、Password → PasswordCell、ContestType → ContestAccessTag Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
572a818d49
commit
5ae830a7f9
62 files changed
+284
-320
No files matched your search
+5
-2
@@ -8,7 +8,7 @@ import { useBreakpoints } from "shared/composables/breakpoints"
|
||||
import storage from "utils/storage"
|
||||
import type { LANGUAGE } from "utils/types"
|
||||
import { beginEditTrace, editTraceExtensions } from "oj/problem/utils/editTrace"
|
||||
import Form from "./Form.vue"
|
||||
import EditorToolbar from "./EditorToolbar.vue"
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
@@ -58,7 +58,10 @@ const changeLanguage = (v: LANGUAGE) => {
|
||||
|
||||
<template>
|
||||
<n-flex vertical>
|
||||
<Form :storage-key="storageKey" @change-language="changeLanguage" />
|
||||
<EditorToolbar
|
||||
:storage-key="storageKey"
|
||||
@change-language="changeLanguage"
|
||||
/>
|
||||
<CodeEditor
|
||||
v-model:value="codeStore.code.value"
|
||||
:language="codeStore.code.language"
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { storeToRefs } from "pinia"
|
||||
import { copyToClipboard, utoa } from "utils/functions"
|
||||
import { copyToClipboard, compressToBase64 } from "utils/functions"
|
||||
import { useCodeStore } from "oj/store/code"
|
||||
import { useProblemStore } from "oj/store/problem"
|
||||
import { useCollabStore } from "shared/store/collab"
|
||||
@@ -227,7 +227,7 @@ const goTestCat = () => {
|
||||
code: codeStore.code.value,
|
||||
input: problemStore.problem?.samples[0].input,
|
||||
}
|
||||
const base64 = utoa(JSON.stringify(data))
|
||||
const base64 = compressToBase64(JSON.stringify(data))
|
||||
const url = `${import.meta.env.PUBLIC_CODE_URL}?share=${encodeURIComponent(base64)}`
|
||||
window.open(url, "_blank")
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { storeToRefs } from "pinia"
|
||||
import { useCodeStore } from "oj/store/code"
|
||||
import { useProblemStore } from "oj/store/problem"
|
||||
import { createTestSubmission } from "utils/judge"
|
||||
import type { Problem, ProblemFiltered, ProblemStatus } from "utils/types"
|
||||
import type { ProblemDetail, ProblemRow, ProblemStatus } from "utils/types"
|
||||
import Copy from "shared/components/Copy.vue"
|
||||
import { useDark } from "@vueuse/core"
|
||||
import { MdPreview } from "md-editor-v3"
|
||||
@@ -13,7 +13,7 @@ import "md-editor-v3/lib/preview.css"
|
||||
import { getSimilarProblems } from "oj/api"
|
||||
import SQLDataTable from "./SQLDataTable.vue"
|
||||
|
||||
type Sample = Problem["samples"][number] & {
|
||||
type Sample = ProblemDetail["samples"][number] & {
|
||||
id: number
|
||||
msg: string
|
||||
status: ProblemStatus
|
||||
@@ -45,7 +45,7 @@ const sqlChangedTables = computed(() => {
|
||||
const router = useRouter()
|
||||
|
||||
// 相似题目推荐
|
||||
const similarProblems = ref<ProblemFiltered[]>([])
|
||||
const similarProblems = ref<ProblemRow[]>([])
|
||||
const similarLoaded = ref(false)
|
||||
|
||||
async function loadSimilarProblems() {
|
||||
@@ -409,7 +409,7 @@ function type(status: ProblemStatus) {
|
||||
{{ sp.title }}
|
||||
</n-button>
|
||||
</n-flex>
|
||||
<!-- getSimilarProblems 已经过 filterResult,难度是中文,不是 Low/Mid/High -->
|
||||
<!-- getSimilarProblems 已经过 toProblemRow,难度是中文,不是 Low/Mid/High -->
|
||||
<n-tag
|
||||
v-if="sp.difficulty"
|
||||
size="small"
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useBreakpoints } from "shared/composables/breakpoints"
|
||||
import storage from "utils/storage"
|
||||
import type { LANGUAGE } from "utils/types"
|
||||
import { beginEditTrace, editTraceExtensions } from "oj/problem/utils/editTrace"
|
||||
import Form from "./Form.vue"
|
||||
import EditorToolbar from "./EditorToolbar.vue"
|
||||
|
||||
const FlowchartEditor = defineAsyncComponent(
|
||||
() => import("shared/components/FlowchartEditor/index.vue"),
|
||||
@@ -43,14 +43,14 @@ const teacherCollab = computed(() => collabHere.value && collabStore.isTeacher)
|
||||
let teacherLanguageBefore: LANGUAGE | null = null
|
||||
|
||||
/**
|
||||
* 协作中**教师的语言选择跟着学生走**(选择器同时禁用,见 Form.vue),学生中途切了
|
||||
* 协作中**教师的语言选择跟着学生走**(选择器同时禁用,见 EditorToolbar.vue),学生中途切了
|
||||
* 还会再同步一次。
|
||||
*
|
||||
* 写的是 codeStore 而不是只改编辑器的高亮:提交、语法检查、去自测猫读的都是
|
||||
* `codeStore.code.language` —— 只改高亮的话,老师会拿着自己那档语言提交学生的代码
|
||||
* (学生写 C、老师选的是 Python,当场 CE),工具栏还可能显示「提交流程图」。
|
||||
*
|
||||
* 直接写 store 不会连带重载模板代码:那是 Form 里选择器的 `update:value` 才做的事。
|
||||
* 直接写 store 不会连带重载模板代码:那是 EditorToolbar 里选择器的 `update:value` 才做的事。
|
||||
*
|
||||
* **学生端一个字都不动**(早退出),他的语言本来就是权威那一份 —— 服务端的
|
||||
* `room_language` 只发给教师,学生本地那份 `room.language` 停在建房那一刻,
|
||||
@@ -139,10 +139,13 @@ provide("flowchartEditorRef", flowchartEditorRef)
|
||||
|
||||
<template>
|
||||
<n-flex vertical>
|
||||
<Form :storage-key="storageKey" @change-language="changeLanguage" />
|
||||
<EditorToolbar
|
||||
:storage-key="storageKey"
|
||||
@change-language="changeLanguage"
|
||||
/>
|
||||
<!--
|
||||
协作中教师这边不会落到流程图分支:上面那个 watch 已经把他的语言换成了学生的,
|
||||
而求助入口本身就排掉了流程图(Form.vue 的 showHelpButton、服务端的
|
||||
而求助入口本身就排掉了流程图(EditorToolbar.vue 的 showHelpButton、服务端的
|
||||
COLLAB_LANGUAGES),所以 room.language 不可能是 Flowchart。
|
||||
学生自己切到流程图就是不写代码了,编辑器卸载、协作正常结束(SyncCodeEditor
|
||||
的 detach),这是原来就有的语义。
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProblemFiltered } from "utils/types"
|
||||
import type { ProblemRow } from "utils/types"
|
||||
import { Icon } from "@iconify/vue"
|
||||
|
||||
defineProps<{
|
||||
problem: ProblemFiltered
|
||||
problem: ProblemRow
|
||||
}>()
|
||||
</script>
|
||||
<template>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { errorCode } from "utils/api"
|
||||
import { toRefs } from "vue"
|
||||
|
||||
// 工具函数
|
||||
import { atou, utoa } from "utils/functions"
|
||||
import { decompressFromBase64, compressToBase64 } from "utils/functions"
|
||||
import { sortFlowchartCriteria } from "utils/constants"
|
||||
|
||||
// 组合式函数
|
||||
@@ -235,7 +235,7 @@ async function submitFlowchartData() {
|
||||
|
||||
const mermaidCode = convertToMermaid(flowchartData)
|
||||
lastSubmittedMermaidCode.value = mermaidCode
|
||||
const compressed = utoa(JSON.stringify(flowchartData))
|
||||
const compressed = compressToBase64(JSON.stringify(flowchartData))
|
||||
|
||||
loading.value = true
|
||||
latestRating.value = { score: 0, grade: "" }
|
||||
@@ -372,9 +372,9 @@ function closeModal() {
|
||||
function loadToEditor() {
|
||||
if (myFlowchartZippedStr.value) {
|
||||
// 老提交的压缩数据可能是坏的(格式换过、存了一半),
|
||||
// 不兜住的话 atou/JSON.parse 直接抛,按钮点了毫无反应
|
||||
// 不兜住的话 decompressFromBase64/JSON.parse 直接抛,按钮点了毫无反应
|
||||
try {
|
||||
const json = JSON.parse(atou(myFlowchartZippedStr.value))
|
||||
const json = JSON.parse(decompressFromBase64(myFlowchartZippedStr.value))
|
||||
flowchartEditorRef?.value?.setFlowchartData({
|
||||
nodes: json.nodes || [],
|
||||
edges: json.edges || [],
|
||||
|
||||
Reference in new issue
Block a user