提交 3321b0aa 编写于 作者: fxy060608's avatar fxy060608

feat(v3): add onWebInvokeService

上级 f20a6cad
......@@ -2481,8 +2481,8 @@ var serviceContext = (function () {
/**
* 触发 service 层,与 onMethod 对应
*/
function publish (name, res) {
return UniServiceJSBridge.emit('api.' + name, res)
function publish (name, ...args) {
return UniServiceJSBridge.emit('api.' + name, ...args)
}
let lastStatusBarStyle;
......@@ -9329,7 +9329,7 @@ var serviceContext = (function () {
function onWebInvokeAppService ({
name,
arg
}, pageId) {
}, pageIds) {
if (name === 'postMessage') ; else {
uni[name](arg);
}
......@@ -9438,6 +9438,7 @@ var serviceContext = (function () {
const WEBVIEW_READY = 'webviewReady';
const VD_SYNC_CALLBACK = 'vdSyncCallback';
const INVOKE_API = 'invokeApi';
const WEB_INVOKE_APPSERVICE$1 = 'WEB_INVOKE_APPSERVICE';
function perf (type, startTime) {
/* eslint-disable no-undef */
......@@ -9527,6 +9528,8 @@ var serviceContext = (function () {
function initSubscribeHandlers () {
const {
on,
emit,
subscribe,
publishHandler,
subscribeHandler
......@@ -9549,6 +9552,10 @@ var serviceContext = (function () {
// 防止首页 webview 初始化过早, service 还未开始监听
publishHandler(WEBVIEW_READY, Object.create(null), [1]);
}
// 应该使用subscribe,兼容老版本先用 on api 吧
on('api.' + WEB_INVOKE_APPSERVICE$1, function (data, webviewIds) {
emit('onWebInvokeAppService', data, webviewIds);
});
subscribe(VD_SYNC, onVdSync);
subscribe(VD_SYNC_CALLBACK, onVdSyncCallback);
......
......@@ -53,7 +53,7 @@ export default function initOn (on, {
function onWebInvokeAppService ({
name,
arg
}, pageId) {
}, pageIds) {
if (name === 'postMessage') {
// TODO 小程序后退、组件销毁、分享时通知
} else {
......
......@@ -7,7 +7,8 @@ export {
pack,
unpack,
invoke
} from 'uni-core/service/bridge'
}
from 'uni-core/service/bridge'
export function requireNativePlugin (name) {
return uni.requireNativePlugin(name)
......@@ -16,8 +17,8 @@ export function requireNativePlugin (name) {
/**
* 触发 service 层,与 onMethod 对应
*/
export function publish (name, res) {
return UniServiceJSBridge.emit('api.' + name, res)
export function publish (name, ...args) {
return UniServiceJSBridge.emit('api.' + name, ...args)
}
let lastStatusBarStyle
......@@ -74,4 +75,4 @@ export function base64ToArrayBuffer (data) {
export function arrayBufferToBase64 (data) {
return encode(data)
}
}
......@@ -18,10 +18,11 @@ import onVdSync from './on-vd-sync'
import onVdSyncCallback from './on-vd-sync-callback'
import onInvokeApi from './on-invoke-api'
import onWebInvokeApi from './on-web-invoke-api'
export function initSubscribeHandlers () {
const {
on,
emit,
subscribe,
publishHandler,
subscribeHandler
......@@ -36,8 +37,6 @@ export function initSubscribeHandlers () {
subscribeHandler(data.type, data.data, data.pageId)
})
registerPlusMessage(WEB_INVOKE_APPSERVICE, onWebInvokeApi)
subscribe(WEBVIEW_READY, onWebviewReady)
const entryPagePath = '/' + __uniConfig.entryPagePath
......@@ -46,6 +45,10 @@ export function initSubscribeHandlers () {
// 防止首页 webview 初始化过早, service 还未开始监听
publishHandler(WEBVIEW_READY, Object.create(null), [1])
}
// 应该使用subscribe,兼容老版本先用 on api 吧
on('api.' + WEB_INVOKE_APPSERVICE, function (data, webviewIds) {
emit('onWebInvokeAppService', data, webviewIds)
})
subscribe(VD_SYNC, onVdSync)
subscribe(VD_SYNC_CALLBACK, onVdSyncCallback)
......
export default function onInvokeApi (data) {
// TODO
console.log('onInvokeApi', data)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册