发货方式优化及消息功能优化

This commit is contained in:
Dev
2026-10-08 20:34:08 +08:00
parent f21b010ced
commit 7e3e999b74
23 changed files with 371 additions and 455 deletions
+4 -73
View File
@@ -9,15 +9,6 @@ const TYPE_TABS = [
{ key: '2', label: '需求消息' },
];
// tabBar 页面(与 app.json 的 tabBar.list 保持一致):
// navigateTo 无法跳转 tab 页,必须用 switchTab;而 switchTab 不支持带参数
const TAB_PAGES = [
'pages/home/home',
'pages/goods/list/index',
'pages/message/list/index',
'pages/usercenter/index',
];
Page({
data: {
tabs: TYPE_TABS,
@@ -30,10 +21,7 @@ Page({
pageSize: 10,
unreadCount: 0,
hasMore: true,
loading: false,
showTextAndTitle: false,
currentMessage: {},
confirmBtn: '关闭'
loading: false
},
onLoad() {
@@ -94,61 +82,11 @@ Page({
this.loadList(true);
},
showDialog(e) {
// 点击消息进入详情页(关闭交给小程序的返回:左上角/右滑手势/物理返回键)
onMessageTap(e) {
const id = e.currentTarget.dataset.id;
const item = this.data.list.find(msg => msg.id == id);
const jumpPage = item?.extra_json?.page || '';
this.setData({
showTextAndTitle: true,
currentMessage: item || {},
//携带跳转页面时提供「前往查看」
confirmBtn: jumpPage ? '前往查看' : '关闭'
});
messageSetRead({ id: id }).then(() => {
if (!item) {
return;
}
const idx = this.data.list.findIndex(msg => msg.id == id);
if (idx === -1) {
return;
}
//原来未读的消息:本地未读数-1并同步tabbar红点
if (!this.data.list[idx].is_read) {
const typeKey = String(item.message_type);
const unreadMap = { ...this.data.unreadMap };
unreadMap[typeKey] = Math.max(Number(unreadMap[typeKey] || 0) - 1, 0);
const totalUnread = Math.max(this.data.totalUnread - 1, 0);
this.setData({ unreadMap, totalUnread });
this.syncTabBarUnread(totalUnread);
}
this.setData({ [`list[${idx}].is_read`]: 1 });
});
},
//弹窗确认:有跳转页面则前往,否则仅关闭
onDialogConfirm() {
const jumpPage = String(this.data.currentMessage?.extra_json?.page || '').replace(/^\//, '');
this.setData({ showTextAndTitle: false });
if (!jumpPage) {
return;
}
const pathname = jumpPage.split('?')[0];
//tabBar 页只能 switchTab(不支持带参数),其余走 navigateTo
if (TAB_PAGES.indexOf(pathname) !== -1) {
wx.switchTab({
url: '/' + pathname,
fail: () => {
wx.showToast({ title: '页面跳转失败', icon: 'none' });
}
});
return;
}
wx.navigateTo({
url: '/' + jumpPage,
fail: () => {
//页面路径不存在或超出页面栈时降级提示
wx.showToast({ title: '页面跳转失败', icon: 'none' });
}
url: `/pages/message/detail/index?id=${id}`
});
},
@@ -169,13 +107,6 @@ Page({
});
},
onMessageTap(e) {
const { type, id } = e.currentTarget.dataset;
wx.navigateTo({
url: `/pages/message/detail/index?type=${type}&id=${id}`
});
},
onShow() {
this.loadList(true);
},