| | |
| | | if (!den) return '0.00'; |
| | | return (num / den).toFixed(2); |
| | | }, |
| | | // 综合得分展示:直接使用后端 avgScore,格式化为两位小数 |
| | | formatScore(val) { |
| | | const n = Number(val); |
| | | return isNaN(n) ? '0.00' : n.toFixed(2); |
| | | }, |
| | | // 解析比例字符串:"14.29%"、"0"、"0.5" → 数值(百分比);无效返回 null |
| | | parsePercent(value) { |
| | | if (value == null || value === '') return null; |
| | |
| | | const arr = Array.isArray(list) ? list : (list && (list.list || list.rows)) || []; |
| | | const options = []; |
| | | let total = 0; |
| | | let avgScore = null; |
| | | arr.forEach((item) => { |
| | | // 综合得分:后端返回的题目级 avgScore(与题目同级) |
| | | if (avgScore == null) { |
| | | const rawAvg = Number(item && item.avgScore); |
| | | if (!isNaN(rawAvg)) avgScore = rawAvg; |
| | | } |
| | | const details = Array.isArray(item && item.subtaskDetailRatioExportList) |
| | | ? item.subtaskDetailRatioExportList |
| | | : []; |
| | |
| | | total += count; |
| | | }); |
| | | }); |
| | | return { options, total }; |
| | | return { options, total, avgScore }; |
| | | }, |
| | | // 单题选项统计(真实接口 /smartor/serviceSubtaskDetail/sltdMydTotalByScore) |
| | | async fetchSingleQuestion() { |
| | |
| | | const res = await sltdMydTotalByScore(payload); |
| | | console.log('[sltdMydTotalByScore 单题] code=', res && res.code, 'data=', JSON.stringify(res && res.data).slice(0, 1500)); |
| | | const list = res && res.code === 200 ? res.data : []; |
| | | const { options, total } = this.normalizeSingleQuestion(list); |
| | | const { options, total, avgScore } = this.normalizeSingleQuestion(list); |
| | | this.singleQuestionData = options.map((o) => ({ |
| | | option: o.option, |
| | | count: o.count, |
| | |
| | | })); |
| | | this.singleQuestionMeta = { |
| | | total: total.toLocaleString(), |
| | | score: this.scoreOfOptions(options), |
| | | score: this.formatScore(avgScore), |
| | | }; |
| | | if (!options.length) this.notify('当前条件下暂无该题的选项统计数据', 'warning'); |
| | | } catch (e) { |