refactor(请求): 去掉 axios,所有请求统一从 authFetch 出门;换 token 时断网不再平白弹登录框
Deploy / deploy (push) Canceled after 0s
Deploy / deploy (push) Canceled after 0s
utils/api 改成基于 authFetch 的一层 fetch 封装,调用方用法不变;下载测试点也走 authFetch,token 过期时会换一张重试。换 token 那一步断网时,AI 流式接口和自学上报 原来会拿掉 token 重发、弹登录框,现在和普通请求一样报「网络异常」。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13843c79a0
commit
d6c3171d13
9 files changed
+103
-192
No files matched your search
@@ -93,7 +93,7 @@ export function getProblemProgress() {
|
||||
|
||||
/**
|
||||
* 「随便来一道」:当前知识点和类型里,先挑能用 language 做的、自己没做对的简单 / 中等题,
|
||||
* 返回题号。空串的参数拦截器会去掉
|
||||
* 返回题号。空串的参数 utils/api 会去掉
|
||||
*/
|
||||
export function getRandomProblem(params: { tag: string; type: string; language: string }) {
|
||||
return api.get<string>("problems/random", { params })
|
||||
@@ -357,9 +357,7 @@ export function getContestClassView(contestID: string) {
|
||||
export function uploadAvatar(file: File) {
|
||||
const form = new window.FormData()
|
||||
form.append("image", file)
|
||||
return api.post("me/avatar", form, {
|
||||
headers: { "content-type": "multipart/form-data" },
|
||||
})
|
||||
return api.post("me/avatar", form)
|
||||
}
|
||||
|
||||
export function updateProfile(data: { realName?: string; mood?: string }) {
|
||||
@@ -551,8 +549,8 @@ export function getLearnProgress(type: "python" | "c") {
|
||||
/**
|
||||
* 上报自学留痕。`opened` 为真表示刚进这一课,否则只是补停留时长。
|
||||
*
|
||||
* 走裸 fetch 而不是 axios,是为了 `keepalive`:离开页面那一下的最后一次上报,
|
||||
* axios 发出去也会随页面卸载被浏览器掐掉,学生每节课的最后一段时长就永远丢了。
|
||||
* 直接走 authFetch 而不是 utils/api,是为了 `keepalive`:离开页面那一下的最后一次上报,
|
||||
* 不带它会随页面卸载被浏览器掐掉,学生每节课的最后一段时长就永远丢了。
|
||||
* 失败一律吞掉 —— 留痕是旁路,不该让学生看到任何报错。
|
||||
*/
|
||||
export function reportLearnProgress(
|
||||
|
||||
Reference in new issue
Block a user