remove useAxios.

This commit is contained in:
2023-01-23 21:35:10 +08:00
parent 8e05cb601d
commit b060262f70
18 changed files with 459 additions and 194 deletions

View File

@@ -23,10 +23,14 @@ const route = useRoute()
const contestID = <string>route.params.contestID
const theme = useThemeVars()
const style = computed(() => "color: " + theme.value.primaryColor)
const { data: hasSolved, execute } = submissionExists(props.problem.id)
if (contestID) {
execute()
}
const solved = ref(false)
onMounted(() => {
if (contestID) {
checkSubmisson()
}
})
const samples = ref<Sample[]>(
props.problem.samples.map((sample, index) => ({
...sample,
@@ -45,6 +49,12 @@ const disabled = computed(
code.value === SOURCES[code.language]
)
)
async function checkSubmisson() {
const res = await submissionExists(props.problem.id)
solved.value = res.data
}
async function test(sample: Sample, index: number) {
samples.value = samples.value.map((sample) => {
if (sample.id === index) {
@@ -87,7 +97,7 @@ const type = (status: ProblemStatus) =>
<template>
<n-alert
v-if="problem.my_status === 0 || (contestID && hasSolved)"
v-if="problem.my_status === 0 || (contestID && solved)"
type="success"
title="🎉 本 题 已 经 被 你 解 决 啦"
/>

View File

@@ -1,6 +1,7 @@
<script setup lang="ts">
import { getProblem } from "oj/api"
import { isDesktop, isMobile } from "~/shared/composables/breakpoints"
import { Problem } from "utils/types"
const Editor = defineAsyncComponent(() => import("./components/Editor.vue"))
const Panel = defineAsyncComponent(() => import("./components/Panel.vue"))
@@ -19,13 +20,18 @@ interface Props {
const props = withDefaults(defineProps<Props>(), {
contestID: "",
})
const problem = ref<Problem>()
const { data: problem, isFinished } = getProblem(props.problemID)
async function init() {
const res = await getProblem(props.problemID)
problem.value = res.data
}
onMounted(init)
provide("problem", readonly(problem))
</script>
<template>
<n-grid v-if="isFinished && problem" x-gap="16" :cols="2">
<n-grid v-if="problem" x-gap="16" :cols="2">
<n-gi :span="isDesktop ? 1 : 2">
<n-tabs default-value="content">
<n-tab-pane name="content" tab="题目描述">

View File

@@ -39,12 +39,11 @@ const theme = useThemeVars()
const userStore = useUserStore()
const problems = ref<ProblemFiltered[]>([])
const total = ref(0)
const { data } = getProblemTagList()
const tags = ref<{ id: number; name: string }[]>([])
const tagOptions = computed(() => [
{ label: "全部", value: "" },
...(data.value?.map((t) => ({ label: t.name, value: t.name })) || []),
...(tags.value?.map((t) => ({ label: t.name, value: t.name })) || []),
])
const query = reactive<Query>({
@@ -73,6 +72,11 @@ async function listProblems() {
problems.value = res.results
}
async function listTags() {
const res = await getProblemTagList()
tags.value = res.data
}
function routerPush() {
router.push({
path: route.path,
@@ -115,13 +119,16 @@ watch(
// TODO: 这里会在登录时候执行两次有BUG
watch(() => userStore.isFinished && userStore.isAuthed, listProblems)
onMounted(listProblems)
onMounted(() => {
listProblems()
listTags()
})
const columns: DataTableColumn<ProblemFiltered>[] = [
{
title: "状态",
key: "status",
width: 80,
width: 60,
render: (row) => {
if (row.status === "passed") {
return h(NIcon, { color: theme.value.successColor }, () => h(Select))