From 567d6a121ca747c65afd75b2b5df817cd9bb61c7 Mon Sep 17 00:00:00 2001 From: mackwang Date: Wed, 24 Jun 2026 16:10:00 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20web=E6=94=AF=E6=8C=81titlebar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/wx/component-config/index.js | 2 + .../template/wx/component-config/titlebar.js | 12 + .../runtime/components/web/mpx-titlebar.vue | 248 ++++++++++++++++++ .../lib/template-compiler/compiler.js | 9 +- .../lib/utils/dom-tag-config.js | 4 +- 5 files changed, 272 insertions(+), 3 deletions(-) create mode 100644 packages/webpack-plugin/lib/platform/template/wx/component-config/titlebar.js create mode 100644 packages/webpack-plugin/lib/runtime/components/web/mpx-titlebar.vue diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/index.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/index.js index b5a65229fb..87fc21394e 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/index.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/index.js @@ -44,6 +44,7 @@ const customBuiltInComponent = require('./custom-built-in-component') const rootPortal = require('./root-portal') const stickyHeader = require('./sticky-header') const stickySection = require('./sticky-section') +const titlebar = require('./titlebar') /** * 未命中上方任一组件 test 的标签,仍须走 normalizeComponentRules 中的通用 @@ -144,6 +145,7 @@ module.exports = function getComponentConfigs ({ warn, error }) { rootPortal({ print }), stickyHeader({ print }), stickySection({ print }), + titlebar({ print }), defaultCatchAllComponentConfig() ] } diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/titlebar.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/titlebar.js new file mode 100644 index 0000000000..874f96666e --- /dev/null +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/titlebar.js @@ -0,0 +1,12 @@ +const TAG_NAME = 'titlebar' + +module.exports = function () { + return { + // 匹配标签名,可传递正则 + test: TAG_NAME, + web (tag, { el }) { + el.isBuiltIn = true + return 'mpx-titlebar' + } + } +} diff --git a/packages/webpack-plugin/lib/runtime/components/web/mpx-titlebar.vue b/packages/webpack-plugin/lib/runtime/components/web/mpx-titlebar.vue new file mode 100644 index 0000000000..3695e1259d --- /dev/null +++ b/packages/webpack-plugin/lib/runtime/components/web/mpx-titlebar.vue @@ -0,0 +1,248 @@ + + + diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index a077e024e4..ef3b5ea18d 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -2824,7 +2824,14 @@ function getVirtualHostRoot (options, meta) { } if (ctorType === 'page') { if (isWeb(mode)) { - return createASTElement('page') + const rootView = createASTElement('titlebar', [ + { + name: 'pageConfig', + value: '{{ this.$options.__mpxPageConfig }}' + } + ]) + processElement(rootView, rootView, options, meta) + return rootView } if (isReact(mode)) { const rootView = createASTElement('view', [ diff --git a/packages/webpack-plugin/lib/utils/dom-tag-config.js b/packages/webpack-plugin/lib/utils/dom-tag-config.js index a07accc10f..f7058b7893 100644 --- a/packages/webpack-plugin/lib/utils/dom-tag-config.js +++ b/packages/webpack-plugin/lib/utils/dom-tag-config.js @@ -65,7 +65,7 @@ const isNativeMiniTag = makeMap( 'sticky-section,functional-page-navigator,navigator,audio,camera,' + 'channel-live,channel-video,image,live-player,live-pusher,video,' + 'voip-room,map,canvas,web-view,ad,ad-custom,official-account,' + - 'open-data,native-component,aria-component,page-meta' + 'open-data,native-component,aria-component,page-meta,titlebar' ) /** @@ -78,7 +78,7 @@ const isBuildInWebTag = makeMap( 'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' + 'mpx-switch,mpx-web-view,mpx-checkbox,mpx-movable-view,mpx-radio,' + 'mpx-form,mpx-navigator,mpx-rich-text,' + - 'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text' + 'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text,mpx-titlebar' ) /** From e518c9e1086448079bf6157a45e282afcc9cbdd0 Mon Sep 17 00:00:00 2001 From: mackwang Date: Wed, 24 Jun 2026 16:13:27 +0800 Subject: [PATCH 2/4] =?UTF-8?q?docs:=20web=E6=94=AF=E6=8C=81titlebar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs-vitepress/api/app-config.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs-vitepress/api/app-config.md b/docs-vitepress/api/app-config.md index 2effb37fc1..871e7d3418 100644 --- a/docs-vitepress/api/app-config.md +++ b/docs-vitepress/api/app-config.md @@ -178,3 +178,32 @@ mpx.config.webConfig.routeConfig = { mpx.config.webConfig.disablePageTransition = true ``` 此处的 `disablePageTransition` 后续将被废弃,请使用编译阶段的[disablePageTransition](compile.md#webconfig)进行配置 + +### webConfig.enableTitleBar + +`boolean = false` + +是否在 Web 输出时启用内置标题栏(`mpx-titlebar`)组件。默认为 `false`,即不渲染标题栏。 + +设为 `true` 后,Mpx 会在每个页面的根节点外层自动注入 `` 组件,读取 `app.json` 的 `window` 配置及当前页面 json 配置,渲染与小程序视觉一致的 fixed 标题栏(含安全区适配与返回按钮)。 + +> **注意**:若页面 json 中将 `navigationStyle` 配置为 `'custom'`,则该页面的标题栏会自动隐藏,以支持自定义导航栏场景。 + +```js +import mpx from '@mpxjs/core' + +mpx.config.webConfig.enableTitleBar = true +``` + +### webConfig.safeAreaInsetTop + +`number = 24` + +在 **Android** 设备上,标题栏顶部安全区(状态栏)的高度(单位:px)。仅在 `enableTitleBar` 为 `true` 且非 iOS 设备时生效;iOS 设备会自动使用 `env(safe-area-inset-top)` 获取安全区高度,无需手动配置。 + +```js +import mpx from '@mpxjs/core' + +// 将 Android 状态栏高度设为 28px(默认 24px) +mpx.config.webConfig.safeAreaInsetTop = 28 +``` From 5832646861cc83932f824da06ab03f9e53f10246 Mon Sep 17 00:00:00 2001 From: mackwang Date: Wed, 1 Jul 2026 18:13:34 +0800 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20web=20titlebar=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=9C=A8=20processTemplate=20=E4=B8=AD=E6=8C=89?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=8F=92=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 compiler.js 中 page+web 模式下插入 titlebar AST 节点的逻辑,还原为 createASTElement('page') - 删除 platform/template/wx/component-config/titlebar.js 及其注册 - 移除 dom-tag-config.js 中 mpx-titlebar 的 isBuildInWebTag 注册 - processTemplate.js 中对 page 类型按编译期 navigationStyle 判断插入 mpx-titlebar,注册为 builtInComponent 而非全局组件 - processJSON.js 处理 app 时写入 mpx.appJson 供编译期复用 - mpx-titlebar.vue:简化 props(移除 windowConfig,pageConfig 接收已合并配置)、移除冗余 cfg computed、navigator.userAgent 移至 computed 避免 SSR 崩溃、删除 console.log Co-Authored-By: Claude Opus 4.6 --- .../template/wx/component-config/index.js | 2 - .../template/wx/component-config/titlebar.js | 12 ------ .../runtime/components/web/mpx-titlebar.vue | 35 +++++++---------- .../lib/template-compiler/compiler.js | 9 +---- .../lib/utils/dom-tag-config.js | 2 +- packages/webpack-plugin/lib/web/index.js | 3 +- .../webpack-plugin/lib/web/processJSON.js | 5 ++- .../webpack-plugin/lib/web/processTemplate.js | 38 ++++++++++++++++++- 8 files changed, 59 insertions(+), 47 deletions(-) delete mode 100644 packages/webpack-plugin/lib/platform/template/wx/component-config/titlebar.js diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/index.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/index.js index 87fc21394e..b5a65229fb 100644 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/index.js +++ b/packages/webpack-plugin/lib/platform/template/wx/component-config/index.js @@ -44,7 +44,6 @@ const customBuiltInComponent = require('./custom-built-in-component') const rootPortal = require('./root-portal') const stickyHeader = require('./sticky-header') const stickySection = require('./sticky-section') -const titlebar = require('./titlebar') /** * 未命中上方任一组件 test 的标签,仍须走 normalizeComponentRules 中的通用 @@ -145,7 +144,6 @@ module.exports = function getComponentConfigs ({ warn, error }) { rootPortal({ print }), stickyHeader({ print }), stickySection({ print }), - titlebar({ print }), defaultCatchAllComponentConfig() ] } diff --git a/packages/webpack-plugin/lib/platform/template/wx/component-config/titlebar.js b/packages/webpack-plugin/lib/platform/template/wx/component-config/titlebar.js deleted file mode 100644 index 874f96666e..0000000000 --- a/packages/webpack-plugin/lib/platform/template/wx/component-config/titlebar.js +++ /dev/null @@ -1,12 +0,0 @@ -const TAG_NAME = 'titlebar' - -module.exports = function () { - return { - // 匹配标签名,可传递正则 - test: TAG_NAME, - web (tag, { el }) { - el.isBuiltIn = true - return 'mpx-titlebar' - } - } -} diff --git a/packages/webpack-plugin/lib/runtime/components/web/mpx-titlebar.vue b/packages/webpack-plugin/lib/runtime/components/web/mpx-titlebar.vue index 3695e1259d..de689ecc23 100644 --- a/packages/webpack-plugin/lib/runtime/components/web/mpx-titlebar.vue +++ b/packages/webpack-plugin/lib/runtime/components/web/mpx-titlebar.vue @@ -1,46 +1,34 @@