Commit 77feff42 by Lin

feat(equity): 添加模块索引同步功能并优化接待中心列表监控

- 在权益详情页中新增根据 ID 同步 currentModuleIndex 的功能
- 在接待中心列表中添加 watch 监控 currentDisplayList 的变化,输出调试信息
- 引入 watch 函数以增强列表变化的响应性
- 优化接待列表的时间解析逻辑,确保时间戳处理一致性
1 parent 9492412c
...@@ -294,6 +294,17 @@ function ensurePageToolList(): void { ...@@ -294,6 +294,17 @@ function ensurePageToolList(): void {
} }
} }
/** 根据 id 同步 currentModuleIndex(须定义在 watch(id) 之前,UTS 无函数声明提升) */
function syncModuleIndex(): void {
const list = moduleList.value;
for (let i = 0; i < list.length; i++) {
if ((list[i] as UTSJSONObject).id == id.value) {
currentModuleIndex.value = i;
return;
}
}
}
/** shukeRequest 返回体中的列表数组(与 `useBoutiqueLogic` / simgle 容错一致) */ /** shukeRequest 返回体中的列表数组(与 `useBoutiqueLogic` / simgle 容错一致) */
function readShukeDataArray(res: any | null): any[] { function readShukeDataArray(res: any | null): any[] {
if (res == null) { if (res == null) {
...@@ -569,21 +580,9 @@ watch(watchStatus, () => { ...@@ -569,21 +580,9 @@ watch(watchStatus, () => {
watch(id, () => { watch(id, () => {
ensurePageToolList(); ensurePageToolList();
// ✅ 性能优化:同步更新当前模块索引
syncModuleIndex(); syncModuleIndex();
}, { immediate: true }); }, { immediate: true });
/** ✅ 性能优化:根据 id 同步 currentModuleIndex */
function syncModuleIndex(): void {
const list = moduleList.value;
for (let i = 0; i < list.length; i++) {
if ((list[i] as UTSJSONObject).id == id.value) {
currentModuleIndex.value = i;
return;
}
}
}
watch(moduleList, (list: Array<any>) => { watch(moduleList, (list: Array<any>) => {
ensurePageToolList(); ensurePageToolList();
}, { deep: true, immediate: true }); }, { deep: true, immediate: true });
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { computed } from 'vue' import { computed, watch } from 'vue'
import { getStr } from '../types/reception-center-helpers.uts' import { getStr } from '../types/reception-center-helpers.uts'
import { textOrDash, formatPhone, isBlankDisplayText } from '@/utils/format-utils.uts' import { textOrDash, formatPhone, isBlankDisplayText } from '@/utils/format-utils.uts'
import { getCustomerPhone, formatReceptionDateTime, getDurationStr, getReceptionResultBadgeBgClass, getReceptionResultBadgeTextClass } from './reception-list-helpers.uts' import { getCustomerPhone, formatReceptionDateTime, getDurationStr, getReceptionResultBadgeBgClass, getReceptionResultBadgeTextClass } from './reception-list-helpers.uts'
...@@ -151,6 +151,21 @@ const currentDisplayList = computed((): UTSJSONObject[] => { ...@@ -151,6 +151,21 @@ const currentDisplayList = computed((): UTSJSONObject[] => {
return props.receptionRecordList return props.receptionRecordList
}) })
/** 调试:列表变化时打印 currentDisplayList(控制台 / HBuilderX 运行日志) */
watch(
(): UTSJSONObject[] => currentDisplayList.value,
(list: UTSJSONObject[]): void => {
if (list == null) {
console.log('[ListReception] currentDisplayList: null')
return
}
const n = list.length
console.log('[ListReception] currentDisplayList length=', n)
console.log('[ListReception] currentDisplayList JSON=', JSON.stringify(list))
},
{ immediate: true, deep: true }
)
/** ✅ 性能优化:判断是否应该显示骨架屏 */ /** ✅ 性能优化:判断是否应该显示骨架屏 */
const shouldShowSkeleton = computed(() => { const shouldShowSkeleton = computed(() => {
// ✅ 优先检查强制显示标志(用于横竖屏切换、Tab 切换等场景) // ✅ 优先检查强制显示标志(用于横竖屏切换、Tab 切换等场景)
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import { get } from '@/utils/common.uts' import { get } from '@/utils/common.uts'
import { isBlankDisplayText, formatDateTimeLike } from '@/utils/format-utils.uts' import { isBlankDisplayText, formatDateTimeLike } from '@/utils/format-utils.uts'
import { getStr, getTs } from '../types/reception-center-helpers.uts' import { getStr, getTs } from '../types/reception-center-helpers.uts'
import { parseIntValue, parseNumberValue } from '../receptionDetail.helper.uts'
/** /**
* 解析到店日期字段为时间戳 * 解析到店日期字段为时间戳
...@@ -98,6 +99,75 @@ export function formatReceptionDateTime(item: UTSJSONObject, kind: 'start' | 'en ...@@ -98,6 +99,75 @@ export function formatReceptionDateTime(item: UTSJSONObject, kind: 'start' | 'en
} }
/** /**
* 解析 YYYY-MM-DD HH:mm:ss(或纯数字时间戳字符串),与接待详情页逻辑一致
*/
function parseReceptionDateTimeMs(raw: string): number | null {
const s = raw.trim()
if (s == '') {
return null
}
const parts = s.split(' ')
if (parts.length < 2) {
const n = parseNumberValue(s)
if (n != null && n > 0) {
return n
}
return null
}
const ymd = parts[0].split('-')
const hms = parts[1].split(':')
if (ymd.length != 3 || hms.length < 2) {
const n = parseNumberValue(s)
if (n != null && n > 0) {
return n
}
return null
}
const y = parseIntValue(ymd[0])
const mo = parseIntValue(ymd[1])
const d = parseIntValue(ymd[2])
const h = parseIntValue(hms[0])
const min = parseIntValue(hms[1])
const sec = hms.length >= 3 ? parseIntValue(hms[2]) : 0
if (y == null || mo == null || d == null || h == null || min == null) {
return null
}
const ss = sec != null ? sec : 0
return new Date(y, mo - 1, d, h, min, ss).getTime()
}
/**
* 将起止字段解析为毫秒时间戳;优先 primary(startTime/endTime),再 fallback(receptionStartTime/receptionEndTime)
*/
function resolveReceptionBoundaryMs(item: UTSJSONObject, primaryKey: string, fallbackKey: string): number | null {
const tryRaw = (raw: any | null): number | null => {
if (raw == null) {
return null
}
if (typeof raw == 'number') {
if (raw > 0) {
return raw
}
return null
}
const str = `${raw}`.trim()
if (str == '' || isBlankDisplayText(str)) {
return null
}
return parseReceptionDateTimeMs(str)
}
let ms = tryRaw(get(item, primaryKey))
if (ms != null && ms > 0) {
return ms
}
ms = tryRaw(get(item, fallbackKey))
if (ms != null && ms > 0) {
return ms
}
return null
}
/**
* 格式化接待时长字符串 * 格式化接待时长字符串
*/ */
export function getDurationStr(item: UTSJSONObject): string { export function getDurationStr(item: UTSJSONObject): string {
...@@ -107,17 +177,27 @@ export function getDurationStr(item: UTSJSONObject): string { ...@@ -107,17 +177,27 @@ export function getDurationStr(item: UTSJSONObject): string {
} }
// 兼容后端仅给 duration(秒) // 兼容后端仅给 duration(秒)
const secAny = item['duration'] const secAny = item['duration']
if (secAny == null) { if (secAny != null) {
return ''
}
const secNum = typeof secAny == 'number' ? secAny : parseFloat(`${secAny}`) const secNum = typeof secAny == 'number' ? secAny : parseFloat(`${secAny}`)
if (isNaN(secNum) || secNum < 0) { if (!isNaN(secNum) && secNum >= 0) {
return ''
}
const diffSec = Math.floor(secNum) const diffSec = Math.floor(secNum)
const min = Math.floor(diffSec / 60) const min = Math.floor(diffSec / 60)
const sec = diffSec % 60 const sec = diffSec % 60
return `${min}分${sec}秒` return `${min}分${sec}秒`
}
}
// 无 duration 时:用开始/结束时间推算(与 formatReceptionDateTime 字段优先级一致)
const startMs = resolveReceptionBoundaryMs(item, 'startTime', 'receptionStartTime')
const endMs = resolveReceptionBoundaryMs(item, 'endTime', 'receptionEndTime')
if (startMs != null && endMs != null && startMs > 0 && endMs > 0) {
const diffSec = Math.floor((endMs - startMs) / 1000)
if (diffSec >= 0) {
const min = Math.floor(diffSec / 60)
const sec = diffSec % 60
return `${min}分${sec}秒`
}
}
return ''
} }
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!