diff --git a/packages/uni-app-plus/dist/uni-app-service.es.js b/packages/uni-app-plus/dist/uni-app-service.es.js index cb55443c05fd406c2340027312aa3ffd82a52996..0f1ef1e390133887e0cb0ab7bab93c3c23591739 100644 --- a/packages/uni-app-plus/dist/uni-app-service.es.js +++ b/packages/uni-app-plus/dist/uni-app-service.es.js @@ -17216,6 +17216,14 @@ var serviceContext = (function (vue) { } } + const downgrade = plus.os.name === 'Android' && parseInt(plus.os.version) < 6; + const ANI_SHOW = downgrade ? 'slide-in-right' : 'pop-in'; + const ANI_DURATION = 300; + const ANI_CLOSE = downgrade ? 'slide-out-right' : 'pop-out'; + const VIEW_WEBVIEW_PATH = '_www/__uniappview.html'; + const WEBVIEW_ID_PREFIX = 'webviewId'; + const SDK_UNI_MP_NATIVE_EVENT = 'uniMPNativeEvent'; + function initGlobalEvent() { const plusGlobalEvent = plus.globalEvent; const weexGlobalEvent = weex.requireModule('globalEvent'); @@ -17254,6 +17262,11 @@ var serviceContext = (function (vue) { }); } }); + weexGlobalEvent.addEventListener(SDK_UNI_MP_NATIVE_EVENT, function (res) { + if (res && res.event) { + emit(SDK_UNI_MP_NATIVE_EVENT + '.' + res.event, res.data); + } + }); plusGlobalEvent.addEventListener('plusMessage', subscribePlusMessage); // nvue webview post message plusGlobalEvent.addEventListener('WebviewPostMessage', subscribePlusMessage); @@ -17484,13 +17497,6 @@ var serviceContext = (function (vue) { }); } - const downgrade = plus.os.name === 'Android' && parseInt(plus.os.version) < 6; - const ANI_SHOW = downgrade ? 'slide-in-right' : 'pop-in'; - const ANI_DURATION = 300; - const ANI_CLOSE = downgrade ? 'slide-out-right' : 'pop-out'; - const VIEW_WEBVIEW_PATH = '_www/__uniappview.html'; - const WEBVIEW_ID_PREFIX = 'webviewId'; - function initNVue(webviewStyle, routeMeta, path) { if (path && routeMeta.isNVue) { webviewStyle.uniNView = { @@ -19160,7 +19166,11 @@ var serviceContext = (function (vue) { } resolve(); }); - }); + }); + function onHostEventReceive(name, fn) { + UniServiceJSBridge.on(SDK_UNI_MP_NATIVE_EVENT + '.' + name, fn); + } + const onNativeEventReceive = onHostEventReceive; const EventType = { load: 'load', @@ -19929,6 +19939,8 @@ var serviceContext = (function (vue) { restoreGlobal: restoreGlobal, sendHostEvent: sendHostEvent, navigateToMiniProgram: navigateToMiniProgram, + onHostEventReceive: onHostEventReceive, + onNativeEventReceive: onNativeEventReceive, createRewardedVideoAd: createRewardedVideoAd, createFullScreenVideoAd: createFullScreenVideoAd, createInterstitialAd: createInterstitialAd, diff --git a/packages/uni-app-plus/src/service/api/plugin/sdk.ts b/packages/uni-app-plus/src/service/api/plugin/sdk.ts index 724b2545e2f8f99d60bcf3d8f28dcc2ad66b1fe3..0601537efc96246b601b0b889995dc36a1f7a02e 100644 --- a/packages/uni-app-plus/src/service/api/plugin/sdk.ts +++ b/packages/uni-app-plus/src/service/api/plugin/sdk.ts @@ -1,5 +1,6 @@ import { defineAsyncApi } from '@dcloudio/uni-api' import { sendNativeEvent } from './requireNativePlugin' +import { SDK_UNI_MP_NATIVE_EVENT } from '../../constants' export const sendHostEvent = sendNativeEvent @@ -26,3 +27,12 @@ export const navigateToMiniProgram = }) } ) + +export function onHostEventReceive( + name: string, + fn: (...args: unknown[]) => void +) { + UniServiceJSBridge.on(SDK_UNI_MP_NATIVE_EVENT + '.' + name, fn) +} + +export const onNativeEventReceive = onHostEventReceive diff --git a/packages/uni-app-plus/src/service/constants.ts b/packages/uni-app-plus/src/service/constants.ts index b06e91eb46df1c8e3f22ab3110a0ee743df3e2ef..928583c777ea1ed48f2f527f134d657bc195931f 100644 --- a/packages/uni-app-plus/src/service/constants.ts +++ b/packages/uni-app-plus/src/service/constants.ts @@ -8,3 +8,5 @@ export const ANI_CLOSE = downgrade ? 'slide-out-right' : 'pop-out' export const VIEW_WEBVIEW_PATH = '_www/__uniappview.html' export const WEBVIEW_ID_PREFIX = 'webviewId' + +export const SDK_UNI_MP_NATIVE_EVENT = 'uniMPNativeEvent' diff --git a/packages/uni-app-plus/src/service/framework/app/initGlobalEvent.ts b/packages/uni-app-plus/src/service/framework/app/initGlobalEvent.ts index 7cc34dfeda5ae80472e1d468dfb7776f4d3527d8..d1851a7975502515cc7075021f4b6ea2e1756b18 100644 --- a/packages/uni-app-plus/src/service/framework/app/initGlobalEvent.ts +++ b/packages/uni-app-plus/src/service/framework/app/initGlobalEvent.ts @@ -5,6 +5,7 @@ import { ON_THEME_CHANGE, ON_KEYBOARD_HEIGHT_CHANGE, } from '@dcloudio/uni-shared' +import { SDK_UNI_MP_NATIVE_EVENT } from '../../constants' import { EVENT_BACKBUTTON, backbuttonListener, @@ -62,6 +63,15 @@ export function initGlobalEvent() { } ) + weexGlobalEvent.addEventListener( + SDK_UNI_MP_NATIVE_EVENT, + function (res: { event: string; data: unknown }) { + if (res && res.event) { + emit(SDK_UNI_MP_NATIVE_EVENT + '.' + res.event, res.data) + } + } + ) + plusGlobalEvent.addEventListener('plusMessage', subscribePlusMessage) // nvue webview post message plusGlobalEvent.addEventListener('WebviewPostMessage', subscribePlusMessage) diff --git a/packages/uni-h5-vite/src/index.ts b/packages/uni-h5-vite/src/index.ts index 9e7b6bd0ccc51117c71088d3dd0cfc726b4fb231..b5def064fd3c6ef4f8d0d5b19c422b6f3dca9eb2 100644 --- a/packages/uni-h5-vite/src/index.ts +++ b/packages/uni-h5-vite/src/index.ts @@ -6,7 +6,7 @@ import { uniViteInjectPlugin, UNI_EASYCOM_EXCLUDE, } from '@dcloudio/uni-cli-shared' -import { uniH5PLugin } from './plugin' +import { uniH5Plugin } from './plugin' import { uniCssPlugin } from './plugins/css' import { uniEasycomPlugin } from './plugins/easycom' import { uniInjectPlugin } from './plugins/inject' @@ -35,5 +35,5 @@ export default [ uniSSRPlugin(), uniSetupPlugin(), uniRenderjsPlugin(), - uniH5PLugin(), + uniH5Plugin(), ] diff --git a/packages/uni-h5-vite/src/plugin/index.ts b/packages/uni-h5-vite/src/plugin/index.ts index ff185f7b97f2f8b0f4238c3a082e4f4e1a83828c..bd607f9856a30d447c08a6e54394ef3afb52960c 100644 --- a/packages/uni-h5-vite/src/plugin/index.ts +++ b/packages/uni-h5-vite/src/plugin/index.ts @@ -10,7 +10,7 @@ import { createUni } from './uni' import { createConfig } from './config' import { isString } from '@vue/shared' -export function uniH5PLugin(): UniVitePlugin { +export function uniH5Plugin(): UniVitePlugin { const configOptions: { resolvedConfig: ResolvedConfig | null } = {