UNPKG

@scu-xiaochuan/scu-pecourse-utils

Version:

48 lines 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.start = start; const http_1 = require("../http"); const utils_1 = require("./utils"); async function start({ teacherName, studentUid, password, timeout, callback, }) { const apiService = new http_1.ApiService(); const api = new http_1.Api(apiService); const { token } = await api.login({ username: studentUid, password, apiService, }); apiService.initAuth(token); const termId = await api.getTermId(); const courses = await api.getCourses({ studentUid, termId }); const { courseId, teacherUid } = (0, utils_1.findTeacher)(teacherName, courses); console.log(`已找到${teacherName}的课课程号为${courseId}`); let count = 1; const timer = setTimeout(async () => { const res = await api.choose({ courseClassId: courseId, studentUid, teacherName, teacherUid, }); if (res) { callback?.({ status: true, msg: '选课成功', }); console.log('选课成功'); clearInterval(timer); } else { const msg = `已经选课${count++}次`; callback?.({ status: false, msg, }); console.log(msg); } }, timeout || 1000); return () => { clearInterval(timer); }; } //# sourceMappingURL=index.js.map