|
@@ -0,0 +1,446 @@
|
|
|
|
|
+// 青岛黄海学院(qdhhc.edu.cn) 拾光课程表适配脚本
|
|
|
|
|
+// 非该大学开发者适配,开发者无法及时发现问题
|
|
|
|
|
+// 出现问题请提issues或者提交pr更改,这更加快速
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 节次与周次合并去重函数
|
|
|
|
|
+ * @param {Array<Object>} courses 原始解析课程数组
|
|
|
|
|
+ * @returns {Array<Object>} 合并去重后的课程数组
|
|
|
|
|
+ */
|
|
|
|
|
+function mergeAndDistinctCourses(courses) {
|
|
|
|
|
+ if (!Array.isArray(courses) || courses.length <= 1) return courses;
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 深拷贝并规范周次数据,过滤无效项
|
|
|
|
|
+ const list = courses.map(c => ({
|
|
|
|
|
+ ...c,
|
|
|
|
|
+ name: c.name || '',
|
|
|
|
|
+ teacher: c.teacher || '',
|
|
|
|
|
+ position: c.position || '',
|
|
|
|
|
+ weeks: Array.isArray(c.weeks) ? [...c.weeks].sort((a, b) => a - b) : []
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ // 阶段 1:合并连续节次与完全重复记录(前提:名称、教师、地点、星期、周次一致)
|
|
|
|
|
+ list.sort((a, b) => {
|
|
|
|
|
+ return a.name.localeCompare(b.name) ||
|
|
|
|
|
+ a.teacher.localeCompare(b.teacher) ||
|
|
|
|
|
+ a.position.localeCompare(b.position) ||
|
|
|
|
|
+ (a.day || 0) - (b.day || 0) ||
|
|
|
|
|
+ a.weeks.join(',').localeCompare(b.weeks.join(',')) ||
|
|
|
|
|
+ (a.startSection || 0) - (b.startSection || 0);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const step1Merged = [];
|
|
|
|
|
+ let current = list[0];
|
|
|
|
|
+
|
|
|
|
|
+ for (let i = 1; i < list.length; i++) {
|
|
|
|
|
+ const next = list[i];
|
|
|
|
|
+
|
|
|
|
|
+ const isSameCourseAndWeeks =
|
|
|
|
|
+ current.name === next.name &&
|
|
|
|
|
+ current.teacher === next.teacher &&
|
|
|
|
|
+ current.position === next.position &&
|
|
|
|
|
+ current.day === next.day &&
|
|
|
|
|
+ current.weeks.join(',') === next.weeks.join(',');
|
|
|
|
|
+
|
|
|
|
|
+ const isContinuous = current.endSection + 1 === next.startSection;
|
|
|
|
|
+ const isDuplicate = current.startSection === next.startSection && current.endSection === next.endSection;
|
|
|
|
|
+
|
|
|
|
|
+ if (isSameCourseAndWeeks && isContinuous) {
|
|
|
|
|
+ // 节次连续:延长结束节次 (如 1-2 节 + 3-4 节 -> 1-4 节)
|
|
|
|
|
+ current.endSection = next.endSection;
|
|
|
|
|
+ } else if (isSameCourseAndWeeks && isDuplicate) {
|
|
|
|
|
+ // 完全重复:跳过
|
|
|
|
|
+ continue;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ step1Merged.push(current);
|
|
|
|
|
+ current = next;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ step1Merged.push(current);
|
|
|
|
|
+
|
|
|
|
|
+ // 阶段 2:合并同节次的周次(前提:名称、教师、地点、星期、开始/结束节次一致)
|
|
|
|
|
+ step1Merged.sort((a, b) => {
|
|
|
|
|
+ return a.name.localeCompare(b.name) ||
|
|
|
|
|
+ a.teacher.localeCompare(b.teacher) ||
|
|
|
|
|
+ a.position.localeCompare(b.position) ||
|
|
|
|
|
+ (a.day || 0) - (b.day || 0) ||
|
|
|
|
|
+ (a.startSection || 0) - (b.startSection || 0) ||
|
|
|
|
|
+ (a.endSection || 0) - (b.endSection || 0);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const step2Merged = [];
|
|
|
|
|
+ let cur = step1Merged[0];
|
|
|
|
|
+
|
|
|
|
|
+ for (let i = 1; i < step1Merged.length; i++) {
|
|
|
|
|
+ const nxt = step1Merged[i];
|
|
|
|
|
+
|
|
|
|
|
+ const isSameCourseAndSection =
|
|
|
|
|
+ cur.name === nxt.name &&
|
|
|
|
|
+ cur.teacher === nxt.teacher &&
|
|
|
|
|
+ cur.position === nxt.position &&
|
|
|
|
|
+ cur.day === nxt.day &&
|
|
|
|
|
+ cur.startSection === nxt.startSection &&
|
|
|
|
|
+ cur.endSection === nxt.endSection;
|
|
|
|
|
+
|
|
|
|
|
+ if (isSameCourseAndSection) {
|
|
|
|
|
+ // 周次合并去重 (如 1-8 周 + 9-16 周 -> 1-16 周)
|
|
|
|
|
+ cur.weeks = Array.from(new Set([...cur.weeks, ...nxt.weeks])).sort((a, b) => a - b);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ step2Merged.push(cur);
|
|
|
|
|
+ cur = nxt;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ step2Merged.push(cur);
|
|
|
|
|
+
|
|
|
|
|
+ return step2Merged;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 解析周次字符串,处理单双周和周次范围。
|
|
|
|
|
+ */
|
|
|
|
|
+function parseWeeks(weekStr) {
|
|
|
|
|
+ if (!weekStr) return [];
|
|
|
|
|
+
|
|
|
|
|
+ const weekSets = weekStr.split(',');
|
|
|
|
|
+ let weeks = [];
|
|
|
|
|
+
|
|
|
|
|
+ for (const set of weekSets) {
|
|
|
|
|
+ const trimmedSet = set.trim();
|
|
|
|
|
+
|
|
|
|
|
+ const rangeMatch = trimmedSet.match(/(\d+)-(\d+)周/);
|
|
|
|
|
+ const singleMatch = trimmedSet.match(/^(\d+)周/); // 匹配以数字周结束的
|
|
|
|
|
+
|
|
|
|
|
+ let start = 0;
|
|
|
|
|
+ let end = 0;
|
|
|
|
|
+ let processed = false;
|
|
|
|
|
+
|
|
|
|
|
+ if (rangeMatch) { // 范围, 如 "1-5周"
|
|
|
|
|
+ start = Number(rangeMatch[1]);
|
|
|
|
|
+ end = Number(rangeMatch[2]);
|
|
|
|
|
+ processed = true;
|
|
|
|
|
+ } else if (singleMatch) { // 单个周, 如 "6周"
|
|
|
|
|
+ start = end = Number(singleMatch[1]);
|
|
|
|
|
+ processed = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (processed) {
|
|
|
|
|
+ // 确定单双周
|
|
|
|
|
+ const isSingle = trimmedSet.includes('(单)');
|
|
|
|
|
+ const isDouble = trimmedSet.includes('(双)');
|
|
|
|
|
+
|
|
|
|
|
+ for (let w = start; w <= end; w++) {
|
|
|
|
|
+ if (isSingle && w % 2 === 0) continue; // 单周跳过偶数
|
|
|
|
|
+ if (isDouble && w % 2 !== 0) continue; // 双周跳过奇数
|
|
|
|
|
+ weeks.push(w);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 去重并排序
|
|
|
|
|
+ return [...new Set(weeks)].sort((a, b) => a - b);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 解析 API 返回的 JSON 数据。
|
|
|
|
|
+ */
|
|
|
|
|
+function parseJsonData(jsonData) {
|
|
|
|
|
+ console.log("JS: parseJsonData 正在解析 JSON 数据...");
|
|
|
|
|
+
|
|
|
|
|
+ // 检查JSON结构:新的数据在 kbList 字段中
|
|
|
|
|
+ if (!jsonData || !Array.isArray(jsonData.kbList)) {
|
|
|
|
|
+ console.warn("JS: JSON 数据结构错误或缺少 kbList 字段。");
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const rawCourseList = jsonData.kbList;
|
|
|
|
|
+ const initialCourseList = [];
|
|
|
|
|
+
|
|
|
|
|
+ for (const rawCourse of rawCourseList) {
|
|
|
|
|
+ // 关键字段检查: kcmc(课名), xm(教师), cdmc(教室), xqj(星期), jcs(节次范围), zcd(周次描述)
|
|
|
|
|
+ if (!rawCourse.kcmc || !rawCourse.xm || !rawCourse.cdmc ||
|
|
|
|
|
+ !rawCourse.xqj || !rawCourse.jcs || !rawCourse.zcd) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const weeksArray = parseWeeks(rawCourse.zcd);
|
|
|
|
|
+
|
|
|
|
|
+ // 周次有效性检查
|
|
|
|
|
+ if (weeksArray.length === 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 解析节次范围,例如 "1-2"
|
|
|
|
|
+ const sectionParts = rawCourse.jcs.split('-');
|
|
|
|
|
+ const startSection = Number(sectionParts[0]);
|
|
|
|
|
+ const endSection = Number(sectionParts[sectionParts.length - 1]);
|
|
|
|
|
+
|
|
|
|
|
+ const day = Number(rawCourse.xqj); // xqj: 星期几 (周一为1, 周日为7)
|
|
|
|
|
+
|
|
|
|
|
+ // 数字有效性检查
|
|
|
|
|
+ if (isNaN(day) || isNaN(startSection) || isNaN(endSection) || day < 1 || day > 7 || startSection > endSection) {
|
|
|
|
|
+ // console.warn(`JS: 课程 ${rawCourse.kcmc} 星期或节次数据无效,跳过。`);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ initialCourseList.push({
|
|
|
|
|
+ name: rawCourse.kcmc.trim(),
|
|
|
|
|
+ teacher: rawCourse.xm.trim(),
|
|
|
|
|
+ position: rawCourse.cdmc.trim(),
|
|
|
|
|
+ day: day,
|
|
|
|
|
+ startSection: startSection,
|
|
|
|
|
+ endSection: endSection,
|
|
|
|
|
+ weeks: weeksArray
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 调用合并与去重函数,整理连续节次与单双周周次
|
|
|
|
|
+ const finalCourseList = mergeAndDistinctCourses(initialCourseList);
|
|
|
|
|
+
|
|
|
|
|
+ console.log(`JS: JSON 数据解析与合并完成,整理后共 ${finalCourseList.length} 门课程。`);
|
|
|
|
|
+ return finalCourseList;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function validateYearInput(input) {
|
|
|
|
|
+ console.log("JS: validateYearInput 被调用,输入: " + input);
|
|
|
|
|
+ if (/^[0-9]{4}$/.test(input)) {
|
|
|
|
|
+ console.log("JS: validateYearInput 验证通过。");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log("JS: validateYearInput 验证失败。");
|
|
|
|
|
+ return "请输入四位数字的学年!";
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function promptUserToStart() {
|
|
|
|
|
+ console.log("JS: 流程开始:显示公告。");
|
|
|
|
|
+ return await window.shiguangBridgePromise.showAlert(
|
|
|
|
|
+ "教务系统课表导入",
|
|
|
|
|
+ "导入前请确保您已在浏览器中成功登录教务系统",
|
|
|
|
|
+ "好的,开始导入"
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function getAcademicYear() {
|
|
|
|
|
+ const currentYear = new Date().getFullYear().toString();
|
|
|
|
|
+ console.log("JS: 提示用户输入学年。");
|
|
|
|
|
+ return await window.shiguangBridgePromise.showPrompt(
|
|
|
|
|
+ "选择学年",
|
|
|
|
|
+ "请输入要导入课程的起始学年(例如 2025-2026 应输入2025):",
|
|
|
|
|
+ currentYear,
|
|
|
|
|
+ "validateYearInput"
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function selectSemester() {
|
|
|
|
|
+ const semesters = ["第一学期", "第二学期"];
|
|
|
|
|
+ console.log("JS: 提示用户选择学期。");
|
|
|
|
|
+ const semesterIndex = await window.shiguangBridgePromise.showSingleSelection(
|
|
|
|
|
+ "选择学期",
|
|
|
|
|
+ JSON.stringify(semesters),
|
|
|
|
|
+ 0
|
|
|
|
|
+ );
|
|
|
|
|
+ return semesterIndex;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 将选择索引转换为 API 所需的学期码。
|
|
|
|
|
+ */
|
|
|
|
|
+function getSemesterCode(semesterIndex) {
|
|
|
|
|
+ // semesterIndex 3 (第一学期), 12 (第二学期)
|
|
|
|
|
+ return semesterIndex === 0 ? "3" : "12";
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function fetchSemesterStartDate(academicYear, semesterCode) {
|
|
|
|
|
+ const url = "http://jwxt.qdhhc.edu.cn/jwglxt/kbcx/xskbcxZccx_cxZcByXnxq.html?gnmkdm=N2154";
|
|
|
|
|
+ const requestBody = `xnm=${academicYear}&xqm=${semesterCode}`;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const response = await fetch(url, {
|
|
|
|
|
+ method: "POST",
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ "accept": "application/json, text/javascript, */*; q=0.01",
|
|
|
|
|
+ "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
|
|
|
+ "x-requested-with": "XMLHttpRequest"
|
|
|
|
|
+ },
|
|
|
|
|
+ body: requestBody,
|
|
|
|
|
+ credentials: "include"
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (response.ok) {
|
|
|
|
|
+ const json = await response.json();
|
|
|
|
|
+ if (Array.isArray(json) && json.length > 0) {
|
|
|
|
|
+ const firstWeekObj = json.find(item => String(item.zs) === "1" || String(item.zsmc) === "1") || json[0];
|
|
|
|
|
+
|
|
|
|
|
+ if (firstWeekObj.rq) {
|
|
|
|
|
+ const startDateStr = firstWeekObj.rq.split('/')[0];
|
|
|
|
|
+ if (/^\d{4}-\d{2}-\d{2}$/.test(startDateStr)) {
|
|
|
|
|
+ return startDateStr;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (firstWeekObj.zcrq) {
|
|
|
|
|
+ const match = firstWeekObj.zcrq.match(/(\d{4}-\d{2}-\d{2})/);
|
|
|
|
|
+ if (match) return match[1];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error("JS: 获取学期开学时间失败:", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function fetchAndParseCourses(academicYear, semesterIndex) {
|
|
|
|
|
+ const semesterCode = getSemesterCode(semesterIndex);
|
|
|
|
|
+ const requestBody = `xnm=${academicYear}&xqm=${semesterCode}&kzlx=ck&xsdm=&kclbdm=`;
|
|
|
|
|
+
|
|
|
|
|
+ const semesterStartDate = await fetchSemesterStartDate(academicYear, semesterCode);
|
|
|
|
|
+ console.log("JS: 获取到的开学日期为:", semesterStartDate);
|
|
|
|
|
+
|
|
|
|
|
+ const targetUrls = [
|
|
|
|
|
+ "http://jwxt.qdhhc.edu.cn/jwglxt/kbcx/xskbcx_cxXsgrkb.html?gnmkdm=N2151"
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ for (const url of targetUrls) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const response = await fetch(url, {
|
|
|
|
|
+ method: "POST",
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
|
|
|
|
+ },
|
|
|
|
|
+ body: requestBody,
|
|
|
|
|
+ credentials: "include"
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (response.ok) {
|
|
|
|
|
+ const jsonText = await response.text();
|
|
|
|
|
+ const jsonData = JSON.parse(jsonText);
|
|
|
|
|
+ if (jsonData && jsonData.kbList) {
|
|
|
|
|
+ const parsedCourses = parseJsonData(jsonData);
|
|
|
|
|
+ if (parsedCourses.length > 0) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ courses: parsedCourses,
|
|
|
|
|
+ config: {
|
|
|
|
|
+ semesterStartDate: semesterStartDate,
|
|
|
|
|
+ semesterTotalWeeks: 20
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error(`JS: 接口请求失败: ${url}`, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ window.shiguangBridge.showToast("未能获取课表数据,请检查网络环境或登录状态。");
|
|
|
|
|
+ return null;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function saveCourses(parsedCourses) {
|
|
|
|
|
+ window.shiguangBridge.showToast(`正在保存 ${parsedCourses.length} 门课程...`);
|
|
|
|
|
+ console.log(`JS: 尝试保存 ${parsedCourses.length} 门课程...`);
|
|
|
|
|
+ try {
|
|
|
|
|
+ await window.shiguangBridgePromise.saveImportedCourses(JSON.stringify(parsedCourses, null, 2));
|
|
|
|
|
+ console.log("JS: 课程保存成功!");
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ window.shiguangBridge.showToast(`课程保存失败: ${error.message}`);
|
|
|
|
|
+ console.error('JS: Save Courses Error:', error);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const TimeSlots = [
|
|
|
|
|
+ { number: 1, startTime: "08:00", endTime: "08:45" },
|
|
|
|
|
+ { number: 2, startTime: "08:50", endTime: "09:35" },
|
|
|
|
|
+ { number: 3, startTime: "10:05", endTime: "10:50" },
|
|
|
|
|
+ { number: 4, startTime: "10:55", endTime: "11:40" },
|
|
|
|
|
+ { number: 5, startTime: "11:45", endTime: "12:30" },
|
|
|
|
|
+ { number: 6, startTime: "14:00", endTime: "14:45" },
|
|
|
|
|
+ { number: 7, startTime: "14:50", endTime: "15:35" },
|
|
|
|
|
+ { number: 8, startTime: "16:05", endTime: "16:50" },
|
|
|
|
|
+ { number: 9, startTime: "16:55", endTime: "17:40" },
|
|
|
|
|
+ { number: 10, startTime: "19:10", endTime: "19:55" },
|
|
|
|
|
+ { number: 11, startTime: "20:00", endTime: "20:45" }
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
|
|
+async function importPresetTimeSlots(timeSlots) {
|
|
|
|
|
+ console.log(`JS: 准备导入 ${timeSlots.length} 个预设时间段。`);
|
|
|
|
|
+
|
|
|
|
|
+ if (timeSlots.length > 0) {
|
|
|
|
|
+ window.shiguangBridge.showToast(`正在导入 ${timeSlots.length} 个预设时间段...`);
|
|
|
|
|
+ try {
|
|
|
|
|
+ await window.shiguangBridgePromise.savePresetTimeSlots(JSON.stringify(timeSlots));
|
|
|
|
|
+ window.shiguangBridge.showToast("预设时间段导入成功!");
|
|
|
|
|
+ console.log("JS: 预设时间段导入成功。");
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ window.shiguangBridge.showToast("导入时间段失败: " + error.message);
|
|
|
|
|
+ console.error('JS: Save Time Slots Error:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ window.shiguangBridge.showToast("警告:时间段为空,未导入时间段信息。");
|
|
|
|
|
+ console.warn("JS: 警告:传入时间段为空,未导入时间段信息。");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async function runImportFlow() {
|
|
|
|
|
+
|
|
|
|
|
+ const alertConfirmed = await promptUserToStart();
|
|
|
|
|
+ if (!alertConfirmed) {
|
|
|
|
|
+ window.shiguangBridge.showToast("用户取消了导入。");
|
|
|
|
|
+ console.log("JS: 用户取消了导入流程。");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const academicYear = await getAcademicYear();
|
|
|
|
|
+ if (academicYear === null) {
|
|
|
|
|
+ window.shiguangBridge.showToast("导入已取消。");
|
|
|
|
|
+ console.log("JS: 获取学年失败/取消,流程终止。");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(`JS: 已选择学年: ${academicYear}`);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ const semesterIndex = await selectSemester();
|
|
|
|
|
+ if (semesterIndex === null || semesterIndex === -1) {
|
|
|
|
|
+ window.shiguangBridge.showToast("导入已取消。");
|
|
|
|
|
+ console.log("JS: 选择学期失败/取消,流程终止。");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(`JS: 已选择学期索引: ${semesterIndex}`);
|
|
|
|
|
+
|
|
|
|
|
+ const result = await fetchAndParseCourses(academicYear, semesterIndex);
|
|
|
|
|
+ if (result === null) {
|
|
|
|
|
+ console.log("JS: 课程获取或解析失败,流程终止。");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const { courses, config } = result;
|
|
|
|
|
+
|
|
|
|
|
+ const saveResult = await saveCourses(courses);
|
|
|
|
|
+ if (!saveResult) {
|
|
|
|
|
+ console.log("JS: 课程保存失败,流程终止。");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ await window.shiguangBridgePromise.saveCourseConfig(JSON.stringify(config));
|
|
|
|
|
+ let configMsg = `课表配置更新成功!`;
|
|
|
|
|
+ if (config.semesterStartDate) {
|
|
|
|
|
+ configMsg += `开学日期:${config.semesterStartDate}`;
|
|
|
|
|
+ }
|
|
|
|
|
+ window.shiguangBridge.showToast(configMsg);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ window.shiguangBridge.showToast(`课表配置保存失败: ${error.message}`);
|
|
|
|
|
+ console.error('JS: Save Config Error:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ await importPresetTimeSlots(TimeSlots);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ window.shiguangBridge.showToast(`课程导入成功,共导入 ${courses.length} 门课程!`);
|
|
|
|
|
+ console.log("JS: 整个导入流程执行完毕并成功。");
|
|
|
|
|
+ window.shiguangBridge.notifyTaskCompletion();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+runImportFlow();
|