# 六步对应的代码片段(C1–C6) 全部用 `cocorobo_page_eval` 执行,`urlMatch` 传 `"pbl-student-table"`。代码**一律写成 `(async () => { ... })()` 自执行**:直接传 `async () => {}` 在客户端里会报 `An object could not be cloned.`。 C1 / C2 在第零步打开的列表页 `https://beta.pbl.cocorobo.cn/pbl-student-table/dist/#/` 上跑,同源 fetch 就能打到 `pbl.cocorobo.cn/api/pbl/`(CORS 放行)。**不需要先开 `https://pbl.cocorobo.cn/` 首页。** ## C1 拿课程(第一步) ```js (async () => { const uid = '' const oid = '' const p = new URLSearchParams({ type: '2', uid, oid, org: oid, typea: '', typeb: '', typec: '', typed: '', typeE: '', cu: '', cn: '', page: '1', pageSize: '50' }) const r = await fetch('https://pbl.cocorobo.cn/api/pbl/selectCourseNew2?' + p.toString(), { credentials: 'include' }) const j = await r.json() const rows = Array.isArray(j) && Array.isArray(j[0]) ? j[0] : Array.isArray(j) && j[0] && typeof j[0] === 'object' && 'courseId' in j[0] ? j : null if (!rows) return { ok: false, http: r.status, raw: JSON.stringify(j).slice(0, 300) } return { ok: true, total: rows.length, courses: rows.map(c => ({ courseId: c.courseId, title: c.title, classes: String(c.juri || '').split(',').map(s => s.trim()).filter(Boolean) })) } })() ``` 八个空串参数必须原样发出;`URLSearchParams` 会保留,手拼会丢,丢了返回空数组或 SQL 错误。 ## C2 拿班级(第二步) ```js (async () => { const courseId = '' const j = await (await fetch('https://pbl.cocorobo.cn/api/pbl/selectCourseDetail3?courseId=' + courseId, { credentials: 'include' })).json() if (!Array.isArray(j)) return { ok: false, raw: JSON.stringify(j).slice(0, 300) } const parts = j.filter(Array.isArray) const classPart = parts.find(p => p.length && p.every(r => r && r.id && r.name)) || [] const courseRow = (j[0] && j[0][0]) || {} return { ok: true, title: courseRow.title || '', classes: classPart.map(c => ({ id: c.id, name: c.name })) } })() ``` 班级是“每行都有 `id` 和 `name`”的那个数组(你那边是第二个数组)。按形状取,不写死下标。 其它数组里带 `classid` 的是选课绑定记录,不是班级名。 ## C3 打开分析页(第三步) ```js (() => { const target = 'https://beta.pbl.cocorobo.cn/pbl-student-table/dist/#/pptEasyClass?type=0&courseId=&userid=&oid=&org=&tcid=<班级id>&tType=1&screenType=2' if (location.href === target) return { ok: true, mode: 'already' } location.href = target return { ok: true, mode: 'navigate', target } })() ``` - `mode: 'navigate'` → 等 4–5 秒(`Start-Sleep -Seconds 5`,不要在页面里写长 `await`),再核一遍: `(() => ({ href: location.href, tcid: (document.querySelector('#app')||{}).__vue__ && document.querySelector('#app').__vue__.$route.query.tcid, hasOpen: typeof window.openDataBoard }))()` `href` 变成分析页地址、`tcid` 等于目标班级 id、`hasOpen` 是 `function`,才能进 C4。 - `mode: 'already'` → 页面本来就在这一班,直接进 C4。 - **不要用 `cocorobo_open_page` 再开一次分析页**:实测客户端只切页签,`cocorobo_page_eval` 仍对着原来那一页(只有一个工作页时 `urlMatch` 不生效),表现为“地址开了、但 eval 一直返回旧页面”。 - 换班同理:`location.href` 指到新 `tcid` 的地址即可,只切页签不导航会拿到上一个班的数据。 ## C4 执行 window.openDataBoard(第四步) ```js () => { const el = document.querySelector('#app') const root = el && el.__vue__ if (!root) return { ok: false, err: 'page-not-ready' } if (typeof window.openDataBoard === 'function') { window.openDataBoard(); return { ok: true, via: 'window' } } let page = null const seen = new Set() ;(function walk (c, d) { if (!c || seen.has(c) || d > 20 || page) return seen.add(c) if (c.$options && c.$options.methods && c.$options.methods.openDataBoard) { page = c; return } for (const ch of (c.$children || [])) walk(ch, d + 1) })(root, 0) if (!page) return { ok: false, err: 'no-openDataBoard' } page.openDataBoard() return { ok: true, via: 'component', classId: page.tcid2 || '' } } ``` 页面启动后 `window.openDataBoard` 才有值,刚打开时是 `undefined` 就等 1–2 秒;仍没有才走组件方法。 ## C5 看看板数据(第四步之后,每 2–3 秒一次,最多 3 次) ```js () => { const root = document.querySelector('#app') && document.querySelector('#app').__vue__ let db = null const seen = new Set() ;(function walk (c, d) { if (!c || seen.has(c) || d > 20 || db) return seen.add(c) if (c.$refs && c.$refs.dataBoardRef) { db = c.$refs.dataBoardRef; return } for (const ch of (c.$children || [])) walk(ch, d + 1) })(root, 0) if (!db) return { ok: false, err: 'no-panel' } return { ok: true, className: db.getClassClassName || '', students: (db.students || []).length, works: (db.works || []).length, loading: !!db.loading } } ``` 一次一调,不要在页面里写十几秒的 `await sleep`,容易整段超时。 `works` 为 0 时别直接说“没人交”:没上过课的班,面板的 `getDataBoard()` 会抛错,`students` 也停在 0。 ## C6 导出(第五步) ```js () => { const root = document.querySelector('#app') && document.querySelector('#app').__vue__ let db = null const seen = new Set() ;(function walk (c, d) { if (!c || seen.has(c) || d > 20 || db) return seen.add(c) if (c.$refs && c.$refs.dataBoardRef) { db = c.$refs.dataBoardRef; return } for (const ch of (c.$children || [])) walk(ch, d + 1) })(root, 0) if (!db) return { ok: false, err: 'no-panel' } if (!(db.works || []).length) return { ok: false, err: 'no-data' } const call = (name) => { if (typeof window[name] === 'function') { window[name](); return 'window' } if (typeof db[name] === 'function') { db[name](); return 'component' } return 'missing' } return { ok: true, exportData: call('handleExportData'), // 作业数据.xlsx(作业数据 + 课程信息) exportBoard: call('handleExport') // 教学分析面板.pdf } } ``` 返回 `missing` 就是页面版本不对,按失败表说,不要硬编文件。 提示“已导出”只代表动作触发:xlsx 3–5 秒落盘;PDF 先落 UUID `.tmp`,几十秒后才改名。