fix: 完善记录错误状态与缓存失效策略

This commit is contained in:
que01 committed 2026-10-15 13:58:39 +08:00
1 parent 476e3d93dd
commit 8973338c64
13 files changed
+53 -29

No files matched your search

@@ -28,6 +28,7 @@ Page({
data: {
subView: "form",
records: [],
recordsError: "",
// 字段全部来自后台已发布的咨询表单,模板只负责呈现。
fields: [],
values: {},
@@ -76,10 +77,13 @@ Page({
this.loadRecords();
},
loadRecords() {
if (!wx.getStorageSync(customerTokenKey())) return;
if (!wx.getStorageSync(customerTokenKey()))
return this.setData({ records: [], recordsError: "" });
this.setData({ recordsError: "" });
customerRequest("/customer/inquiry-submissions")
.then((items) =>
this.setData({
recordsError: "",
records: (items || []).map((item) => ({
...item,
title: item.inquiryForm?.name || "品牌咨询",
@@ -90,7 +94,9 @@ Page({
})),
}),
)
.catch(() => {});
.catch((error) =>
this.setData({ recordsError: error.message || "记录加载失败,请下拉或稍后重试" }),
);
},
switchView(e) {
this.setData({ subView: e.currentTarget.dataset.view });
@@ -21,7 +21,8 @@
</view>
</block>
<block wx:else>
<view wx:if="{{!records.length}}" class="empty"><text class="empty-icon">▣</text><text class="empty-title">暂无咨询记录</text><text>提交需求后,可以在这里查看处理进度。</text><button bindtap="switchToForm">新建咨询</button></view>
<view wx:if="{{recordsError}}" class="empty"><text class="empty-icon">!</text><text class="empty-title">记录加载失败</text><text>{{recordsError}}</text><button bindtap="loadRecords">重新加载</button></view>
<view wx:elif="{{!records.length}}" class="empty"><text class="empty-icon">▣</text><text class="empty-title">暂无咨询记录</text><text>提交需求后,可以在这里查看处理进度。</text><button bindtap="switchToForm">新建咨询</button></view>
<view wx:else class="history-list">
<view wx:for="{{records}}" wx:key="id" class="history-card">
<view class="history-head"><text class="record-id">单号 #{{item.id}}</text><text class="record-status">{{item.status}}</text></view>
@@ -12,7 +12,7 @@ const statusLabels = {
};
Page({
data: { records: [], loading: false, presentation: {} },
data: { records: [], loading: false, loadError: "", presentation: {} },
onLoad() {
loadWorkspaceWithFallback()
.then((workspace) =>
@@ -21,12 +21,13 @@ Page({
.catch(() => {});
},
onShow() {
if (!wx.getStorageSync(customerTokenKey())) return this.setData({ records: [] });
this.setData({ loading: true });
if (!wx.getStorageSync(customerTokenKey())) return this.setData({ records: [], loadError: "" });
this.setData({ loading: true, loadError: "" });
customerRequest("/customer/inquiry-submissions")
.then((items) =>
this.setData({
loading: false,
loadError: "",
records: items.map((item) => ({
...item,
type: item.inquiryForm?.name || "品牌咨询",
@@ -42,8 +43,7 @@ Page({
}),
)
.catch((error) => {
this.setData({ loading: false });
wx.showToast({ title: error.message || "记录加载失败", icon: "none" });
this.setData({ loading: false, loadError: error.message || "记录加载失败" });
});
},
inquire() {
@@ -1 +1 @@
<view class="page food-records"><view class="head"><view><text class="eyebrow">我的预订</text><text class="title">{{presentation.title || '我的预订记录'}}</text></view><button bindtap="inquire">{{presentation.createAction || '新增预订'}}</button></view><records-module records="{{records}}" presentation="{{presentation}}" bind:create="inquire" /></view>
<view class="page food-records"><view class="head"><view><text class="eyebrow">我的预订</text><text class="title">{{presentation.title || '我的预订记录'}}</text></view><button bindtap="inquire">{{presentation.createAction || '新增预订'}}</button></view><records-module records="{{records}}" load-error="{{loadError}}" presentation="{{presentation}}" bind:create="inquire" /></view>
@@ -2,7 +2,7 @@ const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
const { customerRequest, customerTokenKey } = require("../../utils/request");
Page({
data: { brand: {}, records: [], error: "" },
data: { brand: {}, records: [], error: "", recordsError: "" },
onLoad() {
loadWorkspaceWithFallback()
.then((workspace) =>
@@ -17,10 +17,15 @@ Page({
this.loadRecords();
},
loadRecords() {
if (!wx.getStorageSync(customerTokenKey())) return this.setData({ records: [] });
if (!wx.getStorageSync(customerTokenKey()))
return this.setData({ records: [], recordsError: "" });
customerRequest("/customer/inquiry-submissions")
.then((records) => this.setData({ records: Array.isArray(records) ? records : [] }))
.catch(() => this.setData({ records: [] }));
.then((records) =>
this.setData({ records: Array.isArray(records) ? records : [], recordsError: "" }),
)
.catch((error) =>
this.setData({ recordsError: error.message || "记录加载失败,请稍后重试" }),
);
},
call() {
wx.makePhoneCall({
@@ -1,4 +1,5 @@
<view class="page">
<view wx:if="{{error}}" class="runtime-error">{{error}}</view>
<view wx:if="{{recordsError}}" class="runtime-error">{{recordsError}}</view>
<view wx:elif="{{error}}" class="runtime-error">{{error}}</view>
<linjing-profile wx:else brand="{{brand}}" trust-items="{{trustItems}}" presentation="{{brand.visualPresentation.profile}}" records-count="{{records.length}}" bind:call="call" bind:copy="copyWechat" bind:records="recordsPage" />
</view>