WXL (wul)
5 天以前 a99e82da2b087d7019cdce015c25befc620b9d61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 满意度问题详情工具:接口返回可能是数组,也可能是以 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 ? "单选题" : "多选题";
}