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

@@ -1,4 +1,3 @@
import { useAxios } from "@vueuse/integrations/useAxios"
import http from "utils/http"
import { getACRate } from "utils/functions"
import { DIFFICULTY } from "utils/constants"
@@ -53,7 +52,7 @@ export async function getProblemList(
}
export function getProblemTagList() {
return useAxios<{ id: number; name: string }[]>("problem/tags", http)
return http.get("problem/tags")
}
export function getRandomProblemID() {
@@ -61,7 +60,7 @@ export function getRandomProblemID() {
}
export function getProblem(id: string) {
return useAxios<Problem>("problem", { params: { problem_id: id } }, http)
return http.get("problem", { params: { problem_id: id } })
}
export function getSubmission(id: string) {
@@ -71,12 +70,7 @@ export function getSubmission(id: string) {
}
export function submissionExists(problemID: number) {
return useAxios(
"submission_exists",
{ params: { problem_id: problemID } },
http,
{ immediate: false }
)
return http.get("submission_exists", { params: { problem_id: problemID } })
}
export function submitCode(data: SubmitCodePayload) {
@@ -107,3 +101,7 @@ export function getContestList(query: {
}) {
return http.get("contests", { params: query })
}
export function getContest(id: string) {
return http.get("contest", { params: { id } })
}

View File

@@ -1,5 +1,7 @@
<script setup lang="ts"></script>
<script setup lang="ts">
const route = useRoute()
</script>
<template>contest detail</template>
<template></template>
<style scoped></style>

View File

@@ -126,9 +126,9 @@ function rowProps(row: Contest) {
v-model:value="query.status"
/>
</n-form-item>
<n-form-item>
<n-form-item label="搜索比赛标题">
<n-input
placeholder="关键字"
placeholder="输入后回车"
v-model:value="query.keyword"
@change="search"
/>

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))

View File

@@ -22,14 +22,14 @@ const columns: DataTableColumn<Rank>[] = [
{
title: "排名",
key: "index",
minWidth: 60,
width: 100,
render: (_, index) =>
h("span", {}, index + (query.page - 1) * query.limit + 1),
},
{
title: "用户",
key: "username",
minWidth: 100,
width: 200,
render: (row) =>
h(
NButton,
@@ -38,12 +38,12 @@ const columns: DataTableColumn<Rank>[] = [
),
},
{ title: "骚话", key: "mood", minWidth: 200 },
{ title: "已解决", key: "accepted_number", minWidth: 80 },
{ title: "提交数", key: "submission_number", minWidth: 80 },
{ title: "已解决", key: "accepted_number", width: 100 },
{ title: "提交数", key: "submission_number", width: 100 },
{
title: "正确率",
key: "rate",
minWidth: 80,
width: 100,
render: (row) => getACRate(row.accepted_number, row.submission_number),
},
]