Commit 5ef4f38b by Lin

refactor(receptionCenter): 引入安全获取工具函数以优化数据处理

1 parent 56aca0f5
...@@ -46,6 +46,7 @@ import { computed, nextTick, ref } from 'vue' ...@@ -46,6 +46,7 @@ import { computed, nextTick, ref } from 'vue'
import CardFlow from '../cards/CardFlow.uvue' import CardFlow from '../cards/CardFlow.uvue'
import CardTimeBoard from '../cards/CardTimeBoard.uvue' import CardTimeBoard from '../cards/CardTimeBoard.uvue'
import { useOrientation } from '@/services/adapter/hooks/index.uts' import { useOrientation } from '@/services/adapter/hooks/index.uts'
import { get } from '@/utils/common.uts'
/** ✅ 工具函数:格式化日期为 YYYY-MM-DD */ /** ✅ 工具函数:格式化日期为 YYYY-MM-DD */
function formatYmd(date: Date): string { function formatYmd(date: Date): string {
...@@ -83,9 +84,9 @@ const props = defineProps<{ ...@@ -83,9 +84,9 @@ const props = defineProps<{
allReceptionRecords?: UTSJSONObject[] | null allReceptionRecords?: UTSJSONObject[] | null
}>() }>()
/** ✅ 工具函数:安全获取数字 */ /** ✅ 工具函数:安全获取数字(禁止 obj[key] as any:Android 上 null 会触发 NPE cast to kotlin.Any) */
function getNum(obj: UTSJSONObject, key: string): number { function getNum(obj: UTSJSONObject, key: string): number {
const v = obj[key] as any const v = get(obj, key, null)
if (v == null) return 0 if (v == null) return 0
const n = typeof v == "number" ? v : parseFloat(`${v}`) const n = typeof v == "number" ? v : parseFloat(`${v}`)
return isNaN(n) ? 0 : n return isNaN(n) ? 0 : n
...@@ -185,9 +186,9 @@ function calcTimeBoardData(records: UTSJSONObject[] | null): UTSJSONObject { ...@@ -185,9 +186,9 @@ function calcTimeBoardData(records: UTSJSONObject[] | null): UTSJSONObject {
// today:今日接待数/时长 // today:今日接待数/时长
if (receptionDate == todayStr) { if (receptionDate == todayStr) {
todayCount = todayCount + 1 todayCount = todayCount + 1
const durRaw = item["duration"] as any // 避免 item["duration"] as any:UTS 转 Kotlin 时动态下标 + any 易解析异常,统一走 getNum
const durNum = durRaw != null ? parseFloat(`${durRaw}`) : 0 const durNum = getNum(item, "duration")
const durSec = (typeof durNum == "number" && isNaN(durNum) != true && durNum > 0) ? Math.floor(durNum) : 0 const durSec = durNum > 0 ? Math.floor(durNum) : 0
todayTotalSeconds = todayTotalSeconds + durSec todayTotalSeconds = todayTotalSeconds + durSec
} }
j = j + 1 j = j + 1
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!