Skip to content

Commit

Permalink
修复特殊课表的解析错误2
Browse files Browse the repository at this point in the history
  • Loading branch information
nano71 committed Nov 24, 2024
1 parent a2f0a6b commit b1c3abe
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 40 deletions.
4 changes: 2 additions & 2 deletions android/local.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sdk.dir=C:\\sdk\\android-sdk
flutter.sdk=C:\\sdk\\flutter
flutter.buildMode=debug
flutter.versionName=1.6.241118
flutter.versionCode=71
flutter.versionName=1.6.241125
flutter.versionCode=74
100 changes: 63 additions & 37 deletions lib/common/get.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,61 +167,87 @@ Future<dynamic> getSchedule() async {
}
return list;
}

void step3ForSection(String section) {
List<String> range = section.split("-");
if (range.length == 2) {
for (int i = int.parse(range[0]); i <= int.parse(range[1]); i++) {
weekList.add(i.toString());
}
} else if (range.length == 1) {
weekList.add(range[0]);
}
}
void step3() {
List<String> cache = weekInterval.split(",");
for (int i = 0; i < cache.length; i++) {
if (cache[i].split("-").length == 1) {
weekList.add(cache[i]);
continue;
for (String section in cache) {
step3ForSection(section);
}
}

void handleSingleOrDouble(String section, bool isEven) {
String key = isEven ? "双" : "单";
section = section.replaceAll(key, ""); // 去掉“单”或“双”关键字
List<String> range = section.split("-");

if (range.length == 2) {
for (int i = int.parse(range[0]); i <= int.parse(range[1]); i++) {
if (isEven ? i.isEven : i.isOdd) {
weekList.add(i.toString());
}
}
for (int j = int.parse(cache[i].split("-")[0]); j <= int.parse(cache[i].split("-")[1]); j++) {
weekList.add(j.toString());
} else if (range.length == 1) {
if (int.parse(range[0]).isEven == isEven) {
weekList.add(range[0]);
}
}
}

void step4(bool isEven) {
String key = isEven ? "双" : "单";
if (weekInterval.indexOf(",") != -1) {
List<String> cache = weekInterval.split(",");
if (cache[0].indexOf(key) != -1) {
weekList = cache[0].replaceAll(key, "").split("-");
weekInterval = cache[1];
void step4() {
List<String> cache = weekInterval.split(","); // 按逗号分隔区间
weekList = []; // 初始化周数列表

for (String section in cache) {
if (section.contains("单")) {
handleSingleOrDouble(section, false); // 处理“单”周
} else if (section.contains("双")) {
handleSingleOrDouble(section, true); // 处理“双”周
} else {
weekList = cache[1].replaceAll(key, "").split("-");
weekInterval = cache[0];
step3ForSection(section); // 处理普通区间
}
weekList = initList(isEven);

step3();
weekList.sort((a, b) => int.parse(a) - int.parse(b));
} else {
weekInterval = weekInterval.replaceAll(key, "");
weekList = weekInterval.split("-");
weekList = initList(isEven);
}
}
// weekInterval = "11-14,15-17单";
// weekInterval = "11";
// weekInterval = "11-14双,15-17单";
// weekInterval = "11,15-17双";
// switch (i) {
// case 0:
// weekInterval = "11-14,15-17单";
// break;
// case 1:
// weekInterval = "11-14双,15-17单";
// break;
// case 2:
// weekInterval = "11-14,16-17";
// break;
// case 3:
// weekInterval = "11";
// break;
// }


//单周
if (weekInterval.indexOf("单") != -1) {
step4(false);
//双周
} else if (weekInterval.indexOf("双") != -1) {
step4(true);
} else if (weekInterval.indexOf(",") != -1) {
if (weekInterval.indexOf("-") != -1) {
step3();
} else {
weekInterval = weekInterval.replaceAll(",", "-");
weekList = weekInterval.split("-");
}
print(weekList);
if (weekInterval.contains("单") || weekInterval.contains("双")) {
step4(); // 混合“单/双”处理
} else if (weekInterval.contains(",")) {
step3(); // 普通区间处理
} else {
specialWeek = false;
weekList = weekInterval.split("-");
}



if (lessonList.length > 1 && weekCN != "&nbsp;")
for (int lesson = int.parse(lessonList[0]); lesson <= int.parse(lessonList[1]); lesson++) {
// 普通模式
Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:glutassistantn/common/log.dart';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: "https://pub.flutter-io.cn" # Remove this line if you wish to publis
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.6.241121+72
version: 1.6.241125+74

environment:
sdk: ">=2.14.0 <4.0.0"
Expand Down

0 comments on commit b1c3abe

Please sign in to comment.