提交 1ed294ad 编写于 作者: fxy060608's avatar fxy060608

chore: workflow (+1 squashed commit)

Squashed commits:
[328ce6a83] feat(app): add invokeServiceMethod
上级 7642a0ce
...@@ -393,7 +393,7 @@ declare namespace UniApp { ...@@ -393,7 +393,7 @@ declare namespace UniApp {
* @param event * @param event
* @param callback * @param callback
*/ */
subscribe(event: string, callback: CallbackFunction): void subscribe(event: string, callback: CallbackFunction, once?: boolean): void
/** /**
* 取消订阅 Service 的自定义事件 * 取消订阅 Service 的自定义事件
* 如果没有提供参数,则移除所有的事件监听器; * 如果没有提供参数,则移除所有的事件监听器;
...@@ -417,5 +417,16 @@ declare namespace UniApp { ...@@ -417,5 +417,16 @@ declare namespace UniApp {
* @param pageId * @param pageId
*/ */
publishHandler(event: string, args?: unknown, pageId?: number): void publishHandler(event: string, args?: unknown, pageId?: number): void
/**
* 执行 View 层方法,并获取返回值
* @param name
* @param args
* @param callback
*/
invokeServiceMethod<Args = any, Res = any>(
name: string,
args: Args,
callback?: (res: Res) => void
): void
} }
} }
...@@ -1143,7 +1143,37 @@ uni-input[hidden] { ...@@ -1143,7 +1143,37 @@ uni-input[hidden] {
.uni-label-pointer { .uni-label-pointer {
cursor: pointer; cursor: pointer;
} }
uni-movable-area { uni-map {
width: 300px;
height: 225px;
display: inline-block;
line-height: 0;
overflow: hidden;
position: relative;
}
uni-map[hidden] {
display: none;
}
.uni-map-container {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
background-color: black;
}
.uni-map-slot {
position: absolute;
top: 0;
width: 100%;
height: 100%;
overflow: hidden;
pointer-events: none;
}uni-movable-area {
display: block; display: block;
position: relative; position: relative;
width: 10px; width: 10px;
......
...@@ -2,8 +2,6 @@ export const VD_SYNC = 'vdSync' ...@@ -2,8 +2,6 @@ export const VD_SYNC = 'vdSync'
export const ON_WEBVIEW_READY = 'onWebviewReady' export const ON_WEBVIEW_READY = 'onWebviewReady'
export const INVOKE_SERVICE_API = 'invokeServiceApi'
export let ACTION_MINIFY = true export let ACTION_MINIFY = true
// __tests__ // __tests__
export function setActionMinify(minify: boolean) { export function setActionMinify(minify: boolean) {
......
import { registerServiceMethod } from '@dcloudio/uni-core'
export function subscribeAd() {
// view 层通过 UniViewJSBridge.invokeServiceMethod('getAdData', args, function({data})=>{console.log(data)})
registerServiceMethod('getAdData', (args, resolve) => {
// TODO args: view 层传输的参数,处理完之后,resolve:回传给 service,如resolve({data})
})
}
import { import { subscribeServiceMethod } from '@dcloudio/uni-core'
INVOKE_SERVICE_API, import { ON_WEBVIEW_READY, VD_SYNC } from '../../../../constants'
ON_WEBVIEW_READY,
VD_SYNC,
} from '../../../../constants'
import { onVdSync } from '../../dom' import { onVdSync } from '../../dom'
import { onPlusMessage } from '../initGlobalEvent' import { onPlusMessage } from '../initGlobalEvent'
import { subscribeAd } from './ad'
import { subscribeNavigator } from './navigator'
import { subscribeWebviewReady } from './webviewReady' import { subscribeWebviewReady } from './webviewReady'
export function initSubscribeHandlers() { export function initSubscribeHandlers() {
...@@ -21,14 +20,8 @@ export function initSubscribeHandlers() { ...@@ -21,14 +20,8 @@ export function initSubscribeHandlers() {
// 非纯原生 // 非纯原生
subscribe(ON_WEBVIEW_READY, subscribeWebviewReady) subscribe(ON_WEBVIEW_READY, subscribeWebviewReady)
subscribe(VD_SYNC, onVdSync) subscribe(VD_SYNC, onVdSync)
subscribe(INVOKE_SERVICE_API, onInvokeServiceApi) subscribeServiceMethod()
subscribeAd()
subscribeNavigator()
} }
} }
function onInvokeServiceApi({
data: { method, args },
}: {
data: { method: UniApp.OpenType; args: any }
}) {
uni[method] && uni[method](args)
}
import { registerServiceMethod } from '@dcloudio/uni-core'
const API_ROUTE = [
'switchTab',
'reLaunch',
'redirectTo',
'navigateTo',
'navigateBack',
] as const
export function subscribeNavigator() {
API_ROUTE.forEach((name) => {
registerServiceMethod(name, (args) => {
uni[name](args)
})
})
}
import { INVOKE_SERVICE_API } from '../../constants'
function invokeServiceApi(method: string, args: Record<string, any> = {}) {
UniViewJSBridge.publishHandler(INVOKE_SERVICE_API, {
data: {
method,
args,
},
options: {
timestamp: Date.now(),
},
})
}
export function navigateTo(args: Record<string, any>) { export function navigateTo(args: Record<string, any>) {
invokeServiceApi('navigateTo', args) UniViewJSBridge.invokeServiceMethod('navigateTo', args)
} }
export function navigateBack(args: Record<string, any>) { export function navigateBack(args: Record<string, any>) {
invokeServiceApi('navigateBack', args) UniViewJSBridge.invokeServiceMethod('navigateBack', args)
} }
export function reLaunch(args: Record<string, any>) { export function reLaunch(args: Record<string, any>) {
invokeServiceApi('reLaunch', args) UniViewJSBridge.invokeServiceMethod('reLaunch', args)
} }
export function redirectTo(args: Record<string, any>) { export function redirectTo(args: Record<string, any>) {
invokeServiceApi('redirectTo', args) UniViewJSBridge.invokeServiceMethod('redirectTo', args)
} }
export function switchTab(args: Record<string, any>) { export function switchTab(args: Record<string, any>) {
invokeServiceApi('switchTab', args) UniViewJSBridge.invokeServiceMethod('switchTab', args)
} }
export const INVOKE_VIEW_API = 'invokeViewApi' export const INVOKE_VIEW_API = 'invokeViewApi'
export const INVOKE_SERVICE_API = 'invokeServiceApi'
...@@ -2,3 +2,4 @@ export * from './i18n' ...@@ -2,3 +2,4 @@ export * from './i18n'
export * from './view' export * from './view'
export * from './service' export * from './service'
export * from './helpers' export * from './helpers'
export * from './constants'
import { extend } from '@vue/shared' import { extend } from '@vue/shared'
import { INVOKE_VIEW_API } from '../../constants'
import { getCurrentPageId } from '../../helpers'
import { initBridge } from '../../helpers/bridge' import { initBridge } from '../../helpers/bridge'
import { invokeOnCallback } from './invokeOnCallback'
let invokeViewMethodId = 0 import { invokeViewMethod, invokeViewMethodKeepAlive } from './invokeViewMethod'
function publishViewMethodName() {
return getCurrentPageId() + '.' + INVOKE_VIEW_API
}
const invokeViewMethod: UniApp.UniServiceJSBridge['invokeViewMethod'] = (
name: string,
args: unknown,
pageId: number,
callback?: (res: any) => void
) => {
const { subscribe, publishHandler } = UniServiceJSBridge
const id = invokeViewMethodId++
callback && subscribe(INVOKE_VIEW_API + '.' + id, callback, true)
publishHandler(publishViewMethodName(), { id, name, args }, pageId)
}
const invokeViewMethodKeepAlive: UniApp.UniServiceJSBridge['invokeViewMethodKeepAlive'] =
(
name: string,
args: unknown,
callback: (res: any) => void,
pageId: number
) => {
const { subscribe, unsubscribe, publishHandler } = UniServiceJSBridge
const id = invokeViewMethodId++
const subscribeName = INVOKE_VIEW_API + '.' + id
subscribe(subscribeName, callback)
publishHandler(publishViewMethodName(), { id, name, args }, pageId)
return () => {
unsubscribe(subscribeName)
}
}
const invokeOnCallback: UniApp.UniServiceJSBridge['invokeOnCallback'] = (
name: string,
res: unknown
) => UniServiceJSBridge.emit('api.' + name, res)
export const ServiceJSBridge = /*#__PURE__*/ extend( export const ServiceJSBridge = /*#__PURE__*/ extend(
initBridge('view' /* view 指的是 service 层订阅的是 view 层事件 */), initBridge('view' /* view 指的是 service 层订阅的是 view 层事件 */),
...@@ -52,3 +12,8 @@ export const ServiceJSBridge = /*#__PURE__*/ extend( ...@@ -52,3 +12,8 @@ export const ServiceJSBridge = /*#__PURE__*/ extend(
invokeViewMethodKeepAlive, invokeViewMethodKeepAlive,
} }
) )
export {
registerServiceMethod,
subscribeServiceMethod,
} from './subscribeServiceMethod'
export const invokeOnCallback: UniApp.UniServiceJSBridge['invokeOnCallback'] = (
name: string,
res: unknown
) => UniServiceJSBridge.emit('api.' + name, res)
import { INVOKE_VIEW_API } from '../../constants'
import { getCurrentPageId } from '../../helpers/page'
let invokeViewMethodId = 1
function publishViewMethodName() {
return getCurrentPageId() + '.' + INVOKE_VIEW_API
}
export const invokeViewMethod: UniApp.UniServiceJSBridge['invokeViewMethod'] = (
name: string,
args: unknown,
pageId: number,
callback?: (res: any) => void
) => {
const { subscribe, publishHandler } = UniServiceJSBridge
const id = callback ? invokeViewMethodId++ : 0
callback && subscribe(INVOKE_VIEW_API + '.' + id, callback, true)
publishHandler(publishViewMethodName(), { id, name, args }, pageId)
}
export const invokeViewMethodKeepAlive: UniApp.UniServiceJSBridge['invokeViewMethodKeepAlive'] =
(
name: string,
args: unknown,
callback: (res: any) => void,
pageId: number
) => {
const { subscribe, unsubscribe, publishHandler } = UniServiceJSBridge
const id = invokeViewMethodId++
const subscribeName = INVOKE_VIEW_API + '.' + id
subscribe(subscribeName, callback)
publishHandler(publishViewMethodName(), { id, name, args }, pageId)
return () => {
unsubscribe(subscribeName)
}
}
import { formatLog } from '@dcloudio/uni-shared'
import { INVOKE_SERVICE_API } from '../../constants'
type ServiceMethod<Args = any, Res = any> = (
args: Args,
publish: (res: Res) => void
) => void
const serviceMethods: Record<string, ServiceMethod<any>> = Object.create(null)
export function subscribeServiceMethod() {
UniServiceJSBridge.subscribe(INVOKE_SERVICE_API, onInvokeServiceMethod)
}
export function registerServiceMethod<Args = any, Res = any>(
name: string,
fn: ServiceMethod<Args, Res>
) {
if (!serviceMethods[name]) {
serviceMethods[name] = fn
}
}
function onInvokeServiceMethod(
{
id,
name,
args,
}: {
id: number
name: string
args: any
},
pageId: number
) {
const publish = (res: unknown) => {
id &&
UniServiceJSBridge.publishHandler(
INVOKE_SERVICE_API + '.' + id,
res,
pageId
)
}
const handler = serviceMethods[name]
if (handler) {
handler(args, publish)
} else {
publish({})
if (__DEV__) {
console.error(formatLog('invokeViewMethod', name, 'not register'))
}
}
}
export { ServiceJSBridge } from './bridge' export {
ServiceJSBridge,
registerServiceMethod,
subscribeServiceMethod,
} from './bridge'
export { initService, initAppVm, initPageVm } from './init' export { initService, initAppVm, initPageVm } from './init'
export { initServicePlugin } from './plugin' export { initServicePlugin } from './plugin'
import { formatLog } from '@dcloudio/uni-shared' import { extend } from '@vue/shared'
import { INVOKE_VIEW_API } from '../../constants'
import { initBridge } from '../../helpers/bridge'
export const ViewJSBridge = /*#__PURE__*/ initBridge('service')
function normalizeViewMethodName(pageId: number, name: string) {
return pageId + '.' + name
}
export function subscribeViewMethod(pageId: number) {
UniViewJSBridge.subscribe(
normalizeViewMethodName(pageId, INVOKE_VIEW_API),
onInvokeViewMethod
)
}
/**
* 仅 h5 平台需要主动取消监听
* @param pageId
*/
export function unsubscribeViewMethod(pageId: number) {
if (__DEV__) {
console.log(formatLog('unsubscribeViewMethod', pageId, INVOKE_VIEW_API))
}
UniViewJSBridge.unsubscribe(normalizeViewMethodName(pageId, INVOKE_VIEW_API))
Object.keys(viewMethods).forEach((name) => {
if (name.indexOf(pageId + '.') === 0) {
if (__DEV__) {
console.log(formatLog('unsubscribeViewMethod', name))
}
delete viewMethods[name]
}
})
}
type ViewMethod<Args = any, Res = any> = ( import { initBridge } from '../../helpers/bridge'
args: Args, import { invokeServiceMethod } from './invokeServiceMethod'
publish: (res: Res) => void
) => void export const ViewJSBridge = /*#__PURE__*/ extend(initBridge('service'), {
const viewMethods: Record<string, ViewMethod<any>> = Object.create(null) invokeServiceMethod,
})
export function registerViewMethod<Args = any, Res = any>(
pageId: number, export {
name: string, subscribeViewMethod,
fn: ViewMethod<Args, Res> unsubscribeViewMethod,
) { registerViewMethod,
name = normalizeViewMethodName(pageId, name) unregisterViewMethod,
if (!viewMethods[name]) { } from './subscribeViewMethod'
viewMethods[name] = fn
}
}
export function unregisterViewMethod(pageId: number, name: string) {
name = normalizeViewMethodName(pageId, name)
delete viewMethods[name]
}
function onInvokeViewMethod(
{
id,
name,
args,
}: {
id: number
name: string
args: any
},
pageId: number
) {
name = normalizeViewMethodName(pageId, name)
const publish = (res: unknown) => {
UniViewJSBridge.publishHandler(INVOKE_VIEW_API + '.' + id, res)
}
const handler = viewMethods[name]
if (handler) {
handler(args, publish)
} else {
publish({})
if (__DEV__) {
console.error(formatLog('invokeViewMethod', name, 'not register'))
}
}
}
import { INVOKE_SERVICE_API } from '../../constants'
let invokeServiceMethodId = 1
export const invokeServiceMethod: UniApp.UniViewJSBridge['invokeServiceMethod'] =
(name: string, args: unknown, callback?: (res: any) => void) => {
const { subscribe, publishHandler } = UniViewJSBridge
const id = callback ? invokeServiceMethodId++ : 0
callback && subscribe(INVOKE_SERVICE_API + '.' + id, callback, true)
publishHandler(INVOKE_SERVICE_API, { id, name, args })
}
import { formatLog } from '@dcloudio/uni-shared'
import { INVOKE_VIEW_API } from '../../constants'
type ViewMethod<Args = any, Res = any> = (
args: Args,
publish: (res: Res) => void
) => void
const viewMethods: Record<string, ViewMethod<any>> = Object.create(null)
function normalizeViewMethodName(pageId: number, name: string) {
return pageId + '.' + name
}
export function subscribeViewMethod(pageId: number) {
UniViewJSBridge.subscribe(
normalizeViewMethodName(pageId, INVOKE_VIEW_API),
onInvokeViewMethod
)
}
/**
* 仅 h5 平台需要主动取消监听
* @param pageId
*/
export function unsubscribeViewMethod(pageId: number) {
if (__DEV__) {
console.log(formatLog('unsubscribeViewMethod', pageId, INVOKE_VIEW_API))
}
UniViewJSBridge.unsubscribe(normalizeViewMethodName(pageId, INVOKE_VIEW_API))
Object.keys(viewMethods).forEach((name) => {
if (name.indexOf(pageId + '.') === 0) {
if (__DEV__) {
console.log(formatLog('unsubscribeViewMethod', name))
}
delete viewMethods[name]
}
})
}
export function registerViewMethod<Args = any, Res = any>(
pageId: number,
name: string,
fn: ViewMethod<Args, Res>
) {
name = normalizeViewMethodName(pageId, name)
if (!viewMethods[name]) {
viewMethods[name] = fn
}
}
export function unregisterViewMethod(pageId: number, name: string) {
name = normalizeViewMethodName(pageId, name)
delete viewMethods[name]
}
function onInvokeViewMethod(
{
id,
name,
args,
}: {
id: number
name: string
args: any
},
pageId: number
) {
name = normalizeViewMethodName(pageId, name)
const publish = (res: unknown) => {
id && UniViewJSBridge.publishHandler(INVOKE_VIEW_API + '.' + id, res)
}
const handler = viewMethods[name]
if (handler) {
handler(args, publish)
} else {
publish({})
if (__DEV__) {
console.error(formatLog('invokeViewMethod', name, 'not register'))
}
}
}
...@@ -307,7 +307,6 @@ const initI18nVideoMsgsOnce = /* @__PURE__ */ uniShared.once(() => { ...@@ -307,7 +307,6 @@ const initI18nVideoMsgsOnce = /* @__PURE__ */ uniShared.once(() => {
useI18n().add(uniI18n.LOCALE_ZH_HANT, normalizeMessages(name, { danmu: "\u5F48\u5E55", volume: "\u97F3\u91CF" })); useI18n().add(uniI18n.LOCALE_ZH_HANT, normalizeMessages(name, { danmu: "\u5F48\u5E55", volume: "\u97F3\u91CF" }));
} }
}); });
const INVOKE_VIEW_API = "invokeViewApi";
const E = function() { const E = function() {
}; };
E.prototype = { E.prototype = {
...@@ -381,17 +380,28 @@ function initBridge(subscribeNamespace) { ...@@ -381,17 +380,28 @@ function initBridge(subscribeNamespace) {
} }
}; };
} }
const ViewJSBridge = /* @__PURE__ */ initBridge("service"); const INVOKE_VIEW_API = "invokeViewApi";
const INVOKE_SERVICE_API = "invokeServiceApi";
let invokeServiceMethodId = 1;
const invokeServiceMethod = (name, args, callback) => {
const { subscribe, publishHandler } = UniViewJSBridge;
const id = callback ? invokeServiceMethodId++ : 0;
callback && subscribe(INVOKE_SERVICE_API + "." + id, callback, true);
publishHandler(INVOKE_SERVICE_API, { id, name, args });
};
const viewMethods = Object.create(null);
function normalizeViewMethodName(pageId, name) { function normalizeViewMethodName(pageId, name) {
return pageId + "." + name; return pageId + "." + name;
} }
const viewMethods = Object.create(null);
function registerViewMethod(pageId, name, fn) { function registerViewMethod(pageId, name, fn) {
name = normalizeViewMethodName(pageId, name); name = normalizeViewMethodName(pageId, name);
if (!viewMethods[name]) { if (!viewMethods[name]) {
viewMethods[name] = fn; viewMethods[name] = fn;
} }
} }
const ViewJSBridge = /* @__PURE__ */ shared.extend(initBridge("service"), {
invokeServiceMethod
});
uniShared.passive(true); uniShared.passive(true);
const onEventPrevent = /* @__PURE__ */ vue.withModifiers(() => { const onEventPrevent = /* @__PURE__ */ vue.withModifiers(() => {
}, ["prevent"]); }, ["prevent"]);
...@@ -582,13 +592,14 @@ function createNativeEvent(evt) { ...@@ -582,13 +592,14 @@ function createNativeEvent(evt) {
} }
return event; return event;
} }
let invokeViewMethodId = 0; const invokeOnCallback = (name, res) => UniServiceJSBridge.emit("api." + name, res);
let invokeViewMethodId = 1;
function publishViewMethodName() { function publishViewMethodName() {
return getCurrentPageId() + "." + INVOKE_VIEW_API; return getCurrentPageId() + "." + INVOKE_VIEW_API;
} }
const invokeViewMethod = (name, args, pageId, callback) => { const invokeViewMethod = (name, args, pageId, callback) => {
const { subscribe, publishHandler } = UniServiceJSBridge; const { subscribe, publishHandler } = UniServiceJSBridge;
const id = invokeViewMethodId++; const id = callback ? invokeViewMethodId++ : 0;
callback && subscribe(INVOKE_VIEW_API + "." + id, callback, true); callback && subscribe(INVOKE_VIEW_API + "." + id, callback, true);
publishHandler(publishViewMethodName(), { id, name, args }, pageId); publishHandler(publishViewMethodName(), { id, name, args }, pageId);
}; };
...@@ -602,7 +613,6 @@ const invokeViewMethodKeepAlive = (name, args, callback, pageId) => { ...@@ -602,7 +613,6 @@ const invokeViewMethodKeepAlive = (name, args, callback, pageId) => {
unsubscribe(subscribeName); unsubscribe(subscribeName);
}; };
}; };
const invokeOnCallback = (name, res) => UniServiceJSBridge.emit("api." + name, res);
const ServiceJSBridge = /* @__PURE__ */ shared.extend(initBridge("view"), { const ServiceJSBridge = /* @__PURE__ */ shared.extend(initBridge("view"), {
invokeOnCallback, invokeOnCallback,
invokeViewMethod, invokeViewMethod,
......
...@@ -396,7 +396,6 @@ const initI18nVideoMsgsOnce = /* @__PURE__ */ once(() => { ...@@ -396,7 +396,6 @@ const initI18nVideoMsgsOnce = /* @__PURE__ */ once(() => {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, { danmu: "\u5F48\u5E55", volume: "\u97F3\u91CF" })); useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, { danmu: "\u5F48\u5E55", volume: "\u97F3\u91CF" }));
} }
}); });
const INVOKE_VIEW_API = "invokeViewApi";
const E = function() { const E = function() {
}; };
E.prototype = { E.prototype = {
...@@ -470,7 +469,16 @@ function initBridge(subscribeNamespace) { ...@@ -470,7 +469,16 @@ function initBridge(subscribeNamespace) {
} }
}; };
} }
const ViewJSBridge = /* @__PURE__ */ initBridge("service"); const INVOKE_VIEW_API = "invokeViewApi";
const INVOKE_SERVICE_API = "invokeServiceApi";
let invokeServiceMethodId = 1;
const invokeServiceMethod = (name, args, callback) => {
const { subscribe, publishHandler } = UniViewJSBridge;
const id2 = callback ? invokeServiceMethodId++ : 0;
callback && subscribe(INVOKE_SERVICE_API + "." + id2, callback, true);
publishHandler(INVOKE_SERVICE_API, { id: id2, name, args });
};
const viewMethods = Object.create(null);
function normalizeViewMethodName(pageId, name) { function normalizeViewMethodName(pageId, name) {
return pageId + "." + name; return pageId + "." + name;
} }
...@@ -491,7 +499,6 @@ function unsubscribeViewMethod(pageId) { ...@@ -491,7 +499,6 @@ function unsubscribeViewMethod(pageId) {
} }
}); });
} }
const viewMethods = Object.create(null);
function registerViewMethod(pageId, name, fn) { function registerViewMethod(pageId, name, fn) {
name = normalizeViewMethodName(pageId, name); name = normalizeViewMethodName(pageId, name);
if (!viewMethods[name]) { if (!viewMethods[name]) {
...@@ -509,7 +516,7 @@ function onInvokeViewMethod({ ...@@ -509,7 +516,7 @@ function onInvokeViewMethod({
}, pageId) { }, pageId) {
name = normalizeViewMethodName(pageId, name); name = normalizeViewMethodName(pageId, name);
const publish = (res) => { const publish = (res) => {
UniViewJSBridge.publishHandler(INVOKE_VIEW_API + "." + id2, res); id2 && UniViewJSBridge.publishHandler(INVOKE_VIEW_API + "." + id2, res);
}; };
const handler = viewMethods[name]; const handler = viewMethods[name];
if (handler) { if (handler) {
...@@ -521,6 +528,9 @@ function onInvokeViewMethod({ ...@@ -521,6 +528,9 @@ function onInvokeViewMethod({
} }
} }
} }
const ViewJSBridge = /* @__PURE__ */ extend(initBridge("service"), {
invokeServiceMethod
});
const LONGPRESS_TIMEOUT = 350; const LONGPRESS_TIMEOUT = 350;
const LONGPRESS_THRESHOLD = 10; const LONGPRESS_THRESHOLD = 10;
const passiveOptions$2 = passive(true); const passiveOptions$2 = passive(true);
...@@ -1350,13 +1360,14 @@ function initAppConfig$1(appConfig) { ...@@ -1350,13 +1360,14 @@ function initAppConfig$1(appConfig) {
function initViewPlugin(app) { function initViewPlugin(app) {
initAppConfig$1(app._context.config); initAppConfig$1(app._context.config);
} }
let invokeViewMethodId = 0; const invokeOnCallback = (name, res) => UniServiceJSBridge.emit("api." + name, res);
let invokeViewMethodId = 1;
function publishViewMethodName() { function publishViewMethodName() {
return getCurrentPageId() + "." + INVOKE_VIEW_API; return getCurrentPageId() + "." + INVOKE_VIEW_API;
} }
const invokeViewMethod = (name, args, pageId, callback) => { const invokeViewMethod = (name, args, pageId, callback) => {
const { subscribe, publishHandler } = UniServiceJSBridge; const { subscribe, publishHandler } = UniServiceJSBridge;
const id2 = invokeViewMethodId++; const id2 = callback ? invokeViewMethodId++ : 0;
callback && subscribe(INVOKE_VIEW_API + "." + id2, callback, true); callback && subscribe(INVOKE_VIEW_API + "." + id2, callback, true);
publishHandler(publishViewMethodName(), { id: id2, name, args }, pageId); publishHandler(publishViewMethodName(), { id: id2, name, args }, pageId);
}; };
...@@ -1370,7 +1381,6 @@ const invokeViewMethodKeepAlive = (name, args, callback, pageId) => { ...@@ -1370,7 +1381,6 @@ const invokeViewMethodKeepAlive = (name, args, callback, pageId) => {
unsubscribe(subscribeName); unsubscribe(subscribeName);
}; };
}; };
const invokeOnCallback = (name, res) => UniServiceJSBridge.emit("api." + name, res);
const ServiceJSBridge = /* @__PURE__ */ extend(initBridge("view"), { const ServiceJSBridge = /* @__PURE__ */ extend(initBridge("view"), {
invokeOnCallback, invokeOnCallback,
invokeViewMethod, invokeViewMethod,
...@@ -2027,11 +2037,11 @@ function operateVideoPlayer(videoId, pageId, type, data) { ...@@ -2027,11 +2037,11 @@ function operateVideoPlayer(videoId, pageId, type, data) {
data data
}, pageId); }, pageId);
} }
function operateMap(id2, pageId, type, data) { function operateMap(id2, pageId, type, data, operateMapCallback2) {
UniServiceJSBridge.invokeViewMethod("map." + id2, { UniServiceJSBridge.invokeViewMethod("map." + id2, {
type, type,
data data
}, pageId); }, pageId, operateMapCallback2);
} }
function getRootInfo(fields2) { function getRootInfo(fields2) {
const info = {}; const info = {};
...@@ -3013,28 +3023,44 @@ const createVideoContext = /* @__PURE__ */ defineSyncApi(API_CREATE_VIDEO_CONTEX ...@@ -3013,28 +3023,44 @@ const createVideoContext = /* @__PURE__ */ defineSyncApi(API_CREATE_VIDEO_CONTEX
} }
return new VideoContext(id2, getPageIdByVm(getCurrentPageVm())); return new VideoContext(id2, getPageIdByVm(getCurrentPageVm()));
}); });
const operateMapCallback = (options, res) => {
const errMsg = res.errMsg || "";
if (new RegExp("\\:\\s*fail").test(errMsg)) {
options.fail && options.fail(res);
} else {
options.success && options.success(res);
}
options.complete && options.complete(res);
};
const operateMapWrap = (id2, pageId, type, options) => {
operateMap(id2, pageId, type, options, (res) => {
options && operateMapCallback(options, res);
});
};
class MapContext { class MapContext {
constructor(id2, pageId) { constructor(id2, pageId) {
this.id = id2; this.id = id2;
this.pageId = pageId; this.pageId = pageId;
} }
getCenterLocation(options) { getCenterLocation(options) {
operateMap(this.id, this.pageId, "getCenterLocation", options); operateMapWrap(this.id, this.pageId, "getCenterLocation", options);
} }
moveToLocation() { moveToLocation() {
operateMap(this.id, this.pageId, "moveToLocation"); operateMapWrap(this.id, this.pageId, "moveToLocation");
} }
getScale(options) { getScale(options) {
operateMap(this.id, this.pageId, "getScale", options); operateMapWrap(this.id, this.pageId, "getScale", options);
} }
getRegion(options) { getRegion(options) {
operateMap(this.id, this.pageId, "getRegion", options); operateMapWrap(this.id, this.pageId, "getRegion", options);
} }
includePoints(options) { includePoints(options) {
operateMap(this.id, this.pageId, "includePoints", options); operateMapWrap(this.id, this.pageId, "includePoints", options);
} }
translateMarker(options) { translateMarker(options) {
operateMap(this.id, this.pageId, "translateMarker", options); operateMapWrap(this.id, this.pageId, "translateMarker", options);
}
$getAppMap() {
} }
addCustomLayer() { addCustomLayer() {
} }
...@@ -3054,9 +3080,7 @@ class MapContext { ...@@ -3054,9 +3080,7 @@ class MapContext {
} }
moveAlong() { moveAlong() {
} }
openMapAp() { openMapApp() {
}
$getAppMap() {
} }
} }
const createMapContext = /* @__PURE__ */ defineSyncApi(API_CREATE_MAP_CONTEXT, (id2, context) => { const createMapContext = /* @__PURE__ */ defineSyncApi(API_CREATE_MAP_CONTEXT, (id2, context) => {
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
"@types/sass": "^1.16.0" "@types/sass": "^1.16.0"
}, },
"uni-app": { "uni-app": {
"compilerVersion": "3.1.22" "compilerVersion": "3.1.23"
}, },
"gitHead": "3b83cc9dc4c9a214747c626f79693559c338044f" "gitHead": "3b83cc9dc4c9a214747c626f79693559c338044f"
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册