|
|
@@ -7,11 +7,6 @@ for(let i=1990; i<=2100; i++){
|
|
|
yearArr.push(i);
|
|
|
}
|
|
|
|
|
|
-//获取本月最大日期
|
|
|
-function getDaysInMonth(year, month) {
|
|
|
- return new Date(year, month, 0).getDate();
|
|
|
-}
|
|
|
-
|
|
|
//根据URL特征判断当前所在界面
|
|
|
function checkCurrentPage() {
|
|
|
const currenturl = window.location.href.toLowerCase(); //获取当前URL并转为小写
|
|
|
@@ -27,12 +22,12 @@ function checkCurrentPage() {
|
|
|
return -1; //未知错误,返回值-1
|
|
|
}
|
|
|
|
|
|
-//显示一个公告信息弹窗
|
|
|
+//显示是否确认导入课程弹窗
|
|
|
async function confirmAlert() {
|
|
|
try {
|
|
|
const confirmed = await window.AndroidBridgePromise.showAlert(
|
|
|
"重要提醒",
|
|
|
- "自动加载上课时间段仅支持珠海校区,\n每周第一天默认为星期日,可自行修改。\n是否确认获取课表?",
|
|
|
+ "自动加载上课时间段仅支持珠海校区,\n是否确认获取课表?",
|
|
|
"确认",
|
|
|
);
|
|
|
if (confirmed) {
|
|
|
@@ -48,12 +43,25 @@ async function confirmAlert() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//显示到设置中选择开学日期的提醒
|
|
|
+async function setinfoAlert() {
|
|
|
+ const confirmed = await window.AndroidBridgePromise.showAlert(
|
|
|
+ "重要提醒",
|
|
|
+ "导入课程信息成功,请到设置界面选择当前学期的开学日期",
|
|
|
+ "好的"
|
|
|
+ );
|
|
|
+ if (!confirmed) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
//显示一个是否手动输入学年学期信息的弹窗
|
|
|
async function confirmGetXNXQAlert() {
|
|
|
try {
|
|
|
const confirmed = await window.AndroidBridgePromise.showAlert(
|
|
|
"重要提醒",
|
|
|
- "是否确认手动输入学年学期信息?",
|
|
|
+ "自动获取学年学期信息失败,\n是否确认手动输入学年学期信息?",
|
|
|
"确认",
|
|
|
);
|
|
|
if (confirmed) {
|
|
|
@@ -77,7 +85,6 @@ async function getSession() {
|
|
|
36
|
|
|
);
|
|
|
if (selectedIndex !== null && selectedIndex >= 0 && selectedIndex < yearArr.length) {
|
|
|
- AndroidBridge.showToast("你选择了" + yearArr[selectedIndex] + '-' + (Number(yearArr[selectedIndex])+1) + "学年");
|
|
|
return (yearArr[selectedIndex] + '-' + (Number(yearArr[selectedIndex])+1));
|
|
|
} else {
|
|
|
AndroidBridge.showToast("用户取消了选择!");
|
|
|
@@ -99,10 +106,8 @@ async function getSemester() {
|
|
|
);
|
|
|
if (selectedIndex !== null && selectedIndex >= 0 && selectedIndex < 2) {
|
|
|
if(selectedIndex === 0) {
|
|
|
- AndroidBridge.showToast("你选择了第一学期");
|
|
|
return 1;
|
|
|
}else{
|
|
|
- AndroidBridge.showToast("你选择了第二学期");
|
|
|
return 2;
|
|
|
}
|
|
|
} else {
|
|
|
@@ -137,7 +142,6 @@ async function importPresetTimeSlots() {
|
|
|
try {
|
|
|
const result = await window.AndroidBridgePromise.savePresetTimeSlots(JSON.stringify(timeSlots));
|
|
|
if (result === true) {
|
|
|
- //AndroidBridge.showToast("时间段导入成功!");
|
|
|
} else {
|
|
|
AndroidBridge.showToast("时间段导入失败!");
|
|
|
}
|
|
|
@@ -302,7 +306,7 @@ function autoGetTotalWeekNum(courses) {
|
|
|
async function saveCourses(courseData) {
|
|
|
let xnxqID = getSessionSemester();
|
|
|
if (xnxqID === -1) {
|
|
|
- AndroidBridge.showToast("无法自动获取学年学期信息!");
|
|
|
+ //无法自动获取学年学期信息,询问是否手动输入
|
|
|
if(await confirmGetXNXQAlert()){
|
|
|
const session = await getSession();
|
|
|
if(session === -1){
|
|
|
@@ -313,6 +317,7 @@ async function saveCourses(courseData) {
|
|
|
return -1;
|
|
|
}
|
|
|
xnxqID = (session + '-' + semester);
|
|
|
+ AndroidBridge.showToast("你选择的学年学期信息:" + xnxqID);
|
|
|
}else {
|
|
|
return -1;
|
|
|
}
|
|
|
@@ -331,7 +336,7 @@ async function saveCourses(courseData) {
|
|
|
try {
|
|
|
const result = await window.AndroidBridgePromise.saveImportedCourses(JSON.stringify(courses));
|
|
|
if (result === true) {
|
|
|
- //AndroidBridge.showToast("课程导入成功!");
|
|
|
+ //课程导入成功!
|
|
|
return totalWeeksNum;
|
|
|
} else {
|
|
|
AndroidBridge.showToast("课程导入失败!");
|
|
|
@@ -347,75 +352,20 @@ async function saveCourses(courseData) {
|
|
|
//导入课表配置
|
|
|
async function saveConfig(semesterTotalWeeks) {
|
|
|
// 注意:只传入要修改的字段,其他字段(如 semesterTotalWeeks)会使用 Kotlin 模型中的默认值
|
|
|
- let semesterStartData = "";
|
|
|
- let choseResult = 1;
|
|
|
-
|
|
|
- //显示三次单项选择框,向用户获取开学时间
|
|
|
- try {
|
|
|
- const yearIndex = await window.AndroidBridgePromise.showSingleSelection(
|
|
|
- "请选择开学时间(年份)",
|
|
|
- JSON.stringify(yearArr),
|
|
|
- 36
|
|
|
- );
|
|
|
- if (yearIndex !== null && yearIndex >= 0 && yearIndex < yearArr.length) {
|
|
|
- const year = yearArr[yearIndex];
|
|
|
- const monthIndex = await window.AndroidBridgePromise.showSingleSelection(
|
|
|
- "请选择开学时间(月份)",
|
|
|
- JSON.stringify([1,2,3,4,5,6,7,8,9,10,11,12]),
|
|
|
- 2
|
|
|
- );
|
|
|
- if (monthIndex !== null && monthIndex >= 0 && monthIndex < 12) {
|
|
|
- const month =[1,2,3,4,5,6,7,8,9,10,11,12][monthIndex];
|
|
|
- const dayArr = [];
|
|
|
- for (let i = 1; i <= getDaysInMonth(year,month); i++) {
|
|
|
- dayArr.push(i);
|
|
|
- }
|
|
|
- const dayIndex = await window.AndroidBridgePromise.showSingleSelection(
|
|
|
- "请选择开学时间(日期)",
|
|
|
- JSON.stringify(dayArr),
|
|
|
- 7
|
|
|
- );
|
|
|
- if (dayIndex !== null && dayIndex >= 0 && dayIndex < dayArr.length) {
|
|
|
- const day = dayArr[dayIndex];
|
|
|
- const yearStr = year.toString();
|
|
|
- const monthStr = month.toString().padStart(2,"0"); //补充为两位
|
|
|
- const dayStr = day.toString().padStart(2,"0"); //补充为两位
|
|
|
- semesterStartData = yearStr + '-' + monthStr + '-' + dayStr;
|
|
|
- AndroidBridge.showToast("你选择的开学时间为:" + semesterStartData);
|
|
|
- } else {
|
|
|
- choseResult = 0;
|
|
|
- }
|
|
|
- } else {
|
|
|
- choseResult = 0;
|
|
|
- }
|
|
|
- } else {
|
|
|
- choseResult = 0;
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- AndroidBridge.showToast("显示列表出错!" + error.message);
|
|
|
- return -1; // 出现错误时也返回 -1
|
|
|
- }
|
|
|
-
|
|
|
- if(!choseResult){
|
|
|
- AndroidBridge.showToast("用户取消了选择,将按默认开学日期2026-3-9导入配置");
|
|
|
- semesterStartData = "2026-03-09";
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
try {
|
|
|
const courseConfigData = {
|
|
|
- "semesterStartDate": semesterStartData, //月份要使用两位数,否则软件会崩溃
|
|
|
+ // "semesterStartDate": semesterStartData, //月份要使用两位数,否则软件会崩溃
|
|
|
"semesterTotalWeeks": Number(semesterTotalWeeks),
|
|
|
"defaultClassDuration": 45,
|
|
|
"defaultBreakDuration": 10,
|
|
|
- "firstDayOfWeek": 7
|
|
|
+ "firstDayOfWeek": 1
|
|
|
};
|
|
|
const configJsonString = JSON.stringify(courseConfigData);
|
|
|
const result = await window.AndroidBridgePromise.saveCourseConfig(configJsonString);
|
|
|
if (result === true) {
|
|
|
+ //课表配置导入成功
|
|
|
return 0;
|
|
|
- //AndroidBridge.showToast("课表配置导入成功!");
|
|
|
} else {
|
|
|
AndroidBridge.showToast("课表配置导入失败");
|
|
|
return -1;
|
|
|
@@ -443,19 +393,29 @@ async function runAllDemosSequentially() {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- //确认窗口
|
|
|
+ //确认是否导入课程
|
|
|
const alertResult = await confirmAlert();
|
|
|
if (!alertResult) {
|
|
|
return; // 用户取消,立即退出函数
|
|
|
}
|
|
|
|
|
|
+ //导入课程,返回-1表示导入失败
|
|
|
const totalNum = await saveCourses();
|
|
|
if(totalNum === -1) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ //导入预设上课时间段
|
|
|
await importPresetTimeSlots();
|
|
|
+
|
|
|
+ //导入课表配置
|
|
|
const saveConfigResult = await saveConfig(totalNum);
|
|
|
- if(saveConfigResult === -1)
|
|
|
+ if(saveConfigResult === 0)
|
|
|
+ {
|
|
|
+ //课表导入成功,提示用户设置开学日期
|
|
|
+ await setinfoAlert();
|
|
|
+ }
|
|
|
+ else if(saveConfigResult === -1)
|
|
|
{
|
|
|
return;
|
|
|
}
|