在题目详情页显示数据统计

This commit is contained in:
2025-10-03 15:28:25 +08:00
parent e462bd0864
commit 8ede959fc2
13 changed files with 132 additions and 99 deletions

View File

@@ -101,7 +101,6 @@ const problemPermissionOptions: SelectOption[] = [
{ label: "管理全部题目", value: PROBLEM_PERMISSION.ALL },
]
async function listUsers() {
if (query.page < 1) query.page = 1
const offset = (query.page - 1) * query.limit
@@ -198,17 +197,10 @@ async function handleEditUser() {
onMounted(listUsers)
// 监听搜索关键词变化(防抖)
watchDebounced(
() => query.keyword,
listUsers,
{ debounce: 500, maxWait: 1000 },
)
watchDebounced(() => query.keyword, listUsers, { debounce: 500, maxWait: 1000 })
// 监听其他查询条件变化
watch(
() => [query.page, query.limit, query.type],
listUsers,
)
watch(() => [query.page, query.limit, query.type], listUsers)
</script>
<template>

View File

@@ -1,9 +1,9 @@
<template>
<n-grid :cols="isDesktop ? 5: 1" :x-gap="20">
<n-grid :cols="isDesktop ? 5 : 1" :x-gap="20">
<n-gi :span="2">
<n-flex vertical size="large">
<n-flex align="center" justify="space-between">
<n-h3 style="margin: 0;">请选择时间范围智能分析学习情况</n-h3>
<n-h3 style="margin: 0">请选择时间范围智能分析学习情况</n-h3>
<n-select
style="width: 140px"
:options="options"

View File

@@ -96,7 +96,6 @@ async function listContests() {
total.value = res.data.total
}
function search(value: string) {
query.keyword = value
}
@@ -108,17 +107,13 @@ function clear() {
onMounted(listContests)
// 监听搜索关键词变化(防抖)
watchDebounced(
() => query.keyword,
listContests,
{ debounce: 500, maxWait: 1000 },
)
watchDebounced(() => query.keyword, listContests, {
debounce: 500,
maxWait: 1000,
})
// 监听其他查询条件变化
watch(
() => [query.page, query.limit, query.status, query.tag],
listContests,
)
watch(() => [query.page, query.limit, query.status, query.tag], listContests)
function rowProps(row: Contest) {
return {

View File

@@ -9,6 +9,7 @@ import { createTestSubmission } from "~/utils/judge"
import storage from "~/utils/storage"
import { LANGUAGE } from "~/utils/types"
import Submit from "./Submit.vue"
import StatisticsPanel from "~/shared/components/StatisticsPanel.vue"
interface Props {
storageKey: string
@@ -26,6 +27,8 @@ const userStore = useUserStore()
const emit = defineEmits(["changeLanguage"])
const statisticPanel = ref(false)
function copy() {
copyText(code.value)
message.success("代码复制成功")
@@ -58,8 +61,7 @@ async function test() {
}
const menu = computed<DropdownOption[]>(() => [
{ label: "提交信息", key: "submissions", show: isMobile.value },
{ label: "自测猫", key: "test", show: isMobile.value },
{ label: "去自测猫", key: "test", show: isMobile.value },
{ label: "复制代码", key: "copy" },
{ label: "重置代码", key: "reset" },
])
@@ -82,9 +84,6 @@ const options: DropdownOption[] = problem.value!.languages.map((it) => ({
async function select(key: string) {
switch (key) {
case "submissions":
goSubmissions()
break
case "reset":
reset()
break
@@ -106,6 +105,10 @@ function gotoTestCat() {
const url = import.meta.env.PUBLIC_CODE_URL
window.open(url, "_blank")
}
function showStatisticsPanel() {
statisticPanel.value = true
}
</script>
<template>
@@ -124,19 +127,38 @@ function gotoTestCat() {
<n-flex align="center" v-if="!withTest">
<Submit />
<n-button v-if="isDesktop" @click="gotoTestCat">自测猫</n-button>
<n-button v-if="isDesktop" @click="goSubmissions">提交信息</n-button>
<n-button
:size="isDesktop ? 'medium' : 'small'"
v-if="!userStore.isSuperAdmin && userStore.showSubmissions"
@click="goSubmissions"
>
提交信息
</n-button>
<n-button
:size="isDesktop ? 'medium' : 'small'"
v-if="userStore.isSuperAdmin"
@click="showStatisticsPanel"
>
数据统计
</n-button>
<n-dropdown size="large" :options="menu" @select="select">
<n-button :size="isDesktop ? 'medium' : 'small'">操作</n-button>
</n-dropdown>
<n-button
v-if="isDesktop && userStore.isSuperAdmin"
type="warning"
@click="goEdit"
>
<n-button v-if="isDesktop && userStore.isSuperAdmin" @click="goEdit">
编辑
</n-button>
</n-flex>
</n-flex>
<n-modal
v-if="userStore.isSuperAdmin"
v-model:show="statisticPanel"
preset="card"
:style="{ maxWidth: isDesktop && '70vw', maxHeight: '80vh' }"
:content-style="{ overflow: 'auto' }"
title="提交记录的统计"
>
<StatisticsPanel :problem="problem!._id" username="" />
</n-modal>
</template>
<style scoped>

View File

@@ -55,7 +55,7 @@ const numbers = computed(() => {
{
icon: "streamline-emojis:sparkles",
title: parseFloat(beatRate.value),
content: "击败用户",
content: "击败用户",
int: false,
suffix: "%",
},

View File

@@ -75,16 +75,9 @@ const query = reactive({
page: 1,
})
const showList = computed(() => {
if (!userStore.isAuthed) return false
else if (userStore.isSuperAdmin) return true
else return configStore.config.submission_list_show_all
})
const errorMsg = computed(() => {
if (!userStore.isAuthed) return "请先登录"
else if (!configStore.config.submission_list_show_all)
return "提交列表已被管理员关闭"
else if (!userStore.showSubmissions) return "提交列表已被管理员关闭"
else return ""
})
@@ -102,7 +95,6 @@ async function listSubmissions() {
}
async function getRankOfThisProblem() {
loading.value = true
const res = await getRankOfProblem(<string>route.params.problemID ?? "")
loading.value = false
@@ -122,7 +114,12 @@ onMounted(() => {
watch(query, listSubmissions)
</script>
<template>
<n-alert class="tip" type="error" v-if="!showList" :title="errorMsg" />
<n-alert
class="tip"
type="error"
v-if="!userStore.showSubmissions"
:title="errorMsg"
/>
<template v-if="!loading && route.name === 'problem' && userStore.isAuthed">
<template v-if="class_name">
@@ -134,7 +131,7 @@ watch(query, listSubmissions)
>你们班共有 <b>{{ class_ac_count }}</b> 人答案正确
</div>
<n-button
v-if="showList"
v-if="userStore.showSubmissions"
@click="
router.push({
name: 'submissions',
@@ -153,7 +150,12 @@ watch(query, listSubmissions)
</n-flex>
</template>
</n-alert>
<n-alert class="tip" type="error" :show-icon="false" v-if="rank === -1 && class_ac_count > 0">
<n-alert
class="tip"
type="error"
:show-icon="false"
v-if="rank === -1 && class_ac_count > 0"
>
<template #header>
<n-flex>
<div>
@@ -162,7 +164,7 @@ watch(query, listSubmissions)
共有 <b>{{ class_ac_count }}</b> 人答案正确
</div>
<n-button
v-if="showList"
v-if="userStore.showSubmissions"
secondary
@click="
router.push({
@@ -194,7 +196,7 @@ watch(query, listSubmissions)
<div></div>
<n-button
secondary
v-if="showList"
v-if="userStore.showSubmissions"
@click="
router.push({
name: 'submissions',
@@ -212,7 +214,12 @@ watch(query, listSubmissions)
</n-flex>
</template>
</n-alert>
<n-alert class="tip" type="error" :show-icon="false" v-if="rank === -1 && all_ac_count > 0">
<n-alert
class="tip"
type="error"
:show-icon="false"
v-if="rank === -1 && all_ac_count > 0"
>
<template #header>
<n-flex align="center">
<div>
@@ -220,7 +227,7 @@ watch(query, listSubmissions)
<b>{{ all_ac_count }}</b> 人答案正确
</div>
<n-button
v-if="showList"
v-if="userStore.showSubmissions"
secondary
@click="
router.push({
@@ -242,7 +249,7 @@ watch(query, listSubmissions)
</template>
</template>
<template v-if="showList">
<template v-if="userStore.showSubmissions">
<n-data-table striped :columns="columns" :data="submissions" />
<Pagination
:total="total"

View File

@@ -51,7 +51,6 @@ const { query, clearQuery } = usePagination<ProblemQuery>({
author: useRouteQuery("author", "").value,
})
async function listProblems() {
if (query.page < 1) query.page = 1
const offset = (query.page - 1) * query.limit

View File

@@ -25,10 +25,7 @@ export const useAIStore = defineStore("ai", () => {
const mdContent = ref("")
async function fetchDetailsData(
start: string,
end: string,
) {
async function fetchDetailsData(start: string, end: string) {
loading.details = true
const res = await getAIDetailData(start, end)
detailsData.start = res.data.start
@@ -42,10 +39,7 @@ export const useAIStore = defineStore("ai", () => {
loading.details = false
}
async function fetchWeeklyData(
end: string,
duration: string,
) {
async function fetchWeeklyData(end: string, duration: string) {
loading.weekly = true
const res = await getAIWeeklyData(end, duration)
weeklyData.value = res.data

View File

@@ -12,7 +12,7 @@ import { useUserStore } from "~/shared/store/user"
import { LANGUAGE_SHOW_VALUE } from "~/utils/constants"
import { renderTableTitle } from "~/utils/renders"
import ButtonWithSearch from "./components/ButtonWithSearch.vue"
import StatisticsPanel from "./components/StatisticsPanel.vue"
import StatisticsPanel from "~/shared/components/StatisticsPanel.vue"
import SubmissionLink from "./components/SubmissionLink.vue"
import SubmissionDetail from "./detail.vue"

View File

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

View File

@@ -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: () => "比赛" }),

View File

@@ -27,6 +27,9 @@
<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">
@@ -125,6 +128,9 @@ const person = reactive({
count: 0,
rate: 0,
})
const route = useRoute()
const router = useRouter()
const list = ref([])
const listUnaccepted = ref([])
const [unaccepted, toggleUnaccepted] = useToggle()
@@ -138,6 +144,15 @@ const subOptions = computed<Duration>(() => {
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)

View File

@@ -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,
}