refactor axios.

This commit is contained in:
2023-01-08 15:07:32 +08:00
parent e306e6b463
commit a3456595a5
4 changed files with 12 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
import { getACRate } from "./../utils/functions"
import { DIFFICULTY } from "./../utils/constants"
import { Problem, LANGUAGE } from "./../utils/types"
import { Problem, SubmitCodePayload } from "./../utils/types"
import http from "./../utils/http"
import { useAxios } from "@vueuse/integrations/useAxios"
@@ -65,11 +65,6 @@ export function getSubmission(id: string) {
})
}
export function submitCode(data: {
problem_id: number
contest_id?: number
language: LANGUAGE
code: string
}) {
export function submitCode(data: SubmitCodePayload) {
return http.post("submission", data)
}

View File

@@ -8,7 +8,7 @@ import {
} from "../../../utils/constants"
import { isMobile } from "../../../utils/breakpoints"
import { submitCode } from "../../api"
import { Problem } from "../../../utils/types"
import { LANGUAGE, Problem, SubmitCodePayload } from "../../../utils/types"
const { problem, contestID = "" } = defineProps<{
contestID?: string
@@ -85,13 +85,12 @@ const submitDisabled = computed(() => {
})
async function submit() {
const data = {
const data: SubmitCodePayload = {
problem_id: problem.id,
language: state.language,
code: state.values[state.language],
}
if (contestID) {
//@ts-ignore
data.contest_id = parseInt(contestID)
}
const res = await submitCode(data)

View File

@@ -12,7 +12,7 @@ export function logout() {
}
export function getUserInfo(username: string) {
return useAxios("profile", { method: "get", params: { username } }, http, {
return useAxios("profile", { params: { username } }, http, {
immediate: false,
})
}

View File

@@ -49,3 +49,10 @@ export interface Problem {
contest: null
my_status: number
}
export interface SubmitCodePayload {
problem_id: number
language: LANGUAGE
code: string
contest_id?: number
}