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

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

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