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.
dianshang-qianduan/src/utils/studentDemo.js

31 lines
829 B
JavaScript

export const STUDENT_DEMO_STORAGE_KEY = "student-demo-session";
export function getStudentDemoSession() {
try {
const value = sessionStorage.getItem(STUDENT_DEMO_STORAGE_KEY);
return value ? JSON.parse(value) : null;
} catch (error) {
return null;
}
}
export function isStudentDemo() {
return Boolean(getStudentDemoSession()?.token);
}
export function saveStudentDemoSession(login) {
sessionStorage.setItem(STUDENT_DEMO_STORAGE_KEY, JSON.stringify({
token: login.token,
userInfo: login,
expiresAt: Date.now() + 30 * 60 * 1000,
}));
}
export function clearStudentDemoSession() {
sessionStorage.removeItem(STUDENT_DEMO_STORAGE_KEY);
}
export function getDemoAnswerKey(taskKey) {
return `student-demo-answer:${getStudentDemoSession()?.userInfo?.demoTeachingClassId || ""}:${taskKey}`;
}