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

feat(v3): hot reload

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