提交 406330a7 编写于 作者: fxy060608's avatar fxy060608

feat: add invokeViewMethod,invokeViewMethodKeepAlive

上级 aa4c6b69
......@@ -244,6 +244,8 @@ declare namespace UniApp {
type TabBarItemOptions = TabBarNormalItemOptions | TabBarMidButtonOptions
type StopHandle = () => void
interface TabBarOptions {
position?: 'bottom' | 'top'
color: string
......@@ -337,12 +339,25 @@ declare namespace UniApp {
* @param pageId
* @param callback
*/
invokeViewMethod<T = any>(
invokeViewMethod<Args = any, Res = any>(
name: string,
args: unknown,
callback: (res: T) => void,
args: Args,
callback: (res: Res) => void,
pageId: number
): void
/**
* 执行 View 层方法,并持久监听返回值
* @param name
* @param args
* @param pageId
* @param callback
*/
invokeViewMethodKeepAlive<Args = any, Res = any>(
name: string,
args: Args,
callback: (res: Res) => void,
pageId: number
): StopHandle
}
interface UniViewJSBridge {
/**
......
import { createCallbacks, getCurrentPageId } from '@dcloudio/uni-core'
import { getCurrentPageId } from '@dcloudio/uni-core'
import {
API_GET_SELECTED_TEXT_RANGE,
API_TYPE_GET_SELECTED_TEXT_RANGE,
} from '../../protocols/keyboard/getSelectedTextRange'
import { defineAsyncApi } from '../../helpers/api'
import { once } from '@dcloudio/uni-shared'
const getSelectedTextRangeEventCallbacks = createCallbacks(
'getSelectedTextRangeEvent'
)
const onGetSelectedTextRange = /*#__PURE__*/ once(() => {
UniServiceJSBridge.subscribe(
'onGetSelectedTextRange',
({ callbackId, data }: { callbackId: number; data: Data }) => {
const callback = getSelectedTextRangeEventCallbacks.pop(callbackId)
if (callback) {
callback(data)
}
}
)
})
export const getSelectedTextRange =
defineAsyncApi<API_TYPE_GET_SELECTED_TEXT_RANGE>(
API_GET_SELECTED_TEXT_RANGE,
(_, { resolve, reject }) => {
onGetSelectedTextRange()
const pageId = getCurrentPageId()
UniServiceJSBridge.publishHandler(
UniServiceJSBridge.invokeViewMethod<
{},
UniApp.GetSelectedTextRangeSuccessCallbackResult
>(
'getSelectedTextRange',
{
pageId,
callbackId: getSelectedTextRangeEventCallbacks.push(function (
res: UniApp.GetSelectedTextRangeSuccessCallbackResult
{},
(res) => {
if (
typeof res.end === 'undefined' &&
typeof res.start === 'undefined'
) {
if (
typeof res.end === 'undefined' &&
typeof res.start === 'undefined'
) {
reject('no focused')
} else {
resolve(res)
}
}),
reject('no focused')
} else {
resolve(res)
}
},
pageId
getCurrentPageId()
)
}
)
......@@ -1518,6 +1518,8 @@ var serviceContext = (function (vue) {
}
});
const INVOKE_VIEW_API = 'invokeViewApi';
const E = function () {
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
......@@ -1638,12 +1640,6 @@ var serviceContext = (function (vue) {
function getPageById(id) {
return getCurrentPages().find((page) => page.$page.id === id);
}
function getPageVmById(id) {
const page = getPageById(id);
if (page) {
return page.$vm;
}
}
function getCurrentPage() {
const pages = getCurrentPages();
const len = pages.length;
......@@ -1802,10 +1798,31 @@ var serviceContext = (function (vue) {
};
}
let invokeViewMethodId = 0;
function publishViewMethodName() {
return getCurrentPageId() + '.' + INVOKE_VIEW_API;
}
const invokeViewMethod = (name, args, callback, pageId) => {
const { subscribe, publishHandler } = UniServiceJSBridge;
const id = invokeViewMethodId++;
subscribe(INVOKE_VIEW_API + '.' + id, callback, true);
publishHandler(publishViewMethodName(), { id, name, args }, pageId);
};
const invokeViewMethodKeepAlive = (name, args, callback, pageId) => {
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 = (name, res) => UniServiceJSBridge.emit('api.' + name, res);
const ServiceJSBridge = /*#__PURE__*/ extend(initBridge('view' /* view 指的是 service 层订阅的是 view 层事件 */), {
invokeOnCallback(name, res) {
return UniServiceJSBridge.emit('api.' + name, res);
},
invokeOnCallback,
invokeViewMethod,
invokeViewMethodKeepAlive,
});
function initOn() {
......@@ -1842,10 +1859,7 @@ var serviceContext = (function (vue) {
}
function createPageEvent(name) {
return (args, pageId) => {
const vm = getPageVmById(pageId);
if (vm) {
invokeHook(vm, name, args);
}
invokeHook(pageId, name, args);
};
}
......@@ -3841,30 +3855,16 @@ var serviceContext = (function (vue) {
const API_GET_SELECTED_TEXT_RANGE = 'getSelectedTextRange';
const getSelectedTextRangeEventCallbacks = createCallbacks('getSelectedTextRangeEvent');
const onGetSelectedTextRange = /*#__PURE__*/ once(() => {
UniServiceJSBridge.subscribe('onGetSelectedTextRange', ({ callbackId, data }) => {
const callback = getSelectedTextRangeEventCallbacks.pop(callbackId);
if (callback) {
callback(data);
}
});
});
const getSelectedTextRange = defineAsyncApi(API_GET_SELECTED_TEXT_RANGE, (_, { resolve, reject }) => {
onGetSelectedTextRange();
const pageId = getCurrentPageId();
UniServiceJSBridge.publishHandler('getSelectedTextRange', {
pageId,
callbackId: getSelectedTextRangeEventCallbacks.push(function (res) {
if (typeof res.end === 'undefined' &&
typeof res.start === 'undefined') {
reject('no focused');
}
else {
resolve(res);
}
}),
}, pageId);
UniServiceJSBridge.invokeViewMethod('getSelectedTextRange', {}, (res) => {
if (typeof res.end === 'undefined' &&
typeof res.start === 'undefined') {
reject('no focused');
}
else {
resolve(res);
}
}, getCurrentPageId());
});
const API_GET_BACKGROUND_AUDIO_MANAGER = 'getBackgroundAudioManager';
......@@ -8736,7 +8736,6 @@ var serviceContext = (function (vue) {
const VD_SYNC = 'vdSync';
const ON_WEBVIEW_READY = 'onWebviewReady';
const INVOKE_VIEW_API = 'invokeViewApi';
const INVOKE_SERVICE_API = 'invokeServiceApi';
const ACTION_TYPE_DICT = 0;
......@@ -10675,15 +10674,8 @@ var serviceContext = (function (vue) {
switchTab: switchTab
});
let invokeViewMethodId = 0;
const invokeViewMethod = (name, args, callback, pageId) => {
const id = invokeViewMethodId++;
UniServiceJSBridge$1.subscribe(INVOKE_VIEW_API + '.' + id, callback, true);
publishHandler(INVOKE_VIEW_API, { id, name, args }, pageId);
};
const UniServiceJSBridge$1 = /*#__PURE__*/ extend(ServiceJSBridge, {
publishHandler,
invokeViewMethod,
});
function publishHandler(event, args, pageIds) {
args = JSON.stringify(args);
......
......@@ -576,6 +576,7 @@ var __publicField = (obj, key, value) => {
}));
}
});
const INVOKE_VIEW_API = "invokeViewApi";
const E = function() {
};
E.prototype = {
......@@ -641,23 +642,55 @@ var __publicField = (obj, key, value) => {
unsubscribe(event, callback) {
emitter.off(`${subscribeNamespace}.${event}`, callback);
},
subscribeHandler(event, args, pageId2) {
subscribeHandler(event, args, pageId) {
{
console.log(formatLog(subscribeNamespace, "subscribeHandler", pageId2, event, args));
console.log(formatLog(subscribeNamespace, "subscribeHandler", pageId, event, args));
}
emitter.emit(`${subscribeNamespace}.${event}`, args, pageId2);
emitter.emit(`${subscribeNamespace}.${event}`, args, pageId);
}
};
}
const ViewJSBridge = /* @__PURE__ */ initBridge("service");
function normalizeViewMethodName(pageId, name) {
return pageId + "." + name;
}
function subscribeViewMethod(pageId) {
UniViewJSBridge.subscribe(normalizeViewMethodName(pageId, INVOKE_VIEW_API), onInvokeViewMethod);
}
const viewMethods = Object.create(null);
function registerViewMethod(pageId, name, fn) {
name = normalizeViewMethodName(pageId, name);
if (!viewMethods[name]) {
viewMethods[name] = fn;
}
}
function onInvokeViewMethod({
id: id2,
name,
args
}, pageId) {
name = normalizeViewMethodName(pageId, name);
const publish = (res) => {
UniViewJSBridge.publishHandler(INVOKE_VIEW_API + "." + id2, res);
};
const handler = viewMethods[name];
if (handler) {
handler(args, publish);
} else {
publish({});
{
console.error(formatLog("invokeViewMethod", name, "not register"));
}
}
}
const LONGPRESS_TIMEOUT = 350;
const LONGPRESS_THRESHOLD = 10;
const passiveOptions$2 = passive(true);
let longPressTimer = 0;
let longPressTimer;
function clearLongPressTimer() {
if (longPressTimer) {
clearTimeout(longPressTimer);
longPressTimer = 0;
longPressTimer = null;
}
}
let startPageX = 0;
......@@ -5214,7 +5247,7 @@ var __publicField = (obj, key, value) => {
}
function useCurrentPageId() {
{
return parseInt(window.__id__);
return getCurrentPageId();
}
}
function getCurrentPage() {
......@@ -5224,6 +5257,9 @@ var __publicField = (obj, key, value) => {
}
function getCurrentPageId() {
{
if (!window.__id__) {
window.__id__ = plus.webview.currentWebview().id;
}
return parseInt(window.__id__);
}
}
......@@ -5408,18 +5444,14 @@ var __publicField = (obj, key, value) => {
[ON_PAGE_SCROLL, ON_REACH_BOTTOM];
const VD_SYNC = "vdSync";
const ON_WEBVIEW_READY = "onWebviewReady";
const INVOKE_VIEW_API = "invokeViewApi";
const INVOKE_SERVICE_API = "invokeServiceApi";
const ACTION_TYPE_DICT = 0;
const APP_SERVICE_ID = "__uniapp__service";
const UniViewJSBridge$1 = /* @__PURE__ */ extend(ViewJSBridge, {
publishHandler
});
let pageId;
function publishHandler(event, args = {}) {
if (!pageId) {
pageId = plus.webview.currentWebview().id;
}
const pageId = getCurrentPageId() + "";
{
console.log(`[${Date.now()}][View]: ` + pageId + " " + event + " " + JSON.stringify(args));
}
......@@ -5707,7 +5739,6 @@ var __publicField = (obj, key, value) => {
return number < 0 ? -result : result;
}, Upx2pxProtocol);
createCallbacks("canvasEvent");
createCallbacks("getSelectedTextRangeEvent");
({
beforeInvoke() {
initI18nShowModalMsgsOnce();
......@@ -6571,7 +6602,7 @@ var __publicField = (obj, key, value) => {
setup(props2, {
slots
}) {
const pageId2 = useCurrentPageId();
const pageId = useCurrentPageId();
const handlers = useProvideLabel();
const pointer = computed$1(() => props2.for || slots.default && slots.default.length);
const _onClick = withWebEvent(($event) => {
......@@ -6584,7 +6615,7 @@ var __publicField = (obj, key, value) => {
return;
}
if (props2.for) {
UniViewJSBridge.emit("uni-label-click-" + pageId2 + "-" + props2.for, $event, true);
UniViewJSBridge.emit("uni-label-click-" + pageId + "-" + props2.for, $event, true);
} else {
handlers.length && handlers[0]($event, true);
}
......@@ -6622,7 +6653,7 @@ var __publicField = (obj, key, value) => {
});
}
function _addListeners(id2, listeners, watch2) {
const pageId2 = useCurrentPageId();
const pageId = useCurrentPageId();
if (watch2 && !id2) {
return;
}
......@@ -6632,19 +6663,19 @@ var __publicField = (obj, key, value) => {
Object.keys(listeners).forEach((name) => {
if (watch2) {
if (name.indexOf("@") !== 0 && name.indexOf("uni-") !== 0) {
UniViewJSBridge.on(`uni-${name}-${pageId2}-${id2}`, listeners[name]);
UniViewJSBridge.on(`uni-${name}-${pageId}-${id2}`, listeners[name]);
}
} else {
if (name.indexOf("uni-") === 0) {
UniViewJSBridge.on(name, listeners[name]);
} else if (id2) {
UniViewJSBridge.on(`uni-${name}-${pageId2}-${id2}`, listeners[name]);
UniViewJSBridge.on(`uni-${name}-${pageId}-${id2}`, listeners[name]);
}
}
});
}
function _removeListeners(id2, listeners, watch2) {
const pageId2 = useCurrentPageId();
const pageId = useCurrentPageId();
if (watch2 && !id2) {
return;
}
......@@ -6654,13 +6685,13 @@ var __publicField = (obj, key, value) => {
Object.keys(listeners).forEach((name) => {
if (watch2) {
if (name.indexOf("@") !== 0 && name.indexOf("uni-") !== 0) {
UniViewJSBridge.off(`uni-${name}-${pageId2}-${id2}`, listeners[name]);
UniViewJSBridge.off(`uni-${name}-${pageId}-${id2}`, listeners[name]);
}
} else {
if (name.indexOf("uni-") === 0) {
UniViewJSBridge.off(name, listeners[name]);
} else if (id2) {
UniViewJSBridge.off(`uni-${name}-${pageId2}-${id2}`, listeners[name]);
UniViewJSBridge.off(`uni-${name}-${pageId}-${id2}`, listeners[name]);
}
}
});
......@@ -9013,28 +9044,20 @@ var __publicField = (obj, key, value) => {
uniForm.removeField(ctx);
});
}
const pageIds = [];
function getSelectedTextRange(_, resolve) {
const activeElement = document.activeElement;
if (!activeElement) {
return resolve({});
}
const data = {};
if (["input", "textarea"].includes(activeElement.tagName.toLowerCase())) {
data.start = activeElement.selectionStart;
data.end = activeElement.selectionEnd;
}
resolve(data);
}
const UniViewJSBridgeSubscribe = function() {
const pageId2 = getCurrentPageId();
if (pageIds.includes(pageId2))
return;
pageIds.push(pageId2);
UniViewJSBridge.subscribe(pageId2 + ".getSelectedTextRange", function({ pageId: pageId22, callbackId }) {
const activeElement = document.activeElement;
if (!activeElement)
return;
const tagName = activeElement.tagName.toLowerCase();
const tagNames = ["input", "textarea"];
const data = {};
if (tagNames.includes(tagName)) {
data.start = activeElement.selectionStart;
data.end = activeElement.selectionEnd;
}
UniViewJSBridge.publishHandler("onGetSelectedTextRange", {
callbackId,
data
}, pageId22);
});
registerViewMethod(getCurrentPageId(), "getSelectedTextRange", getSelectedTextRange);
};
const FOCUS_DELAY = 200;
let startTime;
......@@ -14119,14 +14142,14 @@ var __publicField = (obj, key, value) => {
};
}
});
function normalizeEvent(pageId2, vm, id2) {
function normalizeEvent(pageId, vm, id2) {
if (!id2) {
id2 = vm.id;
}
if (!id2) {
return;
}
return pageId2 + "." + vm.$options.name.toLowerCase() + "." + id2;
return pageId + "." + vm.$options.name.toLowerCase() + "." + id2;
}
function addSubscribe(name, callback) {
if (!name) {
......@@ -14145,18 +14168,18 @@ var __publicField = (obj, key, value) => {
function useSubscribe(callback, name, multiple) {
const instance = getCurrentInstance();
const vm = instance.proxy;
const pageId2 = multiple || !name ? useCurrentPageId() : 0;
const pageId = multiple || !name ? useCurrentPageId() : 0;
onMounted(() => {
addSubscribe(name || normalizeEvent(pageId2, vm), callback);
addSubscribe(name || normalizeEvent(pageId, vm), callback);
if (multiple || !name) {
watch(() => vm.id, (value, oldValue) => {
addSubscribe(normalizeEvent(pageId2, vm, value), callback);
removeSubscribe(oldValue && normalizeEvent(pageId2, vm, oldValue));
addSubscribe(normalizeEvent(pageId, vm, value), callback);
removeSubscribe(oldValue && normalizeEvent(pageId, vm, oldValue));
});
}
});
onBeforeUnmount(() => {
removeSubscribe(name || normalizeEvent(pageId2, vm));
removeSubscribe(name || normalizeEvent(pageId, vm));
});
}
let index = 0;
......@@ -15362,9 +15385,9 @@ var __publicField = (obj, key, value) => {
if (css) {
initPageCss(route);
}
const pageId2 = plus.webview.currentWebview().id;
window.__id__ = pageId2;
document.title = `${route}[${pageId2}]`;
const pageId = plus.webview.currentWebview().id;
window.__id__ = pageId;
document.title = `${route}[${pageId}]`;
initCssVar(statusbarHeight, windowTop, windowBottom);
if (disableScroll) {
document.addEventListener("touchmove", disableScrollListener);
......@@ -15449,6 +15472,10 @@ var __publicField = (obj, key, value) => {
});
flushPostActionJobs();
}
function initSubscribeHandlers() {
const { subscribe } = UniViewJSBridge;
subscribe(VD_SYNC, onVdSync);
}
function getRootInfo(fields) {
const info = {};
if (fields.id) {
......@@ -15589,23 +15616,12 @@ var __publicField = (obj, key, value) => {
callback(result);
}
const pageVm = { $el: document.body };
function onInvokeViewApi({
id: id2,
name,
args
}) {
const publish = (res) => {
UniViewJSBridge.publishHandler(INVOKE_VIEW_API + "." + id2, res);
};
switch (name) {
case "requestComponentInfo":
return requestComponentInfo(pageVm, args.reqs, publish);
}
}
function initSubscribeHandlers() {
const { subscribe } = UniViewJSBridge;
subscribe(VD_SYNC, onVdSync);
subscribe(INVOKE_VIEW_API, onInvokeViewApi);
function initViewMethods() {
const pageId = getCurrentPageId();
subscribeViewMethod(pageId);
registerViewMethod(pageId, "requestComponentInfo", (args, publish) => {
requestComponentInfo(pageVm, args.reqs, publish);
});
}
window.uni = uni$1;
window.UniViewJSBridge = UniViewJSBridge$1;
......@@ -15613,6 +15629,7 @@ var __publicField = (obj, key, value) => {
window.__$__ = $;
function onWebviewReady() {
initView();
initViewMethods();
initSubscribeHandlers();
preventDoubleTap();
UniViewJSBridge$1.publishHandler(ON_WEBVIEW_READY);
......
......@@ -2,7 +2,6 @@ export const VD_SYNC = 'vdSync'
export const ON_WEBVIEW_READY = 'onWebviewReady'
export const INVOKE_VIEW_API = 'invokeViewApi'
export const INVOKE_SERVICE_API = 'invokeServiceApi'
export let ACTION_MINIFY = true
......
......@@ -2,24 +2,9 @@ import { extend, isArray } from '@vue/shared'
import { ServiceJSBridge } from '@dcloudio/uni-core'
import { formatLog } from '@dcloudio/uni-shared'
import { INVOKE_VIEW_API } from '../../constants'
let invokeViewMethodId = 0
const invokeViewMethod: UniApp.UniServiceJSBridge['invokeViewMethod'] = (
name: string,
args: unknown,
callback: (res: any) => void,
pageId: number
) => {
const id = invokeViewMethodId++
UniServiceJSBridge.subscribe(INVOKE_VIEW_API + '.' + id, callback, true)
publishHandler(INVOKE_VIEW_API, { id, name, args }, pageId)
}
export const UniServiceJSBridge = /*#__PURE__*/ extend(ServiceJSBridge, {
publishHandler,
invokeViewMethod,
})
function publishHandler(
......
import { extend } from '@vue/shared'
import { ViewJSBridge } from '@dcloudio/uni-core'
import { getCurrentPageId, ViewJSBridge } from '@dcloudio/uni-core'
const APP_SERVICE_ID = '__uniapp__service'
......@@ -8,11 +8,9 @@ export const UniViewJSBridge = /*#__PURE__*/ extend(ViewJSBridge, {
publishHandler,
})
let pageId: string
function publishHandler(event: string, args: unknown = {}) {
if (!pageId) {
pageId = plus.webview.currentWebview().id!
}
// 转换为字符串
const pageId = getCurrentPageId() + ''
if (__DEV__) {
console.log(
`[${Date.now()}][View]: ` +
......
import { initSubscribeHandlers } from './subscriber'
import { preventDoubleTap } from './gesture'
export function initView() {
initSubscribeHandlers()
preventDoubleTap()
}
import { VD_SYNC, INVOKE_VIEW_API } from '../../../constants'
import { VD_SYNC } from '../../../constants'
import { onVdSync } from '../dom'
import { onInvokeViewApi } from './invokeViewApi'
export function initSubscribeHandlers() {
const { subscribe } = UniViewJSBridge
subscribe(VD_SYNC, onVdSync)
subscribe(INVOKE_VIEW_API, onInvokeViewApi)
}
import { ComponentPublicInstance } from 'vue'
import { requestComponentInfo } from '../../../../../uni-h5/src/platform'
import { INVOKE_VIEW_API } from '../../../constants'
const pageVm = { $el: document.body } as ComponentPublicInstance
export function onInvokeViewApi({
id,
name,
args,
}: {
id: number
name: string
args: any
}) {
const publish = (res: unknown) => {
UniViewJSBridge.publishHandler(INVOKE_VIEW_API + '.' + id, res)
}
switch (name) {
case 'requestComponentInfo':
return requestComponentInfo(pageVm, args.reqs, publish)
}
}
import { SelectorQueryRequest } from '@dcloudio/uni-api'
import {
subscribeViewMethod,
registerViewMethod,
getCurrentPageId,
} from '@dcloudio/uni-core'
import { ComponentPublicInstance } from 'vue'
import { requestComponentInfo } from '../../../../uni-h5/src/platform'
const pageVm = { $el: document.body } as ComponentPublicInstance
export function initViewMethods() {
const pageId = getCurrentPageId()
subscribeViewMethod(pageId)
registerViewMethod<{ reqs: Array<SelectorQueryRequest> }>(
pageId,
'requestComponentInfo',
(args, publish) => {
requestComponentInfo(pageVm, args.reqs, publish)
}
)
}
......@@ -7,6 +7,7 @@ import * as uni from './api'
import { preventDoubleTap } from './framework/gesture'
import { initSubscribeHandlers } from './framework/subscriber'
import { $ } from './framework/dom/page'
import { initViewMethods } from './framework/viewMethods'
;(window as any).uni = uni
;(window as any).UniViewJSBridge = UniViewJSBridge
;(window as any).rpx2px = uni.upx2px
......@@ -14,6 +15,7 @@ import { $ } from './framework/dom/page'
function onWebviewReady() {
initView()
initViewMethods()
initSubscribeHandlers()
preventDoubleTap()
UniViewJSBridge.publishHandler(ON_WEBVIEW_READY)
......
var lookup = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 62, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
]
function base64Decode (source, target) {
var sourceLength = source.length
var paddingLength = (source[sourceLength - 2] === '=' ? 2 : (source[sourceLength - 1] === '=' ? 1
: 0))
var tmp
var byteIndex = 0
var baseLength = (sourceLength - paddingLength) & 0xfffffffc
for (var i = 0; i < baseLength; i += 4) {
tmp = (lookup[source.charCodeAt(i)] << 18) |
(lookup[source.charCodeAt(i + 1)] << 12) |
(lookup[source.charCodeAt(i + 2)] << 6) |
(lookup[source.charCodeAt(i + 3)])
target[byteIndex++] = (tmp >> 16) & 0xFF
target[byteIndex++] = (tmp >> 8) & 0xFF
target[byteIndex++] = (tmp) & 0xFF
}
if (paddingLength === 1) {
tmp = (lookup[source.charCodeAt(i)] << 10) |
(lookup[source.charCodeAt(i + 1)] << 4) |
(lookup[source.charCodeAt(i + 2)] >> 2)
target[byteIndex++] = (tmp >> 8) & 0xFF
target[byteIndex++] = tmp & 0xFF
}
if (paddingLength === 2) {
tmp = (lookup[source.charCodeAt(i)] << 2) | (lookup[source.charCodeAt(i + 1)] >> 4)
target[byteIndex++] = tmp & 0xFF
}
}
export default {
getRandomValues (arr) {
if (!(
arr instanceof Int8Array ||
arr instanceof Uint8Array ||
arr instanceof Int16Array ||
arr instanceof Uint16Array ||
arr instanceof Int32Array ||
arr instanceof Uint32Array ||
arr instanceof Uint8ClampedArray
)) {
throw new Error('Expected an integer array')
}
if (arr.byteLength > 65536) {
throw new Error('Can only request a maximum of 65536 bytes')
}
var crypto = uni.requireNativePlugin('DCloud-Crypto')
base64Decode(crypto.getRandomValues(arr.byteLength), new Uint8Array(arr.buffer, arr.byteOffset,
arr.byteLength))
return arr
}
}
......@@ -8,3 +8,4 @@ export * from './easycom'
export * from './constants'
export * from './preprocess'
export { checkUpdate } from './checkUpdate'
export { initProvide } from './provide'
import path from 'path'
const libDir = path.resolve(__dirname, '../lib')
export function initProvide() {
const cryptoDefine = [path.join(libDir, 'crypto.js'), 'default']
return {
crypto: cryptoDefine,
'window.crypto': cryptoDefine,
'global.crypto': cryptoDefine,
}
}
......@@ -11,6 +11,7 @@ import {
} from 'vue'
import { extend } from '@vue/shared'
import { debounce } from '@dcloudio/uni-shared'
import { getCurrentPageId, registerViewMethod } from '@dcloudio/uni-core'
import { throttle } from './throttle'
import { useCustomEvent, CustomEventTrigger } from './useEvent'
import { useUserAction } from './useUserAction'
......@@ -21,39 +22,29 @@ import {
} from './useKeyboard'
import { useScopedAttrs } from './useScopedAttrs'
import { useFormField } from './useFormField'
import { getCurrentPageId } from '@dcloudio/uni-core'
const pageIds: number[] = []
const UniViewJSBridgeSubscribe = function () {
const pageId = getCurrentPageId()
if (pageIds.includes(pageId)) return
pageIds.push(pageId)
function getSelectedTextRange(
_: unknown,
resolve: (res: UniApp.GetSelectedTextRangeSuccessCallbackResult) => void
) {
const activeElement = document.activeElement
if (!activeElement) {
return resolve({})
}
const data: UniApp.GetSelectedTextRangeSuccessCallbackResult = {}
if (['input', 'textarea'].includes(activeElement.tagName.toLowerCase())) {
data.start = (activeElement as HTMLInputElement).selectionStart!
data.end = (activeElement as HTMLInputElement).selectionEnd!
}
resolve(data)
}
UniViewJSBridge.subscribe(
pageId + '.getSelectedTextRange',
function ({ pageId, callbackId }: { pageId: number; callbackId: number }) {
const activeElement = document.activeElement
if (!activeElement) return
const tagName = activeElement.tagName.toLowerCase()
const tagNames = ['input', 'textarea']
const data: {
errMsg?: string
start?: number | null
end?: number | null
} = {}
if (tagNames.includes(tagName)) {
data.start = (activeElement as HTMLInputElement).selectionStart
data.end = (activeElement as HTMLInputElement).selectionEnd
}
UniViewJSBridge.publishHandler(
'onGetSelectedTextRange',
{
callbackId,
data,
},
pageId
)
}
const UniViewJSBridgeSubscribe = function () {
// 内部会判断是否已存在,可重复调用 registerViewMethod 时
registerViewMethod<{}, UniApp.GetSelectedTextRangeSuccessCallbackResult>(
getCurrentPageId(),
'getSelectedTextRange',
getSelectedTextRange
)
}
......
export const INVOKE_VIEW_API = 'invokeViewApi'
......@@ -6,7 +6,10 @@ export function initBridge(
subscribeNamespace: 'service' | 'view'
): Omit<
UniApp.UniServiceJSBridge,
'invokeOnCallback' | 'invokeViewMethod' | 'publishHandler'
| 'invokeOnCallback'
| 'invokeViewMethod'
| 'invokeViewMethodKeepAlive'
| 'publishHandler'
> {
// TODO vue3 compatibility builds
const emitter = new E()
......
......@@ -3,9 +3,9 @@ import { ComponentPublicInstance, getCurrentInstance } from 'vue'
import { rpx2px } from './util'
export function useCurrentPageId() {
if (__PLATFORM__ === 'app') {
if (__APP_VIEW__) {
// view 层
return parseInt((window as any).__id__)
return getCurrentPageId()
}
return getCurrentInstance()!.root.proxy!.$page.id
}
......@@ -52,6 +52,9 @@ export function getCurrentPageMeta() {
export function getCurrentPageId() {
if (__APP_VIEW__) {
// view 层
if (!(window as any).__id__) {
;(window as any).__id__ = plus.webview.currentWebview().id!
}
return parseInt((window as any).__id__)
}
const meta = getCurrentPageMeta()
......
import { extend } from '@vue/shared'
import { INVOKE_VIEW_API } from '../../constants'
import { getCurrentPageId } from '../../helpers'
import { initBridge } from '../../helpers/bridge'
let invokeViewMethodId = 0
function publishViewMethodName() {
return getCurrentPageId() + '.' + INVOKE_VIEW_API
}
const invokeViewMethod: UniApp.UniServiceJSBridge['invokeViewMethod'] = (
name: string,
args: unknown,
callback: (res: any) => void,
pageId: number
) => {
const { subscribe, publishHandler } = UniServiceJSBridge
const id = invokeViewMethodId++
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(
initBridge('view' /* view 指的是 service 层订阅的是 view 层事件 */),
{
invokeOnCallback(name: string, res: unknown) {
return UniServiceJSBridge.emit('api.' + name, res)
},
invokeOnCallback,
invokeViewMethod,
invokeViewMethodKeepAlive,
}
)
import { ON_PAGE_SCROLL, ON_REACH_BOTTOM } from '@dcloudio/uni-shared'
import { getPageVmById } from '../../helpers/page'
import { invokeHook } from '../../helpers/hook'
const SUBSCRIBE_LIFECYCLE_HOOKS = [ON_PAGE_SCROLL, ON_REACH_BOTTOM]
......@@ -12,9 +11,6 @@ export function initSubscribe() {
function createPageEvent(name: string) {
return (args: unknown, pageId: number) => {
const vm = getPageVmById(pageId)
if (vm) {
invokeHook(vm, name, args)
}
invokeHook(pageId, name, args)
}
}
import { formatLog } from '@dcloudio/uni-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> = (
args: Args,
publish: (res: Res) => void
) => void
const viewMethods: Record<string, ViewMethod<any>> = Object.create(null)
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
}
}
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'))
}
}
}
export { ViewJSBridge } from './bridge'
export {
ViewJSBridge,
subscribeViewMethod,
unsubscribeViewMethod,
registerViewMethod,
} from './bridge'
export { initView } from './init'
export { initViewPlugin } from './plugin'
export {
......
......@@ -307,6 +307,7 @@ const initI18nVideoMsgsOnce = /* @__PURE__ */ uniShared.once(() => {
useI18n().add(uniI18n.LOCALE_ZH_HANT, normalizeMessages(name, { danmu: "\u5F48\u5E55", volume: "\u97F3\u91CF" }));
}
});
const INVOKE_VIEW_API = "invokeViewApi";
const E = function() {
};
E.prototype = {
......@@ -381,6 +382,16 @@ function initBridge(subscribeNamespace) {
};
}
const ViewJSBridge = /* @__PURE__ */ initBridge("service");
function normalizeViewMethodName(pageId, name) {
return pageId + "." + name;
}
const viewMethods = Object.create(null);
function registerViewMethod(pageId, name, fn) {
name = normalizeViewMethodName(pageId, name);
if (!viewMethods[name]) {
viewMethods[name] = fn;
}
}
uniShared.passive(true);
const onEventPrevent = /* @__PURE__ */ vue.withModifiers(() => {
}, ["prevent"]);
......@@ -599,10 +610,31 @@ function createNativeEvent(evt) {
}
return event;
}
let invokeViewMethodId = 0;
function publishViewMethodName() {
return getCurrentPageId() + "." + INVOKE_VIEW_API;
}
const invokeViewMethod = (name, args, callback, pageId) => {
const { subscribe, publishHandler } = UniServiceJSBridge;
const id = invokeViewMethodId++;
subscribe(INVOKE_VIEW_API + "." + id, callback, true);
publishHandler(publishViewMethodName(), { id, name, args }, pageId);
};
const invokeViewMethodKeepAlive = (name, args, callback, pageId) => {
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 = (name, res) => UniServiceJSBridge.emit("api." + name, res);
const ServiceJSBridge = /* @__PURE__ */ shared.extend(initBridge("view"), {
invokeOnCallback(name, res) {
return UniServiceJSBridge.emit("api." + name, res);
}
invokeOnCallback,
invokeViewMethod,
invokeViewMethodKeepAlive
});
function initAppVm(appVm2) {
appVm2.$vm = appVm2;
......@@ -1380,7 +1412,6 @@ function defineAsyncApi(name, fn, protocol, options) {
}
createCallbacks("canvasEvent");
const API_ON_TAB_BAR_MID_BUTTON_TAP = "onTabBarMidButtonTap";
createCallbacks("getSelectedTextRangeEvent");
const API_GET_STORAGE = "getStorage";
const GetStorageProtocol = {
key: {
......@@ -2883,28 +2914,20 @@ function useFormField(nameKey, value) {
};
uniForm.addField(ctx);
}
const pageIds = [];
function getSelectedTextRange(_, resolve) {
const activeElement = document.activeElement;
if (!activeElement) {
return resolve({});
}
const data = {};
if (["input", "textarea"].includes(activeElement.tagName.toLowerCase())) {
data.start = activeElement.selectionStart;
data.end = activeElement.selectionEnd;
}
resolve(data);
}
const UniViewJSBridgeSubscribe = function() {
const pageId = getCurrentPageId();
if (pageIds.includes(pageId))
return;
pageIds.push(pageId);
UniViewJSBridge.subscribe(pageId + ".getSelectedTextRange", function({ pageId: pageId2, callbackId }) {
const activeElement = document.activeElement;
if (!activeElement)
return;
const tagName = activeElement.tagName.toLowerCase();
const tagNames = ["input", "textarea"];
const data = {};
if (tagNames.includes(tagName)) {
data.start = activeElement.selectionStart;
data.end = activeElement.selectionEnd;
}
UniViewJSBridge.publishHandler("onGetSelectedTextRange", {
callbackId,
data
}, pageId2);
});
registerViewMethod(getCurrentPageId(), "getSelectedTextRange", getSelectedTextRange);
};
function getValueString(value) {
return value === null ? "" : String(value);
......@@ -9677,7 +9700,7 @@ var api = /* @__PURE__ */ Object.freeze({
const uni$1 = api;
const UniServiceJSBridge$1 = /* @__PURE__ */ shared.extend(ServiceJSBridge, {
publishHandler(event, args, pageId) {
UniViewJSBridge.subscribeHandler(pageId + "." + event, args, pageId);
UniViewJSBridge.subscribeHandler(event, args, pageId);
}
});
var TabBar = /* @__PURE__ */ defineSystemComponent({
......
......@@ -396,6 +396,7 @@ const initI18nVideoMsgsOnce = /* @__PURE__ */ once(() => {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, { danmu: "\u5F48\u5E55", volume: "\u97F3\u91CF" }));
}
});
const INVOKE_VIEW_API = "invokeViewApi";
const E = function() {
};
E.prototype = {
......@@ -470,14 +471,60 @@ function initBridge(subscribeNamespace) {
};
}
const ViewJSBridge = /* @__PURE__ */ initBridge("service");
function normalizeViewMethodName(pageId, name) {
return pageId + "." + name;
}
function subscribeViewMethod(pageId) {
UniViewJSBridge.subscribe(normalizeViewMethodName(pageId, INVOKE_VIEW_API), onInvokeViewMethod);
}
function unsubscribeViewMethod(pageId) {
if (process.env.NODE_ENV !== "production") {
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 (process.env.NODE_ENV !== "production") {
console.log(formatLog("unsubscribeViewMethod", name));
}
delete viewMethods[name];
}
});
}
const viewMethods = Object.create(null);
function registerViewMethod(pageId, name, fn) {
name = normalizeViewMethodName(pageId, name);
if (!viewMethods[name]) {
viewMethods[name] = fn;
}
}
function onInvokeViewMethod({
id: id2,
name,
args
}, pageId) {
name = normalizeViewMethodName(pageId, name);
const publish = (res) => {
UniViewJSBridge.publishHandler(INVOKE_VIEW_API + "." + id2, res);
};
const handler = viewMethods[name];
if (handler) {
handler(args, publish);
} else {
publish({});
if (process.env.NODE_ENV !== "production") {
console.error(formatLog("invokeViewMethod", name, "not register"));
}
}
}
const LONGPRESS_TIMEOUT = 350;
const LONGPRESS_THRESHOLD = 10;
const passiveOptions$2 = passive(true);
let longPressTimer = 0;
let longPressTimer;
function clearLongPressTimer() {
if (longPressTimer) {
clearTimeout(longPressTimer);
longPressTimer = 0;
longPressTimer = null;
}
}
let startPageX = 0;
......@@ -857,15 +904,6 @@ function getPageIdByVm(vm) {
return rootProxy.$page.id;
}
}
function getPageById(id2) {
return getCurrentPages().find((page) => page.$page.id === id2);
}
function getPageVmById(id2) {
const page = getPageById(id2);
if (page) {
return page.$vm;
}
}
function getCurrentPage() {
const pages = getCurrentPages();
const len = pages.length;
......@@ -1332,10 +1370,31 @@ function initAppConfig$1(appConfig) {
function initViewPlugin(app) {
initAppConfig$1(app._context.config);
}
let invokeViewMethodId = 0;
function publishViewMethodName() {
return getCurrentPageId() + "." + INVOKE_VIEW_API;
}
const invokeViewMethod = (name, args, callback, pageId) => {
const { subscribe, publishHandler } = UniServiceJSBridge;
const id2 = invokeViewMethodId++;
subscribe(INVOKE_VIEW_API + "." + id2, callback, true);
publishHandler(publishViewMethodName(), { id: id2, name, args }, pageId);
};
const invokeViewMethodKeepAlive = (name, args, callback, pageId) => {
const { subscribe, unsubscribe, publishHandler } = UniServiceJSBridge;
const id2 = invokeViewMethodId++;
const subscribeName = INVOKE_VIEW_API + "." + id2;
subscribe(subscribeName, callback);
publishHandler(publishViewMethodName(), { id: id2, name, args }, pageId);
return () => {
unsubscribe(subscribeName);
};
};
const invokeOnCallback = (name, res) => UniServiceJSBridge.emit("api." + name, res);
const ServiceJSBridge = /* @__PURE__ */ extend(initBridge("view"), {
invokeOnCallback(name, res) {
return UniServiceJSBridge.emit("api." + name, res);
}
invokeOnCallback,
invokeViewMethod,
invokeViewMethodKeepAlive
});
function initOn() {
const { on: on2 } = UniServiceJSBridge;
......@@ -1370,10 +1429,7 @@ function initSubscribe() {
}
function createPageEvent(name) {
return (args, pageId) => {
const vm = getPageVmById(pageId);
if (vm) {
invokeHook(vm, name, args);
}
invokeHook(pageId, name, args);
};
}
function initService() {
......@@ -4247,28 +4303,14 @@ const API_ON_TAB_BAR_MID_BUTTON_TAP = "onTabBarMidButtonTap";
const onTabBarMidButtonTap = /* @__PURE__ */ defineOnApi(API_ON_TAB_BAR_MID_BUTTON_TAP, () => {
});
const API_GET_SELECTED_TEXT_RANGE = "getSelectedTextRange";
const getSelectedTextRangeEventCallbacks = createCallbacks("getSelectedTextRangeEvent");
const onGetSelectedTextRange = /* @__PURE__ */ once(() => {
UniServiceJSBridge.subscribe("onGetSelectedTextRange", ({ callbackId, data }) => {
const callback = getSelectedTextRangeEventCallbacks.pop(callbackId);
if (callback) {
callback(data);
const getSelectedTextRange$1 = /* @__PURE__ */ defineAsyncApi(API_GET_SELECTED_TEXT_RANGE, (_, { resolve, reject }) => {
UniServiceJSBridge.invokeViewMethod("getSelectedTextRange", {}, (res) => {
if (typeof res.end === "undefined" && typeof res.start === "undefined") {
reject("no focused");
} else {
resolve(res);
}
});
});
const getSelectedTextRange = /* @__PURE__ */ defineAsyncApi(API_GET_SELECTED_TEXT_RANGE, (_, { resolve, reject }) => {
onGetSelectedTextRange();
const pageId = getCurrentPageId();
UniServiceJSBridge.publishHandler("getSelectedTextRange", {
pageId,
callbackId: getSelectedTextRangeEventCallbacks.push(function(res) {
if (typeof res.end === "undefined" && typeof res.start === "undefined") {
reject("no focused");
} else {
resolve(res);
}
})
}, pageId);
}, getCurrentPageId());
});
const API_CAN_I_USE = "canIUse";
const CanIUseProtocol = [
......@@ -7927,28 +7969,20 @@ function useFormField(nameKey, value) {
uniForm.removeField(ctx);
});
}
const pageIds = [];
function getSelectedTextRange(_, resolve) {
const activeElement = document.activeElement;
if (!activeElement) {
return resolve({});
}
const data = {};
if (["input", "textarea"].includes(activeElement.tagName.toLowerCase())) {
data.start = activeElement.selectionStart;
data.end = activeElement.selectionEnd;
}
resolve(data);
}
const UniViewJSBridgeSubscribe = function() {
const pageId = getCurrentPageId();
if (pageIds.includes(pageId))
return;
pageIds.push(pageId);
UniViewJSBridge.subscribe(pageId + ".getSelectedTextRange", function({ pageId: pageId2, callbackId }) {
const activeElement = document.activeElement;
if (!activeElement)
return;
const tagName = activeElement.tagName.toLowerCase();
const tagNames = ["input", "textarea"];
const data = {};
if (tagNames.includes(tagName)) {
data.start = activeElement.selectionStart;
data.end = activeElement.selectionEnd;
}
UniViewJSBridge.publishHandler("onGetSelectedTextRange", {
callbackId,
data
}, pageId2);
});
registerViewMethod(getCurrentPageId(), "getSelectedTextRange", getSelectedTextRange);
};
function getValueString(value) {
return value === null ? "" : String(value);
......@@ -13562,6 +13596,10 @@ function setupPage(comp) {
onHide && invokeArrayFns$1(onHide);
}
});
subscribeViewMethod(pageMeta.id);
onBeforeUnmount(() => {
unsubscribeViewMethod(pageMeta.id);
});
return route.query;
}
});
......@@ -18927,7 +18965,7 @@ var api = /* @__PURE__ */ Object.freeze({
canvasGetImageData,
canvasPutImageData,
canvasToTempFilePath,
getSelectedTextRange,
getSelectedTextRange: getSelectedTextRange$1,
$on,
$off,
$once,
......@@ -20314,7 +20352,7 @@ const UniViewJSBridge$1 = /* @__PURE__ */ extend(ViewJSBridge, {
const uni$1 = api;
const UniServiceJSBridge$1 = /* @__PURE__ */ extend(ServiceJSBridge, {
publishHandler(event, args, pageId) {
UniViewJSBridge.subscribeHandler(pageId + "." + event, args, pageId);
UniViewJSBridge.subscribeHandler(event, args, pageId);
}
});
function hexToRgba(hex) {
......@@ -21078,4 +21116,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]);
}
});
export { $emit, $off, $on, $once, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, _sfc_main$1 as Audio, index$s as Button, index$q as Canvas, index$o as Checkbox, index$p as CheckboxGroup, index$4 as CoverImage, index$5 as CoverView, index$n as Editor, index$u as Form, index$m as Icon, index$l as Image, Input, index$t as Label, LayoutComponent, Map$1 as Map, MovableArea, MovableView, index$k as Navigator, index$2 as PageComponent, index$3 as Picker, PickerView, PickerViewColumn, index$j as Progress, index$h as Radio, index$i as RadioGroup, ResizeSensor, index$g as RichText, ScrollView, index$f as Slider, Swiper, SwiperItem, index$e as Switch, index$d as Text, index$c as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$8 as Video, index$b as View, index$7 as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLeftWindowStyle, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onCompassChange, onGyroscopeChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$9 as plugin, preloadPage, previewImage, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setKeepScreenOn, setLeftWindowStyle, setNavigationBarColor, setNavigationBarTitle, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useTabBar, vibrateLong, vibrateShort };
export { $emit, $off, $on, $once, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, _sfc_main$1 as Audio, index$s as Button, index$q as Canvas, index$o as Checkbox, index$p as CheckboxGroup, index$4 as CoverImage, index$5 as CoverView, index$n as Editor, index$u as Form, index$m as Icon, index$l as Image, Input, index$t as Label, LayoutComponent, Map$1 as Map, MovableArea, MovableView, index$k as Navigator, index$2 as PageComponent, index$3 as Picker, PickerView, PickerViewColumn, index$j as Progress, index$h as Radio, index$i as RadioGroup, ResizeSensor, index$g as RichText, ScrollView, index$f as Slider, Swiper, SwiperItem, index$e as Switch, index$d as Text, index$c as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$8 as Video, index$b as View, index$7 as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLeftWindowStyle, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onCompassChange, onGyroscopeChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$9 as plugin, preloadPage, previewImage, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setKeepScreenOn, setLeftWindowStyle, setNavigationBarColor, setNavigationBarTitle, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useTabBar, vibrateLong, vibrateShort };
......@@ -10,6 +10,7 @@ import {
onBeforeActivate,
onBeforeDeactivate,
onBeforeMount,
onBeforeUnmount,
} from 'vue'
import { useRouter } from 'vue-router'
import {
......@@ -21,14 +22,11 @@ import {
ON_WEB_INVOKE_APP_SERVICE,
WEB_INVOKE_APPSERVICE,
} from '@dcloudio/uni-shared'
import { subscribeViewMethod, unsubscribeViewMethod } from '@dcloudio/uni-core'
import { LayoutComponent } from '../..'
import { initApp } from './app'
import { initPage, onPageShow, onPageReady } from './page'
import { usePageMeta, usePageRoute } from './provide'
import {
API_ON_WINDOW_RESIZE,
API_TYPE_ON_WINDOW_RESIZE,
} from '@dcloudio/uni-api'
interface SetupComponentOptions {
init: (vm: ComponentPublicInstance) => void
......@@ -102,6 +100,11 @@ export function setupPage(comp: any) {
}
})
subscribeViewMethod(pageMeta.id!)
onBeforeUnmount(() => {
unsubscribeViewMethod(pageMeta.id!)
})
return route.query
},
})
......
......@@ -4,6 +4,6 @@ import { ServiceJSBridge } from '@dcloudio/uni-core'
export const UniServiceJSBridge = /*#__PURE__*/ extend(ServiceJSBridge, {
publishHandler(event: string, args: any, pageId: number) {
UniViewJSBridge.subscribeHandler(pageId + '.' + event, args, pageId)
UniViewJSBridge.subscribeHandler(event, args, pageId)
},
})
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册