fix: 会话失效时自动重新登录,管理端可改判断依据

This commit is contained in:
Nixevol
2026-11-21 14:39:56 +08:00
parent 4d4fe224bc
commit a6306e8339
7 changed files with 204 additions and 19 deletions
+47 -2
View File
@@ -36,6 +36,8 @@ interface UserRow {
hours_month: string;
study_active: boolean | null;
study_state: string;
study_message: string;
hours_met: boolean;
}
interface SecretField {
@@ -68,6 +70,7 @@ const startHour = ref<number | null>(0);
const startMinute = ref<number | null>(0);
const startSecond = ref<number | null>(0);
const scheduleChoice = ref<"keep" | "on" | "off">("keep");
const hoursChoice = ref<"keep" | "api" | "history">("keep");
const workersValue = ref<number | null>(1);
const proxyScheme = ref("keep");
const settingsReady = ref(false);
@@ -116,6 +119,7 @@ interface SettingsBaseline {
startMinute: number | null;
startSecond: number | null;
scheduleChoice: "keep" | "on" | "off";
hoursChoice: "keep" | "api" | "history";
workers: number | null;
scheme: string;
host: string;
@@ -196,6 +200,8 @@ function asUser(value: unknown): UserRow | null {
hours_month: textOf(value.hours_month),
study_active: typeof value.study_active === "boolean" ? value.study_active : null,
study_state: textOf(value.state) || textOf(value.study_state),
study_message: textOf(value.message) || textOf(value.study_message),
hours_met: value.hours_met === true,
};
}
@@ -214,10 +220,21 @@ function taskText(row: UserRow) {
const state = row.study_state;
if (row.study_active === true || state === "运行中" || state === "学习中" || state === "准备") return "运行中";
if (state === "排队中") return "排队中";
if (state === "会话失效") return "会话失效";
if (state === "学习失败") return "学习失败";
if (state === "已达标" || row.hours_met) return "已达标";
if (state === "已学完") return "已学完";
if (row.study_paused || state === "已停止") return "已停止";
return "未开始";
}
function taskClass(row: UserRow) {
const text = taskText(row);
if (text === "运行中" || text === "排队中") return "ok";
if (text === "会话失效" || text === "学习失败") return "late";
return "quiet";
}
function taskCanStop(row: UserRow) {
const text = taskText(row);
return text === "运行中" || text === "排队中";
@@ -500,6 +517,7 @@ function resetSettingsForm() {
startMinute.value = null;
startSecond.value = null;
scheduleChoice.value = "keep";
hoursChoice.value = "keep";
workersValue.value = null;
proxyScheme.value = "keep";
proxyHost.value = "";
@@ -518,6 +536,7 @@ function captureSettings(): SettingsBaseline {
startMinute: startMinute.value,
startSecond: startSecond.value,
scheduleChoice: scheduleChoice.value,
hoursChoice: hoursChoice.value,
workers: workersValue.value,
scheme: proxyScheme.value,
host: proxyHost.value,
@@ -533,6 +552,7 @@ function applyRowSettings(row: UserRow) {
startMinute.value = row.study_start_minute;
startSecond.value = row.study_start_second;
scheduleChoice.value = row.study_schedule_enabled === false ? "off" : "on";
hoursChoice.value = row.hours_source === "history" ? "history" : "api";
workersValue.value = row.course_workers;
}
@@ -616,6 +636,7 @@ function applySavedRow(row: UserRow, sent: {
monthlyTarget: number | null;
scheduleEnabled: boolean | null;
workers: number | null;
hoursSource: "api" | "history" | null;
day: number | null;
hour: number | null;
minute: number | null;
@@ -628,6 +649,7 @@ function applySavedRow(row: UserRow, sent: {
if (sent.monthlyTarget != null) next.monthly_target = sent.monthlyTarget;
if (sent.scheduleEnabled != null) next.study_schedule_enabled = sent.scheduleEnabled;
if (sent.workers != null) next.course_workers = sent.workers;
if (sent.hoursSource) next.hours_source = sent.hoursSource;
if (sent.day != null && sent.hour != null && sent.minute != null && sent.second != null) {
next.study_start_day = sent.day;
next.study_start_hour = sent.hour;
@@ -653,6 +675,7 @@ async function saveSettings() {
|| startSecond.value !== baseline.startSecond;
const scheduleChanged = scheduleChoice.value !== baseline.scheduleChoice && scheduleValue() !== null;
const workersChanged = workersValue.value !== baseline.workers;
const hoursChanged = hoursChoice.value !== baseline.hoursChoice && hoursChoice.value !== "keep";
const proxyTouched = proxyScheme.value !== baseline.scheme
|| proxyHost.value.trim() !== baseline.host
|| proxyPort.value !== baseline.port
@@ -691,12 +714,13 @@ async function saveSettings() {
const sentTarget = targetChanged ? monthlyTarget.value : null;
const sentSchedule = scheduleChanged ? scheduleValue() : null;
const sentWorkers = workersChanged ? workersValue.value : null;
const sentHours = hoursChanged ? hoursChoice.value : null;
const sentDay = scheduleTouched ? startDay.value : null;
const sentHour = scheduleTouched ? startHour.value : null;
const sentMinute = scheduleTouched ? startMinute.value : null;
const sentSecond = scheduleTouched ? startSecond.value : null;
const sentScheme = proxyTouched && proxyScheme.value !== "keep" ? proxyScheme.value : null;
if (sentTarget == null && sentSchedule == null && sentWorkers == null && sentDay == null && sentScheme == null) {
if (sentTarget == null && sentSchedule == null && sentWorkers == null && sentDay == null && sentScheme == null && sentHours == null) {
settingsOpen.value = false;
return;
}
@@ -714,6 +738,7 @@ async function saveSettings() {
second: sentSecond,
schedule_enabled: sentSchedule,
workers: sentWorkers,
hours_source: sentHours,
scheme: sentScheme,
host: sentScheme && proxyManual.value ? proxyHost.value.trim() : "",
port: sentScheme && proxyManual.value ? proxyPort.value : null,
@@ -730,6 +755,7 @@ async function saveSettings() {
monthlyTarget: sentTarget,
scheduleEnabled: sentSchedule,
workers: sentWorkers,
hoursSource: sentHours === "history" || sentHours === "api" ? sentHours : null,
day: sentDay,
hour: sentHour,
minute: sentMinute,
@@ -932,7 +958,15 @@ onMounted(() => {
:official="row.official_month_hours"
/>
</td>
<td :class="taskText(row) === '运行中' ? 'ok' : 'quiet'">{{ taskText(row) }}</td>
<td :class="taskClass(row)">
<n-tooltip v-if="row.study_message" placement="top">
<template #trigger>
<span>{{ taskText(row) }}</span>
</template>
{{ row.study_message }}
</n-tooltip>
<template v-else>{{ taskText(row) }}</template>
</td>
<td class="when">{{ formatRefreshTime(row.study_opened_at) || "—" }}</td>
<td class="when">{{ row.proxy || "—" }}</td>
<td class="when">{{ formatRefreshTime(row.last_refresh_at) }}</td>
@@ -1006,6 +1040,17 @@ onMounted(() => {
<n-time-picker v-model:formatted-value="startTime" value-format="HH:mm:ss" :actions="null" placeholder="保持不变" :disabled="scheduleTimeDisabled" />
</div>
</n-form-item>
<n-form-item label="判断依据">
<div class="hours-source-field">
<n-radio-group v-model:value="hoursChoice" size="small">
<n-radio-button v-if="settingsIds.length !== 1" value="keep">保持不变</n-radio-button>
<n-radio-button value="api">官方统计数据</n-radio-button>
<n-radio-button value="history">历史统计数据</n-radio-button>
</n-radio-group>
<p v-if="hoursChoice === 'api'" class="field-hint">根据官方接口返回进行判断(官方统计可能会延后,导致学时可能会多刷)</p>
<p v-else-if="hoursChoice === 'history'" class="field-hint">根据学习历史统计本月学时</p>
</div>
</n-form-item>
<n-form-item label="同时学习课程数">
<div class="target-control">
<n-select class="worker-select" v-model:value="workersValue" :options="workerOptions" placeholder="保持不变" />
+14
View File
@@ -1687,6 +1687,20 @@ a.history-title:hover {
margin: 0 0 12px;
}
.hours-source-field {
display: flex;
flex-direction: column;
gap: 6px;
min-width: 0;
}
.field-hint {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.secret-field {
padding: 8px 0;
border-bottom: 1px solid var(--line);