st-comp 0.0.231 → 0.0.232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "st-comp",
3
3
  "public": true,
4
- "version": "0.0.231",
4
+ "version": "0.0.232",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -33,6 +33,7 @@ import dayjs from "dayjs";
33
33
  import { ref, onMounted, onUnmounted, nextTick, computed } from "vue";
34
34
  import * as echarts from "echarts";
35
35
  import AverageTips from "../AverageTips/index.vue";
36
+ import { formatIndicatorNumber } from "../../utils"
36
37
  import { stMath } from "st-func";
37
38
  const { round } = stMath;
38
39
 
@@ -63,7 +64,7 @@ const subIndicator = computed({
63
64
 
64
65
  const subIndicatorTips = computed(() => {
65
66
  const { data, activeIndex } = props;
66
- return data?.subIndicator?.map((item) => ({ label: item.key, color: item.color, value: item.data[activeIndex] || "-" })) || [];
67
+ return data?.subIndicator?.map((item) => ({ label: item.key, color: item.color, value: `${item.data[activeIndex]}-${formatIndicatorNumber(item.data[activeIndex])}` })) || [];
67
68
  });
68
69
  onMounted(() => {
69
70
  subChart = echarts.init(subChartRef.value);
@@ -9,6 +9,7 @@
9
9
  import { computed, watch, ref } from "vue";
10
10
  import Tips from "../Tips/index.vue";
11
11
  import { stMath } from "st-func";
12
+ import { formatIndicatorNumber } from "../../utils";
12
13
  const { round, formatValue } = stMath;
13
14
 
14
15
  const props = defineProps({
@@ -84,7 +85,7 @@ const mainIndicatorTips = computed(() => {
84
85
  const { data, activeIndex } = props;
85
86
  return (
86
87
  data?.mainIndicator?.map((item) => {
87
- return { label: item.key, value: round(item.data[activeIndex]), color: item.color };
88
+ return { label: item.key, value: formatIndicatorNumber(item.data[activeIndex]), color: item.color };
88
89
  }) || []
89
90
  );
90
91
  });
@@ -222,3 +222,37 @@ export const getWarningLineOptions = (mainChartIns, warningLineData, props, conf
222
222
  ];
223
223
  }, []);
224
224
  };
225
+
226
+ // 格式化指标数据,整数保留两位小数,小数保留两位有效数字 AI生成
227
+ export function formatIndicatorNumber(value) {
228
+ // ----- 辅助函数:转换为有效的有限数字 -----
229
+ function toValidNumber(v) {
230
+ if (typeof v === 'number') {
231
+ return Number.isFinite(v) ? v : null; // 排除 NaN / Infinity
232
+ }
233
+ if (typeof v === 'string') {
234
+ const trimmed = v.trim();
235
+ if (trimmed === '') return null; // 空字符串视为异常
236
+ const num = Number(trimmed);
237
+ return Number.isFinite(num) ? num : null; // 转换后必须为有限数字
238
+ }
239
+ return null; // 其他类型一律异常
240
+ }
241
+ const validNum = toValidNumber(value);
242
+ if (validNum === null) return "-";
243
+
244
+ try {
245
+ if (validNum >= 1 || validNum <= -1) {
246
+ // 整数:保留两位小数
247
+ return round(validNum);
248
+ } else {
249
+ // 非整数:先获得两位有效数字的科学计数法形式
250
+ const precisionStr = validNum.toPrecision(3);
251
+ // 最后一位小数进行四舍五入
252
+ return round(precisionStr, precisionStr.split('.')[1].length - 1)
253
+ }
254
+ } catch (e) {
255
+ // 防御性捕获(理论上不会发生)
256
+ return "-";
257
+ }
258
+ }