feat: 首页顶部改为本年、本月、今日和累计学时,以及累计学分和可用积分
This commit is contained in:
+12
-9
@@ -492,7 +492,7 @@ class EunivClient:
|
|||||||
period_resp = self._request("GET", f"{STUDY_API}/v1/frw/user/info")
|
period_resp = self._request("GET", f"{STUDY_API}/v1/frw/user/info")
|
||||||
period = period_resp.json()
|
period = period_resp.json()
|
||||||
if not isinstance(period, dict) or "yearScores" not in period:
|
if not isinstance(period, dict) or "yearScores" not in period:
|
||||||
raise RuntimeError("本年和本月学分返回无法识别")
|
raise RuntimeError("学习信息返回无法识别")
|
||||||
|
|
||||||
score_resp = self._request("POST", f"{YXT_API}/v1/customapiforweb/getscoreorpointorhour", json={})
|
score_resp = self._request("POST", f"{YXT_API}/v1/customapiforweb/getscoreorpointorhour", json={})
|
||||||
score_payload = score_resp.json()
|
score_payload = score_resp.json()
|
||||||
@@ -503,26 +503,29 @@ class EunivClient:
|
|||||||
today_resp = self._request("GET", f"{STUDY_API}/v1/studyapi/studyhour/todayscorehours")
|
today_resp = self._request("GET", f"{STUDY_API}/v1/studyapi/studyhour/todayscorehours")
|
||||||
today = today_resp.json()
|
today = today_resp.json()
|
||||||
|
|
||||||
|
periods = self._period_minutes()
|
||||||
return {
|
return {
|
||||||
"name": info.get("cnName") or "",
|
"name": info.get("cnName") or "",
|
||||||
"avatar": info.get("headPictureUrl") or "",
|
"avatar": info.get("headPictureUrl") or "",
|
||||||
"department": info.get("departmentName") or "",
|
"department": info.get("departmentName") or "",
|
||||||
"level": period.get("levelName") or info.get("userClassLevelName") or "",
|
"level": period.get("levelName") or info.get("userClassLevelName") or "",
|
||||||
"year_score": period.get("yearScores") or "0.00",
|
"year_hours": periods["year"],
|
||||||
"month_score": period.get("monthScores") or "0.00",
|
"month_hours": periods["month"],
|
||||||
|
"today_hours": today.get("studyHours"),
|
||||||
"total_hours": score.get("actualStudyHour") or "",
|
"total_hours": score.get("actualStudyHour") or "",
|
||||||
"total_score": score.get("actualStudyScore") or period.get("totalScores") or "",
|
"total_score": score.get("actualStudyScore") or period.get("totalScores") or "",
|
||||||
"today_hours": today.get("studyHours"),
|
"points": "" if score.get("ablePoint") is None else score.get("ablePoint"),
|
||||||
"today_score": today.get("studyScore"),
|
|
||||||
"month_hours": self._month_study_hours(),
|
|
||||||
"trainings": _by_closeness(self.online_trainings(), "sort_days"),
|
"trainings": _by_closeness(self.online_trainings(), "sort_days"),
|
||||||
"exams": _by_closeness(self.my_exams(), "sort_at"),
|
"exams": _by_closeness(self.my_exams(), "sort_at"),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _month_study_hours(self) -> str:
|
def _period_minutes(self) -> dict[str, str]:
|
||||||
text = self._study_period_page()
|
text = self._study_period_page()
|
||||||
match = re.search(r'id="spMonthlyPeriod" title="(\d+)分钟"', text)
|
found = {}
|
||||||
return match.group(1) if match else ""
|
for key, element in (("year", "spAnnualPeriod"), ("month", "spMonthlyPeriod")):
|
||||||
|
match = re.search(rf'id="{element}" title="(\d+)分钟"', text)
|
||||||
|
found[key] = match.group(1) if match else ""
|
||||||
|
return found
|
||||||
|
|
||||||
def _ensure_site(self) -> None:
|
def _ensure_site(self) -> None:
|
||||||
if self._profile.get("token") and not getattr(self, "_site_ready", False):
|
if self._profile.get("token") and not getattr(self, "_site_ready", False):
|
||||||
|
|||||||
@@ -72,13 +72,12 @@ class FakeClient:
|
|||||||
"avatar": "https://example.test/a.jpg",
|
"avatar": "https://example.test/a.jpg",
|
||||||
"department": "测试部门",
|
"department": "测试部门",
|
||||||
"level": "Scientist",
|
"level": "Scientist",
|
||||||
"year_score": "1.00",
|
"year_hours": "100",
|
||||||
"month_score": "0.20",
|
"month_hours": "60",
|
||||||
|
"today_hours": 1,
|
||||||
"total_hours": "10",
|
"total_hours": "10",
|
||||||
"total_score": "3.00",
|
"total_score": "3.00",
|
||||||
"today_hours": "1",
|
"points": 20,
|
||||||
"today_score": "0.10",
|
|
||||||
"month_hours": "60",
|
|
||||||
"exams": [{"name": "安全考试", "status": "已完成", "start": "2026-05-20 00:01:00"}],
|
"exams": [{"name": "安全考试", "status": "已完成", "start": "2026-05-20 00:01:00"}],
|
||||||
"trainings": [],
|
"trainings": [],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,12 @@ interface HomeProfile {
|
|||||||
avatar: string;
|
avatar: string;
|
||||||
department: string;
|
department: string;
|
||||||
level: string;
|
level: string;
|
||||||
year_score: string;
|
year_hours: string;
|
||||||
month_score: string;
|
|
||||||
month_hours: string;
|
month_hours: string;
|
||||||
|
today_hours: string | number | null;
|
||||||
total_hours: string;
|
total_hours: string;
|
||||||
total_score: string;
|
total_score: string;
|
||||||
|
points: string | number | null;
|
||||||
exams: ExamItem[];
|
exams: ExamItem[];
|
||||||
trainings: TrainingItem[];
|
trainings: TrainingItem[];
|
||||||
}
|
}
|
||||||
@@ -37,15 +38,24 @@ const loading = ref(false);
|
|||||||
let timer = 0;
|
let timer = 0;
|
||||||
let requestId = 0;
|
let requestId = 0;
|
||||||
|
|
||||||
|
function amount(value: string | number | null | undefined) {
|
||||||
|
if (value === null || value === undefined || value === "") return "—";
|
||||||
|
const numeric = Number(value);
|
||||||
|
if (!Number.isFinite(numeric)) return String(value);
|
||||||
|
if (Number.isInteger(numeric)) return String(numeric);
|
||||||
|
return String(value);
|
||||||
|
}
|
||||||
|
|
||||||
const facts = computed(() => {
|
const facts = computed(() => {
|
||||||
const current = profile.value;
|
const current = profile.value;
|
||||||
if (!current) return [];
|
if (!current) return [];
|
||||||
return [
|
return [
|
||||||
{ label: "本年学分", value: current.year_score },
|
{ label: "本年学时", value: amount(current.year_hours) },
|
||||||
{ label: "本月学分", value: current.month_score },
|
{ label: "本月学时", value: amount(current.month_hours) },
|
||||||
{ label: "本月学时", value: current.month_hours },
|
{ label: "今日学时", value: amount(current.today_hours) },
|
||||||
{ label: "累计学时", value: current.total_hours },
|
{ label: "累计学时", value: amount(current.total_hours) },
|
||||||
{ label: "累计学分", value: current.total_score },
|
{ label: "累计学分", value: amount(current.total_score) },
|
||||||
|
{ label: "可用积分", value: amount(current.points) },
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -414,7 +414,7 @@ select {
|
|||||||
|
|
||||||
.facts {
|
.facts {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
grid-template-columns: repeat(6, minmax(0, 1fr));
|
||||||
gap: 8px 16px;
|
gap: 8px 16px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user