From bca8166f51dd325684af967f9ecc3f036fa7c838 Mon Sep 17 00:00:00 2001 From: yandadaFreedom <525966780@qq.com> Date: Tue, 31 Oct 2023 20:48:16 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81getEnterOptionsSy?= =?UTF-8?q?nc=20api=20&=20navigator=E7=BB=84=E4=BB=B6=E6=94=AF=E6=8C=81swi?= =?UTF-8?q?tchTab=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/api-proxy/src/web/api/index.js | 2 ++ packages/api-proxy/src/web/api/lifecycle/index.js | 12 ++++++++++++ packages/core/src/platform/createApp.js | 1 + .../lib/runtime/components/web/mpx-navigator.vue | 5 +++++ 4 files changed, 20 insertions(+) create mode 100644 packages/api-proxy/src/web/api/lifecycle/index.js diff --git a/packages/api-proxy/src/web/api/index.js b/packages/api-proxy/src/web/api/index.js index 25a28ad347..f66ad06d90 100644 --- a/packages/api-proxy/src/web/api/index.js +++ b/packages/api-proxy/src/web/api/index.js @@ -63,3 +63,5 @@ export * from './animation' // createIntersectionObserver export * from './create-intersection-observer' + +export * from './lifecycle' diff --git a/packages/api-proxy/src/web/api/lifecycle/index.js b/packages/api-proxy/src/web/api/lifecycle/index.js new file mode 100644 index 0000000000..c4eaf200a7 --- /dev/null +++ b/packages/api-proxy/src/web/api/lifecycle/index.js @@ -0,0 +1,12 @@ +import { isBrowser, throwSSRWarning } from '../../../common/js' +function getEnterOptionsSync () { + if (!isBrowser) { + throwSSRWarning('getEnterOptionsSync API is running in non browser environments') + return + } + return global.__mpxEnterOptions || {} +} + +export { + getEnterOptionsSync +} diff --git a/packages/core/src/platform/createApp.js b/packages/core/src/platform/createApp.js index 66279d2010..8598ac1575 100644 --- a/packages/core/src/platform/createApp.js +++ b/packages/core/src/platform/createApp.js @@ -43,6 +43,7 @@ export default function createApp (option, config = {}) { shareTicket: '', referrerInfo: {} } + global.__mpxEnterOptions = options this.$options.onLaunch && this.$options.onLaunch.call(this, options) global.__mpxAppCbs = global.__mpxAppCbs || { show: [], diff --git a/packages/webpack-plugin/lib/runtime/components/web/mpx-navigator.vue b/packages/webpack-plugin/lib/runtime/components/web/mpx-navigator.vue index 11c56994dc..29244fd6c7 100644 --- a/packages/webpack-plugin/lib/runtime/components/web/mpx-navigator.vue +++ b/packages/webpack-plugin/lib/runtime/components/web/mpx-navigator.vue @@ -50,6 +50,11 @@ url: this.url }) break + case 'switchTab': + mpx.switchTab && mpx.switchTab({ + url: this.url + }) + break } } }) From 7e25dab04b1acda865a9aee5f37d2013e90ace96 Mon Sep 17 00:00:00 2001 From: yandadaFreedom <525966780@qq.com> Date: Thu, 18 Jan 2024 20:32:22 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=AE=9DgetEnterOptionsSync=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/api-proxy/src/platform/api/lifecycle/index.ali.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/api-proxy/src/platform/api/lifecycle/index.ali.js diff --git a/packages/api-proxy/src/platform/api/lifecycle/index.ali.js b/packages/api-proxy/src/platform/api/lifecycle/index.ali.js new file mode 100644 index 0000000000..cde6425113 --- /dev/null +++ b/packages/api-proxy/src/platform/api/lifecycle/index.ali.js @@ -0,0 +1,7 @@ +function getEnterOptionsSync () { + my.getEnterOptionsSync() +} + +export { + getEnterOptionsSync +} From ef2b86537f3faa720b7d41aefe41ea40be30281c Mon Sep 17 00:00:00 2001 From: xuegan Date: Mon, 22 Jan 2024 15:03:51 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=E8=A1=A5=E5=85=85=E8=B7=A8=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E8=BE=93=E5=87=BAmode=E7=9B=B8=E5=85=B3=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs-vuepress/guide/advance/platform.md | 35 +++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/docs-vuepress/guide/advance/platform.md b/docs-vuepress/guide/advance/platform.md index 4180a9600c..cae4abd329 100644 --- a/docs-vuepress/guide/advance/platform.md +++ b/docs-vuepress/guide/advance/platform.md @@ -308,11 +308,35 @@ module.exports = { ``` -属性维度的编译也可以对整个节点进行条件编译,例如只想在百度小程序中输出某个节点: +属性维度的编译也可以对整个节点进行条件编译,例如只想在支付宝小程序中输出某个节点: ```html -this is view +this is view ``` +需要注意使用上述用法时,整个节点以及子节点都会被认为是支付宝小程序节点,在构建时框架不会对节点属性进行平台语法转换。 +```html + + + tap click + +``` +上述示例为错误写法,假如srcMode为微信小程序,用上述写法构建输出支付宝小程序时,bindtap 不会被转为 onTap,在支付宝平台执行时事件会无响应。 + +正确写法如下: +```html + + + tap click + +``` +有时开发者期望使用 @ali 这种方式仅控制节点的展示,保留节点属性的平台转换能力,为此 Mpx 实现了一个隐式属性条件编译能力 +```html + + + tap click + +``` +在对应的平台前加一个_,例如@_ali、@_swan、@_tt等,使用该隐式规则仅有条件编译能力,平台语法转换能力依旧。 有时候我们不仅需要对节点属性进行条件编译,可能还需要对节点标签进行条件编译。 @@ -416,6 +440,13 @@ env 属性维度的编译同样支持对整个节点或者节点标签名进行 this is a view component this is a view component ``` +如果只声明了 env,没有声明 mode,跨平台输出时框架对于节点属性默认会进行转换: +```html + +this is a view component +this is a view component +``` + ### 其他注意事项 * 当目标平台为支付宝时,需要启用支付宝最新的component2编译才能保障框架正常工作,关于component2[点此查看详情](https://docs.alipay.com/mini/framework/custom-component-overview); From b55e54f8337d9dd4e69a7d90ae8f1e4cf342ba55 Mon Sep 17 00:00:00 2001 From: xuegan Date: Mon, 22 Jan 2024 18:44:44 +0800 Subject: [PATCH 4/5] =?UTF-8?q?docs:=20=E4=BF=AE=E6=94=B9api/compile?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B8=AD=E7=9A=84externalClasses=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs-vuepress/api/compile.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs-vuepress/api/compile.md b/docs-vuepress/api/compile.md index 262c147156..db4a027df6 100644 --- a/docs-vuepress/api/compile.md +++ b/docs-vuepress/api/compile.md @@ -160,7 +160,7 @@ module.exports = defineConfig({ ``` ::: warning -抹平支付宝和微信之间的差异,微信转支付宝时可以使用该功能。 +抹平支付宝和微信之间的差异,当使用了微信 **externalClasses** 语法时,跨端输出需要在 @mpxjs/webpack-plugin 的配置中添加此配置来辅助框架进行转换。 ::: ### resolveMode From ff0f09623967bae904a9e4b911a6586d5b2115dd Mon Sep 17 00:00:00 2001 From: xuegan Date: Mon, 22 Jan 2024 19:26:47 +0800 Subject: [PATCH 5/5] =?UTF-8?q?docs:=20=E8=B0=83=E6=95=B4=E8=B7=A8?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E8=BE=93=E5=87=BA=E6=97=B6mode=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E7=BC=96=E8=AF=91=E7=9B=B8=E5=85=B3=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs-vuepress/guide/advance/platform.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/docs-vuepress/guide/advance/platform.md b/docs-vuepress/guide/advance/platform.md index cae4abd329..f707c12e00 100644 --- a/docs-vuepress/guide/advance/platform.md +++ b/docs-vuepress/guide/advance/platform.md @@ -313,30 +313,36 @@ module.exports = { ```html this is view ``` -需要注意使用上述用法时,整个节点以及子节点都会被认为是支付宝小程序节点,在构建时框架不会对节点属性进行平台语法转换。 +需要注意使用上述用法时,节点自身在构建时框架不会对节点属性进行平台语法转换,但对于其子节点,框架并不会继承父级节点 mode,会进行正常跨平台语法转换。 ```html - + tap click +// srcMode 为 wx 跨端输出 ali 结果为 + + tap click + ``` -上述示例为错误写法,假如srcMode为微信小程序,用上述写法构建输出支付宝小程序时,bindtap 不会被转为 onTap,在支付宝平台执行时事件会无响应。 +上述示例为错误写法,假如srcMode为微信小程序,用上述写法构建输出支付宝小程序时,父节点 bindtap 不会被转为 onTap,在支付宝平台执行时事件会无响应。 正确写法如下: ```html - + + tap click + +// 输出 ali 产物 + tap click ``` 有时开发者期望使用 @ali 这种方式仅控制节点的展示,保留节点属性的平台转换能力,为此 Mpx 实现了一个隐式属性条件编译能力 ```html - - tap click - +test ``` -在对应的平台前加一个_,例如@_ali、@_swan、@_tt等,使用该隐式规则仅有条件编译能力,平台语法转换能力依旧。 +在对应的平台前加一个_,例如@_ali、@_swan、@_tt等,使用该隐式规则仅有条件编译能力,节点属性语法转换能力依旧。 有时候我们不仅需要对节点属性进行条件编译,可能还需要对节点标签进行条件编译。