消息跳转优化
This commit is contained in:
@@ -9,6 +9,15 @@ const TYPE_TABS = [
|
|||||||
{ key: '2', label: '需求消息' },
|
{ 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({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
tabs: TYPE_TABS,
|
tabs: TYPE_TABS,
|
||||||
@@ -118,13 +127,29 @@ Page({
|
|||||||
|
|
||||||
//弹窗确认:有跳转页面则前往,否则仅关闭
|
//弹窗确认:有跳转页面则前往,否则仅关闭
|
||||||
onDialogConfirm() {
|
onDialogConfirm() {
|
||||||
const jumpPage = this.data.currentMessage?.extra_json?.page || '';
|
const jumpPage = String(this.data.currentMessage?.extra_json?.page || '').replace(/^\//, '');
|
||||||
this.setData({ showTextAndTitle: false });
|
this.setData({ showTextAndTitle: false });
|
||||||
if (jumpPage) {
|
if (!jumpPage) {
|
||||||
wx.navigateTo({
|
return;
|
||||||
url: '/' + String(jumpPage).replace(/^\//, '')
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
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' });
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onPullDownRefresh() {
|
onPullDownRefresh() {
|
||||||
|
|||||||
Reference in New Issue
Block a user