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

feat(v3): hot reload

上级 78c79a17
......@@ -16,15 +16,28 @@ const {
const definePages = require('./define-pages')
const appConfigService = require('./app-config-service')
function getTabBarPages (appJson) {
return appJson.tabBar &&
appJson.tabBar.list &&
appJson.tabBar.list.length &&
appJson.tabBar.list
}
function isTabBarPage (pathName, tabBarPages) {
return tabBarPages.find(item => item.pagePath === pathName)
}
function parseEntryPagePath (appJson, manifestJson) {
const argsJsonStr = manifestJson.plus.arguments
if (argsJsonStr) {
try {
const args = JSON.parse(argsJsonStr)
const pathName = args.path || args.pathName
if (pathName && pathName !== appJson.pages[0]) {
if (pathName && appJson.pages[0] !== pathName) {
appJson.entryPagePath = pathName
appJson.realEntryPagePath = appJson.pages[0]
if (!isTabBarPage(pathName, getTabBarPages(appJson))) {
appJson.realEntryPagePath = appJson.pages[0]
}
}
} catch (e) {}
}
......@@ -32,12 +45,13 @@ function parseEntryPagePath (appJson, manifestJson) {
appJson.entryPagePath = appJson.pages[0]
}
}
module.exports = function (appJson, manifestJson, {
pagesJson,
manifest,
normalizeNetworkTimeout
}) {
parseEntryPagePath(appJson, manifestJson)
}) {
parseEntryPagePath(appJson, manifestJson)
// timeout
normalizeNetworkTimeout(appJson)
......@@ -61,7 +75,7 @@ module.exports = function (appJson, manifestJson, {
manifestJson.permissions.UniNView = {
'description': 'UniNView原生渲染'
}
// TODO 需要考虑 condition
manifestJson.plus.launchwebview.id = '1' // 首页 id 固定 为 1
// 删除首页 style 中的 uni-app 配置(不注入 app-view.js)
delete manifestJson.plus.launchwebview['uni-app']
......
......@@ -100,15 +100,15 @@ export function navigateBack ({
uni.hideToast() // 后退时,关闭 toast,loading
// 当前页面是 condition 进入
if (currentPage.$page.id === 1 && __uniConfig.realEntryPagePath) {
if (currentPage.$page.meta.isQuit) {
quit()
} else if (currentPage.$page.id === 1 && __uniConfig.realEntryPagePath) {
// condition
uni.reLaunch({
url: '/' + __uniConfig.realEntryPagePath
})
} else {
currentPage.$page.meta.isQuit
? quit()
: back(delta, animationType, animationDuration)
back(delta, animationType, animationDuration)
}
return {
errMsg: 'navigateBack:ok'
......
......@@ -49,7 +49,9 @@ export function getApp ({
if (allowDefault) { // 返回默认实现
return defaultApp
}
console.error('[warn]: getApp() 操作失败,v3模式加速了首页 nvue 的启动速度,当在首页 nvue 中使用 getApp() 不一定可以获取真正的 App 对象。详情请参考:https://uniapp.dcloud.io/collocation/frame/window?id=getapp')
console.error(
'[warn]: getApp() 操作失败,v3模式加速了首页 nvue 的启动速度,当在首页 nvue 中使用 getApp() 不一定可以获取真正的 App 对象。详情请参考:https://uniapp.dcloud.io/collocation/frame/window?id=getapp'
)
}
function initGlobalListeners () {
......@@ -138,6 +140,31 @@ function initTabBar () {
})
}
function initHotReload () {
const reloadUrl = weex.config.reloadUrl
if (!reloadUrl) {
return
}
if (reloadUrl === __uniConfig.entryPagePath) {
return
}
const reloadPath = '/' + reloadUrl
const routeOptions = __uniRoutes.find(route => route.path === reloadPath)
if (!routeOptions) {
return
}
if (routeOptions.meta.isNVue) { // 暂不处理 nvue
return
}
if (!routeOptions.meta.isTabBar) {
__uniConfig.realEntryPagePath = __uniConfig.realEntryPagePath || __uniConfig.entryPagePath
}
__uniConfig.entryPagePath = reloadUrl
if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] reloadUrl(${reloadUrl})`)
}
}
export function registerApp (appVm) {
if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] registerApp`)
......@@ -156,6 +183,8 @@ export function registerApp (appVm) {
getCurrentPages
})
initHotReload()
initTabBar()
initGlobalListeners()
......@@ -167,4 +196,4 @@ export function registerApp (appVm) {
__uniConfig.ready = true
process.env.NODE_ENV !== 'production' && perf('registerApp')
}
}
......@@ -32,8 +32,13 @@ export function registerPage ({
}) {
const routeOptions = JSON.parse(JSON.stringify(__uniRoutes.find(route => route.path === path)))
if (openType === 'reLaunch' || pages.length === 0) {
// pages.length===0 表示首页触发 redirectTo
if (
openType === 'reLaunch' ||
(
openType === 'redirect' &&
pages.length === 0
) // 首页 redirect
) {
routeOptions.meta.isQuit = true
} else if (!routeOptions.meta.isTabBar) {
routeOptions.meta.isQuit = false
......
......@@ -4,8 +4,8 @@ import {
import {
parsePullToRefresh
} from './pull-to-refresh-parser'
} from './pull-to-refresh-parser'
import {
parseStyleUnit
} from './style-unit-parser'
......@@ -44,7 +44,11 @@ export function parseWebviewStyle (id, path, routeOptions = {}) {
const titleNView = parseTitleNView(routeOptions)
if (titleNView) {
if (id === 1 && __uniConfig.realEntryPagePath) {
if (
id === 1 &&
__uniConfig.realEntryPagePath &&
!routeOptions.meta.isQuit // 可能是tabBar
) {
titleNView.autoBackButton = true
}
webviewStyle.titleNView = titleNView
......@@ -74,4 +78,4 @@ export function parseWebviewStyle (id, path, routeOptions = {}) {
}
return webviewStyle
}
}
......@@ -67,8 +67,8 @@ export default function parsePage (vuePageOptions) {
},
events: {
// 支付宝小程序有些页面事件只能放在events下
onBack(){
this.$vm.__call_hook('onBackPress');
onBack () {
this.$vm.__call_hook('onBackPress')
}
},
__r: handleRef,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册