生成的测评链接

This commit is contained in:
朱潮 2025-11-16 23:11:15 +08:00
parent d1d786078c
commit e22a116872
3 changed files with 68 additions and 118 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1769,49 +1769,8 @@
const urlParams = new URLSearchParams(window.location.search);
const assessmentParam = urlParams.get('assessment');
if (assessmentParam) {
try {
// 使用 UTF-8 兼容的解码方法
const assessmentParams = JSON.parse(this.base64ToUtf64(assessmentParam));
// 应用筛选条件
if (assessmentParams.selectedSubject) {
document.getElementById('subjectFilterSelect').value = assessmentParams.selectedSubject;
this.onSubjectFilterChange();
}
if (assessmentParams.selectedSemester) {
document.getElementById('gradeFilterSelect').value = assessmentParams.selectedSemester;
this.onGradeFilterChange();
}
if (assessmentParams.selectedUnit) {
// 延迟设置单元,等待年级选择后再设置单元
setTimeout(() => {
document.getElementById('unitFilterSelect').value = assessmentParams.selectedUnit;
this.onUnitFilterChange();
}, 100);
}
if (assessmentParams.scoreRange) {
document.getElementById('scoreRangeSelect').value = assessmentParams.scoreRange;
this.onScoreRangeChange();
}
// 显示提示信息
this.showNotification('测评配置已自动加载,请填写学员信息后开始答题');
} catch (error) {
console.error('解析测评参数失败:', error);
this.showErrorDialog('测评链接解析失败',
`测评链接参数解析失败,请手动配置测评。<br><br>
可能的原因:<br>
• 链接格式不正确<br>
• 链接已损坏<br>
• 浏览器兼容性问题`
);
}
}
// 注意现在不再使用assessment参数因为测评链接直接使用会话ID
// 保留此函数是为了向后兼容但不再处理assessment参数
}
async loadQuestions() {
@ -2053,23 +2012,14 @@
}
displayAutoRules() {
// 显示自动配置结果区域
document.getElementById('autoRulesDisplay').style.display = 'grid';
// 显示自动配置结果区域
document.getElementById('autoRulesDisplay').style.display = 'none';
// 更新各类型题目数量
document.getElementById('autoBasicCount').textContent = this.currentRules['基础题'];
document.getElementById('autoAdvancedCount').textContent = this.currentRules['进阶题'];
document.getElementById('autoCompetitionCount').textContent = this.currentRules['竞赛题'];
// 计算并更新分数
// 计算题目总数和总分数
const basicScore = this.currentRules['基础题'] * 5;
const advancedScore = this.currentRules['进阶题'] * 10;
const competitionScore = this.currentRules['竞赛题'] * 15;
document.getElementById('autoBasicScore').textContent = basicScore;
document.getElementById('autoAdvancedScore').textContent = advancedScore;
document.getElementById('autoCompetitionScore').textContent = competitionScore;
// 更新总计
const totalQuestions = this.currentRules['基础题'] + this.currentRules['进阶题'] + this.currentRules['竞赛题'];
const totalScore = basicScore + advancedScore + competitionScore;
@ -2365,21 +2315,6 @@
}
}
// UTF-8 字符串转 Base64 编码
utf8ToBase64(str) {
// 将字符串转换为 UTF-8 字节
const utf8Bytes = new TextEncoder().encode(str);
// 将字节转换为 Base64
return btoa(String.fromCharCode(...utf8Bytes));
}
// Base64 解码为 UTF-8 字符串
base64ToUtf64(base64) {
// 将 Base64 转换为字节
const bytes = Uint8Array.from(atob(base64), c => c.charCodeAt(0));
// 将字节转换为 UTF-8 字符串
return new TextDecoder().decode(bytes);
}
async generateAssessmentLink() {
try {
@ -2435,8 +2370,17 @@
generateBtn.querySelector('.button-text').textContent = '正在生成链接...';
generateBtn.disabled = true;
// 构建测评参数(包含学员信息和配置)
const assessmentParams = {
// 调用后端API创建会话和开始答题一样的逻辑
const response = await fetch('/api/create-session', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: studentName,
school: studentSchool,
grade: studentGrade,
phone: studentPhone,
selectedSubject: document.getElementById('subjectFilterSelect').value || '',
selectedSemester: document.getElementById('gradeFilterSelect').value || '',
selectedExamType: '',
@ -2447,18 +2391,21 @@
selectedTagsList: [],
questionsConfig: this.currentRules,
scoreRange: scoreRange
};
})
});
// 使用 UTF-8 兼容的 Base64 编码
const encodedParams = this.utf8ToBase64(JSON.stringify(assessmentParams));
if (!response.ok) {
throw new Error(`创建会话失败: ${response.status}`);
}
// 生成测评链接
const baseUrl = window.location.origin + window.location.pathname.split('/').slice(0, -1).join('/') + '/survey.html';
const assessmentLink = `${baseUrl}?assessment=${encodedParams}`;
const result = await response.json();
if (result.success) {
// 生成答题页面链接
const assessmentLink = `${window.location.origin}/quiz/${result.sessionId}`;
// 复制链接到剪贴板
await navigator.clipboard.writeText(assessmentLink);
// 显示成功对话框
this.showDialog({
title: '测评链接生成成功!',
@ -2471,7 +2418,7 @@
学生信息:${studentName} | ${studentSchool} | ${studentGrade}
</div>
<div style="background: #f5f5f5; padding: 15px; border-radius: 8px; word-break: break-all; font-size: 14px; color: #333; text-align: left;">
<strong>测评链接:</strong><br>
<strong>答题链接:</strong><br>
${assessmentLink}
</div>
<div style="color: #999; font-size: 12px; margin-top: 15px;">
@ -2483,7 +2430,10 @@
});
// 可选:在控制台输出链接,方便调试
console.log('生成的测评链接:', assessmentLink);
console.log('生成的答题链接:', assessmentLink);
} else {
throw new Error('创建会话失败');
}
} catch (error) {
console.error('生成测评链接失败:', error);