fix(统计面板): 班级选择不再记本地,别让上一个人的班悄悄留在框里
Some checks failed
Deploy / deploy (push) Has been cancelled

提交统计弹框里的「班级或用户」原来点过「统计」就永久写进 localStorage
(statisticsClass),下次打开自动带上。机房一台电脑对一个班,下课换班或者
换个人坐这台机器时,上一个人查的班还留在选择框里,老师没注意就按了「统计」,
看到的整个是别人的班。

改成不存也不读,每次打开都从空的开始 —— 宁可多选一次。登录框的 LOGIN_CLASS
不动,那记的是这台机器的身份,不是一次临时查询。

STORAGE_KEY.STATISTICS_CLASS 随之没有调用方,一并删掉。
This commit is contained in:
2026-09-10 20:57:34 -06:00
parent 2b07040aee
commit a833819679
2 changed files with 10 additions and 12 deletions

View File

@@ -198,8 +198,7 @@
import { h } from "vue"
import { formatISO, sub, type Duration } from "date-fns"
import { getSubmissionStatistics, getSubmissionStatisticsItems } from "oj/api"
import { PANEL_DURATION_OPTIONS, STORAGE_KEY } from "utils/constants"
import storage from "utils/storage"
import { PANEL_DURATION_OPTIONS } from "utils/constants"
import { useConfigStore } from "../store/config"
import { useHiddenStudents } from "../composables/hiddenStudents"
import { Doughnut } from "vue-chartjs"
@@ -417,14 +416,16 @@ const classOptions = computed<SelectOption[]>(
})) ?? [],
)
// 机房电脑一台对一个班,用过的班级记在本地,下次打开就带上(和登录框同一套做法)
function lastUsedClass() {
const last = storage.get(STORAGE_KEY.STATISTICS_CLASS)
return typeof last === "string" ? last : ""
}
/**
* 班级/用户**不记本地**:这个选择框每次打开都从空的开始。
*
* 曾经把上次的班级写进 localStoragestatisticsClass下次打开自动带上。但那正是
* 最危险的地方 —— 下课换了班、或者换个人坐这台机器,上一个人查的班悄悄留在框里,
* 老师没注意就按了「统计」,看到的整个是别人的班。宁可多选一次。
* 登录框那份 LOGIN_CLASS 是另一回事:那记的是这台机器的身份,不是一次临时查询。
*/
const query = reactive({
username: props.username || lastUsedClass(),
username: props.username,
problem: props.problem,
duration: options[0].value,
})
@@ -744,8 +745,6 @@ async function fetchStatistics() {
listUnaccepted.value = res.dataUnaccepted
listAttempted.value = res.dataAttempted
personCount.value = res.personCount
// 查过的班级记下来,下次打开直接带上
if (query.username) storage.set(STORAGE_KEY.STATISTICS_CLASS, query.username)
const expanded = expandedRowKeys.value[0]
for (const key of Object.keys(items)) delete items[key]

View File

@@ -144,7 +144,6 @@ export const STORAGE_KEY = {
ADMIN_PROBLEM_TAGS: "adminProblemTags",
DEMO_MODE: "demoMode",
LOGIN_CLASS: "loginClass",
STATISTICS_CLASS: "statisticsClass",
}
export const DIFFICULTY = {