Skip to content

Commit

Permalink
获取的bug修复
Browse files Browse the repository at this point in the history
  • Loading branch information
nano71 committed Nov 24, 2021
1 parent aaca070 commit d60e305
Show file tree
Hide file tree
Showing 20 changed files with 854 additions and 398 deletions.
Binary file added images/g.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 45 additions & 39 deletions lib/common/get.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import 'dart:io';
import 'package:gbk2utf8/gbk2utf8.dart';
import 'package:glutassistantn/common/cookie.dart';
import 'package:glutassistantn/common/io.dart';
import 'package:glutassistantn/widget/lists.dart';
import 'package:html/dom.dart' as dom;
import 'package:html/parser.dart';
import 'package:http/http.dart';

import '../config.dart';
import '../data.dart';
import 'init.dart';

Future<void> getWeek() async {
try {
Expand Down Expand Up @@ -47,7 +45,7 @@ Future<void> getWeek() async {
}
}

Future<bool> getSchedule() async {
Future<String> getSchedule() async {
print("getSchedule...");
Map _schedule = schedule;
Map<String, String> _weekList = {
Expand All @@ -68,7 +66,7 @@ Future<bool> getSchedule() async {
.timeout(const Duration(seconds: 3));
if (response.body.contains("j_username")) {
print("登录过期");
return false;
return "fail";
} else {
dom.Document document = parse(gbk
.decode(response.bodyBytes)
Expand Down Expand Up @@ -148,18 +146,16 @@ Future<bool> getSchedule() async {
await writeSchedule(jsonEncode(_schedule));
}
print("getSchedule End");
return true;
} on SocketException catch (e) {
print("超时");
return false;
return "success";
} on TimeoutException catch (e) {
print("网络错误");
return false;
print("getExam Error");
return Global.timeOutError;
} on SocketException catch (e) {
print("getExam Error");
return Global.socketError;
}
}

getScheduleErrorR() {}

Future<void> getName() async {
print("getName...");
var response = await get(Global.getNameUrl, headers: {"cookie": mapCookieToString()})
Expand All @@ -177,7 +173,6 @@ int getLocalWeek(DateTime nowDate, DateTime pastDate) {

List getSemester() {
int y = DateTime.now().year;
int m = DateTime.now().month;
return [
(y - 1980).toString(),
];
Expand All @@ -194,38 +189,50 @@ Future<List> getScore() async {
"sortColumn": "",
"Submit": "查询"
};
var response =
await post(Global.getScoreUrl, body: postData, headers: {"cookie": mapCookieToString()})
.timeout(const Duration(milliseconds: 6000));
if (response.headers["location"] == "/academic/common/security/login.jsp") {
return ["登录过期"];
}
dom.Document document = parse(response.body);
var dataList = document.querySelectorAll(".datalist > tbody >tr");
List list = [];
for (int i = 1; i < dataList.length; i++) {
List _list = [];
_list.add(dataList[i].querySelectorAll("td")[0].text.trim());
_list.add(dataList[i].querySelectorAll("td")[1].text.trim());
_list.add(dataList[i].querySelectorAll("td")[3].text.trim());
_list.add(dataList[i].querySelectorAll("td")[4].text.trim());
_list.add(dataList[i].querySelectorAll("td")[5].text.trim());
_list.add(dataList[i].querySelectorAll("td")[6].text.trim());
list.add(_list);
try {
var response =
await post(Global.getScoreUrl, body: postData, headers: {"cookie": mapCookieToString()})
.timeout(const Duration(seconds: 3));
if (response.headers["location"] == "/academic/common/security/login.jsp") {
return ["登录过期"];
}
dom.Document document = parse(response.body);
var dataList = document.querySelectorAll(".datalist > tbody >tr");
List list = [];
for (int i = 1; i < dataList.length; i++) {
List _list = [];
_list.add(dataList[i].querySelectorAll("td")[0].text.trim());
_list.add(dataList[i].querySelectorAll("td")[1].text.trim());
_list.add(dataList[i].querySelectorAll("td")[3].text.trim());
_list.add(dataList[i].querySelectorAll("td")[4].text.trim());
_list.add(dataList[i].querySelectorAll("td")[5].text.trim());
_list.add(dataList[i].querySelectorAll("td")[6].text.trim());
list.add(_list);
}
print("getScore End");
return list;
} on TimeoutException catch (e) {
print("getScore Error");
return [Global.timeOutError];
} on SocketException catch (e) {
print("getScore Error");
return [Global.socketError];
}
print("getScore End");
return list;
}

Future<String> getExam() async {
print("getExam");
try {
var response = await post(Global.getExamUrl, headers: {"cookie": mapCookieToString()})
.timeout(const Duration(milliseconds: 6000));
.timeout(const Duration(seconds: 3));
dom.Document document = parse(gbk.decode(response.bodyBytes));
if (document.querySelector("title")!.text.contains("提示信息")) {
return "fail";
} else {
examList = [];
examListC = [];
examListA = 0;
examListB = 0;
document = parse(response.body);
examList = [];
var _row = document.querySelectorAll(".datalist> tbody > tr");
Expand Down Expand Up @@ -264,27 +271,26 @@ Future<String> getExam() async {
}
} on TimeoutException catch (e) {
print("getExam Error");
return "超时" + e.toString();
return Global.timeOutError;
} on SocketException catch (e) {
print("getExam Error");
return "网络连接失败" + e.toString();
return Global.socketError;
}
}

Future getCareer() async {
print("getCareer");
_next(url) async {
var response = await get(Uri.http(Global.jwUrl, url), headers: {"cookie": mapCookieToString()})
.timeout(const Duration(milliseconds: 6000));
.timeout(const Duration(seconds: 3));
dom.Document document = parse(gbk.decode(response.bodyBytes));
print(document.querySelectorAll("tr").length);
}

var response = await get(Global.getCareerUrl, headers: {"cookie": mapCookieToString()})
.timeout(const Duration(milliseconds: 6000));
.timeout(const Duration(seconds: 3));
dom.Document document = parse(gbk.decode(response.bodyBytes));
if (gbk.decode(response.bodyBytes).contains("用户名不能为空!")) {

} else {
String url = document
.querySelectorAll("a")[3]
Expand Down
31 changes: 23 additions & 8 deletions lib/common/login.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'dart:async';
import 'dart:io';

import 'package:glutassistantn/common/cookie.dart';
import 'package:http/http.dart';

Expand All @@ -9,11 +12,19 @@ Future<String> codeCheck(String code) async {
var postData = {
"captchaCode": code,
};
var response = await post(_url, body: postData, headers: {"cookie": mapCookieToString()})
.timeout(const Duration(milliseconds: 6000));
String result = "success";
if (response.body != "true") result = "fail";
return result;
try {
var response = await post(_url, body: postData, headers: {"cookie": mapCookieToString()})
.timeout(const Duration(seconds: 3));
String result = "success";
if (response.body != "true") result = "fail";
return result;
} on TimeoutException catch (e) {
print("getExam Error");
return Global.timeOutError;
} on SocketException catch (e) {
print("getExam Error");
return Global.socketError;
}
}

Future<String> login(String username, String password, String code) async {
Expand All @@ -22,14 +33,18 @@ Future<String> login(String username, String password, String code) async {
var postData = {"j_username": username, "j_password": password, "j_captcha": code};
var response =
await post(Global.loginUrl, body: postData, headers: {"cookie": mapCookieToString()})
.timeout(const Duration(milliseconds: 6000));
.timeout(const Duration(seconds: 3));
if (response.headers['location'] == "/academic/index_new.jsp") {
parseRawCookies(response.headers['set-cookie']);
return "success";
} else {
return "fail";
}
} catch (e) {
return e.toString();
} on TimeoutException catch (e) {
print("getExam Error");
return Global.timeOutError;
} on SocketException catch (e) {
print("getExam Error");
return Global.socketError;
}
}
21 changes: 17 additions & 4 deletions lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Global {
initialPage: 0,
keepPage: true,
);
static String timeOutError = "连接教务超时,教务可能维护中";
static String socketError = "网络连接失败";
static Map<String, String> cookie = {};
static String jwUrl = "jw.glutnn.cn";
static Uri getCodeUrl = Uri.http(jwUrl, "/academic/getCaptcha.do");
Expand All @@ -21,7 +23,8 @@ class Global {
static Uri getNameUrl = Uri.http(jwUrl, "/academic/student/studentinfo/studentInfoModifyIndex.do",
{"frombase": "0", "wantTag": "0"});
static Uri getScoreUrl = Uri.http(jwUrl, "/academic/manager/score/studentOwnScore.do");
static Uri getCareerUrl = Uri.http(jwUrl, "/academic/manager/studyschedule/studentSelfSchedule.jsdo");
static Uri getCareerUrl =
Uri.http(jwUrl, "/academic/manager/studyschedule/studentSelfSchedule.jsdo");
static List<String> getScheduleUrl = [jwUrl, "/academic/student/currcourse/currcourse.jsdo"];
static List<String> codeCheckUrl = [jwUrl, "/academic/checkCaptcha.do"];
static double schedulePageTouchMovesMinValue = 70.0;
Expand All @@ -35,7 +38,13 @@ readGradient() {
begin: Alignment.centerLeft,
end: Alignment.topRight,
);
} else if (writeData["color"] == "blue") {
} else if (writeData["color"] == "pink") {
return const LinearGradient(
colors: [Color(0xfffb7766), Color(0xfffc6caa)],
begin: Alignment.centerLeft,
end: Alignment.topRight,
);
}else if (writeData["color"] == "blue") {
return const LinearGradient(
colors: [Color(0xff66cefb), Color(0xff4175f7)],
begin: Alignment.centerLeft,
Expand Down Expand Up @@ -65,6 +74,8 @@ readGradient() {
readColor() {
if (writeData["color"] == "blue") {
return Colors.blue;
} else if (writeData["color"] == "pink") {
return Colors.pinkAccent[100];
} else if (writeData["color"] == "red") {
return Colors.redAccent;
} else if (writeData["color"] == "yellow") {
Expand All @@ -77,7 +88,7 @@ readColor() {
}

readColorBegin() {
if (writeData["color"] == "red") {
if (writeData["color"] == "red"||writeData["color"] == "pink") {
return const Color.fromARGB(42, 255, 229, 253);
} else if (writeData["color"] == "blue") {
return const Color.fromARGB(42, 199, 229, 253);
Expand All @@ -93,7 +104,9 @@ readColorBegin() {
readColorEnd() {
if (writeData["color"] == "red") {
return const Color.fromARGB(110, 253, 199, 199);
} else if (writeData["color"] == "blue") {
} else if (writeData["color"] == "pink") {
return const Color.fromARGB(110, 253, 199, 228);
}else if (writeData["color"] == "blue") {
return const Color.fromARGB(110, 199, 229, 253);
} else if (writeData["color"] == "yellow") {
return const Color.fromARGB(110, 253, 246, 199);
Expand Down
11 changes: 11 additions & 0 deletions lib/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ class SetPageIndex {
SetPageIndex(this.index);
}

class QueryExamRe {
int index;

QueryExamRe(this.index);
}
class QueryScoreRe {
int index;

QueryScoreRe(this.index);
}

class ReState {
int index;

Expand Down
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Expand Down
9 changes: 9 additions & 0 deletions lib/pages/career.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ class _CareerPageState extends State<CareerPage> {
},
),
),
SliverToBoxAdapter(
child: Container(
margin: const EdgeInsets.fromLTRB(16, 0, 16, 0),
child: const Text(
"你大学期间的全部课程都在这里",
style: TextStyle(color: Colors.grey),
),
),
),
SliverToBoxAdapter(
child: SizedBox(
height: MediaQuery.of(context).size.height - 125,
Expand Down
Loading

0 comments on commit d60e305

Please sign in to comment.