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

feat(app): add reLaunch

上级 4d414c76
......@@ -4405,6 +4405,7 @@ var serviceContext = (function (vue) {
};
const API_NAVIGATE_TO = 'navigateTo';
const API_REDIRECT_TO = 'redirectTo';
const API_RE_LAUNCH = 'reLaunch';
const API_SWITCH_TAB = 'switchTab';
const API_NAVIGATE_BACK = 'navigateBack';
const API_PRELOAD_PAGE = 'preloadPage';
......@@ -4418,10 +4419,13 @@ var serviceContext = (function (vue) {
},
}, createAnimationProtocol(ANIMATION_OUT));
const RedirectToProtocol = BaseRouteProtocol;
const ReLaunchProtocol = BaseRouteProtocol;
const NavigateToOptions =
/*#__PURE__*/ createRouteOptions(API_NAVIGATE_TO);
const RedirectToOptions =
/*#__PURE__*/ createRouteOptions(API_REDIRECT_TO);
const ReLaunchOptions =
/*#__PURE__*/ createRouteOptions(API_RE_LAUNCH);
const NavigateBackOptions = {
formatArgs: {
delta(value, params) {
......@@ -8993,6 +8997,9 @@ var serviceContext = (function (vue) {
function addCurrentPage(page) {
pages.push(page);
}
function getAllPages() {
return pages;
}
function getCurrentPages$1() {
const curPages = [];
pages.forEach((page) => {
......@@ -9724,6 +9731,42 @@ var serviceContext = (function (vue) {
});
}
const reLaunch = defineAsyncApi(API_RE_LAUNCH, ({ url }, { resolve, reject }) => {
const { path, query } = parseUrl(url);
navigate(path, () => {
_reLaunch({
url,
path,
query,
})
.then(resolve)
.catch(reject);
});
}, ReLaunchProtocol, ReLaunchOptions);
function _reLaunch({ url, path, query }) {
return new Promise((resolve) => {
// 获取目前所有页面
const pages = getAllPages().slice(0);
const routeOptions = __uniRoutes.find((route) => route.path === path);
if (routeOptions.meta.isTabBar) {
tabBar$1.switchTab(path.slice(1));
}
showWebview(registerPage({
url,
path,
query,
openType: 'reLaunch',
}), 'none', 0, () => {
pages.forEach((page) => {
removePage(page);
closeWebview(page.$getAppWebview(), 'none');
});
resolve(undefined);
});
setStatusBarStyle();
});
}
var uni$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
upx2px: upx2px,
......@@ -9853,7 +9896,8 @@ var serviceContext = (function (vue) {
createInteractiveAd: createInteractiveAd,
navigateBack: navigateBack,
navigateTo: navigateTo,
redirectTo: redirectTo
redirectTo: redirectTo,
reLaunch: reLaunch
});
let invokeViewMethodId = 0;
......
......@@ -55,6 +55,7 @@ export * from './ad/interactiveAd'
export * from './route/navigateBack'
export * from './route/navigateTo'
export * from './route/redirectTo'
export * from './route/reLaunch'
export {
upx2px,
......
......@@ -9,7 +9,7 @@ import {
} from '@dcloudio/uni-api'
import { ANI_DURATION, ANI_SHOW } from '../../constants'
import { navigate } from './utils'
import { navigate, RouteOptions } from './utils'
import { showWebview } from './webview'
import { registerPage } from '../../framework/page'
......@@ -43,10 +43,7 @@ export const navigateTo = defineAsyncApi<API_TYPE_NAVIGATE_TO>(
NavigateToOptions
)
interface NavigateToOptions {
url: string
path: string
query: Record<string, any>
interface NavigateToOptions extends RouteOptions {
aniType: string
aniDuration: number
}
......
import {
API_RE_LAUNCH,
API_TYPE_RE_LAUNCH,
defineAsyncApi,
ReLaunchOptions,
ReLaunchProtocol,
} from '@dcloudio/uni-api'
import { parseUrl } from '@dcloudio/uni-shared'
import { ComponentPublicInstance } from 'vue'
import tabBar from '../../framework/app/tabBar'
import { registerPage } from '../../framework/page'
import { getAllPages, removePage } from '../../framework/page/getCurrentPages'
import { setStatusBarStyle } from '../../statusBar'
import { navigate, RouteOptions } from './utils'
import { closeWebview, showWebview } from './webview'
export const reLaunch = defineAsyncApi<API_TYPE_RE_LAUNCH>(
API_RE_LAUNCH,
({ url }, { resolve, reject }) => {
const { path, query } = parseUrl(url)
navigate(path, () => {
_reLaunch({
url,
path,
query,
})
.then(resolve)
.catch(reject)
})
},
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) => {
removePage(page)
closeWebview(
(page as ComponentPublicInstance).$getAppWebview!(),
'none'
)
})
resolve(undefined)
}
)
setStatusBarStyle()
})
}
......@@ -9,7 +9,7 @@ import { parseUrl } from '@dcloudio/uni-shared'
import { getCurrentPage } from '@dcloudio/uni-core'
import { removePage } from '../../framework/page/getCurrentPages'
import { registerPage } from '../../framework/page'
import { navigate } from './utils'
import { navigate, RouteOptions } from './utils'
import { showWebview } from './webview'
import { setStatusBarStyle } from '../../statusBar'
import { ComponentPublicInstance } from 'vue'
......@@ -32,11 +32,7 @@ export const redirectTo = defineAsyncApi<API_TYPE_REDIRECT_TO>(
RedirectToOptions
)
interface RedirectToOptions {
url: string
path: string
query: Record<string, any>
}
interface RedirectToOptions extends RouteOptions {}
function _redirectTo({
url,
......
......@@ -6,6 +6,11 @@ import {
preloadWebview,
} from '../../framework/webview'
export interface RouteOptions {
url: string
path: string
query: Record<string, any>
}
interface PendingNavigator {
path: string
nvue?: boolean
......
......@@ -8,6 +8,10 @@ export function addCurrentPage(page: ComponentPublicInstance) {
pages.push(page)
}
export function getAllPages() {
return pages
}
export function getCurrentPages() {
const curPages: ComponentPublicInstance[] = []
pages.forEach((page) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册