feat: 首页查看更多

This commit is contained in:
R524809
2026-04-30 17:19:04 +08:00
parent 7126d3a941
commit 44182d011d
5 changed files with 65 additions and 14 deletions
+2 -1
View File
@@ -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"
}
}
+8 -6
View File
@@ -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;
}
+17 -5
View File
@@ -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 ──
+3 -2
View File
@@ -142,8 +142,9 @@
<view
wx:if="{{!item.skeleton}}"
class="home-hot-card__action"
></view
>
>
<toy-icon name="arrow-right" size="36rpx" color="#2b2b2b" />
</view>
</view>
</view>
</view>
+35
View File
@@ -40,3 +40,38 @@ const formatNumber = (n: number) => {
const s = n.toString();
return s[1] ? s : '0' + s;
};
export type MiniProgramQuery = Record<string, string>;
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 };
}