提交 0200ea64 编写于 作者: fxy060608's avatar fxy060608

refactor: reLaunch

上级 6c898e6b
import {
API_TYPE_RE_LAUNCH,
DefineAsyncApiFn,
ReLaunchOptions,
} from '@dcloudio/uni-api'
import { parseUrl } from '@dcloudio/uni-shared'
import tabBar from '../../framework/app/tabBar'
import { registerPage } from '../../framework/page/register'
import { getAllPages } from '../../framework/page/getCurrentPages'
import { setStatusBarStyle } from '../../statusBar'
import { closePage, navigate, RouteOptions } from './utils'
import { showWebview } from './webview'
interface ReLaunchOptions extends RouteOptions {}
export const $reLaunch: DefineAsyncApiFn<API_TYPE_RE_LAUNCH> = (
{ url },
{ resolve, reject }
) => {
const { path, query } = parseUrl(url)
navigate(path, () => {
_reLaunch({
url,
path,
query,
})
.then(resolve)
.catch(reject)
})
}
function _reLaunch({ url, path, query }: ReLaunchOptions): Promise<undefined> {
return new Promise((resolve) => {
// 获取目前所有页面
const pages = getAllPages().slice(0)
const routeOptions = __uniRoutes.find((route) => route.path === path)!
if (routeOptions.meta.isTabBar) {
tabBar.switchTab(path.slice(1))
}
showWebview(
registerPage({
url,
path,
query,
openType: 'reLaunch',
}),
'none',
0,
() => {
pages.forEach((page) => closePage(page, 'none'))
resolve(undefined)
}
)
setStatusBarStyle()
})
}
......@@ -2,33 +2,10 @@ import {
API_RE_LAUNCH,
API_TYPE_RE_LAUNCH,
defineAsyncApi,
DefineAsyncApiFn,
ReLaunchOptions,
ReLaunchProtocol,
} from '@dcloudio/uni-api'
import { parseUrl } from '@dcloudio/uni-shared'
import tabBar from '../../framework/app/tabBar'
import { registerPage } from '../../framework/page'
import { getAllPages } from '../../framework/page/getCurrentPages'
import { setStatusBarStyle } from '../../statusBar'
import { closePage, navigate, RouteOptions } from './utils'
import { showWebview } from './webview'
export const $reLaunch: DefineAsyncApiFn<API_TYPE_RE_LAUNCH> = (
{ url },
{ resolve, reject }
) => {
const { path, query } = parseUrl(url)
navigate(path, () => {
_reLaunch({
url,
path,
query,
})
.then(resolve)
.catch(reject)
})
}
import { $reLaunch } from './_reLaunch'
export const reLaunch = defineAsyncApi<API_TYPE_RE_LAUNCH>(
API_RE_LAUNCH,
......@@ -36,32 +13,3 @@ export const reLaunch = defineAsyncApi<API_TYPE_RE_LAUNCH>(
ReLaunchProtocol,
ReLaunchOptions
)
interface ReLaunchOptions extends RouteOptions {}
function _reLaunch({ url, path, query }: ReLaunchOptions): Promise<undefined> {
return new Promise((resolve) => {
// 获取目前所有页面
const pages = getAllPages().slice(0)
const routeOptions = __uniRoutes.find((route) => route.path === path)!
if (routeOptions.meta.isTabBar) {
tabBar.switchTab(path.slice(1))
}
showWebview(
registerPage({
url,
path,
query,
openType: 'reLaunch',
}),
'none',
0,
() => {
pages.forEach((page) => closePage(page, 'none'))
resolve(undefined)
}
)
setStatusBarStyle()
})
}
......@@ -4,14 +4,16 @@ import {
ON_APP_ENTER_FOREGROUND,
ON_THEME_CHANGE,
ON_KEYBOARD_HEIGHT_CHANGE,
addLeadingSlash,
} from '@dcloudio/uni-shared'
import { $reLaunch } from '../../api/route/_reLaunch'
import {
EVENT_BACKBUTTON,
backbuttonListener,
parseRedirectInfo,
initEnterOptions,
getEnterOptions,
initEnterReLaunch,
RedirectInfo,
} from './utils'
export function initGlobalEvent() {
......@@ -89,3 +91,14 @@ export function onPlusMessage<T>(
) {
UniServiceJSBridge.subscribe('plusMessage.' + type, callback, once)
}
function initEnterReLaunch(info: RedirectInfo) {
__uniConfig.realEntryPagePath =
__uniConfig.realEntryPagePath || __uniConfig.entryPagePath
__uniConfig.entryPagePath = info.path
__uniConfig.entryPageQuery = info.query
$reLaunch(
{ url: addLeadingSlash(info.path) + info.query },
{ resolve() {}, reject() {} }
)
}
import { extend } from '@vue/shared'
import { addLeadingSlash, parseQuery } from '@dcloudio/uni-shared'
import { parseQuery } from '@dcloudio/uni-shared'
import { createLaunchOptions, LaunchOptions } from '@dcloudio/uni-core'
import { $reLaunch } from '../../api/route/reLaunch'
export const EVENT_BACKBUTTON = 'backbutton'
......@@ -35,17 +34,6 @@ export function initEnterOptions({
})
}
export function initEnterReLaunch(info: RedirectInfo) {
__uniConfig.realEntryPagePath =
__uniConfig.realEntryPagePath || __uniConfig.entryPagePath
__uniConfig.entryPagePath = info.path
__uniConfig.entryPageQuery = info.query
$reLaunch(
{ url: addLeadingSlash(info.path) + info.query },
{ resolve() {}, reject() {} }
)
}
export function initLaunchOptions({
path,
query,
......@@ -60,7 +48,7 @@ export function initLaunchOptions({
return launchOptions
}
interface RedirectInfo extends Omit<LaunchOptions, 'query' | 'scene'> {
export interface RedirectInfo extends Omit<LaunchOptions, 'query' | 'scene'> {
query: string
userAction: boolean
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册