提交 2bb3a826 编写于 作者: fxy060608's avatar fxy060608

fix(h5): onBackPress

上级 f1174f1c
......@@ -373,9 +373,6 @@ function initBridge(subscribeNamespace) {
emitter.off(`${subscribeNamespace}.${event}`, callback);
},
subscribeHandler(event, args, pageId) {
if (process.env.NODE_ENV !== "production") {
console.log(uniShared.formatLog(subscribeNamespace, "subscribeHandler", pageId, event, args));
}
emitter.emit(`${subscribeNamespace}.${event}`, args, pageId);
}
};
......@@ -10587,6 +10584,7 @@ function onPageHeadBackButton() {
} else {
uni.navigateBack({
from: "backbutton"
}).catch(() => {
});
}
}
......
import { isFunction, extend, isString, hyphenate, isPlainObject, isArray, hasOwn, isObject, capitalize, toRawType, makeMap as makeMap$1, isPromise, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, formatLog, passive, initCustomDataset, invokeArrayFns, normalizeTarget, isBuiltInComponent, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, ON_ERROR, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { once, passive, initCustomDataset, invokeArrayFns, normalizeTarget, isBuiltInComponent, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, ON_ERROR, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { openBlock, createBlock, mergeProps, createVNode, toDisplayString, withModifiers, getCurrentInstance, defineComponent, ref, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, createTextVNode, injectHook, onBeforeActivate, onBeforeDeactivate, renderList, onDeactivated, createApp, Transition, withCtx, KeepAlive, resolveDynamicComponent, renderSlot } from "vue";
import { initVueI18n, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
......@@ -462,9 +462,6 @@ function initBridge(subscribeNamespace) {
emitter2.off(`${subscribeNamespace}.${event}`, callback);
},
subscribeHandler(event, args, pageId) {
if (process.env.NODE_ENV !== "production") {
console.log(formatLog(subscribeNamespace, "subscribeHandler", pageId, event, args));
}
emitter2.emit(`${subscribeNamespace}.${event}`, args, pageId);
}
};
......@@ -486,15 +483,9 @@ 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];
}
});
......@@ -523,9 +514,6 @@ function onInvokeViewMethod({
handler(args, publish);
} else {
publish({});
if (process.env.NODE_ENV !== "production") {
console.error(formatLog("invokeViewMethod", name, "not register"));
}
}
}
const ViewJSBridge = /* @__PURE__ */ extend(initBridge("service"), {
......@@ -3045,8 +3033,8 @@ class MapContext {
getCenterLocation(options) {
operateMapWrap(this.id, this.pageId, "getCenterLocation", options);
}
moveToLocation() {
operateMapWrap(this.id, this.pageId, "moveToLocation");
moveToLocation(options) {
operateMapWrap(this.id, this.pageId, "moveToLocation", options);
}
getScale(options) {
operateMapWrap(this.id, this.pageId, "getScale", options);
......@@ -17516,15 +17504,15 @@ const chooseLocation = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_LOCATION, (args
reject("cancel");
}
}, ChooseLocationProtocol);
const navigateBack = /* @__PURE__ */ defineAsyncApi(API_NAVIGATE_BACK, ({ delta }, { resolve, reject }) => {
const navigateBack = /* @__PURE__ */ defineAsyncApi(API_NAVIGATE_BACK, (args, { resolve, reject }) => {
let canBack = true;
if (invokeHook(ON_BACK_PRESS) === true) {
if (invokeHook(ON_BACK_PRESS, { from: args.from }) === true) {
canBack = false;
}
if (!canBack) {
return reject(ON_BACK_PRESS);
}
getApp().$router.go(-delta);
getApp().$router.go(-args.delta);
return resolve();
}, NavigateBackProtocol, NavigateBackOptions);
function navigate({ type, url, events }, __id__) {
......@@ -20809,6 +20797,7 @@ function onPageHeadBackButton() {
} else {
uni.navigateBack({
from: "backbutton"
}).catch(() => {
});
}
}
......
......@@ -250,7 +250,7 @@ function onPageHeadBackButton() {
} else {
;(uni.navigateBack as Function)({
from: 'backbutton',
})
}).catch(() => {})
}
}
......
......@@ -10,15 +10,16 @@ import { ON_BACK_PRESS } from '@dcloudio/uni-shared'
export const navigateBack = defineAsyncApi<API_TYPE_NAVIGATE_BACK>(
API_NAVIGATE_BACK,
({ delta }, { resolve, reject }) => {
(args, { resolve, reject }) => {
let canBack = true
if (invokeHook(ON_BACK_PRESS) === true) {
if (invokeHook(ON_BACK_PRESS, { from: (args as any).from }) === true) {
canBack = false
}
if (!canBack) {
return reject(ON_BACK_PRESS)
}
getApp().$router.go(-delta!)
getApp().$router.go(-args.delta!)
return resolve()
},
NavigateBackProtocol,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册