naive-ui.
This commit is contained in:
6
src/oj/composables/code.ts
Normal file
6
src/oj/composables/code.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { Code } from "~/utils/types"
|
||||||
|
|
||||||
|
export const code = reactive<Code>({
|
||||||
|
value: "",
|
||||||
|
language: "C",
|
||||||
|
})
|
||||||
@@ -3,7 +3,7 @@ import { TabsPaneContext } from "element-plus"
|
|||||||
import { SOURCES } from "utils/constants"
|
import { SOURCES } from "utils/constants"
|
||||||
import { Problem } from "utils/types"
|
import { Problem } from "utils/types"
|
||||||
import Monaco from "~/shared/Monaco/index.vue"
|
import Monaco from "~/shared/Monaco/index.vue"
|
||||||
import { useCodeStore } from "oj/store/code"
|
import { code } from "oj/composables/code"
|
||||||
|
|
||||||
const SubmitPanel = defineAsyncComponent(() => import("./SubmitPanel.vue"))
|
const SubmitPanel = defineAsyncComponent(() => import("./SubmitPanel.vue"))
|
||||||
const TestcasePanel = defineAsyncComponent(() => import("./TestcasePanel.vue"))
|
const TestcasePanel = defineAsyncComponent(() => import("./TestcasePanel.vue"))
|
||||||
@@ -14,8 +14,6 @@ interface Props {
|
|||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
|
|
||||||
const { code } = useCodeStore()
|
|
||||||
|
|
||||||
code.language = props.problem.languages[0] || "C"
|
code.language = props.problem.languages[0] || "C"
|
||||||
code.value = props.problem.template[code.language] || SOURCES[code.language]
|
code.value = props.problem.template[code.language] || SOURCES[code.language]
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Flag, CloseBold, Select, CopyDocument } from "@element-plus/icons-vue"
|
import { Flag, CloseBold, Select, CopyDocument } from "@element-plus/icons-vue"
|
||||||
import copy from "copy-text-to-clipboard"
|
import copy from "copy-text-to-clipboard"
|
||||||
import { useCodeStore } from "oj/store/code"
|
import { code } from "oj/composables/code"
|
||||||
import { SOURCES } from "utils/constants"
|
import { SOURCES } from "utils/constants"
|
||||||
import { Problem, ProblemStatus } from "utils/types"
|
import { Problem, ProblemStatus } from "utils/types"
|
||||||
import { createTestSubmission } from "utils/judge"
|
import { createTestSubmission } from "utils/judge"
|
||||||
@@ -33,7 +33,6 @@ const samples = ref<Sample[]>(
|
|||||||
loading: false,
|
loading: false,
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
const { code } = useCodeStore()
|
|
||||||
|
|
||||||
const disabled = computed(
|
const disabled = computed(
|
||||||
() =>
|
() =>
|
||||||
|
|||||||
@@ -5,12 +5,11 @@ import { SOURCES, JUDGE_STATUS, SubmissionStatus } from "utils/constants"
|
|||||||
import { submissionMemoryFormat, submissionTimeFormat } from "utils/functions"
|
import { submissionMemoryFormat, submissionTimeFormat } from "utils/functions"
|
||||||
import { Problem, Submission, SubmitCodePayload } from "utils/types"
|
import { Problem, Submission, SubmitCodePayload } from "utils/types"
|
||||||
import { getSubmission, submitCode } from "oj/api"
|
import { getSubmission, submitCode } from "oj/api"
|
||||||
import { useCodeStore } from "oj/store/code"
|
import { code } from "oj/composables/code"
|
||||||
|
|
||||||
import SubmissionResultTag from "../../components/SubmissionResultTag.vue"
|
import SubmissionResultTag from "../../components/SubmissionResultTag.vue"
|
||||||
|
|
||||||
const problem = inject<Ref<Problem>>("problem")
|
const problem = inject<Ref<Problem>>("problem")
|
||||||
const { code } = useCodeStore()
|
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const contestID = <string>route.params.contestID ?? ""
|
const contestID = <string>route.params.contestID ?? ""
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { createTestSubmission } from "utils/judge"
|
import { createTestSubmission } from "utils/judge"
|
||||||
import { useCodeStore } from "oj/store/code"
|
import { code } from "oj/composables/code"
|
||||||
|
|
||||||
const input = ref("")
|
const input = ref("")
|
||||||
const result = ref("")
|
const result = ref("")
|
||||||
const { code } = useCodeStore()
|
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
const res = await createTestSubmission(code, input.value)
|
const res = await createTestSubmission(code, input.value)
|
||||||
|
|||||||
@@ -5,6 +5,26 @@ import { isDesktop } from "~/shared/composables/breakpoints"
|
|||||||
import { getProblemList, getProblemTagList, getRandomProblemID } from "oj/api"
|
import { getProblemList, getProblemTagList, getRandomProblemID } from "oj/api"
|
||||||
|
|
||||||
import Pagination from "~/shared/Pagination/index.vue"
|
import Pagination from "~/shared/Pagination/index.vue"
|
||||||
|
import { DataTableColumn, NIcon, NSpace, NTag, useThemeVars } from "naive-ui"
|
||||||
|
import { Select, SemiSelect } from "@element-plus/icons-vue"
|
||||||
|
|
||||||
|
interface Query {
|
||||||
|
keyword: string
|
||||||
|
difficulty: string
|
||||||
|
tag: string
|
||||||
|
page: number
|
||||||
|
limit: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProblemFiltered {
|
||||||
|
_id: string
|
||||||
|
title: string
|
||||||
|
difficulty: "简单" | "中等" | "困难"
|
||||||
|
tags: string[]
|
||||||
|
submission: number
|
||||||
|
rate: string
|
||||||
|
status: "not_test" | "passed" | "failed"
|
||||||
|
}
|
||||||
|
|
||||||
const difficultyOptions = [
|
const difficultyOptions = [
|
||||||
{ label: "全部", value: "" },
|
{ label: "全部", value: "" },
|
||||||
@@ -15,24 +35,30 @@ const difficultyOptions = [
|
|||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
const theme = useThemeVars()
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const problems = ref([])
|
const problems = ref<ProblemFiltered[]>([])
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
|
|
||||||
const { data: tags } = getProblemTagList()
|
const { data } = getProblemTagList()
|
||||||
|
|
||||||
const query = reactive({
|
const tagOptions = computed(() => [
|
||||||
keyword: route.query.keyword ?? "",
|
{ label: "全部", value: "" },
|
||||||
difficulty: route.query.difficulty ?? "",
|
...(data.value?.map((t) => ({ label: t.name, value: t.name })) || []),
|
||||||
tag: route.query.tag ?? "",
|
])
|
||||||
|
|
||||||
|
const query = reactive<Query>({
|
||||||
|
keyword: <string>route.query.keyword ?? "",
|
||||||
|
difficulty: <string>route.query.difficulty ?? "",
|
||||||
|
tag: <string>route.query.tag ?? "",
|
||||||
page: parseInt(<string>route.query.page) || 1,
|
page: parseInt(<string>route.query.page) || 1,
|
||||||
limit: parseInt(<string>route.query.limit) || 10,
|
limit: parseInt(<string>route.query.limit) || 10,
|
||||||
})
|
})
|
||||||
|
|
||||||
async function listProblems() {
|
async function listProblems() {
|
||||||
query.keyword = route.query.keyword ?? ""
|
query.keyword = <string>route.query.keyword ?? ""
|
||||||
query.difficulty = route.query.difficulty ?? ""
|
query.difficulty = <string>route.query.difficulty ?? ""
|
||||||
query.tag = route.query.tag ?? ""
|
query.tag = <string>route.query.tag ?? ""
|
||||||
query.page = parseInt(<string>route.query.page) || 1
|
query.page = parseInt(<string>route.query.page) || 1
|
||||||
query.limit = parseInt(<string>route.query.limit) || 10
|
query.limit = parseInt(<string>route.query.limit) || 10
|
||||||
|
|
||||||
@@ -54,17 +80,14 @@ function routerPush() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function search() {
|
function search(value: string) {
|
||||||
query.page = 1
|
query.keyword = value
|
||||||
routerPush()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear() {
|
function clear() {
|
||||||
query.keyword = ""
|
query.keyword = ""
|
||||||
query.tag = ""
|
query.tag = ""
|
||||||
query.difficulty = ""
|
query.difficulty = ""
|
||||||
query.page = 1
|
|
||||||
routerPush()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRandom() {
|
async function getRandom() {
|
||||||
@@ -72,14 +95,10 @@ async function getRandom() {
|
|||||||
router.push("/problem/" + res.data)
|
router.push("/problem/" + res.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
function goProblem(row: any) {
|
|
||||||
router.push("/problem/" + row._id)
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(() => query.page, routerPush)
|
watch(() => query.page, routerPush)
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => [query.tag, query.difficulty, query.limit],
|
() => [query.tag, query.difficulty, query.limit, query.keyword],
|
||||||
() => {
|
() => {
|
||||||
query.page = 1
|
query.page = 1
|
||||||
routerPush()
|
routerPush()
|
||||||
@@ -97,90 +116,86 @@ watch(
|
|||||||
watch(() => userStore.isFinished && userStore.isAuthed, listProblems)
|
watch(() => userStore.isFinished && userStore.isAuthed, listProblems)
|
||||||
|
|
||||||
onMounted(listProblems)
|
onMounted(listProblems)
|
||||||
|
|
||||||
|
const columns: DataTableColumn<ProblemFiltered>[] = [
|
||||||
|
{
|
||||||
|
title: "状态",
|
||||||
|
key: "status",
|
||||||
|
width: 80,
|
||||||
|
render: (row) => {
|
||||||
|
if (row.status === "passed") {
|
||||||
|
return h(NIcon, { color: theme.value.successColor }, () => h(Select))
|
||||||
|
} else if (row.status === "failed") {
|
||||||
|
return h(NIcon, { color: theme.value.errorColor }, () => h(SemiSelect))
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ title: "编号", key: "_id", width: 100 },
|
||||||
|
{ title: "标题", key: "title", minWidth: 200 },
|
||||||
|
{
|
||||||
|
title: "难度",
|
||||||
|
key: "difficulty",
|
||||||
|
width: 100,
|
||||||
|
render: (row) =>
|
||||||
|
h(NTag, { type: getTagColor(row.difficulty) }, () => row.difficulty),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "标签",
|
||||||
|
key: "tags",
|
||||||
|
width: 260,
|
||||||
|
render: (row) =>
|
||||||
|
h(NSpace, () => row.tags.map((t) => h(NTag, { key: t }, () => t))),
|
||||||
|
},
|
||||||
|
{ title: "提交数", key: "submission", width: 100 },
|
||||||
|
{ title: "通过率", key: "rate", width: 100 },
|
||||||
|
]
|
||||||
|
|
||||||
|
function rowProps(row: ProblemFiltered) {
|
||||||
|
return {
|
||||||
|
style: "cursor: pointer",
|
||||||
|
onClick() {
|
||||||
|
router.push("/problem/" + row._id)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<el-form inline>
|
<n-form :inline="isDesktop" label-placement="left">
|
||||||
<el-form-item label="难度">
|
<n-form-item label="难度">
|
||||||
<el-select v-model="query.difficulty">
|
<n-select
|
||||||
<el-option
|
class="select"
|
||||||
v-for="item in difficultyOptions"
|
v-model:value="query.difficulty"
|
||||||
:key="item.value"
|
:options="difficultyOptions"
|
||||||
:label="item.label"
|
|
||||||
:value="item.value"
|
|
||||||
>
|
|
||||||
</el-option>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="标签">
|
|
||||||
<el-select v-model="query.tag" clearable>
|
|
||||||
<el-option
|
|
||||||
v-for="item in tags"
|
|
||||||
:key="item.id"
|
|
||||||
:label="item.name"
|
|
||||||
:value="item.name"
|
|
||||||
>
|
|
||||||
</el-option>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="搜索">
|
|
||||||
<el-input
|
|
||||||
v-model="query.keyword"
|
|
||||||
placeholder="输入编号或标题后回车"
|
|
||||||
clearable
|
|
||||||
@change="search"
|
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</n-form-item>
|
||||||
<el-form-item>
|
<n-form-item label="标签">
|
||||||
<el-button type="" @click="clear">重置</el-button>
|
<n-select
|
||||||
<el-button type="" @click="getRandom">随机一题</el-button>
|
class="select"
|
||||||
</el-form-item>
|
v-model:value="query.tag"
|
||||||
</el-form>
|
:options="tagOptions"
|
||||||
<el-table class="pointer" :data="problems" stripe @row-click="goProblem">
|
clearable
|
||||||
<el-table-column v-if="isDesktop" label="状态" :width="80">
|
/>
|
||||||
<template #default="scope">
|
</n-form-item>
|
||||||
<el-icon
|
<n-form-item label="搜索">
|
||||||
v-if="scope.row.status === 'passed'"
|
<n-input placeholder="输入编号或标题后回车" clearable @change="search" />
|
||||||
color="var(--el-color-success)"
|
</n-form-item>
|
||||||
><i-ep-select
|
<n-form-item>
|
||||||
/></el-icon>
|
<n-space>
|
||||||
<el-icon
|
<n-button @click="clear">重置</n-button>
|
||||||
v-if="scope.row.status === 'failed'"
|
<n-button @click="getRandom">随机一题</n-button>
|
||||||
color="var(--el-color-error)"
|
</n-space>
|
||||||
><i-ep-semi-select
|
</n-form-item>
|
||||||
/></el-icon>
|
</n-form>
|
||||||
</template>
|
<n-data-table
|
||||||
</el-table-column>
|
striped
|
||||||
<el-table-column prop="_id" label="编号" :width="isDesktop ? 100 : 60" />
|
size="small"
|
||||||
<el-table-column prop="title" label="标题" />
|
:data="problems"
|
||||||
<el-table-column label="难度" width="100">
|
:columns="columns"
|
||||||
<template #default="scope">
|
:row-props="rowProps"
|
||||||
<el-tag disable-transitions :type="getTagColor(scope.row.difficulty)">
|
/>
|
||||||
{{ scope.row.difficulty }}
|
|
||||||
</el-tag>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column v-if="isDesktop" label="标签" :width="200">
|
|
||||||
<template #default="scope">
|
|
||||||
<el-space>
|
|
||||||
<el-tag
|
|
||||||
disable-transitions
|
|
||||||
v-for="tag in scope.row.tags"
|
|
||||||
:key="tag"
|
|
||||||
type="info"
|
|
||||||
>{{ tag }}</el-tag
|
|
||||||
>
|
|
||||||
</el-space>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
v-if="isDesktop"
|
|
||||||
prop="submission"
|
|
||||||
label="提交数"
|
|
||||||
width="100"
|
|
||||||
/>
|
|
||||||
<el-table-column v-if="isDesktop" prop="rate" label="通过率" width="100" />
|
|
||||||
</el-table>
|
|
||||||
<Pagination
|
<Pagination
|
||||||
:total="total"
|
:total="total"
|
||||||
v-model:limit="query.limit"
|
v-model:limit="query.limit"
|
||||||
@@ -189,7 +204,7 @@ onMounted(listProblems)
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.pointer {
|
.select {
|
||||||
cursor: pointer;
|
width: 120px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
import { Code } from "utils/types"
|
|
||||||
|
|
||||||
export const useCodeStore = defineStore("code", () => {
|
|
||||||
const code = reactive<Code>({
|
|
||||||
value: "",
|
|
||||||
language: "C",
|
|
||||||
})
|
|
||||||
|
|
||||||
return { code }
|
|
||||||
})
|
|
||||||
@@ -22,14 +22,16 @@ export function buildProblemCodeKey(problemID: string, contestID = "") {
|
|||||||
return `${STORAGE_KEY.PROBLEM_CODE}_NaN_${problemID}`
|
return `${STORAGE_KEY.PROBLEM_CODE}_NaN_${problemID}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTagColor(tag: "Low" | "Mid" | "High") {
|
export function getTagColor(
|
||||||
return {
|
tag: "Low" | "Mid" | "High" | "简单" | "中等" | "困难"
|
||||||
|
) {
|
||||||
|
return <"success" | "info" | "error">{
|
||||||
Low: "success",
|
Low: "success",
|
||||||
Mid: "",
|
Mid: "info",
|
||||||
High: "danger",
|
High: "error",
|
||||||
简单: "success",
|
简单: "success",
|
||||||
中等: "",
|
中等: "info",
|
||||||
困难: "danger",
|
困难: "error",
|
||||||
}[tag]
|
}[tag]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user