生成的测评链接
This commit is contained in:
parent
d1d786078c
commit
e22a116872
Binary file not shown.
Binary file not shown.
@ -1769,49 +1769,8 @@
|
|||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const assessmentParam = urlParams.get('assessment');
|
const assessmentParam = urlParams.get('assessment');
|
||||||
|
|
||||||
if (assessmentParam) {
|
// 注意:现在不再使用assessment参数,因为测评链接直接使用会话ID
|
||||||
try {
|
// 保留此函数是为了向后兼容,但不再处理assessment参数
|
||||||
// 使用 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>
|
|
||||||
• 浏览器兼容性问题`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadQuestions() {
|
async loadQuestions() {
|
||||||
@ -2053,23 +2012,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
displayAutoRules() {
|
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 basicScore = this.currentRules['基础题'] * 5;
|
||||||
const advancedScore = this.currentRules['进阶题'] * 10;
|
const advancedScore = this.currentRules['进阶题'] * 10;
|
||||||
const competitionScore = this.currentRules['竞赛题'] * 15;
|
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 totalQuestions = this.currentRules['基础题'] + this.currentRules['进阶题'] + this.currentRules['竞赛题'];
|
||||||
const totalScore = basicScore + advancedScore + competitionScore;
|
const totalScore = basicScore + advancedScore + competitionScore;
|
||||||
@ -2365,22 +2315,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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() {
|
async generateAssessmentLink() {
|
||||||
try {
|
try {
|
||||||
// 验证学员信息(和开始答题一样的验证逻辑)
|
// 验证学员信息(和开始答题一样的验证逻辑)
|
||||||
@ -2435,55 +2370,70 @@
|
|||||||
generateBtn.querySelector('.button-text').textContent = '正在生成链接...';
|
generateBtn.querySelector('.button-text').textContent = '正在生成链接...';
|
||||||
generateBtn.disabled = true;
|
generateBtn.disabled = true;
|
||||||
|
|
||||||
// 构建测评参数(包含学员信息和配置)
|
// 调用后端API创建会话(和开始答题一样的逻辑)
|
||||||
const assessmentParams = {
|
const response = await fetch('/api/create-session', {
|
||||||
selectedSubject: document.getElementById('subjectFilterSelect').value || '',
|
method: 'POST',
|
||||||
selectedSemester: document.getElementById('gradeFilterSelect').value || '',
|
headers: {
|
||||||
selectedExamType: '',
|
'Content-Type': 'application/json'
|
||||||
selectedUnit: document.getElementById('unitFilterSelect').value || '',
|
},
|
||||||
selectedCategory: '',
|
body: JSON.stringify({
|
||||||
selectedQuestionType: '',
|
name: studentName,
|
||||||
selectedTag: this.selectedTag,
|
school: studentSchool,
|
||||||
selectedTagsList: [],
|
grade: studentGrade,
|
||||||
questionsConfig: this.currentRules,
|
phone: studentPhone,
|
||||||
scoreRange: scoreRange
|
selectedSubject: document.getElementById('subjectFilterSelect').value || '',
|
||||||
};
|
selectedSemester: document.getElementById('gradeFilterSelect').value || '',
|
||||||
|
selectedExamType: '',
|
||||||
// 使用 UTF-8 兼容的 Base64 编码
|
selectedUnit: document.getElementById('unitFilterSelect').value || '',
|
||||||
const encodedParams = this.utf8ToBase64(JSON.stringify(assessmentParams));
|
selectedCategory: '',
|
||||||
|
selectedQuestionType: '',
|
||||||
// 生成测评链接
|
selectedTag: this.selectedTag,
|
||||||
const baseUrl = window.location.origin + window.location.pathname.split('/').slice(0, -1).join('/') + '/survey.html';
|
selectedTagsList: [],
|
||||||
const assessmentLink = `${baseUrl}?assessment=${encodedParams}`;
|
questionsConfig: this.currentRules,
|
||||||
|
scoreRange: scoreRange
|
||||||
// 复制链接到剪贴板
|
})
|
||||||
await navigator.clipboard.writeText(assessmentLink);
|
|
||||||
|
|
||||||
// 显示成功对话框
|
|
||||||
this.showDialog({
|
|
||||||
title: '测评链接生成成功!',
|
|
||||||
content: `<div style="text-align: center; padding: 20px;">
|
|
||||||
<div style="font-size: 48px; margin-bottom: 20px;">🎉</div>
|
|
||||||
<div style="color: #4CAF50; font-size: 18px; font-weight: bold; margin-bottom: 15px;">
|
|
||||||
测评链接已生成并复制到剪贴板!
|
|
||||||
</div>
|
|
||||||
<div style="color: #666; margin-bottom: 20px;">
|
|
||||||
学生信息:${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>
|
|
||||||
${assessmentLink}
|
|
||||||
</div>
|
|
||||||
<div style="color: #999; font-size: 12px; margin-top: 15px;">
|
|
||||||
请将此链接发送给学生,学生点击后即可开始答题
|
|
||||||
</div>
|
|
||||||
</div>`,
|
|
||||||
onConfirm: null,
|
|
||||||
showCancel: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 可选:在控制台输出链接,方便调试
|
if (!response.ok) {
|
||||||
console.log('生成的测评链接:', assessmentLink);
|
throw new Error(`创建会话失败: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
// 生成答题页面链接
|
||||||
|
const assessmentLink = `${window.location.origin}/quiz/${result.sessionId}`;
|
||||||
|
|
||||||
|
// 复制链接到剪贴板
|
||||||
|
await navigator.clipboard.writeText(assessmentLink);
|
||||||
|
// 显示成功对话框
|
||||||
|
this.showDialog({
|
||||||
|
title: '测评链接生成成功!',
|
||||||
|
content: `<div style="text-align: center; padding: 20px;">
|
||||||
|
<div style="font-size: 48px; margin-bottom: 20px;">🎉</div>
|
||||||
|
<div style="color: #4CAF50; font-size: 18px; font-weight: bold; margin-bottom: 15px;">
|
||||||
|
测评链接已生成并复制到剪贴板!
|
||||||
|
</div>
|
||||||
|
<div style="color: #666; margin-bottom: 20px;">
|
||||||
|
学生信息:${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>
|
||||||
|
${assessmentLink}
|
||||||
|
</div>
|
||||||
|
<div style="color: #999; font-size: 12px; margin-top: 15px;">
|
||||||
|
请将此链接发送给学生,学生点击后即可开始答题
|
||||||
|
</div>
|
||||||
|
</div>`,
|
||||||
|
onConfirm: null,
|
||||||
|
showCancel: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// 可选:在控制台输出链接,方便调试
|
||||||
|
console.log('生成的答题链接:', assessmentLink);
|
||||||
|
} else {
|
||||||
|
throw new Error('创建会话失败');
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('生成测评链接失败:', error);
|
console.error('生成测评链接失败:', error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user