Make WeChat launch path pages/home/index and document the index redirect.

Keep 20261011 hub visuals on home; index only reLaunches to avoid missing page wxss.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Eric 2026-10-11 16:03:31 +08:00
parent d0262eb58d
commit dc7a46ee0b
17 changed files with 559 additions and 439 deletions

View File

@ -117,6 +117,11 @@ pnpm dev:api
- **发布流**:本地调试 → 当前开发分支 commit/push → 部署脚本上线 → 冒烟;配置与发版均以 git 为准 - **发布流**:本地调试 → 当前开发分支 commit/push → 部署脚本上线 → 冒烟;配置与发版均以 git 为准
- 主开发分支:`pre4`(`pre3` 已封存本轮);发版前与 README / 远程对齐 - 主开发分支:`pre4`(`pre3` 已封存本轮);发版前与 README / 远程对齐
## pre4 摘要
- 微信启动页改为 **`pages/home/index`**(话题/体验码同路径);`pages/index` 兼容跳转
- 首页样式源码在 `h5/src/pages/home`,`home/index.scss` 进 weapp `pxExclude`(真 px)
## pre3 摘要(已合入) ## pre3 摘要(已合入)
微信提审与包体: 微信提审与包体:
@ -126,4 +131,6 @@ pnpm dev:api
- **安全区**:自定义顶栏内联尺寸用大写 `PX` 跳过 Taro rpx;阅读页顶栏不再叠状态栏 padding - **安全区**:自定义顶栏内联尺寸用大写 `PX` 跳过 Taro rpx;阅读页顶栏不再叠状态栏 padding
- **代码质量**:`lazyCodeLoading` · 分包 + `optimizeMainPackage`(主包 ≪1.5MB)· 导航图标走 `https://nomadro.cn/icons`(包内图片合计 ≤200K) - **代码质量**:`lazyCodeLoading` · 分包 + `optimizeMainPackage`(主包 ≪1.5MB)· 导航图标走 `https://nomadro.cn/icons`(包内图片合计 ≤200K)
构建微信包:`pnpm build:weapp` → 开发者工具打开 `apps/miniprogram/weapp`(读 `dist/`)。图片域名需放行 `nomadro.cn`。 构建微信包:`pnpm build:weapp` / `pnpm dev:weapp` → 开发者工具打开 `apps/miniprogram/weapp`(读 `dist/`)。图片域名需放行 `nomadro.cn`。
微信启动首页为 **`pages/home/index`**(官方话题/体验码同路径;视觉对齐 tag **`20261011`**)。`pages/index/index` 仅作兼容:`reLaunch` → home(勿与 home 共用组件入口,否则页面 wxss 缺失)。详见 `apps/miniprogram/weapp/README.md`。

View File

