提交 4d63d070 编写于 作者: fxy060608's avatar fxy060608

fix(app): launch without interceptor

上级 a2a08763
...@@ -233,15 +233,17 @@ export function defineSyncApi<T extends ApiLike>( ...@@ -233,15 +233,17 @@ export function defineSyncApi<T extends ApiLike>(
) as unknown as T ) as unknown as T
} }
export type DefineAsyncApiFn<T extends AsyncApiLike, P = AsyncApiOptions<T>> = (
args: P extends undefined ? undefined : Omit<P, CALLBACK_TYPES>,
res: {
resolve: (res: AsyncApiRes<P> | void) => void
reject: (errMsg?: string, errRes?: any) => void
}
) => void
export function defineAsyncApi<T extends AsyncApiLike, P = AsyncApiOptions<T>>( export function defineAsyncApi<T extends AsyncApiLike, P = AsyncApiOptions<T>>(
name: string, name: string,
fn: ( fn: DefineAsyncApiFn<T>,
args: P extends undefined ? undefined : Omit<P, CALLBACK_TYPES>,
res: {
resolve: (res: AsyncApiRes<P> | void) => void
reject: (errMsg?: string, errRes?: any) => void
}
) => void,
protocol?: ApiProtocols<T>, protocol?: ApiProtocols<T>,
options?: ApiOptions<T> options?: ApiOptions<T>
) { ) {
......
...@@ -114,3 +114,7 @@ export { ...@@ -114,3 +114,7 @@ export {
export { handlePromise } from './helpers/api/promise' export { handlePromise } from './helpers/api/promise'
export { invokeApi, wrapperReturnValue } from './helpers/interceptor' export { invokeApi, wrapperReturnValue } from './helpers/interceptor'
export { requestComponentObserver } from './helpers/requestComponentObserver' export { requestComponentObserver } from './helpers/requestComponentObserver'
// types
export { DefineAsyncApiFn } from './helpers/api'
...@@ -68,10 +68,10 @@ export * from './ad/interstitialAd' ...@@ -68,10 +68,10 @@ export * from './ad/interstitialAd'
export * from './ad/interactiveAd' export * from './ad/interactiveAd'
export * from './route/navigateBack' export * from './route/navigateBack'
export * from './route/navigateTo' export { navigateTo } from './route/navigateTo'
export * from './route/redirectTo' export * from './route/redirectTo'
export * from './route/reLaunch' export * from './route/reLaunch'
export * from './route/switchTab' export { switchTab } from './route/switchTab'
export * from './route/preloadPage' export * from './route/preloadPage'
export { export {
......
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
API_NAVIGATE_TO, API_NAVIGATE_TO,
API_TYPE_NAVIGATE_TO, API_TYPE_NAVIGATE_TO,
defineAsyncApi, defineAsyncApi,
DefineAsyncApiFn,
NavigateToOptions, NavigateToOptions,
NavigateToProtocol, NavigateToProtocol,
} from '@dcloudio/uni-api' } from '@dcloudio/uni-api'
...@@ -13,32 +14,37 @@ import { navigate, RouteOptions } from './utils' ...@@ -13,32 +14,37 @@ import { navigate, RouteOptions } from './utils'
import { showWebview } from './webview' import { showWebview } from './webview'
import { registerPage } from '../../framework/page' import { registerPage } from '../../framework/page'
export const $navigateTo: DefineAsyncApiFn<API_TYPE_NAVIGATE_TO> = (
args,
{ resolve, reject }
) => {
const { url, animationType, animationDuration } = args
const { path, query } = parseUrl(url)
const [aniType, aniDuration] = initAnimation(
path,
animationType,
animationDuration
)
navigate(
path,
() => {
_navigateTo({
url,
path,
query,
aniType,
aniDuration,
})
.then(resolve)
.catch(reject)
},
(args as any).openType === 'appLaunch'
)
}
export const navigateTo = defineAsyncApi<API_TYPE_NAVIGATE_TO>( export const navigateTo = defineAsyncApi<API_TYPE_NAVIGATE_TO>(
API_NAVIGATE_TO, API_NAVIGATE_TO,
(args, { resolve, reject }) => { $navigateTo,
const { url, animationType, animationDuration } = args
const { path, query } = parseUrl(url)
const [aniType, aniDuration] = initAnimation(
path,
animationType,
animationDuration
)
navigate(
path,
() => {
_navigateTo({
url,
path,
query,
aniType,
aniDuration,
})
.then(resolve)
.catch(reject)
},
(args as any).openType === 'appLaunch'
)
},
NavigateToProtocol, NavigateToProtocol,
NavigateToOptions NavigateToOptions
) )
......
...@@ -2,6 +2,7 @@ import { ...@@ -2,6 +2,7 @@ import {
API_SWITCH_TAB, API_SWITCH_TAB,
API_TYPE_SWITCH_TAB, API_TYPE_SWITCH_TAB,
defineAsyncApi, defineAsyncApi,
DefineAsyncApiFn,
SwitchTabOptions, SwitchTabOptions,
SwitchTabProtocol, SwitchTabProtocol,
} from '@dcloudio/uni-api' } from '@dcloudio/uni-api'
...@@ -16,25 +17,30 @@ import { setStatusBarStyle } from '../../statusBar' ...@@ -16,25 +17,30 @@ import { setStatusBarStyle } from '../../statusBar'
import { closePage, navigate, RouteOptions } from './utils' import { closePage, navigate, RouteOptions } from './utils'
import { closeWebview, showWebview } from './webview' import { closeWebview, showWebview } from './webview'
export const $switchTab: DefineAsyncApiFn<API_TYPE_SWITCH_TAB> = (
args,
{ resolve, reject }
) => {
const { url } = args
const { path, query } = parseUrl(url)
navigate(
path,
() => {
_switchTab({
url,
path,
query,
})
.then(resolve)
.catch(reject)
},
(args as any).openType === 'appLaunch'
)
}
export const switchTab = defineAsyncApi<API_TYPE_SWITCH_TAB>( export const switchTab = defineAsyncApi<API_TYPE_SWITCH_TAB>(
API_SWITCH_TAB, API_SWITCH_TAB,
(args, { resolve, reject }) => { $switchTab,
const { url } = args
const { path, query } = parseUrl(url)
navigate(
path,
() => {
_switchTab({
url,
path,
query,
})
.then(resolve)
.catch(reject)
},
(args as any).openType === 'appLaunch'
)
},
SwitchTabProtocol, SwitchTabProtocol,
SwitchTabOptions SwitchTabOptions
) )
......
import { getRouteOptions } from '@dcloudio/uni-core' import { getRouteOptions } from '@dcloudio/uni-core'
import { ON_WEBVIEW_READY } from '../../../../constants' import { ON_WEBVIEW_READY } from '../../../../constants'
import { $navigateTo } from '../../../api/route/navigateTo'
import { $switchTab } from '../../../api/route/switchTab'
import { preloadWebview, setPreloadWebview } from '../../webview' import { preloadWebview, setPreloadWebview } from '../../webview'
let isLaunchWebviewReady = false // 目前首页双向确定 ready,可能会导致触发两次 onWebviewReady(主要是 Android) let isLaunchWebviewReady = false // 目前首页双向确定 ready,可能会导致触发两次 onWebviewReady(主要是 Android)
...@@ -42,9 +44,10 @@ function onLaunchWebviewReady() { ...@@ -42,9 +44,10 @@ function onLaunchWebviewReady() {
url: entryPagePath + (__uniConfig.entryPageQuery || ''), url: entryPagePath + (__uniConfig.entryPageQuery || ''),
openType: 'appLaunch', openType: 'appLaunch',
} }
const handler = { resolve() {}, reject() {} }
if (routeOptions.meta.isTabBar) { if (routeOptions.meta.isTabBar) {
return uni.switchTab(args) return $switchTab(args, handler)
} }
return uni.navigateTo(args) return $navigateTo(args, handler)
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册