fix(自主填报): 修正重提跳转按填报类型、补 wx:key 并清理废弃 API 调用
一、填报记录「重新提交」跳错表单(用户反馈)
records.vue 原先按 activeType(当前 tab)决定跳驻店还是跑店表单,
但列表请求无守卫:切 tab 会连发请求且响应顺序不保证,
旧响应回来会盖掉当前 tab 的数据,导致 tab 与实际数据错位。
此时点「重新提交」会拿 A 表的 id 去打开 B 表的表单
(两表 id 各自从 1 开始,撞号常见,故不报错、只静默进错页面)。
改法:把填报类型钉在记录上,而不是靠 tab 状态猜
- fetchList 拉到数据后给每条记录打 reportType
- 新增 recordType(item):优先取记录自带类型,异常数据回退当前 tab
- 归一化、筛选、卡片标题/副标题、展开详情形态、重新提交跳转全部改走它
- 列表请求加自增 listRequestId 守卫,丢弃过期响应(loading 同理)
二、visit.vue 缺 wx:key 告警
小程序 wx:key 只接受简单属性路径,模板字面量写法
(:key="`store-${idx}`")会被编译器静默丢弃,四处循环因此无 key。
按项目既有 _rowKey 模式改:
- 巡店列表 :key="item._rowKey",新增 buildStoreKey/ensureStoreKeys
(重提与草稿的旧数据无该字段,加载时补齐;提交走显式白名单,不外泄)
- 照片 :key="photo",两个 picker :key="item.id"
三、getSystemInfoSync 废弃告警
该调用在 AppNavbar 的 render(getSafeTop)里,每渲染一次告警一次。
改为挂载时取一次并缓存,优先用新接口 uni.getWindowInfo,
取不到再回退旧接口;select.vue 同源调用一并处理。
注:uview 组件库内部 u-overlay/u-popup 的 mode 传 null 告警
(u-popup 的 position computed 无 else 分支)未改,
uni_modules 已被 gitignore 且会被依赖重装覆盖,属组件库问题。
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
<view class="section-extra">{{ storeList.length }} 家门店</view>
|
||||
</view>
|
||||
<view v-if="!storeList.length" class="audit-empty-tip">暂无巡店记录,请点击下方「新增巡店」</view>
|
||||
<view v-for="(item, idx) in storeList" :key="`store-${idx}`" class="visit-store-card">
|
||||
<view v-for="(item, idx) in storeList" :key="item._rowKey" class="visit-store-card">
|
||||
<view class="visit-store-head">
|
||||
<view>
|
||||
<view class="visit-store-title">巡店{{ idx + 1 }}</view>
|
||||
@@ -70,7 +70,7 @@
|
||||
</view>
|
||||
</view>
|
||||
<view v-else class="photo-grid">
|
||||
<view v-for="(photo, photoIdx) in item.photos" :key="`store-${idx}-photo-${photoIdx}`" class="photo-item">
|
||||
<view v-for="(photo, photoIdx) in item.photos" :key="photo" class="photo-item">
|
||||
<image :src="photo" mode="aspectFill" class="photo-image" @tap="previewStorePhotos(idx, photoIdx)"/>
|
||||
<view class="photo-remove" @tap="removeStorePhoto(idx, photoIdx)">x</view>
|
||||
</view>
|
||||
@@ -117,7 +117,7 @@
|
||||
@change="onChainPickerChange"
|
||||
>
|
||||
<picker-view-column>
|
||||
<view v-for="(item, idx) in merchantChainOptions" :key="`chain-${idx}`" class="merchant-picker-item">
|
||||
<view v-for="(item, idx) in merchantChainOptions" :key="item.id" class="merchant-picker-item">
|
||||
{{ item.text }}
|
||||
</view>
|
||||
</picker-view-column>
|
||||
@@ -148,7 +148,7 @@
|
||||
@change="onMerchantPickerChange"
|
||||
>
|
||||
<picker-view-column>
|
||||
<view v-for="(item, idx) in merchantStoreOptions" :key="`merchant-${idx}`" class="merchant-picker-item">
|
||||
<view v-for="(item, idx) in merchantStoreOptions" :key="item.id" class="merchant-picker-item">
|
||||
{{ item.text }}
|
||||
</view>
|
||||
</picker-view-column>
|
||||
@@ -233,6 +233,8 @@ export default {
|
||||
created() {
|
||||
// 门店明细挂实例上而非 data:data 里的一切都会进页面 data 树并被 setData 序列化。
|
||||
this.merchantStore = []
|
||||
// 巡店项 key 的自增种子,同样放实例上,不必进 data 树
|
||||
this.storeKeySeed = 0
|
||||
},
|
||||
async onLoad(options = {}) {
|
||||
const id = options && options.id !== undefined && options.id !== null ? String(options.id).trim() : ''
|
||||
@@ -523,8 +525,23 @@ export default {
|
||||
},
|
||||
|
||||
// ---------- 巡店列表 ----------
|
||||
// wx:key 需要稳定且互不相同的标识;用自增序号,避免同一份数据里出现重复 key
|
||||
buildStoreKey() {
|
||||
this.storeKeySeed = (this.storeKeySeed || 0) + 1
|
||||
return `store_${this.storeKeySeed}`
|
||||
},
|
||||
// 给数组里缺失 _rowKey 的项补齐(重提加载的旧数据没有该字段)
|
||||
ensureStoreKeys(list) {
|
||||
return (Array.isArray(list) ? list : []).map(item => {
|
||||
if (item && item._rowKey) return item
|
||||
return Object.assign({}, item, {_rowKey: this.buildStoreKey()})
|
||||
})
|
||||
},
|
||||
createStoreItem() {
|
||||
return {
|
||||
// 小程序 wx:key 只认属性名,模板字面量会被编译丢弃;
|
||||
// 该字段同时让增删巡店时的节点复用稳定(删除靠后的项不会让前面的项重建)
|
||||
_rowKey: this.buildStoreKey(),
|
||||
visitTime: this.formatDateTime(new Date()),
|
||||
merchantId: '',
|
||||
merchantName: '',
|
||||
@@ -729,7 +746,7 @@ export default {
|
||||
const nextForm = Object.assign(this.buildForm(), this.cloneValue(draft.form || {}))
|
||||
this.form = nextForm
|
||||
const storeList = Array.isArray(draft.storeList) ? draft.storeList : []
|
||||
this.storeList = storeList.map(item => this.normalizeStoreItem(item))
|
||||
this.storeList = this.ensureStoreKeys(storeList.map(item => this.normalizeStoreItem(item)))
|
||||
this.showChainPicker = false
|
||||
this.showMerchantPicker = false
|
||||
this.activePickerIndex = -1
|
||||
@@ -762,7 +779,7 @@ export default {
|
||||
const summary = this.parseStoredJson(record.summary, record.summary || '')
|
||||
this.form.summary = typeof summary === 'string' ? summary : ''
|
||||
const storeList = this.parseStoredJson(record.storeList, [])
|
||||
this.storeList = (Array.isArray(storeList) ? storeList : []).map(item => this.normalizeStoreItem(item))
|
||||
this.storeList = this.ensureStoreKeys((Array.isArray(storeList) ? storeList : []).map(item => this.normalizeStoreItem(item)))
|
||||
} catch (error) {
|
||||
await this.toast(error && error.message ? error.message : '填报记录加载失败')
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user