|
247 | 247 | import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from "vue" |
248 | 248 | import { useI18n } from "vue-i18n" |
249 | 249 | import { useRoute } from "vue-router" |
250 | | -import { useCidReq } from "../../composables/cidReq" |
| 250 | +import { getCourseContext } from "../../utils/courseContext" |
251 | 251 | import DOMPurify from "dompurify" |
| 252 | +import baseService from "../../services/baseService" |
252 | 253 |
|
253 | 254 | const { t } = useI18n({ useScope: "global" }) |
254 | 255 | const route = useRoute() |
@@ -303,12 +304,12 @@ function readCidReqFromRouteAndLocation() { |
303 | 304 | } |
304 | 305 |
|
305 | 306 | /** |
306 | | - * Keep compatibility: if useCidReq() works, bind to it. |
| 307 | + * Keep compatibility: if getCourseContext() works, bind to it. |
307 | 308 | * If it doesn't provide cid for path-based routes, route watcher will override via readCidReqFromRouteAndLocation(). |
308 | 309 | */ |
309 | 310 | function safeBindCidReq() { |
310 | 311 | try { |
311 | | - const r = useCidReq() |
| 312 | + const r = getCourseContext() |
312 | 313 | if (r?.cid && typeof r.cid === "object" && "value" in r.cid) cid.value = toInt(r.cid.value) || 0 |
313 | 314 | if (r?.sid && typeof r.sid === "object" && "value" in r.sid) sid.value = toInt(r.sid.value) || 0 |
314 | 315 | if (r?.gid && typeof r.gid === "object" && "value" in r.gid) gid.value = toInt(r.gid.value) || 0 |
@@ -652,21 +653,21 @@ function ackTitle(msg) { |
652 | 653 |
|
653 | 654 | async function getJSON(url, params) { |
654 | 655 | const full = params ? `${url}?${qs(withCidReq(params))}` : addCidReqToUrl(url) |
655 | | - const r = await fetch(full, { credentials: "same-origin" }) |
656 | | - if (!r.ok) throw new Error("Network error") |
657 | | - return r.json() |
| 656 | + return baseService.get(full) |
658 | 657 | } |
659 | 658 |
|
660 | 659 | async function post(url, params, expectJson = true) { |
661 | 660 | const fullUrl = addCidReqToUrl(url) |
662 | | - const r = await fetch(fullUrl, { |
663 | | - method: "POST", |
664 | | - credentials: "same-origin", |
665 | | - headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" }, |
666 | | - body: new URLSearchParams(withCidReq(params || {})), |
667 | | - }) |
668 | | - if (!r.ok) throw new Error("Network error") |
669 | | - return expectJson ? r.json() : r.text() |
| 661 | + // URLSearchParams body makes axios send application/x-www-form-urlencoded. |
| 662 | + const body = new URLSearchParams(withCidReq(params || {})) |
| 663 | + |
| 664 | + if (expectJson) { |
| 665 | + return baseService.post(fullUrl, body) |
| 666 | + } |
| 667 | + |
| 668 | + const r = await baseService.postRaw(fullUrl, body, { responseType: "text" }) |
| 669 | + |
| 670 | + return r.data |
670 | 671 | } |
671 | 672 |
|
672 | 673 | function byChronoId(a, b) { |
|
0 commit comments