// 满意度问题详情工具:接口返回可能是数组,也可能是以 scriptid 为 key 的对象 export function normalizeTopicList(data) { if (!data) return []; const list = Array.isArray(data) ? data : Object.values(data); return list .filter((topic) => topic && topic.scriptContent) .map((topic) => ({ ...topic, details: (Array.isArray(topic.details) ? topic.details : []).filter( (detail) => detail && detail.optionText ), })); } export function hasPercentage(value) { return value !== null && value !== undefined && value !== ""; } // 后端比例通常是 0~1 的小数,这里兼容直接返回 0~100 的情况 export function percentageOf(value) { if (!hasPercentage(value)) return 0; const num = Number(value); if (!isFinite(num)) return 0; return num > 0 && num <= 1 ? num * 100 : num; } export function formatPercentage(value) { if (!hasPercentage(value)) return "-"; return `${percentageOf(value).toFixed(2)}%`; } export function topicTypeLabel(topic) { return topic && topic.scriptType == 1 ? "单选题" : "多选题"; }