提交 73cf6ffd 编写于 作者: Q qiang

fix(x): 修复 iOS 在 tab 页面执行 redirectTo 页面堆栈错误的问题

上级 ea9e5749
......@@ -1936,49 +1936,6 @@ function back(delta, animationType, animationDuration) {
var webview = getNativeApp().pageManager.findPageById(currentPage.$page.id + "");
backPage(webview);
}
var redirectTo = /* @__PURE__ */ defineAsyncApi(API_REDIRECT_TO, (_ref, _ref2) => {
var {
url
} = _ref;
var {
resolve,
reject
} = _ref2;
var {
path,
query
} = parseUrl(url);
_redirectTo({
url,
path,
query
}).then(resolve).catch(reject);
}, RedirectToProtocol, RedirectToOptions);
function _redirectTo(_ref3) {
var {
url,
path,
query
} = _ref3;
var lastPage = getCurrentPage();
if (lastPage) {
removePage(lastPage);
}
return new Promise((resolve) => {
showWebview(registerPage({
url,
path,
query,
openType: "redirectTo"
}), "none", 0, () => {
if (lastPage) {
closeWebview(lastPage.$nativePage, "none");
}
resolve(void 0);
setStatusBarStyle();
});
});
}
function hasLeadingSlash(str) {
return str.indexOf("/") == 0;
}
......@@ -2063,6 +2020,15 @@ function init() {
page.startRender();
page.show(null);
}
function removeTabBarPage(page) {
var pagePath = getRealPath(page.route, true);
if (tabs.get(pagePath) === page) {
tabs.delete(pagePath);
if (getTabIndex(pagePath) === selected0) {
selected0 = -1;
}
}
}
function getTabBar() {
return tabBar0;
}
......@@ -2081,12 +2047,10 @@ function getTabIndex(path) {
}
return selected;
}
var currentPageRoute = null;
function findPageRoute(path) {
return __uniRoutes.find((route) => route.path === path);
}
function createTab(path, query, callback) {
currentPageRoute = findPageRoute(path);
showWebview(registerPage({
url: path,
path,
......@@ -2094,7 +2058,6 @@ function createTab(path, query, callback) {
openType: "switchTab"
}), "none", 0, callback);
var page = getCurrentPage();
currentPageRoute = null;
tabBar0.appendItem(page.$page.id.toString());
return page;
}
......@@ -2113,9 +2076,6 @@ function findTabPage(path) {
return page;
}
function isTabPage(page) {
if (page.$route === currentPageRoute) {
return true;
}
var has2 = false;
tabs.forEach((value, key) => {
if (value === page) {
......@@ -2167,8 +2127,59 @@ function switchSelect(selected, path) {
selected0 = selected;
}
function closePage(page, animationType, animationDuration) {
removePage(page);
closeWebview(page.$nativePage, animationType, animationDuration);
removePage(page);
removeTabBarPage(page);
}
var redirectTo = /* @__PURE__ */ defineAsyncApi(API_REDIRECT_TO, (_ref, _ref2) => {
var {
url
} = _ref;
var {
resolve,
reject
} = _ref2;
var {
path,
query
} = parseUrl(url);
_redirectTo({
url,
path,
query
}).then(resolve).catch(reject);
}, RedirectToProtocol, RedirectToOptions);
function _redirectTo(_ref3) {
var {
url,
path,
query
} = _ref3;
var lastPage = getCurrentPage();
return new Promise((resolve) => {
showWebview(registerPage({
url,
path,
query,
openType: isTabPage(lastPage) || getAllPages().length === 1 ? "reLaunch" : "redirectTo"
}), "none", 0, () => {
if (lastPage) {
removePages(lastPage);
}
resolve(void 0);
setStatusBarStyle();
});
});
}
function removePages(currentPage) {
if (isTabPage(currentPage)) {
var pages2 = getAllPages().slice(0, -1);
pages2.forEach((page) => {
closePage(page, "none");
});
} else {
closePage(currentPage, "none");
}
}
var $switchTab = (args, _ref) => {
var {
......@@ -2199,7 +2210,7 @@ function _switchTab(_ref2) {
if (selected == -1) {
return Promise.reject("tab ".concat(path, " not found"));
}
var pages2 = getAllPages();
var pages2 = getCurrentPages();
switchSelect(selected, path, query);
for (var index2 = pages2.length - 1; index2 >= 0; index2--) {
var page = pages2[index2];
......
......@@ -7,12 +7,14 @@ import {
} from '@dcloudio/uni-api'
import { parseUrl } from '@dcloudio/uni-shared'
import { getCurrentPage } from '@dcloudio/uni-core'
import { removePage } from '../../../service/framework/page/getCurrentPages'
import { getAllPages } from '../../../service/framework/page/getCurrentPages'
import { registerPage } from '../../framework/page'
import { RouteOptions } from '../../../service/api/route/utils'
import { closeWebview, showWebview } from './webview'
import { showWebview } from './webview'
import { ComponentPublicInstance } from 'vue'
import { setStatusBarStyle } from '../../statusBar'
import { isTabPage } from '../../framework/app/tabBar'
import { closePage } from './utils'
export const redirectTo = defineAsyncApi<API_TYPE_REDIRECT_TO>(
API_REDIRECT_TO,
......@@ -37,10 +39,8 @@ function _redirectTo({
path,
query,
}: RedirectToOptions): Promise<undefined> {
const lastPage = getCurrentPage()
if (lastPage) {
removePage(lastPage)
}
const lastPage = getCurrentPage() as ComponentPublicInstance
// 与 uni-app x 安卓一致,后移除页面
return new Promise((resolve) => {
showWebview(
......@@ -48,16 +48,16 @@ function _redirectTo({
url,
path,
query,
openType: 'redirectTo',
openType:
isTabPage(lastPage) || getAllPages().length === 1
? 'reLaunch'
: 'redirectTo',
}),
'none',
0,
() => {
if (lastPage) {
closeWebview(
(lastPage as ComponentPublicInstance).$nativePage!,
'none'
)
removePages(lastPage)
}
resolve(undefined)
setStatusBarStyle()
......@@ -65,3 +65,14 @@ function _redirectTo({
)
})
}
function removePages(currentPage: ComponentPublicInstance) {
if (isTabPage(currentPage)) {
const pages = getAllPages().slice(0, -1)
pages.forEach((page) => {
closePage(page, 'none')
})
} else {
closePage(currentPage, 'none')
}
}
......@@ -14,7 +14,6 @@ import {
switchSelect,
} from '../../framework/app/tabBar'
import { ComponentPublicInstance } from 'vue'
import { getAllPages } from '../../../service/framework/page/getCurrentPages'
import { closePage } from './utils'
export const $switchTab: DefineAsyncApiFn<API_TYPE_SWITCH_TAB> = (
......@@ -46,7 +45,7 @@ function _switchTab({ url, path, query }: SwitchTabOptions) {
if (selected == -1) {
return Promise.reject(`tab ${path} not found`)
}
const pages = getAllPages()
const pages = getCurrentPages()
switchSelect(selected, path, query)
for (let index = pages.length - 1; index >= 0; index--) {
const page = pages[index] as ComponentPublicInstance
......
import { ComponentPublicInstance } from 'vue'
import { removePage } from '../../../service/framework/page/getCurrentPages'
import { closeWebview } from './webview'
import { removeTabBarPage } from '../../framework/app/tabBar'
export function closePage(
page: ComponentPublicInstance,
animationType: string,
animationDuration?: number
) {
removePage(page)
closeWebview(page.$nativePage!, animationType, animationDuration)
removePage(page)
removeTabBarPage(page)
}
......@@ -127,7 +127,7 @@ export function clearTabBarStatus() {
}
export function removeTabBarPage(page: Page) {
const pagePath = getRealPath(page.$route?.path ?? '', true)
const pagePath = getRealPath(page.route, true)
if (tabs.get(pagePath) === page) {
tabs.delete(pagePath)
if (getTabIndex(pagePath) === selected0) {
......@@ -159,8 +159,6 @@ export function getTabIndex(path: string, list = getTabList()): number {
return selected
}
let currentPageRoute: unknown = null
function findPageRoute(path: string) {
return __uniRoutes.find((route) => route.path === path)!
}
......@@ -170,7 +168,6 @@ function createTab(
query: Record<string, string>,
callback?: () => void
): Page {
currentPageRoute = findPageRoute(path)
showWebview(
registerPage({ url: path, path, query, openType: 'switchTab' }),
'none',
......@@ -178,7 +175,6 @@ function createTab(
callback
)
const page = getCurrentPage() as Page
currentPageRoute = null
tabBar0!.appendItem(page!.$page.id.toString())
return page
}
......@@ -209,9 +205,6 @@ function findTabPage(path: string): Page | null {
}
export function isTabPage(page: Page): boolean {
if (page.$route === currentPageRoute) {
return true
}
let has = false
tabs.forEach((value: Page, key: string) => {
if (value === page) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册