From dc7a46ee0b20d99b6025635abecbf28ab723065e Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 11 Oct 2026 16:03:31 +0800 Subject: [PATCH] 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 --- README.md | 9 +- apps/miniprogram/h5/src/app.config.ts | 8 +- apps/miniprogram/h5/src/components/Chrome.tsx | 4 +- apps/miniprogram/h5/src/pages/game/index.tsx | 2 +- .../h5/src/pages/home/index.config.ts | 5 + apps/miniprogram/h5/src/pages/home/index.scss | 2 + apps/miniprogram/h5/src/pages/home/index.tsx | 430 +++++++++++++++++ .../h5/src/pages/index/index.config.ts | 1 - .../miniprogram/h5/src/pages/index/index.scss | 6 +- apps/miniprogram/h5/src/pages/index/index.tsx | 432 +----------------- apps/miniprogram/h5/src/utils/nav.ts | 4 +- apps/miniprogram/h5/src/utils/pageShare.ts | 2 +- apps/miniprogram/tt/config/index.ts | 1 + apps/miniprogram/weapp/README.md | 9 + apps/miniprogram/weapp/config/index.ts | 12 + .../weapp/scripts/copy-weapp-static.mjs | 22 +- .../weapp/scripts/ensure-page-wxss-plugin.cjs | 49 ++ 17 files changed, 559 insertions(+), 439 deletions(-) create mode 100644 apps/miniprogram/h5/src/pages/home/index.config.ts create mode 100644 apps/miniprogram/h5/src/pages/home/index.scss create mode 100644 apps/miniprogram/h5/src/pages/home/index.tsx create mode 100644 apps/miniprogram/weapp/scripts/ensure-page-wxss-plugin.cjs diff --git a/README.md b/README.md index 76e10e9..9bdf01f 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,11 @@ pnpm dev:api - **发布流**:本地调试 → 当前开发分支 commit/push → 部署脚本上线 → 冒烟;配置与发版均以 git 为准 - 主开发分支:`pre4`(`pre3` 已封存本轮);发版前与 README / 远程对齐 +## pre4 摘要 + +- 微信启动页改为 **`pages/home/index`**(话题/体验码同路径);`pages/index` 兼容跳转 +- 首页样式源码在 `h5/src/pages/home`,`home/index.scss` 进 weapp `pxExclude`(真 px) + ## pre3 摘要(已合入) 微信提审与包体: @@ -126,4 +131,6 @@ pnpm dev:api - **安全区**:自定义顶栏内联尺寸用大写 `PX` 跳过 Taro rpx;阅读页顶栏不再叠状态栏 padding - **代码质量**:`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`。 diff --git a/apps/miniprogram/h5/src/app.config.ts b/apps/miniprogram/h5/src/app.config.ts index a0f7872..2b41a31 100644 --- a/apps/miniprogram/h5/src/app.config.ts +++ b/apps/miniprogram/h5/src/app.config.ts @@ -5,7 +5,7 @@ const tabBar = { borderStyle: 'black', list: [ { - pagePath: 'pages/index/index', + pagePath: 'pages/home/index', text: '首页', iconPath: 'assets/tab/home.png', selectedIconPath: 'assets/tab/home-active.png', @@ -47,7 +47,8 @@ const wantTabBar = !isH5 && process.env.TARO_APP_TABBAR === '1' /** 微信主包必须 ≤1.5MB:首页/我的留主包,其余进分包 */ 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: [ { root: 'pages/nav', @@ -136,7 +137,7 @@ const weappConfig = { }, ], preloadRule: { - 'pages/index/index': { + 'pages/home/index': { network: 'all', packages: ['book', 'nav'], }, @@ -147,6 +148,7 @@ const weappConfig = { const h5Config = { pages: [ + 'pages/home/index', 'pages/index/index', 'pages/nav/index', 'pages/community/index', diff --git a/apps/miniprogram/h5/src/components/Chrome.tsx b/apps/miniprogram/h5/src/components/Chrome.tsx index ac95a93..21796da 100644 --- a/apps/miniprogram/h5/src/components/Chrome.tsx +++ b/apps/miniprogram/h5/src/components/Chrome.tsx @@ -72,7 +72,7 @@ export function CommunityNavbar() { : undefined } > - goPage('/pages/index/index')} aria-label="返回首页"> + goPage('/pages/home/index')} aria-label="返回首页"> {isH5 ? ( ) : ( @@ -100,7 +100,7 @@ export function BrandNav({ const label = section || chip || '社群' return ( - goPage('/pages/index/index')}> + goPage('/pages/home/index')}> {isH5 ? ( goPage('/pages/index/index') + const back = () => goPage('/pages/home/index') const restart = () => gameRef.current?.restart() const interact = () => gameRef.current?.setInput({ interact: true }) diff --git a/apps/miniprogram/h5/src/pages/home/index.config.ts b/apps/miniprogram/h5/src/pages/home/index.config.ts new file mode 100644 index 0000000..9049f0f --- /dev/null +++ b/apps/miniprogram/h5/src/pages/home/index.config.ts @@ -0,0 +1,5 @@ +export default definePageConfig({ + navigationBarTitleText: 'Nomadro', + // 对齐 H5:自定义顶栏,去掉原生导航栏占位 + navigationStyle: 'custom', +}) diff --git a/apps/miniprogram/h5/src/pages/home/index.scss b/apps/miniprogram/h5/src/pages/home/index.scss new file mode 100644 index 0000000..baf76f5 --- /dev/null +++ b/apps/miniprogram/h5/src/pages/home/index.scss @@ -0,0 +1,2 @@ +@use '../../styles/hub.scss'; +@import '../../styles/weapp-parity.scss'; diff --git a/apps/miniprogram/h5/src/pages/home/index.tsx b/apps/miniprogram/h5/src/pages/home/index.tsx new file mode 100644 index 0000000..e9ef08d --- /dev/null +++ b/apps/miniprogram/h5/src/pages/home/index.tsx @@ -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 = { + 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 = `` + +const GLOBE_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 ( +
+ {html ? undefined : children} +
+ ) + } + return ( + + {html ? undefined : children} + + ) +} + +function Txt({ className, children }: { className?: string; children?: ReactNode }) { + if (isH5) return {children} + return {children} +} + +function IndexPage() { + usePageTrack('pages/home/index', '首页') + usePageShare({ title: 'nomadro · 随处工作,自由生活', path: '/pages/home/index' }) + + const [config, setConfig] = useState(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 ( + + {isH5 ? : null} + + + + + {isH5 ? ( + + ) : ( + + + + + )} + {brand} + + + {showQuickNav && isH5 && isDev ? ( + + openDevLink('admin')}> + Admin + + openDevLink('config')}> + Config + + + ) : null} + + + + + + + + + + + + + + + {isH5 ? ( + + ) : ( + + + + + + + + + + + )} + + + 🏝️ 巴厘岛 + + + ☕ 里斯本 + + + 🏔️ 清迈 + + + + + + + 随处工作 + 自由生活 + + + + {portals.map((portal) => ( + goPath(INTERNAL_PORTALS[portal.id])} + > + + {portal.emoji} + + + {cfg?.modules[portal.moduleKey]?.title || portal.name} + + + ))} + + + + + ) +} + +export default markPageShare(IndexPage) diff --git a/apps/miniprogram/h5/src/pages/index/index.config.ts b/apps/miniprogram/h5/src/pages/index/index.config.ts index 9049f0f..dacee01 100644 --- a/apps/miniprogram/h5/src/pages/index/index.config.ts +++ b/apps/miniprogram/h5/src/pages/index/index.config.ts @@ -1,5 +1,4 @@ export default definePageConfig({ navigationBarTitleText: 'Nomadro', - // 对齐 H5:自定义顶栏,去掉原生导航栏占位 navigationStyle: 'custom', }) diff --git a/apps/miniprogram/h5/src/pages/index/index.scss b/apps/miniprogram/h5/src/pages/index/index.scss index baf76f5..f1b9e56 100644 --- a/apps/miniprogram/h5/src/pages/index/index.scss +++ b/apps/miniprogram/h5/src/pages/index/index.scss @@ -1,2 +1,4 @@ -@use '../../styles/hub.scss'; -@import '../../styles/weapp-parity.scss'; +/* 占位:保证本页生成 index.wxss;视觉在 home */ +.index-alias { + min-height: 0; +} diff --git a/apps/miniprogram/h5/src/pages/index/index.tsx b/apps/miniprogram/h5/src/pages/index/index.tsx index 524e918..7ed7ef1 100644 --- a/apps/miniprogram/h5/src/pages/index/index.tsx +++ b/apps/miniprogram/h5/src/pages/index/index.tsx @@ -1,430 +1,14 @@ /** - * 对齐门户 components/sections/hero.tsx(结构 / PORTALS / 开发快捷入口) - * H5 真布局用原生 div(Taro View 自定义元素会弄塌 grid/绝对定位)。 + * 兼容旧路径:跳转到唯一首页 pages/home/index。 + * 不可与 home 共用组件入口,否则样式进 common.wxss、两页都不落 index.wxss → 微信 ENOENT。 */ -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 { View } from '@tarojs/components' +import Taro, { useLoad } from '@tarojs/taro' 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 = { - 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 = `` - -const GLOBE_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', +export default function IndexAliasPage() { + useLoad(() => { + void Taro.reLaunch({ url: '/pages/home/index' }) }) + return } - -/** 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 ( -
- {html ? undefined : children} -
- ) - } - return ( - - {html ? undefined : children} - - ) -} - -function Txt({ className, children }: { className?: string; children?: ReactNode }) { - if (isH5) return {children} - return {children} -} - -function IndexPage() { - usePageTrack('pages/index/index', '首页') - usePageShare({ title: 'nomadro · 随处工作,自由生活', path: '/pages/index/index' }) - - const [config, setConfig] = useState(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 ( - - {isH5 ? : null} - - - - - {isH5 ? ( - - ) : ( - - - - - )} - {brand} - - - {showQuickNav && isH5 && isDev ? ( - - openDevLink('admin')}> - Admin - - openDevLink('config')}> - Config - - - ) : null} - - - - - - - - - - - - - - - {isH5 ? ( - - ) : ( - - - - - - - - - - - )} - - - 🏝️ 巴厘岛 - - - ☕ 里斯本 - - - 🏔️ 清迈 - - - - - - - 随处工作 - 自由生活 - - - - {portals.map((portal) => ( - goPath(INTERNAL_PORTALS[portal.id])} - > - - {portal.emoji} - - - {cfg?.modules[portal.moduleKey]?.title || portal.name} - - - ))} - - - - - ) -} - -export default markPageShare(IndexPage) diff --git a/apps/miniprogram/h5/src/utils/nav.ts b/apps/miniprogram/h5/src/utils/nav.ts index c8b1a2c..00d8e0b 100644 --- a/apps/miniprogram/h5/src/utils/nav.ts +++ b/apps/miniprogram/h5/src/utils/nav.ts @@ -18,7 +18,7 @@ export function goPage(url: string): void { const qs = url.includes('?') ? url.slice(url.indexOf('?')) : '' const full = `${path}${qs}` 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 })) return } @@ -28,7 +28,7 @@ export function goPage(url: string): void { } export function goHome(): void { - goPage('/pages/index/index') + goPage('/pages/home/index') } export function isTabPath(_url: string): boolean { diff --git a/apps/miniprogram/h5/src/utils/pageShare.ts b/apps/miniprogram/h5/src/utils/pageShare.ts index 89b8eb3..6acc0a2 100644 --- a/apps/miniprogram/h5/src/utils/pageShare.ts +++ b/apps/miniprogram/h5/src/utils/pageShare.ts @@ -26,7 +26,7 @@ export function markPageShare(Page: T): T { */ export function usePageShare(opts: PageShareOptions = {}) { const title = opts.title || DEFAULT_TITLE - const path = opts.path || '/pages/index/index' + const path = opts.path || '/pages/home/index' const query = opts.query || '' useDidShow(() => { diff --git a/apps/miniprogram/tt/config/index.ts b/apps/miniprogram/tt/config/index.ts index 3e2b74c..0e8488d 100644 --- a/apps/miniprogram/tt/config/index.ts +++ b/apps/miniprogram/tt/config/index.ts @@ -19,6 +19,7 @@ const pxExclude = (file: string) => /[\\/]styles[\\/]h5-theme\.scss/.test(file) || /[\\/]styles[\\/]weapp-parity\.scss/.test(file) || /[\\/]styles[\\/]page-rem\.scss/.test(file) || + /[\\/]pages[\\/]home[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]index[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]nav[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]book[\\/]index\.scss/.test(file) || diff --git a/apps/miniprogram/weapp/README.md b/apps/miniprogram/weapp/README.md index b1f8593..1b7ae03 100644 --- a/apps/miniprogram/weapp/README.md +++ b/apps/miniprogram/weapp/README.md @@ -10,6 +10,15 @@ pnpm --dir apps/miniprogram/weapp build:weapp # 或根目录 pnpm build:weapp 改页面请改 `apps/miniprogram/h5/src`,不要再复制一份 weapp/src。 +## 首页路径 + +| 路径 | 说明 | +|------|------| +| **`pages/home/`** | **唯一首页源码**(启动页 / 话题 / 体验码) | +| `pages/index/` | 兼容旧路径:`reLaunch` → home(勿与 home 共用组件入口,否则无页面 wxss → 微信 ENOENT) | + +`home/index.scss` 已进 `pxExclude`(真 px)。话题链接填:`pages/home/index`。 + ## 包体与代码质量 | 项 | 做法 | diff --git a/apps/miniprogram/weapp/config/index.ts b/apps/miniprogram/weapp/config/index.ts index e2a58e2..c414ef9 100644 --- a/apps/miniprogram/weapp/config/index.ts +++ b/apps/miniprogram/weapp/config/index.ts @@ -24,6 +24,7 @@ const pxExclude = (file: string) => /[\\/]styles[\\/]h5-theme\.scss/.test(file) || /[\\/]styles[\\/]weapp-parity\.scss/.test(file) || /[\\/]styles[\\/]page-rem\.scss/.test(file) || + /[\\/]pages[\\/]home[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]index[\\/]index\.scss/.test(file) || /[\\/]pages[\\/]nav[\\/]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'), ) // 导航图标不进包:运行时用 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: { enableSourceMap: false, diff --git a/apps/miniprogram/weapp/scripts/copy-weapp-static.mjs b/apps/miniprogram/weapp/scripts/copy-weapp-static.mjs index 727c8bb..0f9a5b2 100644 --- a/apps/miniprogram/weapp/scripts/copy-weapp-static.mjs +++ b/apps/miniprogram/weapp/scripts/copy-weapp-static.mjs @@ -57,6 +57,22 @@ function stripInvalidShareKeys(pagesRoot) { 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') // 主包/分包历史图标一律删掉(改 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( - `[copy-weapp-static] ${out}: icons=cdn assets=${assets} strippedShareJson=${stripped}`, + `[copy-weapp-static] ${out}: icons=cdn assets=${assets} strippedShareJson=${stripped} stubWxss=${stubWxss}`, ) diff --git a/apps/miniprogram/weapp/scripts/ensure-page-wxss-plugin.cjs b/apps/miniprogram/weapp/scripts/ensure-page-wxss-plugin.cjs new file mode 100644 index 0000000..31edaf7 --- /dev/null +++ b/apps/miniprogram/weapp/scripts/ensure-page-wxss-plugin.cjs @@ -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 }