diff --git a/src/platforms/app-plus/service/framework/app.js b/src/platforms/app-plus/service/framework/app.js index 755aa1e18a35d4d5502dcd233b9bb20e9e2d6e71..da95a65e8b96372eb0c5518c17c12c8721930e35 100644 --- a/src/platforms/app-plus/service/framework/app.js +++ b/src/platforms/app-plus/service/framework/app.js @@ -10,6 +10,10 @@ import { TEMP_PATH_BASE } from '../api/constants' +import { + initEntryPage +} from './config' + import { getCurrentPages } from './page' @@ -95,17 +99,17 @@ function initGlobalListeners () { }) }) - globalEvent.addEventListener('uistylechange', function (event) { - const args = { - theme: event.uistyle - } - - callAppHook(appCtx, 'onThemeChange', args) - publish('onThemeChange', args) - - // 兼容旧版本 API - publish('onUIStyleChange', { - style: event.uistyle + globalEvent.addEventListener('uistylechange', function (event) { + const args = { + theme: event.uistyle + } + + callAppHook(appCtx, 'onThemeChange', args) + publish('onThemeChange', args) + + // 兼容旧版本 API + publish('onUIStyleChange', { + style: event.uistyle }) }) @@ -171,50 +175,6 @@ function initTabBar () { } } -function initEntryPage () { - let entryPagePath - let entryPageQuery - - const weexPlus = weex.requireModule('plus') - - if (weexPlus.getRedirectInfo) { - const info = weexPlus.getRedirectInfo() || {} - entryPagePath = info.path - entryPageQuery = info.query ? ('?' + info.query) : '' - } else { - const argsJsonStr = plus.runtime.arguments - if (!argsJsonStr) { - return - } - try { - const args = JSON.parse(argsJsonStr) - entryPagePath = args.path || args.pathName - entryPageQuery = args.query ? ('?' + args.query) : '' - } catch (e) {} - } - - if (!entryPagePath || entryPagePath === __uniConfig.entryPagePath) { - return - } - - const entryRoute = '/' + entryPagePath - const routeOptions = __uniRoutes.find(route => route.path === entryRoute) - if (!routeOptions) { - return - } - - if (!routeOptions.meta.isTabBar) { - __uniConfig.realEntryPagePath = __uniConfig.realEntryPagePath || __uniConfig.entryPagePath - } - - __uniConfig.entryPagePath = entryPagePath - __uniConfig.entryPageQuery = entryPageQuery - - if (process.env.NODE_ENV !== 'production') { - console.log(`[uni-app] entryPagePath(${entryPagePath + entryPageQuery})`) - } -} - export function clearTempFile () { // 统一处理路径 function getPath (path) { @@ -277,4 +237,4 @@ export function registerApp (appVm) { __uniConfig.ready = true process.env.NODE_ENV !== 'production' && perf('registerApp') -} +} diff --git a/src/platforms/app-plus/service/framework/config.js b/src/platforms/app-plus/service/framework/config.js index 098a452931ff4ef470b758735a45df351b6fb6b7..c4d79f8430d313e047d9ab495e740ede806733cd 100644 --- a/src/platforms/app-plus/service/framework/config.js +++ b/src/platforms/app-plus/service/framework/config.js @@ -19,7 +19,7 @@ function parseRoutes (config) { }) } -export function registerConfig (config, Vue) { +export function registerConfig (config, Vue) { Object.assign(__uniConfig, config) __uniConfig.viewport = '' @@ -35,4 +35,55 @@ export function registerConfig (config, Vue) { if (process.env.NODE_ENV !== 'production') { console.log('[uni-app] registerConfig', __uniConfig) } +} + +let isInitEntryPage = false + +export function initEntryPage () { + if (isInitEntryPage) { + return + } + isInitEntryPage = true + + let entryPagePath + let entryPageQuery + + const weexPlus = weex.requireModule('plus') + + if (weexPlus.getRedirectInfo) { + const info = weexPlus.getRedirectInfo() || {} + entryPagePath = info.path + entryPageQuery = info.query ? ('?' + info.query) : '' + } else { + const argsJsonStr = plus.runtime.arguments + if (!argsJsonStr) { + return + } + try { + const args = JSON.parse(argsJsonStr) + entryPagePath = args.path || args.pathName + entryPageQuery = args.query ? ('?' + args.query) : '' + } catch (e) {} + } + + if (!entryPagePath || entryPagePath === __uniConfig.entryPagePath) { + return + } + + const entryRoute = '/' + entryPagePath + const routeOptions = __uniRoutes.find(route => route.path === entryRoute) + if (!routeOptions) { + return + } + + if (!routeOptions.meta.isTabBar) { + __uniConfig.realEntryPagePath = __uniConfig.realEntryPagePath || __uniConfig.entryPagePath + } + + __uniConfig.entryPagePath = entryPagePath + __uniConfig.entryPageQuery = entryPageQuery + + if (process.env.NODE_ENV !== 'production') { + console.log(`[uni-app] entryPagePath(${entryPagePath + entryPageQuery})`) + } } diff --git a/src/platforms/app-plus/service/framework/page.js b/src/platforms/app-plus/service/framework/page.js index f20312599d3fcdc9d415f0ac0eb24924f88e7605..2a0cbc9969118d3f4d96a7a8a2154b1cc51fbdab 100644 --- a/src/platforms/app-plus/service/framework/page.js +++ b/src/platforms/app-plus/service/framework/page.js @@ -17,6 +17,10 @@ import { loadPage } from './load-sub-package' +import { + initEntryPage +} from './config' + const pages = [] export function getCurrentPages (returnAll) { @@ -83,6 +87,9 @@ export function registerPage ({ webview, eventChannel }) { + // fast 模式,nvue 首页时,初始化下 entry page + webview && initEntryPage() + if (preloadWebviews[url]) { webview = preloadWebviews[url] if (webview.__page__) { @@ -137,6 +144,8 @@ export function registerPage ({ console.log(`[uni-app] registerPage(${path},${webview.id})`) } + const isLaunchNVuePage = webview.id === '1' && webview.nvue + initWebview(webview, routeOptions, path, query) const route = path.slice(1) @@ -188,7 +197,7 @@ export function registerPage ({ } // 首页是 nvue 时,在 registerPage 时,执行路由堆栈 - if (webview.id === '1' && webview.nvue) { + if (isLaunchNVuePage) { if ( __uniConfig.splashscreen && __uniConfig.splashscreen.autoclose &&