在题目详情页显示数据统计
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
<template>
|
||||
<n-select
|
||||
style="width: 140px"
|
||||
v-model:value="author"
|
||||
remote
|
||||
@update:show="getAuthorOptions"
|
||||
:options="authorOptions"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getAuthors } from "~/oj/api"
|
||||
|
||||
interface Props {
|
||||
all?: boolean
|
||||
}
|
||||
|
||||
const { all = false } = defineProps<Props>()
|
||||
|
||||
const author = defineModel<string>("value")
|
||||
|
||||
const authorOptions = ref([{ label: "全部", value: "" }])
|
||||
|
||||
async function getAuthorOptions() {
|
||||
authorOptions.value = [{ label: "全部", value: "" }]
|
||||
const res = await getAuthors(all)
|
||||
const remotes = res.data.map(
|
||||
(item: { username: string; problem_count: number }) => ({
|
||||
label: `${item.username} (${item.problem_count})`,
|
||||
value: item.username,
|
||||
}),
|
||||
)
|
||||
authorOptions.value = [...authorOptions.value, ...remotes]
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<n-select
|
||||
style="width: 140px"
|
||||
v-model:value="author"
|
||||
remote
|
||||
@update:show="getAuthorOptions"
|
||||
:options="authorOptions"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getAuthors } from "~/oj/api"
|
||||
|
||||
interface Props {
|
||||
all?: boolean
|
||||
}
|
||||
|
||||
const { all = false } = defineProps<Props>()
|
||||
|
||||
const author = defineModel<string>("value")
|
||||
|
||||
const authorOptions = ref([{ label: "全部", value: "" }])
|
||||
|
||||
async function getAuthorOptions() {
|
||||
authorOptions.value = [{ label: "全部", value: "" }]
|
||||
const res = await getAuthors(all)
|
||||
const remotes = res.data.map(
|
||||
(item: { username: string; problem_count: number }) => ({
|
||||
label: `${item.username} (${item.problem_count})`,
|
||||
value: item.username,
|
||||
}),
|
||||
)
|
||||
authorOptions.value = [...authorOptions.value, ...remotes]
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -69,6 +69,7 @@ const menus = computed<MenuOption[]>(() => [
|
||||
h(RouterLink, { to: "/submission" }, { default: () => "提交" }),
|
||||
key: "submission",
|
||||
icon: renderIcon("streamline-emojis:bouquet"),
|
||||
show: userStore.showSubmissions,
|
||||
},
|
||||
{
|
||||
label: () => h(RouterLink, { to: "/contest" }, { default: () => "比赛" }),
|
||||
|
||||
176
src/shared/components/StatisticsPanel.vue
Normal file
176
src/shared/components/StatisticsPanel.vue
Normal file
@@ -0,0 +1,176 @@
|
||||
<template>
|
||||
<n-flex size="large" vertical>
|
||||
<n-form :show-feedback="false" inline label-placement="left">
|
||||
<n-form-item>
|
||||
<n-input
|
||||
placeholder="用户(可选)"
|
||||
v-model:value="query.username"
|
||||
style="width: 200px"
|
||||
clearable
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<n-input
|
||||
placeholder="题号(可选)"
|
||||
v-model:value="query.problem"
|
||||
style="width: 200px"
|
||||
clearable
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<n-select
|
||||
style="width: 120px"
|
||||
v-model:value="query.duration"
|
||||
:options="options"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<n-button type="primary" @click="handleStatistics">统计</n-button>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="route.name !== 'submissions'">
|
||||
<n-button @click="goSubmissions">前往提交列表</n-button>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<n-space v-if="count.total > 0" size="large">
|
||||
<n-h1 style="margin-bottom: 0">
|
||||
<n-gradient-text type="primary">
|
||||
正确提交数:{{ count.accepted }}
|
||||
</n-gradient-text>
|
||||
</n-h1>
|
||||
<n-h1 style="margin-bottom: 0">
|
||||
<n-gradient-text type="info">
|
||||
总提交数:{{ count.total }}
|
||||
</n-gradient-text>
|
||||
</n-h1>
|
||||
<n-h1 style="margin-bottom: 0">
|
||||
<n-gradient-text type="warning">
|
||||
正确率:{{ count.rate }}
|
||||
</n-gradient-text>
|
||||
</n-h1>
|
||||
</n-space>
|
||||
<n-space v-if="count.total > 0" size="large">
|
||||
<n-h1>
|
||||
<n-gradient-text type="error">
|
||||
回答正确的人数:{{ list.length }}
|
||||
</n-gradient-text>
|
||||
</n-h1>
|
||||
<n-h1 v-if="person.count > 0">
|
||||
<n-gradient-text type="warning">
|
||||
班级人数:{{ person.count }}
|
||||
</n-gradient-text>
|
||||
</n-h1>
|
||||
<n-h1 v-if="person.count > 0">
|
||||
<n-gradient-text type="success">
|
||||
班级完成度:{{ person.rate }}
|
||||
</n-gradient-text>
|
||||
</n-h1>
|
||||
<n-flex v-if="listUnaccepted.length > 0" style="margin-top: 8px">
|
||||
<n-button type="warning" @click="toggleUnaccepted(!unaccepted)">
|
||||
{{ unaccepted ? "隐藏没有完成的" : "显示没有完成的" }}
|
||||
</n-button>
|
||||
</n-flex>
|
||||
</n-space>
|
||||
<n-h1 v-if="count.total === 0">
|
||||
<n-gradient-text type="primary">暂无数据统计</n-gradient-text>
|
||||
</n-h1>
|
||||
<n-space v-if="unaccepted" size="large">
|
||||
<n-h1>这{{ listUnaccepted.length }}位没有完成:</n-h1>
|
||||
<n-h1 v-for="name in listUnaccepted" :key="name">
|
||||
{{ name }}
|
||||
</n-h1>
|
||||
<n-text v-if="message">{{ message }}</n-text>
|
||||
</n-space>
|
||||
<n-data-table v-if="list.length" striped :columns="columns" :data="list" />
|
||||
</n-flex>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { formatISO, sub, type Duration } from "date-fns"
|
||||
import { getSubmissionStatistics } from "oj/api"
|
||||
|
||||
interface Props {
|
||||
problem: string
|
||||
username: string
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const options: SelectOption[] = [
|
||||
{ label: "10分钟内", value: "minutes:10" },
|
||||
{ label: "20分钟内", value: "minutes:20" },
|
||||
{ label: "30分钟内", value: "minutes:30" },
|
||||
{ label: "本节课内", value: "hours:1" },
|
||||
{ label: "两小时内", value: "hours:2" },
|
||||
{ label: "一天内", value: "days:1" },
|
||||
{ label: "一周内", value: "weeks:1" },
|
||||
{ label: "一个月内", value: "months:1" },
|
||||
{ label: "一年内", value: "years:1" },
|
||||
]
|
||||
|
||||
const columns: DataTableColumn[] = [
|
||||
{ title: "用户", key: "username" },
|
||||
{ title: "提交数", key: "submission_count" },
|
||||
{ title: "已解决", key: "accepted_count" },
|
||||
{ title: "正确率", key: "correct_rate" },
|
||||
]
|
||||
|
||||
const query = reactive({
|
||||
username: props.username,
|
||||
problem: props.problem,
|
||||
duration: options[0].value,
|
||||
})
|
||||
|
||||
const count = reactive({
|
||||
total: 0,
|
||||
accepted: 0,
|
||||
rate: 0,
|
||||
})
|
||||
const person = reactive({
|
||||
count: 0,
|
||||
rate: 0,
|
||||
})
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const list = ref([])
|
||||
const listUnaccepted = ref([])
|
||||
const [unaccepted, toggleUnaccepted] = useToggle()
|
||||
const message = ref("")
|
||||
|
||||
const subOptions = computed<Duration>(() => {
|
||||
let dur = options.find((it) => it.value === query.duration) ?? options[0]
|
||||
const x = dur.value!.toString().split(":")
|
||||
const unit = x[0]
|
||||
const n = x[1]
|
||||
return { [unit]: parseInt(n) }
|
||||
})
|
||||
|
||||
function goSubmissions() {
|
||||
router.push({
|
||||
name: "submissions",
|
||||
query: {
|
||||
username: query.username,
|
||||
problem: query.problem,
|
||||
},
|
||||
})
|
||||
}
|
||||
async function handleStatistics() {
|
||||
const current = Date.now()
|
||||
const end = formatISO(current)
|
||||
const start = formatISO(sub(current, subOptions.value))
|
||||
const res = await getSubmissionStatistics(
|
||||
{ start, end },
|
||||
query.problem,
|
||||
query.username,
|
||||
)
|
||||
count.total = res.data.submission_count
|
||||
count.accepted = res.data.accepted_count
|
||||
count.rate = res.data.correct_rate
|
||||
list.value = res.data.data
|
||||
listUnaccepted.value = res.data.data_unaccepted
|
||||
person.count = res.data.person_count
|
||||
person.rate = res.data.person_rate
|
||||
|
||||
toggleUnaccepted(false)
|
||||
message.value = ""
|
||||
}
|
||||
</script>
|
||||
@@ -2,8 +2,11 @@ import { PROBLEM_PERMISSION, STORAGE_KEY, USER_TYPE } from "utils/constants"
|
||||
import storage from "utils/storage"
|
||||
import { Profile, User } from "~/utils/types"
|
||||
import { getProfile } from "../api"
|
||||
import { useConfigStore } from "./config"
|
||||
|
||||
export const useUserStore = defineStore("user", () => {
|
||||
const configStore = useConfigStore()
|
||||
|
||||
const profile = ref<Profile | null>(null)
|
||||
const [isFinished] = useToggle(false)
|
||||
const user = computed<User | null>(() => profile.value?.user ?? null)
|
||||
@@ -13,9 +16,7 @@ export const useUserStore = defineStore("user", () => {
|
||||
user.value?.admin_type === USER_TYPE.ADMIN ||
|
||||
user.value?.admin_type === USER_TYPE.SUPER_ADMIN,
|
||||
)
|
||||
const isTheAdmin = computed(
|
||||
() => user.value?.admin_type === USER_TYPE.ADMIN,
|
||||
)
|
||||
const isTheAdmin = computed(() => user.value?.admin_type === USER_TYPE.ADMIN)
|
||||
const isSuperAdmin = computed(
|
||||
() => user.value?.admin_type === USER_TYPE.SUPER_ADMIN,
|
||||
)
|
||||
@@ -23,6 +24,12 @@ export const useUserStore = defineStore("user", () => {
|
||||
() => user.value?.problem_permission !== PROBLEM_PERMISSION.NONE,
|
||||
)
|
||||
|
||||
const showSubmissions = computed(() => {
|
||||
let flag = configStore.config.submission_list_show_all
|
||||
if (isAdminRole.value) flag = true
|
||||
return flag
|
||||
})
|
||||
|
||||
async function getMyProfile() {
|
||||
isFinished.value = false
|
||||
const res = await getProfile()
|
||||
@@ -44,6 +51,7 @@ export const useUserStore = defineStore("user", () => {
|
||||
isSuperAdmin,
|
||||
hasProblemPermission,
|
||||
isAuthed,
|
||||
showSubmissions,
|
||||
getMyProfile,
|
||||
clearProfile,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user