From 9a50885a5eb51ce8990e8e4f424353493574d484 Mon Sep 17 00:00:00 2001 From: ChinaGamer <1742968988@.qq.com> Date: Wed, 5 Jan 2022 18:16:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/get.dart | 180 +++++++++++++++++++++--------------------- lib/pages/career.dart | 40 +++++++--- 2 files changed, 121 insertions(+), 99 deletions(-) diff --git a/lib/common/get.dart b/lib/common/get.dart index 91893c1..fd0ad5e 100644 --- a/lib/common/get.dart +++ b/lib/common/get.dart @@ -144,6 +144,7 @@ Future getSchedule() async { } } _next() async { + print("获取课表变更(调课/停课/补课)"); String _id = document .querySelector(".button[value='个人课表']")! .attributes["onclick"]! @@ -160,101 +161,105 @@ Future getSchedule() async { var response2 = await get(_url, headers: {"cookie": mapCookieToString()}) .timeout(Duration(seconds: Global.timeOutSec)); document = parse(gbk.decode(response2.bodyBytes)); - dom.Element table = document.querySelectorAll(".infolist_hr")[2]; - List trs = table.querySelectorAll(".infolist_hr_common"); - int _index = 0; - String _name = ""; - String _teacher = ""; - trs.forEach((element) { - List tds = element.querySelectorAll("td"); - int _length = tds.length; - print(_length); - if (_length == 17) { - //周 - String _delWeek = tds[8].innerHtml.trim(); - String _addWeek = tds[13].innerHtml.trim(); - //课节 - List _delTime = tds[10] - .innerHtml - .trim() - .replaceAll("第", "") - .replaceAll("节", "") - .replaceAll("周", "") - .replaceAll("双", "") - .split('-'); - List _addTime = tds[15] - .innerHtml - .trim() - .replaceAll("第", "") - .replaceAll("节", "") - .replaceAll("周", "") - .replaceAll("双", "") - .split('-'); - //星期 - String _delWeekDay = weekDay2Number(tds[9].innerHtml.trim()); - String _addWeekDay = weekDay2Number(tds[14].innerHtml.trim()); - //教室 - String _addRoom = tds[16].innerHtml.trim(); - //老师 - String _addTeacher = tds[4].innerHtml.trim(); - _teacher = _addTeacher; - //课 - String _addName = tds[2].innerHtml.trim(); - _name = _addName; - if (_delWeek != " ") { - for (int i = int.parse(_delTime[0]); i <= int.parse(_delTime[1]); i++) { - _schedule[_delWeek][_delWeekDay][i.toString()] = ["null", "null", "null"]; + List tables = document.querySelectorAll(".infolist_hr"); + if (tables.length >= 3) { + dom.Element table = tables[2]; + List trs = table.querySelectorAll(".infolist_hr_common"); + int _index = 0; + String _name = ""; + String _teacher = ""; + trs.forEach((element) { + List tds = element.querySelectorAll("td"); + int _length = tds.length; + print(_length); + if (_length == 17) { + //周 + String _delWeek = tds[8].innerHtml.trim(); + String _addWeek = tds[13].innerHtml.trim(); + //课节 + List _delTime = tds[10] + .innerHtml + .trim() + .replaceAll("第", "") + .replaceAll("节", "") + .replaceAll("周", "") + .replaceAll("双", "") + .split('-'); + List _addTime = tds[15] + .innerHtml + .trim() + .replaceAll("第", "") + .replaceAll("节", "") + .replaceAll("周", "") + .replaceAll("双", "") + .split('-'); + //星期 + String _delWeekDay = weekDay2Number(tds[9].innerHtml.trim()); + String _addWeekDay = weekDay2Number(tds[14].innerHtml.trim()); + //教室 + String _addRoom = tds[16].innerHtml.trim(); + //老师 + String _addTeacher = tds[4].innerHtml.trim(); + _teacher = _addTeacher; + //课 + String _addName = tds[2].innerHtml.trim(); + _name = _addName; + if (_delWeek != " ") { + for (int i = int.parse(_delTime[0]); i <= int.parse(_delTime[1]); i++) { + _schedule[_delWeek][_delWeekDay][i.toString()] = ["null", "null", "null"]; + } } - } - if (_addWeek != " ") { - for (int i = int.parse(_addTime[0]); i <= int.parse(_addTime[1]); i++) { - _schedule[_addWeek][_addWeekDay][i.toString()] = [_addName, _addTeacher, _addRoom]; + if (_addWeek != " ") { + for (int i = int.parse(_addTime[0]); i <= int.parse(_addTime[1]); i++) { + _schedule[_addWeek][_addWeekDay] + [i.toString()] = [_addName, _addTeacher, _addRoom]; + } } - } - } else if (_length == 10) { - //周 - String _delWeek = tds[1].innerHtml.trim(); - String _addWeek = tds[6].innerHtml.trim(); - //课节 - List _delTime = tds[3] - .innerHtml - .trim() - .replaceAll("第", "") - .replaceAll("节", "") - .replaceAll("周", "") - .replaceAll("双", "") - .split('-'); - List _addTime = tds[8] - .innerHtml - .trim() - .replaceAll("第", "") - .replaceAll("节", "") - .replaceAll("周", "") - .replaceAll("双", "") - .split('-'); - //星期 - String _delWeekDay = weekDay2Number(tds[2].innerHtml.trim()); - String _addWeekDay = weekDay2Number(tds[7].innerHtml.trim()); - //教室 - String _addRoom = tds[9].innerHtml.trim(); + } else if (_length == 10) { + //周 + String _delWeek = tds[1].innerHtml.trim(); + String _addWeek = tds[6].innerHtml.trim(); + //课节 + List _delTime = tds[3] + .innerHtml + .trim() + .replaceAll("第", "") + .replaceAll("节", "") + .replaceAll("周", "") + .replaceAll("双", "") + .split('-'); + List _addTime = tds[8] + .innerHtml + .trim() + .replaceAll("第", "") + .replaceAll("节", "") + .replaceAll("周", "") + .replaceAll("双", "") + .split('-'); + //星期 + String _delWeekDay = weekDay2Number(tds[2].innerHtml.trim()); + String _addWeekDay = weekDay2Number(tds[7].innerHtml.trim()); + //教室 + String _addRoom = tds[9].innerHtml.trim(); - if (_delWeek != " ") { - for (int i = int.parse(_delTime[0]); i <= int.parse(_delTime[1]); i++) { - _schedule[_delWeek][_delWeekDay][i.toString()] = ["null", "null", "null"]; + if (_delWeek != " ") { + for (int i = int.parse(_delTime[0]); i <= int.parse(_delTime[1]); i++) { + _schedule[_delWeek][_delWeekDay][i.toString()] = ["null", "null", "null"]; + } } - } - if (_addWeek != " ") { - for (int i = int.parse(_addTime[0]); i <= int.parse(_addTime[1]); i++) { - _schedule[_addWeek][_addWeekDay][i.toString()] = [_name, _teacher, _addRoom]; - print(_schedule[_addWeek][_addWeekDay][i.toString()]); + if (_addWeek != " ") { + for (int i = int.parse(_addTime[0]); i <= int.parse(_addTime[1]); i++) { + _schedule[_addWeek][_addWeekDay][i.toString()] = [_name, _teacher, _addRoom]; + print(_schedule[_addWeek][_addWeekDay][i.toString()]); + } } } - } - _index++; - }); + _index++; + }); + } } - print(_schedule["19"]["2"]); + print(writeData); await _next(); await writeSchedule(jsonEncode(_schedule)); } @@ -452,7 +457,6 @@ Future getCareer() async { start = i + 1; } if (i == list.length - 1) { - print("结尾了"); newList.add(list.sublist(start, i + 1)); } } diff --git a/lib/pages/career.dart b/lib/pages/career.dart index b9875d9..4241087 100644 --- a/lib/pages/career.dart +++ b/lib/pages/career.dart @@ -40,7 +40,7 @@ class _CareerPageBodyState extends State { GlobalKey textKey = GlobalKey(); final int _week = int.parse(writeData["week"]); int year = 0; - int year2 = 0; + int allYear = 0; @override void initState() { @@ -112,24 +112,42 @@ class _CareerPageBodyState extends State { double _weekProgressDouble() { if (careerInfo[2] != "" && careerInfo[3] != "") { + //年级 year = int.parse(careerInfo[2].replaceAll("级", "").trim()); - year2 = int.parse( + // 全部学年 + allYear = int.parse( careerInfo[3].substring(careerInfo[3].toString().indexOf("年") - 1).replaceAll("年", "")); setState(() {}); } - double semesterPercentage = year2 == 3 ? 1 / 6 : 1 / 8; + //完整的一个学期占比 + double semesterPercentage = allYear == 3 ? 1 / 6 : 1 / 8; + + //本学期 double weekPercentage = (_week * 5 / 100) - 0.05 + (DateTime.now().weekday / 7 * 5 / 100); - int year3 = year + year2 - DateTime.now().year; - next() { + + //剩余学年 :: 2019 + 3年 - 2022 + + int year3 = year + allYear - DateTime.now().year; + print(DateTime.now().month); + if (DateTime.now().month < 3) { + year3++; + } + + //本学期在全部学期占比 + double proportionOfSemesterInAllSemesters = weekPercentage * semesterPercentage; + + //year2 = 3 , year3 = 0 + _next() { if (writeData["semester"] == "秋") - return 1 - year3 / year2 + weekPercentage * semesterPercentage; + return (allYear * 2 - year3 * 2) * semesterPercentage + proportionOfSemesterInAllSemesters; else - return 1 - year3 / year2 + semesterPercentage + weekPercentage * semesterPercentage; + return (allYear * 2 - year3 * 2 + 1) * semesterPercentage + + proportionOfSemesterInAllSemesters; } - if (_week > 20 && DateTime.now().year == year + year2) return 1.00; + if (_week > 20 && DateTime.now().year == year + allYear) return 1.00; if (careerInfo[2] == "" && careerInfo[3] == "") return 0.0; - return next(); + return _next(); } @override @@ -389,7 +407,7 @@ class _CareerPageBodyState extends State { SliverList( delegate: SliverChildBuilderDelegate((BuildContext context, int index) { return CareerListProcess(index); - }, childCount: year2), + }, childCount: allYear), ), ], ), @@ -531,7 +549,7 @@ careerDialog(context, index, type, year) { return NoRippleOverScroll( child: SimpleDialog( title: Row( - mainAxisAlignment:MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start,