@ -5,7 +5,7 @@ const tabBar = {
borderStyle: 'black', borderStyle: 'black',
list: [ list: [
{ {
pagePath: 'pages/index/index', pagePath: 'pages/home/index',
text: '首页', text: '首页',
iconPath: 'assets/tab/home.png', iconPath: 'assets/tab/home.png',
selectedIconPath: 'assets/tab/home-active.png', selectedIconPath: 'assets/tab/home-active.png',
@ -47,7 +47,8 @@ const wantTabBar = !isH5 && process.env.TARO_APP_TABBAR === '1'
/** 微信主包必须 ≤1.5MB:首页/我的留主包,其余进分包 */ /** 微信主包必须 ≤1.5MB:首页/我的留主包,其余进分包 */
const weappConfig = { const weappConfig = {
pages: ['pages/index/index', 'pages/mine/index'], // 启动页 = home(官方话题/体验码默认路径);UI 与 tag 20261011 的 index 同组件
pages: ['pages/home/index', 'pages/mine/index', 'pages/index/index'],
subPackages: [ subPackages: [
{ {
root: 'pages/nav', root: 'pages/nav',
@ -136,7 +137,7 @@ const weappConfig = {
}, },
], ],
preloadRule: { preloadRule: {
'pages/index/index': { 'pages/home/index': {
network: 'all', network: 'all',
packages: ['book', 'nav'], packages: ['book', 'nav'],
}, },
@ -147,6 +148,7 @@ const weappConfig = {
const h5Config = { const h5Config = {
pages: [ pages: [
'pages/home/index',
'pages/index/index', 'pages/index/index',
'pages/nav/index', 'pages/nav/index',
'pages/community/index', 'pages/community/index',

View File

@ -72,7 +72,7 @@ export function CommunityNavbar() {
: undefined : undefined
} }
> >
<H5Box className="logo" onClick={() => goPage('/pages/index/index')} aria-label="返回首页"> <H5Box className="logo" onClick={() => goPage('/pages/home/index')} aria-label="返回首页">
{isH5 ? ( {isH5 ? (
<H5Box html={LOGO_SVG} /> <H5Box html={LOGO_SVG} />
) : ( ) : (
@ -100,7 +100,7 @@ export function BrandNav({
const label = section || chip || '社群' const label = section || chip || '社群'
return ( return (
<H5Box className="portal-topbar"> <H5Box className="portal-topbar">
<H5Box className="portal-logo" onClick={() => goPage('/pages/index/index')}> <H5Box className="portal-logo" onClick={() => goPage('/pages/home/index')}>
{isH5 ? ( {isH5 ? (
<H5Box <H5Box
className="portal-logo-svg" className="portal-logo-svg"

View File

@ -97,7 +97,7 @@ function GamePage() {
} }
}, []) }, [])
const back = () => goPage('/pages/index/index') const back = () => goPage('/pages/home/index')
const restart = () => gameRef.current?.restart() const restart = () => gameRef.current?.restart()
const interact = () => gameRef.current?.setInput({ interact: true }) const interact = () => gameRef.current?.setInput({ interact: true })

View File

@ -0,0 +1,5 @@
export default definePageConfig({
navigationBarTitleText: 'Nomadro',
// 对齐 H5:自定义顶栏,去掉原生导航栏占位
navigationStyle: 'custom',
})

View File

@ -0,0 +1,2 @@
@use '../../styles/hub.scss';
@import '../../styles/weapp-parity.scss';

View File

@ -0,0 +1,430 @@
/**
* 对齐门户 components/sections/hero.tsx(结构 / PORTALS / 开发快捷入口)
* H5 真布局用原生 div(Taro View 自定义元素会弄塌 grid/绝对定位)。
*/
import { useEffect, useState, type CSSProperties, type ReactNode } from 'react'
import { View, Text } from '@tarojs/components'
import Taro, { useDidShow, usePageScroll } from '@tarojs/taro'
import {
isModuleEnabled,
loadRemoteConfig,
subscribeRemoteConfig,
} from '@/services/remoteConfig'
import type { NomadroRemoteConfig } from '@/data/remoteConfig.defaults'
import { applyH5Theme, useNomadroTheme } from '@/utils/h5Theme'
import { goPage } from '@/utils/nav'
import { usePageShare, markPageShare } from '@/utils/pageShare'
import { safePx, useSafeAreaMetrics } from '@/utils/safeArea'
import { usePageTrack } from '@/hooks/usePageTrack'
import './index.scss'
type PortalId = 'nav' | 'book' | 'community' | 'vip'
type Portal = {
id: PortalId
moduleKey: keyof NomadroRemoteConfig['modules']
emoji: string
name: string
main?: boolean
}
const PORTALS: Portal[] = [
{ id: 'nav', moduleKey: 'nav', emoji: '🧭', name: '出海导航', main: false },
{ id: 'book', moduleKey: 'book', emoji: '📖', name: '数字游民', main: false },
{ id: 'community', moduleKey: 'community', emoji: '🌏', name: '旅居社群', main: true },
]
const INTERNAL_PORTALS: Record<PortalId, string> = {
nav: '/pages/nav/index',
book: '/pages/book/index',
community: '/pages/community/index',
vip: '/pages/vip/index',
}
const isH5 = process.env.TARO_ENV === 'h5'
/** 开发快捷入口:默认隐藏 VIP;Admin/Config 仅 H5 开发态 */
const showQuickNav = false
const isDev = process.env.NODE_ENV === 'development'
const LOGO_SVG = `<svg class="hub-logo-icon" viewBox="0 0 40 40" fill="none" aria-hidden="true">
<circle cx="20" cy="20" r="18" stroke="#f06664" stroke-width="2.5"/>
<path d="M12 22c4-8 12-8 16 0" stroke="#f06664" stroke-width="2" stroke-linecap="round"/>
<circle cx="28" cy="14" r="3" fill="#f06664"/>
</svg>`
const GLOBE_SVG = `<svg class="hub-globe-svg" viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<defs>
<radialGradient id="hubGlobeGlow" cx="50%" cy="50%" r="50%">
<stop offset="0%" stop-color="#4ECDC4" stop-opacity="0.3"/>
<stop offset="100%" stop-color="#4ECDC4" stop-opacity="0"/>
</radialGradient>
<linearGradient id="hubOrbitGrad" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#FF6B6B"/>
<stop offset="100%" stop-color="#4ECDC4"/>
</linearGradient>
</defs>
<circle cx="200" cy="200" r="160" fill="url(#hubGlobeGlow)"/>
<circle cx="200" cy="200" r="120" fill="none" stroke="rgba(78,205,196,0.2)" stroke-width="1"/>
<circle cx="200" cy="200" r="90" fill="none" stroke="rgba(78,205,196,0.15)" stroke-width="1"/>
<ellipse class="hub-orbit-ring" cx="200" cy="200" rx="120" ry="40" fill="none" stroke="rgba(78,205,196,0.3)" stroke-width="1.5"/>
<ellipse class="hub-orbit-ring hub-orbit-ring-2" cx="200" cy="200" rx="40" ry="120" fill="none" stroke="rgba(255,107,107,0.3)" stroke-width="1.5"/>
<path class="hub-continent" d="M160 140 Q180 130 200 135 Q220 128 240 140 Q250 155 245 170 Q235 185 220 190 Q200 195 185 188 Q165 180 160 165 Z" fill="rgba(78,205,196,0.4)"/>
<path class="hub-continent" d="M130 210 Q145 200 160 215 Q155 235 140 240 Q125 235 130 210 Z" fill="rgba(78,205,196,0.3)"/>
<path class="hub-continent" d="M250 200 Q270 195 280 210 Q275 230 260 235 Q245 228 250 200 Z" fill="rgba(78,205,196,0.35)"/>
<circle class="hub-pulse-dot" cx="180" cy="155" r="5" fill="#FF6B6B"/>
<circle class="hub-pulse-dot" cx="260" cy="215" r="5" fill="#FFE66D"/>
<circle class="hub-pulse-dot" cx="145" cy="225" r="5" fill="#4ECDC4"/>
<path class="hub-flight-path" d="M180 155 Q220 140 260 215" fill="none" stroke="url(#hubOrbitGrad)" stroke-width="2" stroke-dasharray="6 4"/>
</svg>`
function goPath(path: string) {
goPage(path)
}
function openDevLink(kind: 'vip' | 'admin' | 'config') {
if (kind === 'vip') {
goPath('/pages/vip/index')
return
}
if (isH5 && typeof window !== 'undefined') {
const origin = window.location.origin.includes('10086')
? 'http://localhost:3000'
: window.location.origin
const href = kind === 'admin' ? `${origin}/admin` : `${origin}/admin/config`
window.open(href, '_blank', 'noopener,noreferrer')
return
}
Taro.showToast({
title: kind === 'admin' ? '请用门户 /admin' : '请用门户 /admin/config',
icon: 'none',
})
}
/** H5 用原生标签,避开 taro-view-core 默认 inline */
function Box({
className,
id,
children,
onClick,
html,
style,
'aria-hidden': ariaHidden,
'aria-label': ariaLabel,
'data-theme': dataTheme,
}: {
className?: string
id?: string
children?: ReactNode
onClick?: () => void
html?: string
style?: CSSProperties
'aria-hidden'?: boolean
'aria-label'?: string
'data-theme'?: string
}) {
if (isH5) {
return (
<div
id={id}
className={className}
style={style}
onClick={onClick}
aria-hidden={ariaHidden}
aria-label={ariaLabel}
data-theme={dataTheme}
dangerouslySetInnerHTML={html ? { __html: html } : undefined}
>
{html ? undefined : children}
</div>
)
}
return (
<View
id={id}
className={className}
style={style}
onClick={onClick}
data-theme={dataTheme}
dangerouslySetInnerHTML={html ? { __html: html } : undefined}
>
{html ? undefined : children}
</View>
)
}
function Txt({ className, children }: { className?: string; children?: ReactNode }) {
if (isH5) return <span className={className}>{children}</span>
return <Text className={className}>{children}</Text>
}
function IndexPage() {
usePageTrack('pages/home/index', '首页')
usePageShare({ title: 'nomadro · 随处工作,自由生活', path: '/pages/home/index' })
const [config, setConfig] = useState<NomadroRemoteConfig | null>(null)
const theme = useNomadroTheme()
const [navScrolled, setNavScrolled] = useState(false)
useEffect(() => {
const unsub = subscribeRemoteConfig((r) => setConfig(r.config))
void loadRemoteConfig(true).then((r) => setConfig(r.config))
applyH5Theme(theme)
return unsub
}, [])
useDidShow(() => {
void loadRemoteConfig(true).then((r) => setConfig(r.config))
})
useEffect(() => {
applyH5Theme(theme)
}, [theme])
// H5:锁 16px,并干掉 Taro flexible 脚本改根字号
useEffect(() => {
if (!isH5) return
const html = document.documentElement
const prev = html.style.fontSize
const lock = () => {
html.style.fontSize = '16px'
}
lock()
const id = window.setInterval(lock, 500)
window.addEventListener('resize', lock)
return () => {
clearInterval(id)
window.removeEventListener('resize', lock)
html.style.fontSize = prev
}
}, [])
usePageScroll((e) => {
setNavScrolled(e.scrollTop > 24)
})
useEffect(() => {
if (!isH5) return
const onScroll = () => {
setNavScrolled(window.scrollY > 24)
}
window.addEventListener('scroll', onScroll, { passive: true })
onScroll()
return () => window.removeEventListener('scroll', onScroll)
}, [])
useEffect(() => {
if (!isH5) return
const host = document.getElementById('particle-canvas-host')
if (!host) return
let canvas = host.querySelector('canvas') as HTMLCanvasElement | null
if (!canvas) {
canvas = document.createElement('canvas')
canvas.id = 'particle-canvas'
canvas.className = 'hub-particle-canvas'
canvas.setAttribute('aria-hidden', 'true')
host.appendChild(canvas)
}
const ctx = canvas.getContext('2d')
if (!ctx) return
let particles: { x: number; y: number; r: number; vx: number; vy: number; a: number }[] = []
let w = 0
let h = 0
let raf = 0
let running = true
const resize = () => {
w = canvas!.width = window.innerWidth
h = canvas!.height = window.innerHeight
const n = Math.min(60, Math.floor((w * h) / 22000))
particles = Array.from({ length: n }, () => ({
x: Math.random() * w,
y: Math.random() * h,
r: Math.random() * 1.6 + 0.4,
vx: (Math.random() - 0.5) * 0.3,
vy: (Math.random() - 0.5) * 0.3,
a: Math.random() * 0.4 + 0.15,
}))
}
const draw = () => {
if (!running) return
ctx.clearRect(0, 0, w, h)
particles.forEach((p, i) => {
p.x += p.vx
p.y += p.vy
if (p.x < 0 || p.x > w) p.vx *= -1
if (p.y < 0 || p.y > h) p.vy *= -1
ctx.beginPath()
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2)
ctx.fillStyle = `rgba(255,255,255,${p.a})`
ctx.fill()
for (let j = i + 1; j < particles.length; j++) {
const q = particles[j]!
const d = Math.hypot(p.x - q.x, p.y - q.y)
if (d < 110) {
ctx.beginPath()
ctx.moveTo(p.x, p.y)
ctx.lineTo(q.x, q.y)
ctx.strokeStyle = `rgba(78,205,196,${0.16 * (1 - d / 110)})`
ctx.stroke()
}
}
})
raf = requestAnimationFrame(draw)
}
resize()
draw()
window.addEventListener('resize', resize)
return () => {
running = false
cancelAnimationFrame(raf)
window.removeEventListener('resize', resize)
}
}, [])
const cfg = config
// 配置未就绪:一个入口都不渲染,避免「先闪后藏」被审核盯上
const portals = cfg ? PORTALS.filter((p) => isModuleEnabled(cfg, p.moduleKey)) : []
const brand = cfg?.copy.homeBrand || 'nomadro'
const safe = useSafeAreaMetrics()
const rootSafeStyle = {
// CSS 变量用小写 px(样式表已排除 rpx 转换);内联尺寸必须用 safePx
['--safe-status-bar' as string]: `${safe.statusBarHeight}px`,
['--safe-nav-bar' as string]: `${safe.navBarHeight}px`,
['--safe-menu-pad' as string]: `${safe.menuRightPad}px`,
['--safe-header' as string]: `${safe.headerHeight}px`,
} as CSSProperties
return (
<Box
className={`hub-root${theme === 'light' ? ' hub-root--light' : ''}${!isH5 ? ' hub-root--mini' : ''}`}
data-theme={theme}
style={rootSafeStyle}
>
{isH5 ? <Box id="particle-canvas-host" className="hub-particle-canvas" /> : null}
<Box
className={`hub-navbar${navScrolled ? ' scrolled' : ''}`}
id="navbar"
style={
!isH5
? {
paddingTop: safePx(safe.statusBarHeight),
height: 'auto',
}
: undefined
}
>
<Box
className="hub-nav-container"
style={
!isH5
? {
height: safePx(safe.navBarHeight),
paddingRight: safePx(safe.menuRightPad),
}
: undefined
}
>
<Box className="hub-logo">
{isH5 ? (
<Box className="hub-logo-svg" html={LOGO_SVG} />
) : (
<Box className="hub-logo-mark" aria-hidden>
<Box className="hub-logo-mark-ring" />
<Box className="hub-logo-mark-dot" />
</Box>
)}
<Txt className="hub-logo-text">{brand}</Txt>
</Box>
<Box className="hub-nav-actions">
{showQuickNav && isH5 && isDev ? (
<Box className="hub-dev-nav">
<Box className="hub-dev-link" onClick={() => openDevLink('admin')}>
<Txt>Admin</Txt>
</Box>
<Box className="hub-dev-link" onClick={() => openDevLink('config')}>
<Txt>Config</Txt>
</Box>
</Box>
) : null}
</Box>
</Box>
</Box>
<Box
className="hub-hero"
style={
!isH5
? {
paddingTop: safePx(safe.headerHeight + 8),
}
: undefined
}
>
<Box className="hub-hero-bg-shapes" aria-hidden>
<Box className="hub-shape hub-shape-1" />
<Box className="hub-shape hub-shape-2" />
<Box className="hub-shape hub-shape-3" />
</Box>
<Box className="hub-hero-inner">
<Box className="hub-hero-visual hub-reveal visible">
<Box className="hub-globe-container">
{isH5 ? (
<Box className="hub-globe-wrap" html={GLOBE_SVG} />
) : (
<Box className="hub-globe-css" aria-hidden>
<Box className="hub-globe-css-glow" />
<Box className="hub-globe-css-ring hub-globe-css-ring-a" />
<Box className="hub-globe-css-ring hub-globe-css-ring-b" />
<Box className="hub-globe-css-core" />
<Box className="hub-globe-css-dot hub-globe-css-dot-1" />
<Box className="hub-globe-css-dot hub-globe-css-dot-2" />
<Box className="hub-globe-css-dot hub-globe-css-dot-3" />
<Box className="hub-globe-css-path" />
</Box>
)}
<Box className="hub-floating-cards" aria-hidden>
<Box className="hub-float-card hub-fc-1">
<Txt>🏝️ 巴厘岛</Txt>
</Box>
<Box className="hub-float-card hub-fc-2">
<Txt>☕ 里斯本</Txt>
</Box>
<Box className="hub-float-card hub-fc-3">
<Txt>🏔️ 清迈</Txt>
</Box>
</Box>
</Box>
</Box>
<Box className="hub-hero-title hub-reveal visible">
<Txt>随处工作</Txt>
<Txt className="hub-gradient-text">自由生活</Txt>
</Box>
<Box className="hub-portal-grid hub-reveal visible">
{portals.map((portal) => (
<Box
key={portal.id}
className={`hub-portal-card${portal.main ? ' hub-portal-card--main' : ''}`}
onClick={() => goPath(INTERNAL_PORTALS[portal.id])}
>
<Box className="hub-portal-ico" aria-hidden>
<Txt>{portal.emoji}</Txt>
</Box>
<Txt className="hub-portal-name">
{cfg?.modules[portal.moduleKey]?.title || portal.name}
</Txt>
</Box>
))}
</Box>
</Box>
</Box>
</Box>
)
}
export default markPageShare(IndexPage)

View File

@ -1,5 +1,4 @@
export default definePageConfig({ export default definePageConfig({
navigationBarTitleText: 'Nomadro', navigationBarTitleText: 'Nomadro',
// 对齐 H5:自定义顶栏,去掉原生导航栏占位
navigationStyle: 'custom', navigationStyle: 'custom',
}) })

View File

@ -1,2 +1,4 @@
@use '../../styles/hub.scss'; /* 占位:保证本页生成 index.wxss;视觉在 home */
@import '../../styles/weapp-parity.scss'; .index-alias {
min-height: 0;
}

View File

@ -1,430 +1,14 @@
/** /**
* 对齐门户 components/sections/hero.tsx(结构 / PORTALS / 开发快捷入口) * 兼容旧路径:跳转到唯一首页 pages/home/index。
* H5 真布局用原生 div(Taro View 自定义元素会弄塌 grid/绝对定位)。 * 不可与 home 共用组件入口,否则样式进 common.wxss、两页都不落 index.wxss → 微信 ENOENT。
*/ */
import { useEffect, useState, type CSSProperties, type ReactNode } from 'react' import { View } from '@tarojs/components'
import { View, Text } from '@tarojs/components' import Taro, { useLoad } from '@tarojs/taro'
import Taro, { useDidShow, usePageScroll } from '@tarojs/taro'
import {
isModuleEnabled,
loadRemoteConfig,
subscribeRemoteConfig,
} from '@/services/remoteConfig'
import type { NomadroRemoteConfig } from '@/data/remoteConfig.defaults'
import { applyH5Theme, useNomadroTheme } from '@/utils/h5Theme'
import { goPage } from '@/utils/nav'
import { usePageShare, markPageShare } from '@/utils/pageShare'
import { safePx, useSafeAreaMetrics } from '@/utils/safeArea'
import { usePageTrack } from '@/hooks/usePageTrack'
import './index.scss' import './index.scss'
type PortalId = 'nav' | 'book' | 'community' | 'vip'
type Portal = { export default function IndexAliasPage() {
id: PortalId useLoad(() => {
moduleKey: keyof NomadroRemoteConfig['modules'] void Taro.reLaunch({ url: '/pages/home/index' })
emoji: string
name: string
main?: boolean
}
const PORTALS: Portal[] = [
{ id: 'nav', moduleKey: 'nav', emoji: '🧭', name: '出海导航', main: false },
{ id: 'book', moduleKey: 'book', emoji: '📖', name: '数字游民', main: false },
{ id: 'community', moduleKey: 'community', emoji: '🌏', name: '旅居社群', main: true },
]
const INTERNAL_PORTALS: Record<PortalId, string> = {
nav: '/pages/nav/index',
book: '/pages/book/index',
community: '/pages/community/index',
vip: '/pages/vip/index',
}
const isH5 = process.env.TARO_ENV === 'h5'
/** 开发快捷入口:默认隐藏 VIP;Admin/Config 仅 H5 开发态 */
const showQuickNav = false
const isDev = process.env.NODE_ENV === 'development'
const LOGO_SVG = `<svg class="hub-logo-icon" viewBox="0 0 40 40" fill="none" aria-hidden="true">
<circle cx="20" cy="20" r="18" stroke="#f06664" stroke-width="2.5"/>
<path d="M12 22c4-8 12-8 16 0" stroke="#f06664" stroke-width="2" stroke-linecap="round"/>
<circle cx="28" cy="14" r="3" fill="#f06664"/>
</svg>`
const GLOBE_SVG = `<svg class="hub-globe-svg" viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<defs>
<radialGradient id="hubGlobeGlow" cx="50%" cy="50%" r="50%">
<stop offset="0%" stop-color="#4ECDC4" stop-opacity="0.3"/>
<stop offset="100%" stop-color="#4ECDC4" stop-opacity="0"/>
</radialGradient>
<linearGradient id="hubOrbitGrad" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#FF6B6B"/>
<stop offset="100%" stop-color="#4ECDC4"/>
</linearGradient>
</defs>
<circle cx="200" cy="200" r="160" fill="url(#hubGlobeGlow)"/>
<circle cx="200" cy="200" r="120" fill="none" stroke="rgba(78,205,196,0.2)" stroke-width="1"/>
<circle cx="200" cy="200" r="90" fill="none" stroke="rgba(78,205,196,0.15)" stroke-width="1"/>
<ellipse class="hub-orbit-ring" cx="200" cy="200" rx="120" ry="40" fill="none" stroke="rgba(78,205,196,0.3)" stroke-width="1.5"/>
<ellipse class="hub-orbit-ring hub-orbit-ring-2" cx="200" cy="200" rx="40" ry="120" fill="none" stroke="rgba(255,107,107,0.3)" stroke-width="1.5"/>
<path class="hub-continent" d="M160 140 Q180 130 200 135 Q220 128 240 140 Q250 155 245 170 Q235 185 220 190 Q200 195 185 188 Q165 180 160 165 Z" fill="rgba(78,205,196,0.4)"/>
<path class="hub-continent" d="M130 210 Q145 200 160 215 Q155 235 140 240 Q125 235 130 210 Z" fill="rgba(78,205,196,0.3)"/>
<path class="hub-continent" d="M250 200 Q270 195 280 210 Q275 230 260 235 Q245 228 250 200 Z" fill="rgba(78,205,196,0.35)"/>
<circle class="hub-pulse-dot" cx="180" cy="155" r="5" fill="#FF6B6B"/>
<circle class="hub-pulse-dot" cx="260" cy="215" r="5" fill="#FFE66D"/>
<circle class="hub-pulse-dot" cx="145" cy="225" r="5" fill="#4ECDC4"/>
<path class="hub-flight-path" d="M180 155 Q220 140 260 215" fill="none" stroke="url(#hubOrbitGrad)" stroke-width="2" stroke-dasharray="6 4"/>
</svg>`
function goPath(path: string) {
goPage(path)
}
function openDevLink(kind: 'vip' | 'admin' | 'config') {
if (kind === 'vip') {
goPath('/pages/vip/index')
return
}
if (isH5 && typeof window !== 'undefined') {
const origin = window.location.origin.includes('10086')
? 'http://localhost:3000'
: window.location.origin
const href = kind === 'admin' ? `${origin}/admin` : `${origin}/admin/config`
window.open(href, '_blank', 'noopener,noreferrer')
return
}
Taro.showToast({
title: kind === 'admin' ? '请用门户 /admin' : '请用门户 /admin/config',
icon: 'none',
}) })
return <View className="index-alias" />
} }
/** H5 用原生标签,避开 taro-view-core 默认 inline */
function Box({
className,
id,
children,
onClick,
html,
style,
'aria-hidden': ariaHidden,
'aria-label': ariaLabel,
'data-theme': dataTheme,
}: {
className?: string
id?: string
children?: ReactNode
onClick?: () => void
html?: string
style?: CSSProperties
'aria-hidden'?: boolean
'aria-label'?: string
'data-theme'?: string
}) {
if (isH5) {
return (
<div
id={id}
className={className}
style={style}
onClick={onClick}
aria-hidden={ariaHidden}
aria-label={ariaLabel}
data-theme={dataTheme}
dangerouslySetInnerHTML={html ? { __html: html } : undefined}
>
{html ? undefined : children}
</div>
)
}
return (
<View
id={id}
className={className}
style={style}
onClick={onClick}
data-theme={dataTheme}
dangerouslySetInnerHTML={html ? { __html: html } : undefined}
>
{html ? undefined : children}
</View>
)
}
function Txt({ className, children }: { className?: string; children?: ReactNode }) {
if (isH5) return <span className={className}>{children}</span>
return <Text className={className}>{children}</Text>
}
function IndexPage() {
usePageTrack('pages/index/index', '首页')
usePageShare({ title: 'nomadro · 随处工作,自由生活', path: '/pages/index/index' })
const [config, setConfig] = useState<NomadroRemoteConfig | null>(null)
const theme = useNomadroTheme()
const [navScrolled, setNavScrolled] = useState(false)
useEffect(() => {
const unsub = subscribeRemoteConfig((r) => setConfig(r.config))
void loadRemoteConfig(true).then((r) => setConfig(r.config))
applyH5Theme(theme)
return unsub
}, [])
useDidShow(() => {
void loadRemoteConfig(true).then((r) => setConfig(r.config))
})
useEffect(() => {
applyH5Theme(theme)
}, [theme])
// H5:锁 16px,并干掉 Taro flexible 脚本改根字号
useEffect(() => {
if (!isH5) return
const html = document.documentElement
const prev = html.style.fontSize
const lock = () => {
html.style.fontSize = '16px'
}
lock()
const id = window.setInterval(lock, 500)
window.addEventListener('resize', lock)
return () => {
clearInterval(id)
window.removeEventListener('resize', lock)
html.style.fontSize = prev
}
}, [])
usePageScroll((e) => {
setNavScrolled(e.scrollTop > 24)
})
useEffect(() => {
if (!isH5) return
const onScroll = () => {
setNavScrolled(window.scrollY > 24)
}
window.addEventListener('scroll', onScroll, { passive: true })
onScroll()
return () => window.removeEventListener('scroll', onScroll)
}, [])
useEffect(() => {
if (!isH5) return
const host = document.getElementById('particle-canvas-host')
if (!host) return
let canvas = host.querySelector('canvas') as HTMLCanvasElement | null
if (!canvas) {
canvas = document.createElement('canvas')
canvas.id = 'particle-canvas'
canvas.className = 'hub-particle-canvas'
canvas.setAttribute('aria-hidden', 'true')
host.appendChild(canvas)
}
const ctx = canvas.getContext('2d')
if (!ctx) return
let particles: { x: number; y: number; r: number; vx: number; vy: number; a: number }[] = []
let w = 0
let h = 0
let raf = 0
let running = true
const resize = () => {
w = canvas!.width = window.innerWidth
h = canvas!.height = window.innerHeight
const n = Math.min(60, Math.floor((w * h) / 22000))
particles = Array.from({ length: n }, () => ({
x: Math.random() * w,
y: Math.random() * h,
r: Math.random() * 1.6 + 0.4,
vx: (Math.random() - 0.5) * 0.3,
vy: (Math.random() - 0.5) * 0.3,
a: Math.random() * 0.4 + 0.15,
}))
}
const draw = () => {
if (!running) return
ctx.clearRect(0, 0, w, h)
particles.forEach((p, i) => {
p.x += p.vx
p.y += p.vy
if (p.x < 0 || p.x > w) p.vx *= -1
if (p.y < 0 || p.y > h) p.vy *= -1
ctx.beginPath()
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2)
ctx.fillStyle = `rgba(255,255,255,${p.a})`
ctx.fill()
for (let j = i + 1; j < particles.length; j++) {
const q = particles[j]!
const d = Math.hypot(p.x - q.x, p.y - q.y)
if (d < 110) {
ctx.beginPath()
ctx.moveTo(p.x, p.y)
ctx.lineTo(q.x, q.y)
ctx.strokeStyle = `rgba(78,205,196,${0.16 * (1 - d / 110)})`
ctx.stroke()
}
}
})
raf = requestAnimationFrame(draw)
}
resize()
draw()
window.addEventListener('resize', resize)
return () => {
running = false
cancelAnimationFrame(raf)
window.removeEventListener('resize', resize)
}
}, [])
const cfg = config
// 配置未就绪:一个入口都不渲染,避免「先闪后藏」被审核盯上
const portals = cfg ? PORTALS.filter((p) => isModuleEnabled(cfg, p.moduleKey)) : []
const brand = cfg?.copy.homeBrand || 'nomadro'
const safe = useSafeAreaMetrics()
const rootSafeStyle = {
// CSS 变量用小写 px(样式表已排除 rpx 转换);内联尺寸必须用 safePx
['--safe-status-bar' as string]: `${safe.statusBarHeight}px`,
['--safe-nav-bar' as string]: `${safe.navBarHeight}px`,
['--safe-menu-pad' as string]: `${safe.menuRightPad}px`,
['--safe-header' as string]: `${safe.headerHeight}px`,
} as CSSProperties
return (
<Box
className={`hub-root${theme === 'light' ? ' hub-root--light' : ''}${!isH5 ? ' hub-root--mini' : ''}`}
data-theme={theme}
style={rootSafeStyle}
>
{isH5 ? <Box id="particle-canvas-host" className="hub-particle-canvas" /> : null}
<Box
className={`hub-navbar${navScrolled ? ' scrolled' : ''}`}
id="navbar"
style={
!isH5
? {
paddingTop: safePx(safe.statusBarHeight),
height: 'auto',
}
: undefined
}
>
<Box
className="hub-nav-container"
style={
!isH5
? {
height: safePx(safe.navBarHeight),
paddingRight: safePx(safe.menuRightPad),
}
: undefined
}
>
<Box className="hub-logo">
{isH5 ? (
<Box className="hub-logo-svg" html={LOGO_SVG} />
) : (
<Box className="hub-logo-mark" aria-hidden>
<Box className="hub-logo-mark-ring" />
<Box className="hub-logo-mark-dot" />
</Box>
)}
<Txt className="hub-logo-text">{brand}</Txt>
</Box>
<Box className="hub-nav-actions">
{showQuickNav && isH5 && isDev ? (
<Box className="hub-dev-nav">
<Box className="hub-dev-link" onClick={() => openDevLink('admin')}>
<Txt>Admin</Txt>
</Box>
<Box className="hub-dev-link" onClick={() => openDevLink('config')}>
<Txt>Config</Txt>
</Box>
</Box>
) : null}
</Box>
</Box>
</Box>
<Box
className="hub-hero"
style={
!isH5
? {
paddingTop: safePx(safe.headerHeight + 8),
}
: undefined
}
>
<Box className="hub-hero-bg-shapes" aria-hidden>
<Box className="hub-shape hub-shape-1" />
<Box className="hub-shape hub-shape-2" />
<Box className="hub-shape hub-shape-3" />
</Box>
<Box className="hub-hero-inner">
<Box className="hub-hero-visual hub-reveal visible">
<Box className="hub-globe-container">
{isH5 ? (
<Box className="hub-globe-wrap" html={GLOBE_SVG} />
) : (
<Box className="hub-globe-css" aria-hidden>
<Box className="hub-globe-css-glow" />
<Box className="hub-globe-css-ring hub-globe-css-ring-a" />
<Box className="hub-globe-css-ring hub-globe-css-ring-b" />
<Box className="hub-globe-css-core" />
<Box className="hub-globe-css-dot hub-globe-css-dot-1" />
<Box className="hub-globe-css-dot hub-globe-css-dot-2" />
<Box className="hub-globe-css-dot hub-globe-css-dot-3" />
<Box className="hub-globe-css-path" />
</Box>
)}
<Box className="hub-floating-cards" aria-hidden>
<Box className="hub-float-card hub-fc-1">
<Txt>🏝️ 巴厘岛</Txt>
</Box>
<Box className="hub-float-card hub-fc-2">
<Txt>☕ 里斯本</Txt>
</Box>
<Box className="hub-float-card hub-fc-3">
<Txt>🏔️ 清迈</Txt>
</Box>
</Box>
</Box>
</Box>
<Box className="hub-hero-title hub-reveal visible">
<Txt>随处工作</Txt>
<Txt className="hub-gradient-text">自由生活</Txt>
</Box>
<Box className="hub-portal-grid hub-reveal visible">
{portals.map((portal) => (
<Box
key={portal.id}
className={`hub-portal-card${portal.main ? ' hub-portal-card--main' : ''}`}
onClick={() => goPath(INTERNAL_PORTALS[portal.id])}
>
<Box className="hub-portal-ico" aria-hidden>
<Txt>{portal.emoji}</Txt>
</Box>
<Txt className="hub-portal-name">
{cfg?.modules[portal.moduleKey]?.title || portal.name}
</Txt>
</Box>
))}
</Box>
</Box>
</Box>
</Box>
)
}
export default markPageShare(IndexPage)

View File

@ -18,7 +18,7 @@ export function goPage(url: string): void {
const qs = url.includes('?') ? url.slice(url.indexOf('?')) : '' const qs = url.includes('?') ? url.slice(url.indexOf('?')) : ''
const full = `${path}${qs}` const full = `${path}${qs}`
trackClick('页面跳转', { to: full }) trackClick('页面跳转', { to: full })
if (isH5 && path.includes('/pages/index')) { if (isH5 && (path.includes('/pages/home') || path.includes('/pages/index'))) {
Taro.redirectTo({ url: full }).catch(() => Taro.navigateTo({ url: full })) Taro.redirectTo({ url: full }).catch(() => Taro.navigateTo({ url: full }))
return return
} }
@ -28,7 +28,7 @@ export function goPage(url: string): void {
} }
export function goHome(): void { export function goHome(): void {
goPage('/pages/index/index') goPage('/pages/home/index')
} }
export function isTabPath(_url: string): boolean { export function isTabPath(_url: string): boolean {

View File

@ -26,7 +26,7 @@ export function markPageShare<T extends object>(Page: T): T {
*/ */
export function usePageShare(opts: PageShareOptions = {}) { export function usePageShare(opts: PageShareOptions = {}) {
const title = opts.title || DEFAULT_TITLE const title = opts.title || DEFAULT_TITLE
const path = opts.path || '/pages/index/index' const path = opts.path || '/pages/home/index'
const query = opts.query || '' const query = opts.query || ''
useDidShow(() => { useDidShow(() => {

View File

@ -19,6 +19,7 @@ const pxExclude = (file: string) =>
/[\\/]styles[\\/]h5-theme\.scss/.test(file) || /[\\/]styles[\\/]h5-theme\.scss/.test(file) ||
/[\\/]styles[\\/]weapp-parity\.scss/.test(file) || /[\\/]styles[\\/]weapp-parity\.scss/.test(file) ||
/[\\/]styles[\\/]page-rem\.scss/.test(file) || /[\\/]styles[\\/]page-rem\.scss/.test(file) ||
/[\\/]pages[\\/]home[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]index[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]index[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]nav[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]nav[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]book[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]book[\\/]index\.scss/.test(file) ||

View File

@ -10,6 +10,15 @@ pnpm --dir apps/miniprogram/weapp build:weapp # 或根目录 pnpm build:weapp
改页面请改 `apps/miniprogram/h5/src`,不要再复制一份 weapp/src。 改页面请改 `apps/miniprogram/h5/src`,不要再复制一份 weapp/src。
## 首页路径
| 路径 | 说明 |
|------|------|
| **`pages/home/`** | **唯一首页源码**(启动页 / 话题 / 体验码) |
| `pages/index/` | 兼容旧路径:`reLaunch` → home(勿与 home 共用组件入口,否则无页面 wxss → 微信 ENOENT) |
`home/index.scss` 已进 `pxExclude`(真 px)。话题链接填:`pages/home/index`。
## 包体与代码质量 ## 包体与代码质量
| 项 | 做法 | | 项 | 做法 |

View File

@ -24,6 +24,7 @@ const pxExclude = (file: string) =>
/[\\/]styles[\\/]h5-theme\.scss/.test(file) || /[\\/]styles[\\/]h5-theme\.scss/.test(file) ||
/[\\/]styles[\\/]weapp-parity\.scss/.test(file) || /[\\/]styles[\\/]weapp-parity\.scss/.test(file) ||
/[\\/]styles[\\/]page-rem\.scss/.test(file) || /[\\/]styles[\\/]page-rem\.scss/.test(file) ||
/[\\/]pages[\\/]home[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]index[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]index[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]nav[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]nav[\\/]index\.scss/.test(file) ||
/[\\/]pages[\\/]book[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]book[\\/]index\.scss/.test(file) ||
@ -90,6 +91,17 @@ export default defineConfig(async (merge) => {
path.join(weappNm, '@tarojs/plugin-platform-weapp'), path.join(weappNm, '@tarojs/plugin-platform-weapp'),
) )
// 导航图标不进包:运行时用 https://nomadro.cn/icons(代码质量:图片合计≤200K) // 导航图标不进包:运行时用 https://nomadro.cn/icons(代码质量:图片合计≤200K)
// watch 完成后补缺失页面 wxss(home/index 样式进 common 时 Taro 不落文件)
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { EnsurePageWxssPlugin } = require(path.join(
__dirname,
'..',
'scripts',
'ensure-page-wxss-plugin.cjs',
))
chain.plugin('ensure-page-wxss').use(EnsurePageWxssPlugin, [
{ pagesRoot: path.resolve(__dirname, '..', 'dist', 'pages') },
])
}, },
mini: { mini: {
enableSourceMap: false, enableSourceMap: false,

View File

@ -57,6 +57,22 @@ function stripInvalidShareKeys(pagesRoot) {
return n return n
} }
/** 样式进 common.wxss 时 Taro 可能不落页面 wxss,微信仍会 open 该文件 → ENOENT */
function ensurePageWxss(pagesRoot) {
if (!fs.existsSync(pagesRoot)) return 0
let n = 0
for (const name of fs.readdirSync(pagesRoot)) {
const dir = path.join(pagesRoot, name)
if (!fs.statSync(dir).isDirectory()) continue
const js = path.join(dir, 'index.js')
const wxss = path.join(dir, 'index.wxss')
if (!fs.existsSync(js) || fs.existsSync(wxss)) continue
fs.writeFileSync(wxss, '/* page styles live in common.wxss */\n')
n += 1
}
return n
}
const h5Src = path.join(root, '..', 'h5', 'src') const h5Src = path.join(root, '..', 'h5', 'src')
// 主包/分包历史图标一律删掉(改 CDN) // 主包/分包历史图标一律删掉(改 CDN)
@ -83,7 +99,9 @@ if (fs.existsSync(assetsSrc)) {
} }
} }
const stripped = stripInvalidShareKeys(path.join(root, out, 'pages')) const pagesRoot = path.join(root, out, 'pages')
const stripped = stripInvalidShareKeys(pagesRoot)
const stubWxss = ensurePageWxss(pagesRoot)
console.log( console.log(
`[copy-weapp-static] ${out}: icons=cdn assets=${assets} strippedShareJson=${stripped}`, `[copy-weapp-static] ${out}: icons=cdn assets=${assets} strippedShareJson=${stripped} stubWxss=${stubWxss}`,
) )

View File

@ -0,0 +1,49 @@
const fs = require('fs')
const path = require('path')
const STUB = '/* page styles live in common.wxss */\n'
function ensure(pagesRoot) {
if (!pagesRoot || !fs.existsSync(pagesRoot)) return 0
let n = 0
for (const name of fs.readdirSync(pagesRoot)) {
const dir = path.join(pagesRoot, name)
let st
try {
st = fs.statSync(dir)
} catch {
continue
}
if (!st.isDirectory()) continue
const js = path.join(dir, 'index.js')
const wxss = path.join(dir, 'index.wxss')
if (!fs.existsSync(js) || fs.existsSync(wxss)) continue
fs.writeFileSync(wxss, STUB)
n += 1
}
return n
}
/** 样式进 common 后缺页面 wxss → 微信 ENOENT;编译完成后补空文件 */
class EnsurePageWxssPlugin {
constructor(opts = {}) {
this.pagesRoot = opts.pagesRoot
}
apply(compiler) {
const run = () => {
const n = ensure(this.pagesRoot)
if (n > 0) {
console.log(`[ensure-page-wxss] stubbed ${n} page wxss under ${this.pagesRoot}`)
}
}
compiler.hooks.done.tap('EnsurePageWxssPlugin', () => {
run()
// Taro 部分资源可能略晚于 done 落盘
setTimeout(run, 300)
setTimeout(run, 1200)
})
}
}
module.exports = { EnsurePageWxssPlugin, ensure }