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

feat(v3): add onWebInvokeService

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