Commit 32e40361 by liimin

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

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