fix: 完善记录错误状态与缓存失效策略
This commit is contained in:
1 parent
476e3d93dd
commit
8973338c64
13 files changed
+53
-29
No files matched your search
@@ -66,9 +66,8 @@ export function ImageUrlField({ id, value, onChange, placeholder, scope }: Image
|
||||
});
|
||||
if (!response.ok) throw new Error(`upload failed: ${response.status}`);
|
||||
onChange?.(presign.publicUrl);
|
||||
} catch {
|
||||
setStorageStatus("unavailable");
|
||||
message.error("图片上传失败,请检查对象存储后重试");
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "图片上传失败,请重试");
|
||||
} finally {
|
||||
setUploading(false);
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("小程序代码已上传");
|
||||
void miniAppReleases.refetch();
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-miniapp-releases"] });
|
||||
},
|
||||
});
|
||||
const saveMiniAppSettings = useMutation({
|
||||
@@ -208,14 +208,14 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("小程序上传配置已保存");
|
||||
void miniAppSettings.refetch();
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-miniapp-settings"] });
|
||||
},
|
||||
});
|
||||
const uploadMiniAppRelease = useMutation({
|
||||
mutationFn: (id: string) => client.uploadAdminMiniAppRelease(id),
|
||||
onSuccess: () => {
|
||||
message.success("小程序代码已上传");
|
||||
void miniAppReleases.refetch();
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-miniapp-releases"] });
|
||||
},
|
||||
});
|
||||
const updateMiniAppStatus = useMutation({
|
||||
@@ -228,7 +228,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
}) => client.updateAdminMiniAppReleaseStatus(id, { status }),
|
||||
onSuccess: () => {
|
||||
message.success("小程序发布状态已更新");
|
||||
void miniAppReleases.refetch();
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-miniapp-releases"] });
|
||||
},
|
||||
});
|
||||
const loading = [
|
||||
|
||||
+12
-1
@@ -78,7 +78,18 @@ const FeaturePublicationPage = React.lazy(() =>
|
||||
import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
|
||||
import "antd/dist/reset.css";
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 30_000,
|
||||
retry: 2,
|
||||
refetchOnWindowFocus: false,
|
||||
},
|
||||
mutations: {
|
||||
retry: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
const api = createApiClient;
|
||||
|
||||
function Login({
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
Component({
|
||||
properties: {
|
||||
records: { type: Array, value: [] },
|
||||
loadError: { type: String, value: "" },
|
||||
presentation: { type: Object, value: {} },
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -1 +1 @@
|
||||
<view class="records"><view wx:if="{{!records.length}}" class="empty"><text class="empty-title">{{presentation.emptyTitle}}</text><text>{{presentation.emptyDescription}}</text><button bindtap="create">{{presentation.emptyAction}}</button></view><view wx:else><view class="record" wx:for="{{records}}" wx:key="id"><view class="record-head"><text>{{item.type}}</text><text class="status">{{item.status}}</text></view><text class="project">{{item.project}} · {{item.offeringName}}</text><text class="meta">档案编号 {{item.id}} {{item.createdAt}}</text><view wx:if="{{item.timeline.length}}" class="timeline"><view wx:for="{{item.timeline}}" wx:key="createdAt" class="timeline-item"><text class="timeline-dot">●</text><text>{{item.status}} · {{item.createdAt}}</text></view></view></view></view></view>
|
||||
<view class="records"><view wx:if="{{loadError}}" class="empty"><text class="empty-title">记录加载失败</text><text>{{loadError}}</text></view><view wx:elif="{{!records.length}}" class="empty"><text class="empty-title">{{presentation.emptyTitle}}</text><text>{{presentation.emptyDescription}}</text><button bindtap="create">{{presentation.emptyAction}}</button></view><view wx:else><view class="record" wx:for="{{records}}" wx:key="id"><view class="record-head"><text>{{item.type}}</text><text class="status">{{item.status}}</text></view><text class="project">{{item.project}} · {{item.offeringName}}</text><text class="meta">档案编号 {{item.id}} {{item.createdAt}}</text><view wx:if="{{item.timeline.length}}" class="timeline"><view wx:for="{{item.timeline}}" wx:key="createdAt" class="timeline-item"><text class="timeline-dot">●</text><text>{{item.status}} · {{item.createdAt}}</text></view></view></view></view></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"><view class="head"><text class="title">{{presentation.title}}</text><button bindtap="inquire">{{presentation.createAction}}</button></view><records-module records="{{records}}" presentation="{{presentation}}" bind:create="inquire" /></view>
|
||||
<view class="page"><view class="head"><text class="title">{{presentation.title}}</text><button bindtap="inquire">{{presentation.createAction}}</button></view><records-module records="{{records}}" load-error="{{loadError}}" presentation="{{presentation}}" bind:create="inquire" /></view>
|
||||
@@ -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>
|
||||
Reference in new issue
Block a user