|
@@ -1143,27 +1143,39 @@ export default {
|
|
},
|
|
},
|
|
//匯出所有活動成績至Excel
|
|
//匯出所有活動成績至Excel
|
|
async exportExcel() {
|
|
async exportExcel() {
|
|
- console.log('勾選匯出成績課程名單', this.importSelection);
|
|
|
|
|
|
+ let classSheet = false; //是否生成各班級作答結果分頁 (目前不生成)
|
|
this.$api.htcommunity.findSummaryRecords({ data: this.importSelection })
|
|
this.$api.htcommunity.findSummaryRecords({ data: this.importSelection })
|
|
.then(
|
|
.then(
|
|
(res) => {
|
|
(res) => {
|
|
let scheduleNow = this.propSchedules.find(s => s.id == this.filter.schedule);
|
|
let scheduleNow = this.propSchedules.find(s => s.id == this.filter.schedule);
|
|
let groupNow = this.propGroups.find(g => g.id == this.filter.group);
|
|
let groupNow = this.propGroups.find(g => g.id == this.filter.group);
|
|
let examNow = this.htEvaListShow[this.curEvaIndex];
|
|
let examNow = this.htEvaListShow[this.curEvaIndex];
|
|
|
|
+ let sheetList = []; //分頁名單(分頁名重複防止對策)
|
|
//分頁1 所有班級成績一覽
|
|
//分頁1 所有班級成績一覽
|
|
let navi = [this.$t('htcommunity.eventSchedule') + ':' + scheduleNow.name, this.$t('htcommunity.group') + ':' + groupNow.name, this.$t('htcommunity.eventExam') + ':' + examNow.name, '', '', '', '']
|
|
let navi = [this.$t('htcommunity.eventSchedule') + ':' + scheduleNow.name, this.$t('htcommunity.group') + ':' + groupNow.name, this.$t('htcommunity.eventExam') + ':' + examNow.name, '', '', '', '']
|
|
- let title = [this.$t('htcommunity.schoolName'), this.$t('htcommunity.teacher'), this.$t('htcommunity.class'), this.$t('htcommunity.score'), this.$t('htcommunity.rank')];
|
|
|
|
- let key = ['school', 'creator', 'class', 'score', 'rank'];
|
|
|
|
|
|
+ let title = [this.$t('htcommunity.jointGroup'), this.$t('htcommunity.location'), this.$t('htcommunity.schoolName'), this.$t('htcommunity.teacher'), this.$t('htcommunity.tmid'), this.$t('htcommunity.course'), this.$t('htcommunity.courseGroup'), this.$t('htcommunity.stuNumber'), this.$t('htcommunity.classAverage'), this.$t('htcommunity.classLostRate')];
|
|
|
|
+ let key = ['jointGroupName', 'location', 'school', 'creator', 'creatorId', 'course', 'class', 'stuNum', 'score', 'lostRate'];
|
|
let data = [];
|
|
let data = [];
|
|
res.examClassResults.forEach((item) => {
|
|
res.examClassResults.forEach((item) => {
|
|
let examId = item.examId;
|
|
let examId = item.examId;
|
|
let classId = item.info.id;
|
|
let classId = item.info.id;
|
|
let className = item.info.name;
|
|
let className = item.info.name;
|
|
let groupInfoNow = this.groupListForExport.find(g => g.groupListId == classId);
|
|
let groupInfoNow = this.groupListForExport.find(g => g.groupListId == classId);
|
|
|
|
+ let jointGroupName = groupNow.name;
|
|
let schoolName = groupInfoNow.schoolName;
|
|
let schoolName = groupInfoNow.schoolName;
|
|
|
|
+ let creatorId = groupInfoNow.creatorId;
|
|
let creatorName = groupInfoNow.creatorName;
|
|
let creatorName = groupInfoNow.creatorName;
|
|
- let score = (item.sum.length > 0) ? item.sum.reduce((a, b) => a + b, 0) / item.sum.length : 0;
|
|
|
|
- data.push({ school: schoolName, creator: creatorName, class: className, score: score.toFixed(2), rank: 0 });
|
|
|
|
|
|
+ let countryName = groupInfoNow.countryName;
|
|
|
|
+ let provinceName = groupInfoNow.provinceName;
|
|
|
|
+ let cityName = groupInfoNow.cityName;
|
|
|
|
+ let location = groupInfoNow.location;
|
|
|
|
+ let courseName = groupInfoNow.courseName;
|
|
|
|
+ let stuNum = item.studentIds.length;
|
|
|
|
+ let average = item.average; //平均分數
|
|
|
|
+ let lostStu = item.status.filter((s) => s == 1).length;
|
|
|
|
+ let lostRate = (stuNum > 0) ? (lostStu / stuNum) * 100 : 100; //缺考率
|
|
|
|
+ let score = (item.sum.length > 0) ? item.sum.reduce((a, b) => a + b, 0) / item.sum.length : 0; //總分
|
|
|
|
+ data.push({ jointGroupName: jointGroupName, location: location, school: schoolName, creator: creatorName, creatorId: creatorId, course: courseName, class: className, stuNum: stuNum, score: average.toFixed(2), lostRate: lostRate.toFixed(2) });
|
|
});
|
|
});
|
|
var dataSort = data.sort(function (a, b) { return b.score - a.score; });
|
|
var dataSort = data.sort(function (a, b) { return b.score - a.score; });
|
|
dataSort.forEach((row, rowIndex) => {
|
|
dataSort.forEach((row, rowIndex) => {
|
|
@@ -1175,58 +1187,64 @@ export default {
|
|
let ws = XLSX.utils.aoa_to_sheet(arr);
|
|
let ws = XLSX.utils.aoa_to_sheet(arr);
|
|
ws = excel.export_auto_width(ws, arr);
|
|
ws = excel.export_auto_width(ws, arr);
|
|
let wb = XLSX.utils.book_new();
|
|
let wb = XLSX.utils.book_new();
|
|
- let sheetName = scheduleNow.name + ' ' + this.$t('htcommunity.classScoreOverview');
|
|
|
|
- XLSX.utils.book_append_sheet(wb, ws, sheetName);
|
|
|
|
-
|
|
|
|
- //分頁2~ 各班級學生作答結果
|
|
|
|
- res.examClassResults.forEach((item) => {
|
|
|
|
- let examId = item.examId;
|
|
|
|
- let classId = item.info.id;
|
|
|
|
- let className = item.info.name;
|
|
|
|
- let groupInfoNow = this.groupListForExport.find(g => g.groupListId == classId);
|
|
|
|
- let schoolName = groupInfoNow.schoolName;
|
|
|
|
- let creatorName = groupInfoNow.creatorName;
|
|
|
|
- let naviCls = [this.$t('htcommunity.eventSchedule') + ':' + scheduleNow.name, this.$t('htcommunity.group') + ':' + groupNow.name, this.$t('htcommunity.eventExam') + ':' + examNow.name, this.$t('htcommunity.schoolName') + ':' + schoolName, this.$t('htcommunity.teacher') + ':' + creatorName, this.$t('htcommunity.class') + ':' + className, ''];
|
|
|
|
- let titleCls = [this.$t('htcommunity.student')];
|
|
|
|
- let keyStu = ['stuName'];
|
|
|
|
- for (let i = 0; i < item.studentScores[0].length; i++) {
|
|
|
|
- titleCls.push(this.$t('htcommunity.item') + (i+1));
|
|
|
|
- keyStu.push('item' + i);
|
|
|
|
- }
|
|
|
|
- titleCls.push(this.$t('htcommunity.totalScore'));
|
|
|
|
- titleCls.push(this.$t('htcommunity.rank'));
|
|
|
|
- keyStu.push('total');
|
|
|
|
- keyStu.push('stuRank');
|
|
|
|
- let stus = [];
|
|
|
|
- item.studentIds.forEach((stuid, idx) => {
|
|
|
|
- let stuInfo = res.ufos.find(u => u.id == stuid);
|
|
|
|
- if (typeof stuInfo != "undefined") {
|
|
|
|
- let stuName = stuInfo.name;
|
|
|
|
- let stuScores = item.studentScores[idx]; //該學生各題作答結果
|
|
|
|
- let stusRow = {};
|
|
|
|
- stusRow['stuName'] = stuName;
|
|
|
|
- for (let i = 0; i < stuScores.length; i++) {
|
|
|
|
- let sc = (stuScores[i] >= 0) ? stuScores[i] : 0;
|
|
|
|
- stusRow['item' + i] = sc;
|
|
|
|
- }
|
|
|
|
- stusRow['total'] = item.sum[idx];
|
|
|
|
- stusRow['stuRank'] = 0;
|
|
|
|
- stus.push(stusRow);
|
|
|
|
|
|
+ let sheetName = scheduleNow.name + ' ' + this.$t('htcommunity.classScoreOverview');
|
|
|
|
+ if (!sheetList.includes(sheetName)) {
|
|
|
|
+ sheetList.push(sheetName)
|
|
|
|
+ XLSX.utils.book_append_sheet(wb, ws, sheetName);
|
|
|
|
+ }
|
|
|
|
+ //分頁2~ 各班級學生作答結果
|
|
|
|
+ if (classSheet) {
|
|
|
|
+ res.examClassResults.forEach((item) => {
|
|
|
|
+ let examId = item.examId;
|
|
|
|
+ let classId = item.info.id;
|
|
|
|
+ let className = item.info.name;
|
|
|
|
+ let groupInfoNow = this.groupListForExport.find(g => g.groupListId == classId);
|
|
|
|
+ let schoolName = groupInfoNow.schoolName;
|
|
|
|
+ let creatorName = groupInfoNow.creatorName;
|
|
|
|
+ let naviCls = [this.$t('htcommunity.eventSchedule') + ':' + scheduleNow.name, this.$t('htcommunity.group') + ':' + groupNow.name, this.$t('htcommunity.eventExam') + ':' + examNow.name, this.$t('htcommunity.schoolName') + ':' + schoolName, this.$t('htcommunity.teacher') + ':' + creatorName, this.$t('htcommunity.class') + ':' + className, ''];
|
|
|
|
+ let titleCls = [this.$t('htcommunity.student')];
|
|
|
|
+ let keyStu = ['stuName'];
|
|
|
|
+ for (let i = 0; i < item.studentScores[0].length; i++) {
|
|
|
|
+ titleCls.push(this.$t('htcommunity.item') + (i + 1));
|
|
|
|
+ keyStu.push('item' + i);
|
|
}
|
|
}
|
|
- });
|
|
|
|
- var stusSort = stus.sort(function (a, b) { return b.total - a.total; });
|
|
|
|
- stusSort.forEach((row, rowIndex) => {
|
|
|
|
- stusSort[rowIndex].stuRank = rowIndex + 1;
|
|
|
|
- });
|
|
|
|
- let arrStu = excel.export_json_to_array(keyStu, stusSort);
|
|
|
|
- arrStu.unshift(titleCls);
|
|
|
|
- arrStu.unshift(naviCls);
|
|
|
|
- let wsStu = XLSX.utils.aoa_to_sheet(arrStu);
|
|
|
|
- wsStu = excel.export_auto_width(wsStu, arrStu);
|
|
|
|
- let sheetNameCls = groupNow.name + ' ' + className + '(' + creatorName + ')';
|
|
|
|
- XLSX.utils.book_append_sheet(wb, wsStu, sheetNameCls);
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
|
|
+ titleCls.push(this.$t('htcommunity.totalScore'));
|
|
|
|
+ titleCls.push(this.$t('htcommunity.rank'));
|
|
|
|
+ keyStu.push('total');
|
|
|
|
+ keyStu.push('stuRank');
|
|
|
|
+ let stus = [];
|
|
|
|
+ item.studentIds.forEach((stuid, idx) => {
|
|
|
|
+ let stuInfo = res.ufos.find(u => u.id == stuid);
|
|
|
|
+ if (typeof stuInfo != "undefined") {
|
|
|
|
+ let stuName = stuInfo.name;
|
|
|
|
+ let stuScores = item.studentScores[idx]; //該學生各題作答結果
|
|
|
|
+ let stusRow = {};
|
|
|
|
+ stusRow['stuName'] = stuName;
|
|
|
|
+ for (let i = 0; i < stuScores.length; i++) {
|
|
|
|
+ let sc = (stuScores[i] >= 0) ? stuScores[i] : 0;
|
|
|
|
+ stusRow['item' + i] = sc;
|
|
|
|
+ }
|
|
|
|
+ stusRow['total'] = item.sum[idx];
|
|
|
|
+ stusRow['stuRank'] = 0;
|
|
|
|
+ stus.push(stusRow);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ var stusSort = stus.sort(function (a, b) { return b.total - a.total; });
|
|
|
|
+ stusSort.forEach((row, rowIndex) => {
|
|
|
|
+ stusSort[rowIndex].stuRank = rowIndex + 1;
|
|
|
|
+ });
|
|
|
|
+ let arrStu = excel.export_json_to_array(keyStu, stusSort);
|
|
|
|
+ arrStu.unshift(titleCls);
|
|
|
|
+ arrStu.unshift(naviCls);
|
|
|
|
+ let wsStu = XLSX.utils.aoa_to_sheet(arrStu);
|
|
|
|
+ wsStu = excel.export_auto_width(wsStu, arrStu);
|
|
|
|
+ let sheetNameCls = groupNow.name + ' ' + className + '(' + creatorName + ')';
|
|
|
|
+ if (!sheetList.includes(sheetNameCls)) {
|
|
|
|
+ sheetList.push(sheetNameCls)
|
|
|
|
+ XLSX.utils.book_append_sheet(wb, wsStu, sheetNameCls);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
//檔案做成
|
|
//檔案做成
|
|
let filename = scheduleNow.name + ' ' + examNow.name + ' ' + this.$t('htcommunity.exportScore');
|
|
let filename = scheduleNow.name + ' ' + examNow.name + ' ' + this.$t('htcommunity.exportScore');
|
|
XLSX.writeFile(wb, filename + '.xlsx', {
|
|
XLSX.writeFile(wb, filename + '.xlsx', {
|
|
@@ -1274,6 +1292,9 @@ export default {
|
|
handler(n) {
|
|
handler(n) {
|
|
this.groupListForExport = [];
|
|
this.groupListForExport = [];
|
|
n.stuLists.forEach((s) => {
|
|
n.stuLists.forEach((s) => {
|
|
|
|
+ let countryName = (s.countryName != null) ? s.countryName : "";
|
|
|
|
+ let provinceName = (s.provinceName != null) ? s.provinceName : "";
|
|
|
|
+ let cityName = (s.cityName != null) ? s.cityName : "";
|
|
s.courseLists.forEach((c) => {
|
|
s.courseLists.forEach((c) => {
|
|
c.groupLists.forEach((g) => {
|
|
c.groupLists.forEach((g) => {
|
|
let res = {
|
|
let res = {
|
|
@@ -1287,7 +1308,14 @@ export default {
|
|
examId: (c.examId != null) ? c.examId : '',
|
|
examId: (c.examId != null) ? c.examId : '',
|
|
groupListId: g.id,
|
|
groupListId: g.id,
|
|
groupListName: g.name,
|
|
groupListName: g.name,
|
|
- teacherName: s.creatorName + ' (' + s.schoolName + ')'
|
|
|
|
|
|
+ teacherName: s.creatorName + ' (' + s.schoolName + ')',
|
|
|
|
+ countryId: s.countryId,
|
|
|
|
+ countryName: countryName,
|
|
|
|
+ provinceId: s.provinceId,
|
|
|
|
+ provinceName: provinceName,
|
|
|
|
+ cityId: s.cityId,
|
|
|
|
+ cityName: cityName,
|
|
|
|
+ location: cityName,
|
|
};
|
|
};
|
|
this.groupListForExport.push(res);
|
|
this.groupListForExport.push(res);
|
|
});
|
|
});
|