diff --git a/packages/uni-app-plus/dist/uni-app-service.es.js b/packages/uni-app-plus/dist/uni-app-service.es.js index c7491722f7f46eb76c224fc331e76f68689f33be..120e066535bf2b739765f3bd4aee4d7d52708e06 100644 --- a/packages/uni-app-plus/dist/uni-app-service.es.js +++ b/packages/uni-app-plus/dist/uni-app-service.es.js @@ -17168,8 +17168,8 @@ var serviceContext = (function (vue) { // 需要序列化一遍 const routeOptions = JSON.parse(JSON.stringify(getRouteOptions(path))); routeOptions.meta = initRouteMeta(routeOptions.meta); - if (openType === 'reLaunch' || - (!__uniConfig.realEntryPagePath && getCurrentPages().length === 0) // redirectTo + if (!__uniConfig.realEntryPagePath && + (openType === 'reLaunch' || getCurrentPages().length === 0) // redirectTo ) { routeOptions.meta.isQuit = true; } @@ -17501,6 +17501,26 @@ var serviceContext = (function (vue) { }); } + /** + * 是否处于直达页面 + * @param page + * @returns + */ + function isDirectPage(page) { + return (__uniConfig.realEntryPagePath && + page.$page.route === __uniConfig.entryPagePath); + } + /** + * 重新启动到首页 + */ + function reLaunchEntryPage() { + __uniConfig.entryPagePath = __uniConfig.realEntryPagePath; + delete __uniConfig.realEntryPagePath; + uni.reLaunch({ + url: addLeadingSlash(__uniConfig.entryPagePath), + }); + } + let lastStatusBarStyle; let oldSetStatusBarStyle = plus.navigator.setStatusBarStyle; function restoreOldSetStatusBarStyle(setStatusBarStyle) { @@ -17621,10 +17641,16 @@ var serviceContext = (function (vue) { setStatusBarStyle(popStartStatusBarStyle); } else if (e.type === 'end' && e.result) { + const page = getCurrentPage(); removeCurrentPage(); setStatusBarStyle(); - // 触发前一个页面 onShow - invokeHook(ON_SHOW); + if (page && isDirectPage(page)) { + reLaunchEntryPage(); + } + else { + // 触发前一个页面 onShow + invokeHook(ON_SHOW); + } } }); } @@ -19520,16 +19546,8 @@ var serviceContext = (function (vue) { if (page.$page.meta.isQuit) { quit(); } - else if ( - // 处于直达页面 - page.$page.route === __uniConfig.entryPagePath && - __uniConfig.realEntryPagePath) { - // condition - __uniConfig.entryPagePath = __uniConfig.realEntryPagePath; - delete __uniConfig.realEntryPagePath; - uni.reLaunch({ - url: addLeadingSlash(__uniConfig.entryPagePath), - }); + else if (isDirectPage(page)) { + reLaunchEntryPage(); } else { const { delta, animationType, animationDuration } = args; diff --git a/packages/uni-app-plus/src/service/api/route/direct.ts b/packages/uni-app-plus/src/service/api/route/direct.ts new file mode 100644 index 0000000000000000000000000000000000000000..d2022bc792be5b75d06fb8c40a87c46044630e3d --- /dev/null +++ b/packages/uni-app-plus/src/service/api/route/direct.ts @@ -0,0 +1,23 @@ +import { addLeadingSlash } from '@dcloudio/uni-shared' + +/** + * 是否处于直达页面 + * @param page + * @returns + */ +export function isDirectPage(page: Page.PageInstance) { + return ( + __uniConfig.realEntryPagePath && + page.$page.route === __uniConfig.entryPagePath + ) +} +/** + * 重新启动到首页 + */ +export function reLaunchEntryPage() { + __uniConfig.entryPagePath = __uniConfig.realEntryPagePath + delete __uniConfig.realEntryPagePath + uni.reLaunch({ + url: addLeadingSlash(__uniConfig.entryPagePath!), + }) +} diff --git a/packages/uni-app-plus/src/service/api/route/navigateBack.ts b/packages/uni-app-plus/src/service/api/route/navigateBack.ts index bb74e04467dee79ff74dd40bfd19734d20a676d9..6b943262a9b329f6ba37fb51370b2685513e48c4 100644 --- a/packages/uni-app-plus/src/service/api/route/navigateBack.ts +++ b/packages/uni-app-plus/src/service/api/route/navigateBack.ts @@ -1,3 +1,4 @@ +import { ComponentPublicInstance } from 'vue' import { API_NAVIGATE_BACK, API_TYPE_NAVIGATE_BACK, @@ -11,12 +12,13 @@ import { invokeHook, } from '@dcloudio/uni-core' import { useI18n } from '@dcloudio/uni-core' -import { addLeadingSlash, ON_BACK_PRESS, ON_SHOW } from '@dcloudio/uni-shared' -import { ComponentPublicInstance } from 'vue' +import { ON_BACK_PRESS, ON_SHOW } from '@dcloudio/uni-shared' + import { ANI_CLOSE, ANI_DURATION } from '../../constants' import { removePage } from '../../framework/page/getCurrentPages' import { setStatusBarStyle } from '../../statusBar' import { backWebview, closeWebview } from './webview' +import { isDirectPage, reLaunchEntryPage } from './direct' export const navigateBack = defineAsyncApi( API_NAVIGATE_BACK, @@ -36,17 +38,8 @@ export const navigateBack = defineAsyncApi( uni.hideLoading() if (page.$page.meta.isQuit) { quit() - } else if ( - // 处于直达页面 - page.$page.route === __uniConfig.entryPagePath && - __uniConfig.realEntryPagePath - ) { - // condition - __uniConfig.entryPagePath = __uniConfig.realEntryPagePath - delete __uniConfig.realEntryPagePath - uni.reLaunch({ - url: addLeadingSlash(__uniConfig.entryPagePath), - }) + } else if (isDirectPage(page)) { + reLaunchEntryPage() } else { const { delta, animationType, animationDuration } = args back(delta!, animationType, animationDuration) diff --git a/packages/uni-app-plus/src/service/framework/page/routeOptions.ts b/packages/uni-app-plus/src/service/framework/page/routeOptions.ts index ab3c880c28f19009997a2ea96f732c7195f61678..b00e34610b4733a9c2252b8b789e3d4c4bf17bac 100644 --- a/packages/uni-app-plus/src/service/framework/page/routeOptions.ts +++ b/packages/uni-app-plus/src/service/framework/page/routeOptions.ts @@ -9,8 +9,8 @@ export function initRouteOptions(path: string, openType: UniApp.OpenType) { routeOptions.meta = initRouteMeta(routeOptions.meta) if ( - openType === 'reLaunch' || - (!__uniConfig.realEntryPagePath && getCurrentPages().length === 0) // redirectTo + !__uniConfig.realEntryPagePath && + (openType === 'reLaunch' || getCurrentPages().length === 0) // redirectTo ) { routeOptions.meta.isQuit = true } else if (!routeOptions.meta.isTabBar) { diff --git a/packages/uni-app-plus/src/service/framework/webview/init/event/popGesture.ts b/packages/uni-app-plus/src/service/framework/webview/init/event/popGesture.ts index 4f293c988e4f16eb7e9a04cd426350e5891f79f6..da1dbebf66cfa6a4e464070a620b68c4ddf0b2cf 100644 --- a/packages/uni-app-plus/src/service/framework/webview/init/event/popGesture.ts +++ b/packages/uni-app-plus/src/service/framework/webview/init/event/popGesture.ts @@ -1,5 +1,6 @@ -import { invokeHook } from '@dcloudio/uni-core' +import { getCurrentPage, invokeHook } from '@dcloudio/uni-core' import { ON_SHOW } from '@dcloudio/uni-shared' +import { isDirectPage, reLaunchEntryPage } from '../../../../api/route/direct' import { lastStatusBarStyle, setStatusBarStyle, @@ -22,10 +23,15 @@ export function onWebviewPopGesture(webview: PlusWebviewWebviewObject) { // 拖拽未完成,设置为当前状态栏前景色 setStatusBarStyle(popStartStatusBarStyle) } else if (e.type === 'end' && e.result) { + const page = getCurrentPage() removeCurrentPage() setStatusBarStyle() - // 触发前一个页面 onShow - invokeHook(ON_SHOW) + if (page && isDirectPage(page)) { + reLaunchEntryPage() + } else { + // 触发前一个页面 onShow + invokeHook(ON_SHOW) + } } }) }