Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ let checkIfFull = true
let particlesLoaded = false
let particlesPaused = false
let studentId

let autoReloginTimer = null
const AUTO_RELOGIN_INTERVAL = 7200000 // 2小时 = 7200000毫秒

// 导轨
!(function () {
Expand Down Expand Up @@ -73,6 +74,8 @@ var targetList = JSON.parse(localStorage.getItem("DLSF_target")) || []
targetListRender()
// 如果 cookie 失效,尝试使用用户名密码登录
if (!await checkCookie()) { buttonSaveUser() }
// 启动自动重新登录定时器
startAutoRelogin()
})()


Expand Down Expand Up @@ -145,6 +148,37 @@ async function loginUser() {
}
}

// 启动自动重新登录定时器
function startAutoRelogin() {
const username = localStorage.getItem("DLSF_username")
const password = localStorage.getItem("DLSF_password")

// 只有当用户名和密码都存在时才启动定时器
if (!username || !password) {
console.log("[自动重登录] 用户名或密码未设置,不启动自动重登录")
return
}

// 避免重复创建定时器
if (autoReloginTimer) {
clearInterval(autoReloginTimer)
console.log("[自动重登录] 清除旧的定时器")
}

// 启动新的定时器
autoReloginTimer = setInterval(async () => {
console.log("[自动重登录] 开始执行自动重新登录...")
const success = await loginUser()
if (success) {
console.log("[自动重登录] 重新登录成功")
} else {
console.log("[自动重登录] 重新登录失败")
}
}, AUTO_RELOGIN_INTERVAL)

console.log(`[自动重登录] 定时器已启动,间隔 ${AUTO_RELOGIN_INTERVAL / 1000 / 60} 分钟`)
}

// 获取某门课的全部教学班信息
async function getAccData(courseCode, requestKey = "") {
// 给并发请求加区分标识,避免不同 worker 互相取消请求
Expand Down