|
1 | 1 | import type { UniDialogPage } from '@dcloudio/uni-app-x/types/page' |
2 | 2 | import { ON_HIDE, ON_SHOW } from '@dcloudio/uni-shared' |
3 | 3 | import { invokeHook } from './hook' |
| 4 | +import { getCurrentPage } from '@dcloudio/uni-core' |
| 5 | +import type { ComponentInternalInstance } from 'vue' |
4 | 6 |
|
5 | 7 | export const SYSTEM_DIALOG_PAGE_PATH_STARTER = 'uni:' |
6 | 8 | export const SYSTEM_DIALOG_ACTION_SHEET_PAGE_PATH = 'uni:actionSheet' |
@@ -116,3 +118,38 @@ export function invokeLastDialogPageHookByUniPage( |
116 | 118 | invokeHook(lastDialogPage.vm, hook) |
117 | 119 | } |
118 | 120 | } |
| 121 | + |
| 122 | +export function invokeNewDialogPageHook(page: UniDialogPage, hook: string) { |
| 123 | + let shouldInvoke = false |
| 124 | + const currentPage = getCurrentPage() as unknown as UniPage |
| 125 | + if (isSystemDialogPage(page)) { |
| 126 | + const systemDialogPages = getSystemDialogPages(currentPage) |
| 127 | + shouldInvoke = systemDialogPages.includes(page as UniDialogPage) |
| 128 | + } else { |
| 129 | + const dialogPages = currentPage.getDialogPages() |
| 130 | + shouldInvoke = dialogPages.includes(page as UniDialogPage) |
| 131 | + } |
| 132 | + shouldInvoke && invokeHook(page.vm, hook) |
| 133 | +} |
| 134 | + |
| 135 | +export function getPageInstanceByChild(child: ComponentInternalInstance) { |
| 136 | + let pageInstance: ComponentInternalInstance | null = child |
| 137 | + while (pageInstance && pageInstance.type?.name !== 'Page') { |
| 138 | + pageInstance = pageInstance.parent |
| 139 | + } |
| 140 | + return pageInstance |
| 141 | +} |
| 142 | + |
| 143 | +export const DIALOG_TAG = 'dialog' |
| 144 | +export const SYSTEM_DIALOG_TAG = 'systemDialog' |
| 145 | + |
| 146 | +export function isDialogPageInstance(vm: ComponentInternalInstance | null) { |
| 147 | + if (!vm) return false |
| 148 | + return isNormalDialogPageInstance(vm) || isSystemDialogPageInstance(vm) |
| 149 | +} |
| 150 | +export function isNormalDialogPageInstance(vm: ComponentInternalInstance) { |
| 151 | + return vm.attrs['data-type'] === DIALOG_TAG |
| 152 | +} |
| 153 | +export function isSystemDialogPageInstance(vm: ComponentInternalInstance) { |
| 154 | + return vm.attrs['data-type'] === SYSTEM_DIALOG_TAG |
| 155 | +} |
0 commit comments