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

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

View File

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

View File

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

View File

@@ -9,6 +9,7 @@ import { createTestSubmission } from "~/utils/judge"
import storage from "~/utils/storage" import storage from "~/utils/storage"
import { LANGUAGE } from "~/utils/types" import { LANGUAGE } from "~/utils/types"
import Submit from "./Submit.vue" import Submit from "./Submit.vue"
import StatisticsPanel from "~/shared/components/StatisticsPanel.vue"
interface Props { interface Props {
storageKey: string storageKey: string
@@ -26,6 +27,8 @@ const userStore = useUserStore()
const emit = defineEmits(["changeLanguage"]) const emit = defineEmits(["changeLanguage"])
const statisticPanel = ref(false)
function copy() { function copy() {
copyText(code.value) copyText(code.value)
message.success("代码复制成功") message.success("代码复制成功")
@@ -58,8 +61,7 @@ async function test() {
} }
const menu = computed<DropdownOption[]>(() => [ 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: "copy" },
{ label: "重置代码", key: "reset" }, { label: "重置代码", key: "reset" },
]) ])
@@ -82,9 +84,6 @@ const options: DropdownOption[] = problem.value!.languages.map((it) => ({
async function select(key: string) { async function select(key: string) {
switch (key) { switch (key) {
case "submissions":
goSubmissions()
break
case "reset": case "reset":
reset() reset()
break break
@@ -106,6 +105,10 @@ function gotoTestCat() {
const url = import.meta.env.PUBLIC_CODE_URL const url = import.meta.env.PUBLIC_CODE_URL
window.open(url, "_blank") window.open(url, "_blank")
} }
function showStatisticsPanel() {
statisticPanel.value = true
}
</script> </script>
<template> <template>
@@ -124,19 +127,38 @@ function gotoTestCat() {
<n-flex align="center" v-if="!withTest"> <n-flex align="center" v-if="!withTest">
<Submit /> <Submit />
<n-button v-if="isDesktop" @click="gotoTestCat">自测猫</n-button> <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-dropdown size="large" :options="menu" @select="select">
<n-button :size="isDesktop ? 'medium' : 'small'">操作</n-button> <n-button :size="isDesktop ? 'medium' : 'small'">操作</n-button>
</n-dropdown> </n-dropdown>
<n-button <n-button v-if="isDesktop && userStore.isSuperAdmin" @click="goEdit">
v-if="isDesktop && userStore.isSuperAdmin"
type="warning"
@click="goEdit"
>
编辑 编辑
</n-button> </n-button>
</n-flex> </n-flex>
</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> </template>
<style scoped> <style scoped>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -69,6 +69,7 @@ const menus = computed<MenuOption[]>(() => [
h(RouterLink, { to: "/submission" }, { default: () => "提交" }), h(RouterLink, { to: "/submission" }, { default: () => "提交" }),
key: "submission", key: "submission",
icon: renderIcon("streamline-emojis:bouquet"), icon: renderIcon("streamline-emojis:bouquet"),
show: userStore.showSubmissions,
}, },
{ {
label: () => h(RouterLink, { to: "/contest" }, { default: () => "比赛" }), label: () => h(RouterLink, { to: "/contest" }, { default: () => "比赛" }),

View File

@@ -27,6 +27,9 @@
<n-form-item> <n-form-item>
<n-button type="primary" @click="handleStatistics">统计</n-button> <n-button type="primary" @click="handleStatistics">统计</n-button>
</n-form-item> </n-form-item>
<n-form-item v-if="route.name !== 'submissions'">
<n-button @click="goSubmissions">前往提交列表</n-button>
</n-form-item>
</n-form> </n-form>
<n-space v-if="count.total > 0" size="large"> <n-space v-if="count.total > 0" size="large">
<n-h1 style="margin-bottom: 0"> <n-h1 style="margin-bottom: 0">
@@ -125,6 +128,9 @@ const person = reactive({
count: 0, count: 0,
rate: 0, rate: 0,
}) })
const route = useRoute()
const router = useRouter()
const list = ref([]) const list = ref([])
const listUnaccepted = ref([]) const listUnaccepted = ref([])
const [unaccepted, toggleUnaccepted] = useToggle() const [unaccepted, toggleUnaccepted] = useToggle()
@@ -138,6 +144,15 @@ const subOptions = computed<Duration>(() => {
return { [unit]: parseInt(n) } return { [unit]: parseInt(n) }
}) })
function goSubmissions() {
router.push({
name: "submissions",
query: {
username: query.username,
problem: query.problem,
},
})
}
async function handleStatistics() { async function handleStatistics() {
const current = Date.now() const current = Date.now()
const end = formatISO(current) 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 storage from "utils/storage"
import { Profile, User } from "~/utils/types" import { Profile, User } from "~/utils/types"
import { getProfile } from "../api" import { getProfile } from "../api"
import { useConfigStore } from "./config"
export const useUserStore = defineStore("user", () => { export const useUserStore = defineStore("user", () => {
const configStore = useConfigStore()
const profile = ref<Profile | null>(null) const profile = ref<Profile | null>(null)
const [isFinished] = useToggle(false) const [isFinished] = useToggle(false)
const user = computed<User | null>(() => profile.value?.user ?? null) 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.ADMIN ||
user.value?.admin_type === USER_TYPE.SUPER_ADMIN, user.value?.admin_type === USER_TYPE.SUPER_ADMIN,
) )
const isTheAdmin = computed( const isTheAdmin = computed(() => user.value?.admin_type === USER_TYPE.ADMIN)
() => user.value?.admin_type === USER_TYPE.ADMIN,
)
const isSuperAdmin = computed( const isSuperAdmin = computed(
() => user.value?.admin_type === USER_TYPE.SUPER_ADMIN, () => user.value?.admin_type === USER_TYPE.SUPER_ADMIN,
) )
@@ -23,6 +24,12 @@ export const useUserStore = defineStore("user", () => {
() => user.value?.problem_permission !== PROBLEM_PERMISSION.NONE, () => 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() { async function getMyProfile() {
isFinished.value = false isFinished.value = false
const res = await getProfile() const res = await getProfile()
@@ -44,6 +51,7 @@ export const useUserStore = defineStore("user", () => {
isSuperAdmin, isSuperAdmin,
hasProblemPermission, hasProblemPermission,
isAuthed, isAuthed,
showSubmissions,
getMyProfile, getMyProfile,
clearProfile, clearProfile,
} }