You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
import request from "@/utils/request";
|
|
import { getDemoAnswerKey, getStudentDemoSession, isStudentDemo } from "@/utils/studentDemo";
|
|
|
|
function demoResult(taskKey) {
|
|
try { return JSON.parse(sessionStorage.getItem(getDemoAnswerKey(taskKey)) || "null"); } catch (error) { return null; }
|
|
}
|
|
|
|
export function getStudentTrainingAnswer(taskKey, params) {
|
|
if (isStudentDemo()) return Promise.resolve({ code: 200, data: demoResult(taskKey) });
|
|
return request({
|
|
url: `/api/student-training-answers/${taskKey}`,
|
|
method: "get",
|
|
params,
|
|
});
|
|
}
|
|
|
|
export function saveStudentTrainingAnswer(taskKey, data) {
|
|
if (isStudentDemo()) {
|
|
const answer = { ...data, teachingClassId: getStudentDemoSession()?.userInfo?.demoTeachingClassId };
|
|
sessionStorage.setItem(getDemoAnswerKey(taskKey), JSON.stringify(answer));
|
|
return Promise.resolve({ code: 200, data: answer });
|
|
}
|
|
return request({
|
|
url: `/api/student-training-answers/${taskKey}`,
|
|
method: "post",
|
|
data,
|
|
headers: { repeatSubmit: false },
|
|
});
|
|
}
|
|
|
|
export function deleteStudentTrainingAnswer(taskKey, params) {
|
|
if (isStudentDemo()) { sessionStorage.removeItem(getDemoAnswerKey(taskKey)); return Promise.resolve({ code: 200 }); }
|
|
return request({
|
|
url: `/api/student-training-answers/${taskKey}`,
|
|
method: "delete",
|
|
params,
|
|
});
|
|
}
|
|
|
|
export function uploadStudentTrainingFile(data) {
|
|
if (isStudentDemo()) return Promise.reject(new Error("演示模式不上传文件"));
|
|
return request({
|
|
url: "/common/upload",
|
|
method: "post",
|
|
data,
|
|
headers: {
|
|
"Content-Type": "multipart/form-data",
|
|
repeatSubmit: false,
|
|
},
|
|
});
|
|
}
|