feat: 学时历史可打开对应课程
This commit is contained in:
+26
-4
@@ -330,6 +330,31 @@ _HISTORY_ROW_RE = re.compile(
|
||||
)
|
||||
|
||||
|
||||
def _history_course_path(row: dict) -> str:
|
||||
"""学时记录对应的课程页。已有地址直接用,否则按类型拼播放页。"""
|
||||
explicit = str(row.get("url") or row.get("knowledgeUrl") or row.get("targetUrl") or "").strip()
|
||||
if explicit:
|
||||
return explicit
|
||||
knowledge_id = str(row.get("knowledgeId") or row.get("kngId") or row.get("targetId") or "").replace("-", "").lower()
|
||||
if len(knowledge_id) != 32 or any(char not in "0123456789abcdef" for char in knowledge_id):
|
||||
return ""
|
||||
kind = str(row.get("knowledgeType") or row.get("kngType") or row.get("fileType") or "").strip().lower()
|
||||
folder = "document"
|
||||
for needle, name in (
|
||||
("package", "package"),
|
||||
("scorm", "scorm"),
|
||||
("courseknowledge", "scorm"),
|
||||
("video", "video"),
|
||||
("audio", "video"),
|
||||
("xuanyes", "xuanyes"),
|
||||
("xuan", "xuanyes"),
|
||||
):
|
||||
if needle in kind:
|
||||
folder = name
|
||||
break
|
||||
return f"/kng/view/{folder}/{knowledge_id}.html"
|
||||
|
||||
|
||||
def _history_api_item(row: object) -> dict | None:
|
||||
if not isinstance(row, dict):
|
||||
return None
|
||||
@@ -346,10 +371,7 @@ def _history_api_item(row: object) -> dict | None:
|
||||
elif isinstance(raw_minutes, str) and raw_minutes.strip():
|
||||
match = re.search(r"(\d+)", raw_minutes)
|
||||
minutes = int(match.group(1)) if match else None
|
||||
path = str(row.get("url") or row.get("knowledgeUrl") or row.get("targetUrl") or "").strip()
|
||||
knowledge_id = str(row.get("knowledgeId") or row.get("kngId") or "").replace("-", "")
|
||||
if not path and len(knowledge_id) == 32:
|
||||
path = f"/kng/view/document/{knowledge_id}.html"
|
||||
path = _history_course_path(row)
|
||||
if not title and not studied_at:
|
||||
return None
|
||||
return {
|
||||
|
||||
@@ -1184,6 +1184,33 @@ def test_month_hours_refresh_follows_source() -> None:
|
||||
assert _month_hours(HistoryClient()) == "80"
|
||||
|
||||
|
||||
def test_history_course_path_follows_type_and_keeps_explicit_url() -> None:
|
||||
from euniv.client import _history_api_item
|
||||
|
||||
video = _history_api_item(
|
||||
{
|
||||
"targetName": "视频课",
|
||||
"studyDate": "2026-11-18 10:00",
|
||||
"studyHour": 3,
|
||||
"knowledgeId": "125c7576-c22e-4ae7-be92-ce005171facb",
|
||||
"knowledgeType": "VideoKnowledge",
|
||||
}
|
||||
)
|
||||
assert video is not None
|
||||
assert video["path"] == "/kng/view/video/125c7576c22e4ae7be92ce005171facb.html"
|
||||
named = _history_api_item(
|
||||
{
|
||||
"title": "已有地址",
|
||||
"studiedAt": "2026-11-18",
|
||||
"duration": 1,
|
||||
"url": "/kng/view/package/abc.html",
|
||||
"knowledgeType": "VideoKnowledge",
|
||||
}
|
||||
)
|
||||
assert named is not None
|
||||
assert named["path"] == "/kng/view/package/abc.html"
|
||||
|
||||
|
||||
def test_study_history_parses_period_table() -> None:
|
||||
from euniv.client import EunivClient
|
||||
|
||||
|
||||
@@ -135,13 +135,33 @@ const paged = computed(() => {
|
||||
return rows.slice(start, start + pageSize.value);
|
||||
});
|
||||
|
||||
const EUNIV_ORIGIN = "https://euniv.zte.com.cn";
|
||||
|
||||
function courseHref(path: string) {
|
||||
const text = path.trim();
|
||||
if (text.startsWith("/") && !text.startsWith("//")) return `${EUNIV_ORIGIN}${text}`;
|
||||
try {
|
||||
const url = new URL(text);
|
||||
if (url.protocol === "https:" && url.hostname === "euniv.zte.com.cn") return url.href;
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
const columns: DataTableColumns<HistoryItem> = [
|
||||
{
|
||||
title: "来源",
|
||||
key: "title",
|
||||
ellipsis: { tooltip: true },
|
||||
render(row) {
|
||||
return h("span", { class: "history-title", title: row.title }, row.title || "—");
|
||||
const text = row.title || "—";
|
||||
const href = courseHref(row.path);
|
||||
if (!href) return h("span", { class: "history-title", title: row.title }, text);
|
||||
return h(
|
||||
"a",
|
||||
{ class: "history-title", href, target: "_blank", rel: "noreferrer", title: row.title || "在学习平台打开" },
|
||||
text,
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1556,6 +1556,15 @@ select {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
a.history-title {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a.history-title:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.n-data-table {
|
||||
--n-merged-th-color: transparent;
|
||||
--n-merged-td-color: transparent;
|
||||
|
||||
Reference in New Issue
Block a user