From 44182d011dd1f53c5bd873837cbff7aed200f135 Mon Sep 17 00:00:00 2001 From: R524809 Date: Thu, 30 Apr 2026 17:19:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E9=A1=B5=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=9B=B4=E5=A4=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/pages/home/home.json | 3 ++- miniprogram/pages/home/home.less | 14 +++++++------ miniprogram/pages/home/home.ts | 22 +++++++++++++++----- miniprogram/pages/home/home.wxml | 5 +++-- miniprogram/utils/index.ts | 35 ++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 14 deletions(-) diff --git a/miniprogram/pages/home/home.json b/miniprogram/pages/home/home.json index b8a6143..6981b3a 100644 --- a/miniprogram/pages/home/home.json +++ b/miniprogram/pages/home/home.json @@ -8,6 +8,7 @@ "usingComponents": { "nav-bar": "/components3.0/nav-bar/nav-bar", "category-tabs": "/components3.0/category-tabs/category-tabs", - "van-icon": "@vant/weapp/icon/index" + "van-icon": "@vant/weapp/icon/index", + "toy-icon": "../../toy/icon/icon" } } diff --git a/miniprogram/pages/home/home.less b/miniprogram/pages/home/home.less index 66ad936..da8d9c6 100644 --- a/miniprogram/pages/home/home.less +++ b/miniprogram/pages/home/home.less @@ -164,7 +164,7 @@ } .home-section-panel { - margin-top: @section-gap; + margin-top: 48rpx; box-sizing: border-box; } @@ -192,7 +192,7 @@ } .home-track-scroll { - margin-top: @section-gap-sm; + margin-top: 16rpx; width: 100%; white-space: nowrap; // padding: 16rpx 0 20rpx; @@ -286,7 +286,7 @@ } .home-age-scroll { - margin-top: @section-gap-sm; + margin-top: @section-gap-xs; width: 100%; white-space: nowrap; } @@ -341,7 +341,7 @@ } .home-hot-list { - margin-top: @section-gap-sm; + margin-top: @section-gap-xs; padding: 0 @page-padding-x; display: flex; flex-direction: column; @@ -434,8 +434,10 @@ background: @brand; color: #2b2b2b; font-size: 36rpx; - line-height: 56rpx; - text-align: center; + line-height: 1; + display: flex; + align-items: center; + justify-content: center; flex-shrink: 0; } diff --git a/miniprogram/pages/home/home.ts b/miniprogram/pages/home/home.ts index 0c4e41b..561d98d 100644 --- a/miniprogram/pages/home/home.ts +++ b/miniprogram/pages/home/home.ts @@ -1,4 +1,5 @@ import { NAV_INNER_PX } from '../../utils/navMetrics'; +import { parseMiniProgramUrl } from '../../utils/index'; import { HOME_CURRENT_CAPABILITY_DATA, type HomeDisplayItem, @@ -35,6 +36,7 @@ const AGE_BAND_ICONS = ['🌱', '🚀', '🎓', '🧠', '🏆'] as const; const SECTION_ANCHOR_PREFIX = 'section-'; const TAB_BAR_PATHS = new Set([ '/pages/home/home', + '/pages/category/category', '/pages/age/age', '/pages/favorites/favorites', '/pages/profile/profile', @@ -65,7 +67,6 @@ function sortSectionsByTabs( } function navigateByPath(path?: string, fallbackTitle?: string) { - console.log('path-----:', path); if (!path) { wx.showToast({ title: fallbackTitle ? `${fallbackTitle} 即将上线` : '即将上线', @@ -74,12 +75,23 @@ function navigateByPath(path?: string, fallbackTitle?: string) { return; } - if (TAB_BAR_PATHS.has(path)) { - wx.switchTab({ url: path }); + const { path: basePath, query } = parseMiniProgramUrl(path); + + if (TAB_BAR_PATHS.has(basePath)) { + // tabBar 页面不支持携带 query/hash,统一跳到 basePath + if (Object.keys(query).length > 0) { + console.warn( + '[navigateByPath] tabBar 不支持携带参数,已忽略 query:', + basePath, + query, + ); + } + wx.switchTab({ url: basePath }); return; } - - wx.navigateTo({ url: path }); + wx.navigateTo({ url: path }).catch((err) => { + console.error('navigateByPath error:', err); + }); } // ── Skeleton data ── diff --git a/miniprogram/pages/home/home.wxml b/miniprogram/pages/home/home.wxml index 77fceff..e5f5c2b 100644 --- a/miniprogram/pages/home/home.wxml +++ b/miniprogram/pages/home/home.wxml @@ -142,8 +142,9 @@ + > + + diff --git a/miniprogram/utils/index.ts b/miniprogram/utils/index.ts index 41754bf..2a169cb 100644 --- a/miniprogram/utils/index.ts +++ b/miniprogram/utils/index.ts @@ -40,3 +40,38 @@ const formatNumber = (n: number) => { const s = n.toString(); return s[1] ? s : '0' + s; }; + +export type MiniProgramQuery = Record; + +export function parseMiniProgramUrl(input: string) { + const trimmed = input.trim(); + const pathPart = trimmed.split(/[?#]/, 1)[0] || ''; + const query: MiniProgramQuery = {}; + + const questionIndex = trimmed.indexOf('?'); + const hashIndex = trimmed.indexOf('#'); + const queryStart = + questionIndex >= 0 && (hashIndex < 0 || questionIndex < hashIndex) + ? questionIndex + 1 + : -1; + const queryEnd = hashIndex >= 0 ? hashIndex : trimmed.length; + + if (queryStart >= 0 && queryStart <= queryEnd) { + const queryString = trimmed.slice(queryStart, queryEnd); + for (const pair of queryString.split('&')) { + if (!pair) continue; + const [rawKey, rawValue = ''] = pair.split('=', 2); + if (!rawKey) continue; + const decode = (v: string) => { + try { + return decodeURIComponent(v.replace(/\+/g, ' ')); + } catch { + return v; + } + }; + query[decode(rawKey)] = decode(rawValue); + } + } + + return { path: pathPart, query }; +}