Commit 32e40361 by liimin

fix(ReceptionCenter): 修复记录列表响应式问题并优化代码结构

重构 RecordList.vue 组件,解决 Vue2 响应式更新问题,使用 $set 确保数组更新触发视图渲染
优化代码结构,将网络请求和数据处理逻辑拆分为独立方法
修复日志级别从 info 改为 warn 以更好标识异常记录恢复
1 parent 082f121d
......@@ -5,7 +5,7 @@
<view class="tabs">
<page-tabs :list="tabList" @changeTab="changeTab" />
</view>
<!-- 次级筛选区域容器 -->
<view class="filter-container">
<view class="select-box-list select-component flex">
......@@ -21,11 +21,10 @@
</view>
<template v-if="tabIndex == 1">
<view class="filter-group">
<button-group class="select-component" :selectList="uploadTypeList" @chooseType="changeUploadType" />
<button-group class="select-component" :selectList="uploadTypeList" @chooseType="changeUploadType" />
</view>
</template>
</view>
</view>
<scroll-view class="record-list" scroll-y @scrolltolower="pageonReachBottom">
<view class="record-tips flex" v-if="tabIndex == 1 && isPrePage && list.length && list[0] && list[0].length">
......@@ -280,51 +279,51 @@ export default {
let recordFailListAll = await uni.$dbRecord.getRecords();
this.recordFailList = recordFailListAll.reverse();
},
async getPreRecordFail () {
await this.getPreRecordNum()
this.list[0] = this.preRecordFailList.reverse().map(i => {
return Object.assign(i, {
duration: 0,
})
})
this.isPrePage = true
this.flag = true
this.nothing = !!this.preRecordFailList.length
},
async getPreRecordNum () {
if (!this.recorder) {
this.recorder = this.getRecorder()
}
if (!this.recorder) return
const preRecordList = await this.recorder.getRecords()
this.preRecordFailList =this.formatRecordList(preRecordList)
//[{
// result: '',
// customerPhone: '',
// customerType: 'VIP',
// customerName: '',
// carType: '',
// startTime: '',
// endTime: '' }]
this.preRecordFailList = this.formatRecordList(preRecordList || [])
},
formatRecordList(list) {
if (!list) return []
list.forEach(record => {
// return {
// result: record.result,
// customerPhone: record.customerPhone,
// customerType: record.customerType,
// customerName: record.customerName || '未填写姓名',
// carType: record.carType || '未选择车型',
record.duration=this.formatSeconds(new Date(record.endTime).getTime() - new Date(record.startTime).getTime())
// startTime: record.startTime,
// endTime: record.endTime
// }
let duration = ''
if (record.startTime && record.endTime) {
const startTime = new Date(record.startTime).getTime()
const endTime = new Date(record.endTime).getTime()
duration = this.formatSeconds(endTime - startTime)
}
record.duration = duration
})
return list
},
getRecordFail () {
this.getRecordNum()
this.list[0] = this.formatRecordList(this.recordFailList)
async getRecordFail () {
await this.getRecordNum()
// 修复 Vue2 响应式问题:直接通过索引赋值无法触发视图更新
this.$set(this.list, 0, this.formatRecordList(this.recordFailList))
this.flag = true
this.isPrePage = false
this.nothing = !!this.recordFailList.length
},
async getPreRecordFail () {
await this.getPreRecordNum()
// 这里的 preRecordFailList 是一个数组,我们需要创建一个新数组来触发 reverse,避免修改原数组(虽然这里修改原数组也没大碍)
// 关键:确保 formattedList 是一个数组
const formattedList = [...this.preRecordFailList].reverse()
// 修复 Vue2 响应式问题
// 确保 list[0] 被正确设置
this.$set(this.list, 0, formattedList)
this.isPrePage = true
this.flag = true
// 使用 formattedList.length 来判断,更准确
this.nothing = !formattedList.length
},
init () {
this.getReceptionList()
this.recorder = this.getRecorder()
......@@ -334,39 +333,14 @@ export default {
try {
await uni.$isNetWork()
} catch (error) {
const cache = JSON.parse(uni.$storage.get("recordSuccessList") || "{}")
this.$set(this.list, 0, cache[this.tabIndex] || [])
this.flag = true
this.loadCacheData()
return
}
// 2. 请求数据
uni.showLoading({ mask: true })
try {
const { tabIndex, pageNum, pageSize, reviewFlag, orderFinishFlag } = this
// const { shopMerchantId, sceneType } = uni.$storage.get("userInfo") || {}
const { records = [], total = 0 } = await uni.$api.reception.getList({
// merchantId: shopMerchantId,
pageNum,
pageSize,
reviewFlag,
result:orderFinishFlag===1?'完成':'未完成',
// bussinessType: sceneType == 0 ? 1 : 2,
})||{}
// 3. 数据处理
records.reverse().forEach(e => {
e.duration = e.durationStr || this.formatSeconds(new Date(e.endTime).getTime() - new Date(e.startTime).getTime())
e.orderFinishFlag = e.result === '完成'?1:0
})
// 4. 更新缓存 (仅第一页)
if (pageNum === 1) {
const cache = JSON.parse(uni.$storage.get("recordSuccessList") || "{}")
cache[tabIndex] = records
uni.$storage.set("recordSuccessList", JSON.stringify(cache))
}
// 5. 更新视图
this.$set(this.list, pageNum - 1, records)
this.total = total
await this.fetchNetworkData()
} catch (error) {
console.error('Fetch reception list failed:', error)
} finally {
......@@ -374,15 +348,43 @@ export default {
uni.hideLoading()
}
},
formatTime (num) {
let minutes = Math.floor(num / 60) || '0',
seconds = num % 60 || '0'
seconds = seconds < 10 ? `0${seconds}` : seconds
return {
minutes,
seconds
loadCacheData() {
const cache = JSON.parse(uni.$storage.get("recordSuccessList") || "{}")
this.$set(this.list, 0, cache[this.tabIndex] || [])
this.flag = true
},
async fetchNetworkData() {
const { tabIndex, pageNum, pageSize, reviewFlag, orderFinishFlag } = this
// const { shopMerchantId, sceneType } = uni.$storage.get("userInfo") || {}
const { records = [], total = 0 } = await uni.$api.reception.getList({
// merchantId: shopMerchantId,
pageNum,
pageSize,
reviewFlag,
result: orderFinishFlag === 1 ? '完成' : '未完成',
// bussinessType: sceneType == 0 ? 1 : 2,
}) || {}
// 3. 数据处理
records.reverse().forEach(e => {
e.duration = e.durationStr || this.formatSeconds(new Date(e.endTime).getTime() - new Date(e.startTime).getTime())
e.orderFinishFlag = e.result === '完成' ? 1 : 0
})
// 4. 更新缓存 (仅第一页)
if (pageNum === 1) {
const cache = JSON.parse(uni.$storage.get("recordSuccessList") || "{}")
cache[tabIndex] = records
uni.$storage.set("recordSuccessList", JSON.stringify(cache))
}
// 5. 更新视图
this.$set(this.list, pageNum - 1, records)
this.total = total
},
formatSeconds (seconds) {
seconds = Math.floor(seconds / 1000)
let formattedTime = ''
......@@ -453,20 +455,20 @@ export default {
flex-shrink: 0;
z-index: 10; /* 确保投影覆盖在列表之上 */
position: relative;
/* 新增设计样式 */
// background: #ffffff;
border-radius: toRpx(24);
padding: toRpx(24) toRpx(32);
box-shadow: 0 toRpx(4) toRpx(16) rgba(0, 0, 0, 0.04); /* 减轻投影 */
border: 1px solid #f5f6f8;
.tabs {
flex-shrink: 0;
width: toRpx(336); /* 恢复固定宽度,防止被挤压 */
height: toRpx(84);
}
.filter-container {
display: flex;
align-items: center;
......@@ -489,7 +491,7 @@ export default {
}
.select-component {
margin-left: 0;
margin-left: 0;
}
}
}
......@@ -502,7 +504,7 @@ export default {
position: relative;
z-index: 4;
padding-bottom: toRpx(20); /* 在滚动容器层级增加底部内边距 */
.record-tips {
height: toRpx(76);
background: #f58e341a;
......
......@@ -4,7 +4,7 @@
* @Author: limin
* @Date: 2025-01-02 18:49:17
* @LastEditors: limin
* @LastEditTime: 2025-12-30 18:24:02
* @LastEditTime: 2025-12-30 19:14:28
* @FilePath: \simgle_app\utils\recordManager\TempRecord.js
*/
import utils from '../utils'
......@@ -106,7 +106,7 @@ class TempRecord {
async recoverRecord(record) {
if (!record) return
uni.$logger.local.info('〖接待记录Record〗 == 开始恢复异常记录 ==' + record.id)
uni.$logger.local.warn('〖接待记录Record〗 == 开始恢复异常记录 ==' + record.id)
// 复用 save 逻辑进行持久化
// 专门的入口有利于后续扩展,比如在这里添加恢复失败的特殊重试机制
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!