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

fix(app): launch without interceptor

上级 a2a08763
......@@ -233,15 +233,17 @@ export function defineSyncApi<T extends ApiLike>(
) 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>>(
name: string,
fn: (
args: P extends undefined ? undefined : Omit<P, CALLBACK_TYPES>,
res: {
resolve: (res: AsyncApiRes<P> | void) => void
reject: (errMsg?: string, errRes?: any) => void
}
) => void,
fn: DefineAsyncApiFn<T>,
protocol?: ApiProtocols<T>,
options?: ApiOptions<T>
) {
......
......@@ -114,3 +114,7 @@ export {
export { handlePromise } from './helpers/api/promise'
export { invokeApi, wrapperReturnValue } from './helpers/interceptor'
export { requestComponentObserver } from './helpers/requestComponentObserver'
// types
export { DefineAsyncApiFn } from './helpers/api'
......@@ -68,10 +68,10 @@ export * from './ad/interstitialAd'
export * from './ad/interactiveAd'
export * from './route/navigateBack'
export * from './route/navigateTo'
export { navigateTo } from './route/navigateTo'
export * from './route/redirectTo'
export * from './route/reLaunch'
export * from './route/switchTab'
export { switchTab } from './route/switchTab'
export * from './route/preloadPage'
export {
......
......@@ -4,6 +4,7 @@ import {
API_NAVIGATE_TO,
API_TYPE_NAVIGATE_TO,
defineAsyncApi,
DefineAsyncApiFn,
NavigateToOptions,
NavigateToProtocol,
} from '@dcloudio/uni-api'
......@@ -13,32 +14,37 @@ import { navigate, RouteOptions } from './utils'
import { showWebview } from './webview'
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>(
API_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'
)
},
$navigateTo,
NavigateToProtocol,
NavigateToOptions
)
......
......@@ -2,6 +2,7 @@ import {
API_SWITCH_TAB,
API_TYPE_SWITCH_TAB,
defineAsyncApi,
DefineAsyncApiFn,
SwitchTabOptions,
SwitchTabProtocol,
} from '@dcloudio/uni-api'
......@@ -16,25 +17,30 @@ import { setStatusBarStyle } from '../../statusBar'
import { closePage, navigate, RouteOptions } from './utils'
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>(
API_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'
)
},
$switchTab,
SwitchTabProtocol,
SwitchTabOptions
)
......
import { getRouteOptions } from '@dcloudio/uni-core'
import { ON_WEBVIEW_READY } from '../../../../constants'
import { $navigateTo } from '../../../api/route/navigateTo'
import { $switchTab } from '../../../api/route/switchTab'
import { preloadWebview, setPreloadWebview } from '../../webview'
let isLaunchWebviewReady = false // 目前首页双向确定 ready,可能会导致触发两次 onWebviewReady(主要是 Android)
......@@ -42,9 +44,10 @@ function onLaunchWebviewReady() {
url: entryPagePath + (__uniConfig.entryPageQuery || ''),
openType: 'appLaunch',
}
const handler = { resolve() {}, reject() {} }
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.
先完成此消息的编辑!
想要评论请 注册