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

wip(app): nvue

上级 8e53f46d
...@@ -16848,7 +16848,18 @@ function initVueApp(appVm) { ...@@ -16848,7 +16848,18 @@ function initVueApp(appVm) {
const pages = []; const pages = [];
function addCurrentPage(page) { function addCurrentPage(page) {
pages.push(page); const $page = page.$page;
if (!$page.meta.isNVue) {
return pages.push(page);
}
// 开发阶段热刷新需要移除旧的相同 id 的 page
const index = pages.findIndex((page) => page.$page.id === page.$page.id);
if (index > -1) {
pages.splice(index, 1, page);
}
else {
pages.push(page);
}
} }
function getPageById(id) { function getPageById(id) {
return pages.find((page) => page.$page.id === id); return pages.find((page) => page.$page.id === id);
...@@ -18193,15 +18204,17 @@ function registerPage({ url, path, query, openType, webview, nvuePageVm, eventCh ...@@ -18193,15 +18204,17 @@ function registerPage({ url, path, query, openType, webview, nvuePageVm, eventCh
console.log(formatLog('registerPage', path, webview.id)); console.log(formatLog('registerPage', path, webview.id));
} }
initWebview(webview, path, query, routeOptions.meta); initWebview(webview, path, query, routeOptions.meta);
const route = path.substr(1); const route = path.slice(1);
webview.__uniapp_route = route; webview.__uniapp_route = route;
const pageInstance = initPageInternalInstance(openType, url, query, routeOptions.meta, eventChannel); const pageInstance = initPageInternalInstance(openType, url, query, routeOptions.meta, eventChannel);
const id = parseInt(webview.id); const id = parseInt(webview.id);
if (webview.nvue) { if (webview.nvue) {
if (id === 1 && nvuePageVm) { if (nvuePageVm) {
initNVueEntryPage(webview, nvuePageVm, pageInstance); // 首页或者开发时热刷
initNVuePage(id, nvuePageVm, pageInstance);
} }
else { else {
// 正常路由跳转
createNVuePage(id, webview, pageInstance); createNVuePage(id, webview, pageInstance);
} }
} }
...@@ -18232,18 +18245,20 @@ function initPageOptions({ meta }) { ...@@ -18232,18 +18245,20 @@ function initPageOptions({ meta }) {
windowBottom: tabBarInstance.indexOf(meta.route) >= 0 && tabBarInstance.cover ? tabBarInstance.height : 0, windowBottom: tabBarInstance.indexOf(meta.route) >= 0 && tabBarInstance.cover ? tabBarInstance.height : 0,
}; };
} }
function initNVueEntryPage(webview, nvuePageVm, pageInstance) { function initNVuePage(id, nvuePageVm, pageInstance) {
initPageVm(nvuePageVm, pageInstance); initPageVm(nvuePageVm, pageInstance);
addCurrentPage(nvuePageVm); addCurrentPage(nvuePageVm);
// 首页是 nvue 时,在 registerPage 时,执行路由堆栈 if (id === 1) {
if (__uniConfig.splashscreen && // 首页是 nvue 时,在 registerPage 时,执行路由堆栈
__uniConfig.splashscreen.autoclose && if (__uniConfig.splashscreen &&
!__uniConfig.splashscreen.alwaysShowBeforeRender) { __uniConfig.splashscreen.autoclose &&
plus.navigator.closeSplashscreen(); !__uniConfig.splashscreen.alwaysShowBeforeRender) {
plus.navigator.closeSplashscreen();
}
__uniConfig.onReady(function () {
navigateFinish();
});
} }
__uniConfig.onReady(function () {
navigateFinish();
});
} }
function createNVuePage(pageId, webview, pageInstance) { function createNVuePage(pageId, webview, pageInstance) {
const fakeNVueVm = { const fakeNVueVm = {
......
...@@ -6,7 +6,17 @@ import { getVueApp } from '../app/vueApp' ...@@ -6,7 +6,17 @@ import { getVueApp } from '../app/vueApp'
const pages: ComponentPublicInstance[] = [] const pages: ComponentPublicInstance[] = []
export function addCurrentPage(page: ComponentPublicInstance) { export function addCurrentPage(page: ComponentPublicInstance) {
pages.push(page) const $page = page.$page
if (!$page.meta.isNVue) {
return pages.push(page)
}
// 开发阶段热刷新需要移除旧的相同 id 的 page
const index = pages.findIndex((page) => page.$page.id === page.$page.id)
if (index > -1) {
pages.splice(index, 1, page)
} else {
pages.push(page)
}
} }
export function getPageById(id: number) { export function getPageById(id: number) {
......
...@@ -96,7 +96,7 @@ export function registerPage({ ...@@ -96,7 +96,7 @@ export function registerPage({
initWebview(webview, path, query, routeOptions.meta) initWebview(webview, path, query, routeOptions.meta)
const route = path.substr(1) const route = path.slice(1)
;(webview as any).__uniapp_route = route ;(webview as any).__uniapp_route = route
const pageInstance = initPageInternalInstance( const pageInstance = initPageInternalInstance(
...@@ -110,9 +110,11 @@ export function registerPage({ ...@@ -110,9 +110,11 @@ export function registerPage({
const id = parseInt(webview.id!) const id = parseInt(webview.id!)
if ((webview as any).nvue) { if ((webview as any).nvue) {
if (id === 1 && nvuePageVm) { if (nvuePageVm) {
initNVueEntryPage(webview, nvuePageVm, pageInstance) // 首页或者开发时热刷
initNVuePage(id, nvuePageVm, pageInstance)
} else { } else {
// 正常路由跳转
createNVuePage(id, webview, pageInstance) createNVuePage(id, webview, pageInstance)
} }
} else { } else {
...@@ -146,24 +148,26 @@ function initPageOptions({ meta }: UniApp.UniRoute): PageNodeOptions { ...@@ -146,24 +148,26 @@ function initPageOptions({ meta }: UniApp.UniRoute): PageNodeOptions {
} }
} }
function initNVueEntryPage( function initNVuePage(
webview: PlusWebviewWebviewObject, id: number,
nvuePageVm: ComponentPublicInstance, nvuePageVm: ComponentPublicInstance,
pageInstance: Page.PageInstance['$page'] pageInstance: Page.PageInstance['$page']
) { ) {
initPageVm(nvuePageVm, pageInstance) initPageVm(nvuePageVm, pageInstance)
addCurrentPage(nvuePageVm) addCurrentPage(nvuePageVm)
// 首页是 nvue 时,在 registerPage 时,执行路由堆栈 if (id === 1) {
if ( // 首页是 nvue 时,在 registerPage 时,执行路由堆栈
__uniConfig.splashscreen && if (
__uniConfig.splashscreen.autoclose && __uniConfig.splashscreen &&
!__uniConfig.splashscreen.alwaysShowBeforeRender __uniConfig.splashscreen.autoclose &&
) { !__uniConfig.splashscreen.alwaysShowBeforeRender
plus.navigator.closeSplashscreen() ) {
plus.navigator.closeSplashscreen()
}
__uniConfig.onReady(function () {
navigateFinish()
})
} }
__uniConfig.onReady(function () {
navigateFinish()
})
} }
function createNVuePage( function createNVuePage(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册