依赖方向原来是反的:顶栏、登录框、举手列表这些 shared 组件从 oj/ 里拿东西。 - 跨端的接口挪进 shared/api.ts(按 apps/web/CLAUDE.md 的分法):学生端题目列表、 出题人列表、这节课的题、待弹的成就 - 这节课的 store → shared/store/lesson.ts;头像 RankAvatar → shared/components - 纯函数挪进 utils/:举手列表的错法归类 errorKind、它依赖的答案错误分类 wrongAnswer 和 Python 报错翻译 pythonError、题目列表行的 toProblemRow - 只有后台在用的出题人下拉 AuthorSelect 挪回 admin/components 纯搬家。首页、题目列表、题目页、排名、课堂看板、后台题目列表打开无报错, 顶栏题号框敲 1001 回车直达题目页。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { getProblemList } from "shared/api"
|
|
|
|
/**
|
|
* 按题号直达。课上老师报一个题号、全班去找,是非比赛提交最主要的来路,
|
|
* 所以敲完题号回车就该进题,而不是先落到列表再点一下。
|
|
*
|
|
* 题号对上了(不分大小写)才直达;对不上、或者敲的是题目名,就去列表搜 ——
|
|
* 列表那边的 keyword 是题号和标题一起模糊匹配,这里只是在它前面加了一步。
|
|
*/
|
|
export function useProblemJump() {
|
|
const router = useRouter()
|
|
const jumping = ref(false)
|
|
|
|
async function jump(input: string) {
|
|
const keyword = input.trim()
|
|
if (!keyword) return router.push("/problem")
|
|
jumping.value = true
|
|
// 查询失败就当没对上,照样去列表搜,别让一次网络抖动把回车吞掉
|
|
const res = await getProblemList(0, 20, { keyword }).catch(() => null)
|
|
jumping.value = false
|
|
const exact = res?.results.find((row) => row._id.toLowerCase() === keyword.toLowerCase())
|
|
if (exact) return router.push(`/problem/${exact._id}`)
|
|
return router.push({ path: "/problem", query: { keyword } })
|
|
}
|
|
|
|
return { jump, jumping }
|
|
}
|