Skip to content

Commit 83f5fa2

Browse files
committed
refactor(x-app): 代码优化
1 parent 2579c9f commit 83f5fa2

1 file changed

Lines changed: 4 additions & 19 deletions

File tree

packages/uni-app-plus/src/x/framework/app/initGlobalEvent.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { UniDialogPage } from '@dcloudio/uni-app-x/types/page'
33
import { ON_BACK_PRESS } from '@dcloudio/uni-shared'
44
import {
55
getCurrentPage,
6-
getSystemDialogPages,
6+
getLastDialogPage,
77
invokeHook,
88
} from '@dcloudio/uni-core'
99
import { backbuttonListener } from '../../../service/framework/app/utils'
@@ -16,24 +16,9 @@ export function initGlobalEvent(app: IApp) {
1616
// 目前app-ios和app-harmony均会执行此逻辑,但是app-ios理论上始终不会触发以下dialogPage逻辑
1717
const currentPage = getCurrentPage() as unknown as UniPage
1818
if (currentPage) {
19-
const systemDialogPages = getSystemDialogPages(currentPage)
20-
const dialogPages = currentPage.getDialogPages()
21-
if (systemDialogPages.length > 0 || dialogPages.length > 0) {
22-
const lastSystemDialog = systemDialogPages[systemDialogPages.length - 1]
23-
const lastDialog = dialogPages[dialogPages.length - 1]
24-
25-
if (!systemDialogPages.length) {
26-
handleDialogPageBack(lastDialog as UniDialogPage)
27-
} else if (!dialogPages.length) {
28-
handleDialogPageBack(lastSystemDialog as UniDialogPage)
29-
} else {
30-
handleDialogPageBack(
31-
(parseInt(lastDialog.vm!.$nativePage!.pageId) >
32-
parseInt(lastSystemDialog.vm!.$nativePage!.pageId)
33-
? lastDialog
34-
: lastSystemDialog) as UniDialogPage
35-
)
36-
}
19+
const lastDialogPage = getLastDialogPage(currentPage)
20+
if (lastDialogPage) {
21+
handleDialogPageBack(lastDialogPage)
3722
return true
3823
}
3924
}

0 commit comments

Comments
 (0)