fix copy
This commit is contained in:
@@ -313,6 +313,7 @@ onMounted(loadData)
|
|||||||
:problemID="currentSubmission.problem_display_id"
|
:problemID="currentSubmission.problem_display_id"
|
||||||
:submissionID="currentSubmission.id"
|
:submissionID="currentSubmission.id"
|
||||||
hideList
|
hideList
|
||||||
|
@copied="toggleCodePanel(false)"
|
||||||
/>
|
/>
|
||||||
</n-modal>
|
</n-modal>
|
||||||
</n-flex>
|
</n-flex>
|
||||||
|
|||||||
@@ -334,6 +334,7 @@ watch(query, listSubmissions)
|
|||||||
:problemID="problemID"
|
:problemID="problemID"
|
||||||
:submissionID="submissionID"
|
:submissionID="submissionID"
|
||||||
hideList
|
hideList
|
||||||
|
@copied="toggleCodePanel(false)"
|
||||||
/>
|
/>
|
||||||
</n-modal>
|
</n-modal>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ import {
|
|||||||
submissionMemoryFormat,
|
submissionMemoryFormat,
|
||||||
submissionTimeFormat,
|
submissionTimeFormat,
|
||||||
utoa,
|
utoa,
|
||||||
copyToClipboard,
|
|
||||||
} from "utils/functions"
|
} from "utils/functions"
|
||||||
import { Submission } from "utils/types"
|
import { Submission } from "utils/types"
|
||||||
import SubmissionResultTag from "shared/components/SubmissionResultTag.vue"
|
import SubmissionResultTag from "shared/components/SubmissionResultTag.vue"
|
||||||
import { useBreakpoints } from "shared/composables/breakpoints"
|
import { useBreakpoints } from "shared/composables/breakpoints"
|
||||||
|
import { useCodeStore } from "oj/store/code"
|
||||||
|
import storage from "utils/storage"
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
submissionID: string
|
submissionID: string
|
||||||
@@ -23,9 +24,12 @@ const props = defineProps<{
|
|||||||
hideList?: boolean
|
hideList?: boolean
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
// 在弹框中使用时,父组件监听此事件关闭弹框,否则弹框会挡住已更新的编辑器
|
||||||
|
const emit = defineEmits<{ copied: [] }>()
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const message = useMessage()
|
const codeStore = useCodeStore()
|
||||||
|
|
||||||
const { isMobile, isDesktop } = useBreakpoints()
|
const { isMobile, isDesktop } = useBreakpoints()
|
||||||
|
|
||||||
@@ -72,43 +76,37 @@ function copyToCat() {
|
|||||||
window.open(url, "_blank")
|
window.open(url, "_blank")
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copyToProblem() {
|
function copyToProblem() {
|
||||||
const success = await copyToClipboard(submission.value!.code)
|
const { code, language, contest } = submission.value!
|
||||||
if (success) {
|
// 编辑器的 storageKey 用 display id(problem._id),等于 props.problemID,
|
||||||
message.success("代码复制成功,需要手动粘贴到题目")
|
// 而非 submission.problem(内部数字 id)
|
||||||
} else {
|
const contestIDForKey = contest || null
|
||||||
message.error("代码复制失败")
|
const storageKey = `problem_${props.problemID}_contest_${contestIDForKey}_lang_${language}`
|
||||||
}
|
storage.set(storageKey, code)
|
||||||
|
// 设置语言 + 代码:localStorage 覆盖全新挂载的编辑器,
|
||||||
|
// setCode 覆盖已挂载(同页 modal)的编辑器
|
||||||
|
codeStore.setLanguage(language)
|
||||||
|
codeStore.setCode(code)
|
||||||
|
|
||||||
const contestID = submission.value!.contest
|
|
||||||
const problemSetId = (route.params.problemSetId as string) ?? ""
|
const problemSetId = (route.params.problemSetId as string) ?? ""
|
||||||
if (contestID) {
|
if (contest) {
|
||||||
// 竞赛题目
|
|
||||||
router.push({
|
router.push({
|
||||||
name: "contest problem",
|
name: "contest problem",
|
||||||
params: {
|
params: { contestID: String(contest), problemID: props.problemID },
|
||||||
contestID: String(contestID),
|
|
||||||
problemID: props.problemID,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
} else if (problemSetId) {
|
} else if (problemSetId) {
|
||||||
// 题单题目
|
|
||||||
router.push({
|
router.push({
|
||||||
name: "problemset problem",
|
name: "problemset problem",
|
||||||
params: {
|
params: { problemSetId, problemID: props.problemID },
|
||||||
problemSetId: problemSetId,
|
|
||||||
problemID: props.problemID,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// 普通题目
|
|
||||||
router.push({
|
router.push({
|
||||||
name: "problem",
|
name: "problem",
|
||||||
params: {
|
params: { problemID: props.problemID },
|
||||||
problemID: props.problemID,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit("copied")
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(init)
|
onMounted(init)
|
||||||
|
|||||||
@@ -531,6 +531,7 @@ const flowchartColumns = computed(() => {
|
|||||||
:problemID="problemDisplayID"
|
:problemID="problemDisplayID"
|
||||||
:submissionID="submissionID"
|
:submissionID="submissionID"
|
||||||
hideList
|
hideList
|
||||||
|
@copied="toggleCodePanel(false)"
|
||||||
/>
|
/>
|
||||||
</n-modal>
|
</n-modal>
|
||||||
<n-modal
|
<n-modal
|
||||||
|
|||||||
Reference in New Issue
Block a user